quickpassthrough/internal/ui_main_functions.go

133 lines
3.4 KiB
Go
Raw Normal View History

package internal
import (
2023-04-09 14:37:49 -04:00
"os"
"regexp"
"github.com/HikariKnight/quickpassthrough/internal/configs"
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
)
// This function processes the enter event
func (m *model) processSelection() bool {
switch m.focused {
case GPUS:
// Gets the selected item
selectedItem := m.lists[m.focused].SelectedItem()
// Gets the IOMMU group of the selected item
iommu_group_regex := regexp.MustCompile(`(\d{1,3})`)
iommu_group := iommu_group_regex.FindString(selectedItem.(item).desc)
// Add the gpu group to our model (this is so we can grab the vbios details later)
m.gpu_group = iommu_group
// Get all the gpu devices and related devices (same device id or in the same group)
items := iommuList2ListItem(getIOMMU("-grr", "-i", m.gpu_group, "-F", "vendor:,prod_name,optional_revision:,device_id"))
// Add the devices to the list
m.lists[GPU_GROUP].SetItems(items)
// Change focus to next index
m.focused++
case GPU_GROUP:
// Generate the VBIOS dumper script once the user has selected a GPU
generateVBIOSDumper(*m)
2023-04-09 13:05:49 -04:00
// Change focus to the next view
m.focused++
case USB:
// Gets the selected item
selectedItem := m.lists[m.focused].SelectedItem()
// Gets the IOMMU group of the selected item
iommu_group_regex := regexp.MustCompile(`(\d{1,3})`)
iommu_group := iommu_group_regex.FindString(selectedItem.(item).desc)
// Get the USB controllers in the selected iommu group
items := iommuList2ListItem(getIOMMU("-ur", "-i", iommu_group, "-F", "vendor:,prod_name,optional_revision:,device_id"))
// Add the items to the list
m.lists[USB_GROUP].SetItems(items)
// Change focus to next index
m.focused++
case USB_GROUP:
m.focused++
case VBIOS:
// This is just an OK Dialog
m.focused++
case VIDEO:
// This is a YESNO Dialog
2023-04-09 11:59:40 -04:00
// Gets the selected item
selectedItem := m.lists[m.focused].SelectedItem()
2023-04-09 14:37:49 -04:00
// Get our config struct
config := configs.GetConfig()
// Get the device ids for the selected gpu using ls-iommu
gpu_IDs := getIOMMU("-gr", "-i", m.gpu_group, "--id")
// If the kernel_args file already exists
if fileio.FileExist(config.Path.CMDLINE) {
// Delete it as we will have to make a new one anyway
os.Remove(config.Path.CMDLINE)
}
// Write initial kernel_arg file
configs.Set_Cmdline(gpu_IDs)
// If user selected yes then
2023-04-09 11:59:40 -04:00
if selectedItem.(item).title == "YES" {
// Add disable VFIO video to the config
configs.DisableVFIOVideo(1)
} else {
// Add disable VFIO video to the config
configs.DisableVFIOVideo(0)
2023-04-09 11:59:40 -04:00
}
// If we have files for modprobe
if fileio.FileExist(config.Path.MODPROBE) {
// Configure modprobe
configs.Set_Modprobe(gpu_IDs)
}
// If we have a folder for dracut
if fileio.FileExist(config.Path.DRACUT) {
// Configure dracut
configs.Set_Dracut()
}
2023-04-09 16:01:38 -04:00
// If we have a mkinitcpio.conf file
if fileio.FileExist(config.Path.MKINITCPIO) {
configs.Set_Mkinitcpio()
}
// Go to the next view
//m.focused++
// Because we have no QuickEmu support yet, just skip USB Controller configuration
m.focused = DONE
case INTRO:
// This is an OK Dialog
// Create the config folder and the files related to this system
configs.InitConfigs()
// Go to the next view
m.focused++
case DONE:
// Return true so that the application will exit nicely
return true
}
// Return false as we are not done
return false
}