diff --git a/i18n/cs/chwd.ftl b/i18n/cs/chwd.ftl index 97dae95..b759e3b 100644 --- a/i18n/cs/chwd.ftl +++ b/i18n/cs/chwd.ftl @@ -2,7 +2,6 @@ name-header = Jméno desc-header = Popis priority-header = Priorita -nonfree-header = Placené classids-header = ID Třídy vendorids-header = ID Prodejce @@ -19,7 +18,7 @@ pass-profile-no-match-install = uvedený profil se neshoduje s nainstalovaným p available = DOSTUPNÉ installed = NAINSTALOVÁNO device = Zařízení -no-profile-device = nebyly nalezeny žádné profily pro zařízení '{$device_type}'! +no-profile-device = nebyly nalezeny žádné profily pro zařízení PCI! # Výstup v konzoly invalid-profile = profil '{$invalid_profile}' je neplatný! @@ -27,4 +26,4 @@ all-pci-profiles = Všechny PCI profily: installed-pci-profiles = Instalované PCI profily: pci-profiles-not-found = Žádné PCI profily nebyly nalezeny! no-installed-pci-profiles = Žádné PCI profili nejsou nainstalovány! -no-installed-profile-device = žádný nainstalovaný profil pro zařízení '{$device_type}' nebyl nalezen ! +no-installed-profile-device = žádný nainstalovaný profil pro zařízení PCI nebyl nalezen ! diff --git a/i18n/en/chwd.ftl b/i18n/en/chwd.ftl index 402474f..c5e4762 100644 --- a/i18n/en/chwd.ftl +++ b/i18n/en/chwd.ftl @@ -2,7 +2,6 @@ name-header = Name desc-header = Desc priority-header = Priority -nonfree-header = NonFree classids-header = ClassIDS vendorids-header = VendorIDS @@ -19,7 +18,7 @@ pass-profile-no-match-install = passed profile does not match with installed pro available = AVAILABLE installed = INSTALLED device = Device -no-profile-device = no profiles for '{$device_type}' devices found! +no-profile-device = no profiles for PCI devices found! # console writer invalid-profile = profile '{$invalid_profile}' is invalid! @@ -27,4 +26,4 @@ all-pci-profiles = All PCI profiles: installed-pci-profiles = Installed PCI profiles: pci-profiles-not-found = No PCI profiles found! no-installed-pci-profiles = No installed PCI profiles! -no-installed-profile-device = no installed profile for '{$device_type}' devices found! +no-installed-profile-device = no installed profile for PCI devices found! diff --git a/i18n/ru/chwd.ftl b/i18n/ru/chwd.ftl index 5ab5840..6cc7302 100644 --- a/i18n/ru/chwd.ftl +++ b/i18n/ru/chwd.ftl @@ -2,7 +2,6 @@ name-header = Имя desc-header = Описание priority-header = Приоритет -nonfree-header = Несвободный classids-header = IDS класса vendorids-header = IDS вендора @@ -19,7 +18,7 @@ pass-profile-no-match-install = переданный профиль не сов available = ДОСТУПНО installed = УСТАНОВЛЕНО device = Устройство -no-profile-device = профили для устройств '{$device_type}' не найдены! +no-profile-device = профили для устройств PCI не найдены! # console writer invalid-profile = профиль '{$invalid_profile}' недействительный! @@ -27,4 +26,4 @@ all-pci-profiles = Все PCI профили: installed-pci-profiles = Установленные PCI профили: pci-profiles-not-found = PCI профили не найдены! no-installed-pci-profiles = Нет установленных PCI профилей! -no-installed-profile-device = не найдено ни одного установленного профиля для устройств '{$device_type}'! +no-installed-profile-device = не найдено ни одного установленного профиля для устройств PCI! diff --git a/i18n/sk/chwd.ftl b/i18n/sk/chwd.ftl index b3df202..02d87fa 100644 --- a/i18n/sk/chwd.ftl +++ b/i18n/sk/chwd.ftl @@ -2,7 +2,6 @@ name-header = Meno desc-header = Popis priority-header = Priorita -nonfree-header = Platené classids-header = ID Triedy vendorids-header = ID Predajcu @@ -19,7 +18,7 @@ pass-profile-no-match-install = uvedený profil sa nezhoduje s nainštalovaným available = DOSTUPNÉ installed = NAINŠTALOVANÉ device = Zariadenie -no-profile-device = neboli nájdené žiadne profily pre zariadenia '{$device_type}'! +no-profile-device = neboli nájdené žiadne profily pre zariadenia PCI! # Výstup v konzoly invalid-profile = profil '{$invalid_profile}' je neplatný! @@ -27,4 +26,4 @@ all-pci-profiles = Všetky PCI profily: installed-pci-profiles = Inštalované PCI profily: pci-profiles-not-found = Žiadne PCI profily neboli nájdené! no-installed-pci-profiles = Žiadne PCI profily nie sú nainštalované! -no-installed-profile-device = žiadny nainštalovaný profil pre zariadenie '{$device_type}' nebol nájdený ! +no-installed-profile-device = žiadny nainštalovaný profil pre zariadenie PCI nebol nájdený ! diff --git a/profiles/pci/ai_sdk/profiles.toml b/profiles/pci/ai_sdk/profiles.toml index beb9c9f..aaa7755 100644 --- a/profiles/pci/ai_sdk/profiles.toml +++ b/profiles/pci/ai_sdk/profiles.toml @@ -9,7 +9,6 @@ [nvidia-ai-sdk] desc = 'NVIDIA AI SDK and related tools' -nonfree = true ai_sdk = true #class_ids = "*" class_ids = "0300 0302" @@ -21,7 +20,6 @@ device_name_pattern = '(AD|GV|TU|GA|GH|GM|GP)\w+' [rocm-ai-sdk] desc = 'AMD AI SDK and related tools' -nonfree = true ai_sdk = true class_ids = "*" vendor_ids = "1002" diff --git a/profiles/pci/graphic_drivers/profiles.toml b/profiles/pci/graphic_drivers/profiles.toml index 6e61188..5daecde 100644 --- a/profiles/pci/graphic_drivers/profiles.toml +++ b/profiles/pci/graphic_drivers/profiles.toml @@ -18,7 +18,6 @@ [nvidia-open-dkms] desc = 'Open source NVIDIA drivers for Linux (Latest)' -nonfree = true class_ids = "0300 0302 0380" vendor_ids = "10de" priority = 10 @@ -80,7 +79,6 @@ post_remove = """ [nvidia-dkms] desc = 'Closed source NVIDIA drivers for Linux (Latest)' -nonfree = true class_ids = "0300 0302 0380" vendor_ids = "10de" priority = 12 @@ -142,7 +140,6 @@ post_remove = """ [nvidia-dkms-470xx] desc = 'Closed source NVIDIA drivers for Linux (470xx branch, only for Kepler GPUs)' priority = 14 -nonfree = true class_ids = "0300 0380" vendor_ids = "10de" packages = 'nvidia-470xx-dkms nvidia-470xx-utils nvidia-470xx-settings opencl-nvidia-470xx vulkan-icd-loader lib32-nvidia-470xx-utils lib32-opencl-nvidia-470xx lib32-vulkan-icd-loader libva-nvidia-driver' @@ -168,7 +165,6 @@ post_install = """ [nvidia-dkms-390xx] desc = 'Closed source NVIDIA drivers for Linux (390xx branch, only for Fermi GPUs)' priority = 16 -nonfree = true vendor_ids = "10de" class_ids = "0300 0302 0380" packages = 'nvidia-390xx-dkms nvidia-390xx-utils nvidia-390xx-settings opencl-nvidia-390xx nvidia-390xx-utils nvidia-390xx-settings opencl-nvidia-390xx lib32-nvidia-390xx-utils lib32-opencl-nvidia-390xx' @@ -176,7 +172,6 @@ device_name_pattern = '(GF)\w+' [nouveau] desc = "Open Nouveau driver for NVIDIA graphics cards (Only for old GPUs)" -nonfree = false class_ids = "0300 0302" vendor_ids = "10de" priority = 0 @@ -189,7 +184,6 @@ fi [intel] desc = "Mesa open source driver for Intel" -nonfree = false class_ids = "0300 0302" vendor_ids = "8086" device_ids = "*" @@ -203,7 +197,6 @@ fi [amd] desc = "Mesa open source driver for AMD" -nonfree = false class_ids = "0300 0302" vendor_ids = "1002" device_ids = "*" @@ -217,7 +210,6 @@ fi [fallback] desc = 'Fallback profile' -nonfree = false class_ids = "0300 0380 0302" vendor_ids = "1002 8086 10de" device_ids = "*" @@ -226,7 +218,6 @@ packages = 'mesa lib32-mesa vulkan-swrast xf86-video-vesa' [virtualmachine] desc = 'X.org vmware video driver and open-vm-tools/virtualbox tools' -nonfree = false class_ids = "0300" # Virtualbox version 6.0 uses VMSVGA on Linux guests by default, which has VMWare's VENDORID. # VENDOR VMWare=80ee Virtualbox=15AD Redhat(QXL)=1af4 Redhat(VirtIO)=1b36 cirrus=1013 diff --git a/profiles/pci/handhelds/profiles.toml b/profiles/pci/handhelds/profiles.toml index cc816f7..84f835e 100644 --- a/profiles/pci/handhelds/profiles.toml +++ b/profiles/pci/handhelds/profiles.toml @@ -19,7 +19,6 @@ [steam-deck] desc = 'Valve Steam Deck' -nonfree = false class_ids = "0300" vendor_ids = "1002" device_ids = "1435 163f" @@ -54,7 +53,6 @@ post_remove = """ [phoenix] desc = 'ASUS ROG Ally and Lenovo Legion Go' -nonfree = false class_ids = "0300" vendor_ids = "1002" device_ids = "15bf" diff --git a/profiles/pci/network_drivers/profiles.toml b/profiles/pci/network_drivers/profiles.toml index a34d62c..cebab9b 100644 --- a/profiles/pci/network_drivers/profiles.toml +++ b/profiles/pci/network_drivers/profiles.toml @@ -1,6 +1,5 @@ [broadcom-wl] desc = 'Broadcom 802.11 Linux STA wireless driver' -nonfree = false class_ids = "0200 0280 0282" vendor_ids = "14E4 14A4" device_ids = "4311 4312 4315 4727 4328 4329 432A 432B 432C 432D 0576 4353 4357 4358 4359 4365 4331 43B1 43A0 4360" diff --git a/src/args.rs b/src/args.rs index 87c9360..710b8d5 100644 --- a/src/args.rs +++ b/src/args.rs @@ -16,25 +16,22 @@ // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +use clap::builder::ArgPredicate; use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Args { - /// Show PCI - #[arg(long = "pci")] - pub show_pci: bool, - /// Install profile - #[arg(short, long, number_of_values = 2, value_names = &["usb/pci", "profile"], conflicts_with("remove"))] - pub install: Option>, + #[arg(short, long, value_name = "profile", conflicts_with("remove"))] + pub install: Option, /// Remove profile - #[arg(short, long, number_of_values = 2, value_names = &["usb/pci", "profile"], conflicts_with("install"))] - pub remove: Option>, + #[arg(short, long, value_name = "profile", conflicts_with("install"))] + pub remove: Option, /// Show detailed info for listings - #[arg(short, long)] + #[arg(short, long, requires_if(ArgPredicate::IsPresent, "listings"))] pub detail: bool, /// Force reinstall @@ -42,24 +39,20 @@ pub struct Args { pub force: bool, /// List installed kernels - #[arg(long)] + #[arg(long, group = "listings")] pub list_installed: bool, /// List available profiles for all devices - #[arg(long = "list")] + #[arg(long = "list", group = "listings")] pub list_available: bool, /// List all profiles - #[arg(long)] + #[arg(long, group = "listings")] pub list_all: bool, /// Autoconfigure - #[arg(short, long, number_of_values = 3, value_names = &["usb/pci", "free/nonfree", "classid"], conflicts_with_all(["install", "remove"]))] - pub autoconfigure: Option>, - - /// Print if nvidia card found - #[arg(long = "is_nvidia_card")] - pub is_nvidia_card: bool, + #[arg(short, long, value_name = "classid", conflicts_with_all(["install", "remove"]))] + pub autoconfigure: Option, /// Toggle AI SDK profiles #[arg(long = "ai_sdk")] diff --git a/src/console_writer.rs b/src/console_writer.rs index 4eb50ec..53ad80e 100644 --- a/src/console_writer.rs +++ b/src/console_writer.rs @@ -31,32 +31,32 @@ pub fn handle_arguments_listing(data: &Data, args: &crate::args::Args) { } // List all profiles - if args.list_all && args.show_pci { - let all_pci_profiles = &data.all_pci_profiles; - if !all_pci_profiles.is_empty() { - list_profiles(all_pci_profiles, &fl!("all-pci-profiles")); + if args.list_all { + let all_profiles = &data.all_profiles; + if !all_profiles.is_empty() { + list_profiles(all_profiles, &fl!("all-pci-profiles")); } else { print_warning(&fl!("pci-profiles-not-found")); } } // List installed profiles - if args.list_installed && args.show_pci { - let installed_pci_profiles = &data.installed_pci_profiles; + if args.list_installed { + let installed_profiles = &data.installed_profiles; if args.detail { - print_installed_profiles("PCI", installed_pci_profiles); - } else if !installed_pci_profiles.is_empty() { - list_profiles(installed_pci_profiles, &fl!("installed-pci-profiles")); + print_installed_profiles(installed_profiles); + } else if !installed_profiles.is_empty() { + list_profiles(installed_profiles, &fl!("installed-pci-profiles")); } else { print_warning(&fl!("no-installed-pci-profiles")); } } // List available profiles - if args.list_available && args.show_pci { + if args.list_available { let pci_devices = &data.pci_devices; if args.detail { - crate::device::print_available_profiles_in_detail("PCI", pci_devices); + crate::device::print_available_profiles_in_detail(pci_devices); } else { for pci_device in pci_devices.iter() { let available_profiles = &pci_device.get_available_profiles(); @@ -90,18 +90,18 @@ pub fn list_profiles(profiles: &[Profile], header_msg: &str) { .load_preset(UTF8_FULL) .apply_modifier(UTF8_ROUND_CORNERS) .set_content_arrangement(ContentArrangement::Dynamic) - .set_header(vec![&fl!("name-header"), &fl!("nonfree-header")]); + .set_header(vec![&fl!("name-header"), &fl!("priority-header")]); for profile in profiles.iter() { - table.add_row(vec![&profile.name, &profile.is_nonfree.to_string()]); + table.add_row(vec![&profile.name, &profile.priority.to_string()]); } println!("{table}\n"); } -pub fn print_installed_profiles(device_type: &str, installed_profiles: &[Profile]) { +pub fn print_installed_profiles(installed_profiles: &[Profile]) { if installed_profiles.is_empty() { - print_warning(&fl!("no-installed-profile-device", device_type = device_type)); + print_warning(&fl!("no-installed-profile-device")); return; } diff --git a/src/data.rs b/src/data.rs index fe2b25e..f46c215 100644 --- a/src/data.rs +++ b/src/data.rs @@ -31,8 +31,8 @@ pub struct Data { pub sync_package_manager_database: bool, pub is_ai_sdk_target: bool, pub pci_devices: ListOfDevicesT, - pub installed_pci_profiles: ListOfProfilesT, - pub all_pci_profiles: ListOfProfilesT, + pub installed_profiles: ListOfProfilesT, + pub all_profiles: ListOfProfilesT, pub invalid_profiles: Vec, } @@ -55,24 +55,24 @@ impl Data { pci_device.installed_profiles.clear(); } - self.installed_pci_profiles.clear(); + self.installed_profiles.clear(); // Refill data self.fill_installed_profiles(); - set_matching_profiles(&mut self.pci_devices, &self.installed_pci_profiles, true); + set_matching_profiles(&mut self.pci_devices, &self.installed_profiles, true); } fn fill_installed_profiles(&mut self) { let conf_path = crate::consts::CHWD_PCI_DATABASE_DIR; - let configs = &mut self.installed_pci_profiles; + let configs = &mut self.installed_profiles; fill_profiles(configs, &mut self.invalid_profiles, conf_path, self.is_ai_sdk_target); } fn fill_all_profiles(&mut self) { let conf_path = crate::consts::CHWD_PCI_CONFIG_DIR; - let configs = &mut self.all_pci_profiles; + let configs = &mut self.all_profiles; fill_profiles(configs, &mut self.invalid_profiles, conf_path, self.is_ai_sdk_target); } @@ -82,11 +82,11 @@ impl Data { pci_device.available_profiles.clear(); } - self.all_pci_profiles.clear(); + self.all_profiles.clear(); self.fill_all_profiles(); - set_matching_profiles(&mut self.pci_devices, &self.all_pci_profiles, false); + set_matching_profiles(&mut self.pci_devices, &self.all_profiles, false); self.update_installed_profile_data(); } @@ -139,8 +139,6 @@ fn fill_devices() -> Option { let from_hex = |hex_number: u32, fill: usize| -> String { format!("{:01$x}", hex_number, fill) }; - let dev_type = "PCI".to_owned(); - // Initialize let mut pacc = libpci::PCIAccess::new(true); @@ -159,7 +157,6 @@ fn fill_devices() -> Option { let item_device = iter.device()?; devices.push(Device { - dev_type: dev_type.clone(), class_name: item_class, device_name: item_device, vendor_name: item_vendor, @@ -336,7 +333,6 @@ mod tests { fn test_data() -> Vec { vec![ Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 5".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -349,7 +345,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Audio device".to_string(), device_name: "Family 17h/19h HD Audio Controller".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -362,7 +357,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "SMBus".to_string(), device_name: "FCH SMBus Controller".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -375,7 +369,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 7".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -388,7 +381,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Renoir PCIe Dummy Host Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -401,7 +393,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Ethernet controller".to_string(), device_name: "RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet Controller" .to_string(), @@ -415,7 +406,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Renoir/Cezanne PCIe GPP Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -428,7 +418,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 0".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -441,7 +430,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Network controller".to_string(), device_name: "RTL8852AE 802.11ax PCIe Wireless Network Adapter".to_string(), vendor_name: "Realtek Semiconductor Co., Ltd.".to_string(), @@ -454,7 +442,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Audio device".to_string(), device_name: "Renoir Radeon High Definition Audio Controller".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD/ATI]".to_string(), @@ -467,7 +454,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Renoir PCIe GPP Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -480,7 +466,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 2".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -493,7 +478,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "USB controller".to_string(), device_name: "Renoir/Cezanne USB 3.1".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -506,7 +490,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "SD Host controller".to_string(), device_name: "GL9750 SD Host Controller".to_string(), vendor_name: "Genesys Logic, Inc".to_string(), @@ -519,7 +502,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 4".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -532,7 +514,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Renoir Internal PCIe GPP Bridge to Bus".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -545,7 +526,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Multimedia controller".to_string(), device_name: "ACP/ACP3X/ACP6x Audio Coprocessor".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -558,7 +538,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Renoir/Cezanne Root Complex".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -571,7 +550,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Audio device".to_string(), device_name: "Navi 10 HDMI Audio".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD/ATI]".to_string(), @@ -584,7 +562,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 6".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -597,7 +574,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "IOMMU".to_string(), device_name: "Renoir/Cezanne IOMMU".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -610,7 +586,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Non-Volatile memory controller".to_string(), device_name: "3400 NVMe SSD [Hendrix]".to_string(), vendor_name: "Micron Technology Inc".to_string(), @@ -623,7 +598,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Renoir/Cezanne PCIe GPP Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -636,7 +610,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Navi 10 XL Upstream Port of PCI Express Switch".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD/ATI]".to_string(), @@ -649,7 +622,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "ISA bridge".to_string(), device_name: "FCH LPC Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -662,7 +634,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Renoir/Cezanne PCIe GPP Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -675,7 +646,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "VGA compatible controller".to_string(), device_name: "Cezanne [Radeon Vega Series / Radeon Vega Mobile Series]".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD/ATI]".to_string(), @@ -688,7 +658,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Renoir PCIe Dummy Host Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -701,7 +670,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Navi 10 XL Downstream Port of PCI Express Switch".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD/ATI]".to_string(), @@ -714,7 +682,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 1".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -727,7 +694,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Encryption controller".to_string(), device_name: "Family 17h (Models 10h-1fh) Platform Security Processor".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -740,7 +706,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "PCI bridge".to_string(), device_name: "Renoir/Cezanne PCIe GPP Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -753,7 +718,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Cezanne Data Fabric; Function 3".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -766,7 +730,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Host bridge".to_string(), device_name: "Renoir PCIe Dummy Host Bridge".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -779,7 +742,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "USB controller".to_string(), device_name: "Renoir/Cezanne USB 3.1".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD]".to_string(), @@ -792,7 +754,6 @@ mod tests { installed_profiles: vec![], }, Device { - dev_type: "PCI".to_string(), class_name: "Display controller".to_string(), device_name: "Navi 14 [Radeon RX 5500/5500M / Pro 5500M]".to_string(), vendor_name: "Advanced Micro Devices, Inc. [AMD/ATI]".to_string(), diff --git a/src/device.rs b/src/device.rs index eff2667..437110f 100644 --- a/src/device.rs +++ b/src/device.rs @@ -21,7 +21,6 @@ use std::sync::Arc; #[derive(Debug, Default, Clone)] pub struct Device { - pub dev_type: String, pub class_name: String, pub device_name: String, pub vendor_name: String, @@ -57,7 +56,7 @@ pub fn get_unique_devices(devices: &[Device]) -> Vec { uniq_devices } -pub fn print_available_profiles_in_detail(device_type: &str, devices: &[Device]) { +pub fn print_available_profiles_in_detail(devices: &[Device]) { let mut config_found = false; for device in devices.iter() { let available_profiles = &device.available_profiles; @@ -69,7 +68,7 @@ pub fn print_available_profiles_in_detail(device_type: &str, devices: &[Device]) console_writer::print_status(&format!( "{} {}: {} ({}:{}:{})", - device_type, + "PCI", fl!("device"), device.sysfs_id, device.class_id, @@ -95,6 +94,6 @@ pub fn print_available_profiles_in_detail(device_type: &str, devices: &[Device]) } if !config_found { - console_writer::print_warning(&fl!("no-profile-device", device_type = device_type)); + console_writer::print_warning(&fl!("no-profile-device")); } } diff --git a/src/main.rs b/src/main.rs index 0a54a3e..0c37740 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,48 +37,6 @@ use i18n_embed::DesktopLanguageRequester; use nix::unistd::Uid; use subprocess::Exec; -fn perceed_inst_rem( - args: &Option>, - operation: &mut String, - working_profiles: &mut Vec, -) -> anyhow::Result<()> { - if let Some(values) = args { - let device_type = &values[0]; - let profile = values[1].to_lowercase(); - - if "pci" != device_type && "usb" != device_type { - anyhow::bail!("invalid use of option: {args:?}"); - } - *operation = device_type.to_uppercase(); - working_profiles.push(profile); - } - - Ok(()) -} - -fn perceed_autoconf( - args: &Option>, - operation: &mut String, - autoconf_class_id: &mut String, - is_nonfree: &mut bool, -) -> anyhow::Result<()> { - if let Some(values) = args { - let device_type = &values[0]; - let driver_type = &values[1]; - *is_nonfree = "nonfree" == driver_type; - *autoconf_class_id = values[2].to_lowercase(); - - if ("pci" != device_type && "usb" != device_type) - || ("free" != driver_type && "nonfree" != driver_type) - { - anyhow::bail!("invalid use of option: {args:?}"); - } - *operation = device_type.to_uppercase(); - } - - Ok(()) -} - fn main() -> anyhow::Result<()> { let requested_languages = DesktopLanguageRequester::requested_languages(); let localizer = crate::localization::localizer(); @@ -95,27 +53,20 @@ fn main() -> anyhow::Result<()> { argstruct.list_available = true; } - if argstruct.is_nvidia_card { - misc::check_nvidia_card(); - return Ok(()); - } - let mut working_profiles: Vec = vec![]; - let mut operation = String::new(); let mut autoconf_class_id = String::new(); - let mut autoconf_nonfree_driver = false; - perceed_autoconf( - &argstruct.autoconfigure, - &mut operation, - &mut autoconf_class_id, - &mut autoconf_nonfree_driver, - )?; - perceed_inst_rem(&argstruct.install, &mut operation, &mut working_profiles)?; - perceed_inst_rem(&argstruct.remove, &mut operation, &mut working_profiles)?; - - if !argstruct.show_pci { - argstruct.show_pci = true; + + if let Some(profile) = &argstruct.install { + working_profiles.push(profile.to_lowercase()); + } + + if let Some(profile) = &argstruct.remove { + working_profiles.push(profile.to_lowercase()); + } + + if let Some(class_id) = &argstruct.autoconfigure { + autoconf_class_id = class_id.to_lowercase(); } // 2) Initialize @@ -134,12 +85,8 @@ fn main() -> anyhow::Result<()> { console_writer::handle_arguments_listing(&data_obj, &argstruct); // 4) Auto configuration - let mut prepared_profiles = prepare_autoconfigure( - &data_obj, - &mut argstruct, - &autoconf_class_id, - autoconf_nonfree_driver, - ); + let mut prepared_profiles = + prepare_autoconfigure(&data_obj, &mut argstruct, &autoconf_class_id); working_profiles.append(&mut prepared_profiles); // Transaction @@ -206,7 +153,6 @@ fn prepare_autoconfigure( data: &data::Data, args: &mut args::Args, autoconf_class_id: &str, - autoconf_nonfree_driver: bool, ) -> Vec { if args.autoconfigure.is_none() { return vec![]; @@ -215,7 +161,7 @@ fn prepare_autoconfigure( let mut profiles_name = vec![]; let devices = &data.pci_devices; - let installed_profiles = &data.installed_pci_profiles; + let installed_profiles = &data.installed_profiles; let mut found_device = false; for device in devices.iter() { @@ -223,8 +169,7 @@ fn prepare_autoconfigure( continue; } found_device = true; - let profile = - device.available_profiles.iter().find(|x| autoconf_nonfree_driver || !x.is_nonfree); + let profile = device.available_profiles.first(); let device_info = format!( "{} ({}:{}:{}) {} {} {}", @@ -267,7 +212,7 @@ fn prepare_autoconfigure( if !found_device { console_writer::print_warning(&format!("No device of class '{autoconf_class_id}' found!")); } else if !profiles_name.is_empty() { - args.install = Some(profiles_name.clone()); + args.install = Some(profiles_name.first().unwrap().clone()); } profiles_name @@ -293,13 +238,13 @@ fn get_available_profile(data: &mut data::Data, profile_name: &str) -> Option Option> { // Get the right profiles - let all_profiles = &data.all_pci_profiles; + let all_profiles = &data.all_profiles; misc::find_profile(profile_name, all_profiles) } fn get_installed_profile(data: &data::Data, profile_name: &str) -> Option> { // Get the right profiles - let installed_profiles = &data.installed_pci_profiles; + let installed_profiles = &data.installed_profiles; misc::find_profile(profile_name, installed_profiles) } diff --git a/src/misc.rs b/src/misc.rs index aa5afd7..b3d5f97 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -19,8 +19,8 @@ use std::path::Path; use std::sync::Arc; +use crate::consts; use crate::profile::Profile; -use crate::{consts, data}; #[derive(Debug, PartialEq)] pub enum Transaction { @@ -62,22 +62,6 @@ pub fn find_profile(profile_name: &str, profiles: &[Profile]) -> Option Vec { let mut missing_dirs = vec![]; diff --git a/src/profile.rs b/src/profile.rs index 9f4b8a2..3923b93 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -33,8 +33,6 @@ pub struct HardwareID { #[derive(Debug, Clone)] pub struct Profile { - pub is_nonfree: bool, - pub is_ai_sdk: bool, pub prof_path: String, @@ -139,7 +137,6 @@ pub fn get_invalid_profiles(file_path: &str) -> Result> { fn parse_profile(node: &toml::Table, profile_name: &str) -> Result { let mut profile = Profile { - is_nonfree: node.get("nonfree").and_then(|x| x.as_bool()).unwrap_or(false), is_ai_sdk: node.get("ai_sdk").and_then(|x| x.as_bool()).unwrap_or(false), prof_path: "".to_owned(), name: profile_name.to_owned(), @@ -241,7 +238,6 @@ fn merge_table_left(lhs: &mut toml::Table, rhs: &toml::Table) { pub fn write_profile_to_file(file_path: &str, profile: &Profile) -> bool { let mut table = toml::Table::new(); - table.insert("nonfree".to_owned(), profile.is_nonfree.into()); table.insert("ai_sdk".to_owned(), profile.is_ai_sdk.into()); table.insert("desc".to_owned(), profile.desc.clone().into()); table.insert("packages".to_owned(), profile.packages.clone().into()); @@ -294,7 +290,6 @@ pub fn print_profile_details(profile: &Profile) { .add_row(vec![&fl!("name-header"), &profile.name]) .add_row(vec![&fl!("desc-header"), desc_formatted]) .add_row(vec![&fl!("priority-header"), &profile.priority.to_string()]) - .add_row(vec![&fl!("nonfree-header"), &profile.is_nonfree.to_string()]) .add_row(vec![&fl!("classids-header"), &class_ids]) .add_row(vec![&fl!("vendorids-header"), &vendor_ids]); @@ -323,7 +318,6 @@ mod tests { }]; let parsed_profiles = parsed_profiles.unwrap(); - assert!(parsed_profiles[0].is_nonfree); assert_eq!(parsed_profiles[0].prof_path, prof_path); assert_eq!(parsed_profiles[0].name, "nvidia-dkms.40xxcards"); assert_eq!( @@ -341,7 +335,6 @@ mod tests { assert!(!parsed_profiles[0].post_install.is_empty()); assert!(!parsed_profiles[0].post_remove.is_empty()); - assert!(parsed_profiles[1].is_nonfree); assert_eq!(parsed_profiles[1].prof_path, prof_path); assert_eq!(parsed_profiles[1].name, "nvidia-dkms"); assert_eq!(parsed_profiles[1].priority, 8); diff --git a/tests/profiles/graphic_drivers-invalid-profiles-test.toml b/tests/profiles/graphic_drivers-invalid-profiles-test.toml index 13f6cb3..38a34b9 100644 --- a/tests/profiles/graphic_drivers-invalid-profiles-test.toml +++ b/tests/profiles/graphic_drivers-invalid-profiles-test.toml @@ -34,7 +34,6 @@ device_ids = '*' [nvidia-dkms] desc = 'Closed source NVIDIA drivers for Linux (Latest)' -nonfree = true class_ids = "0300 0380 0302" vendor_ids = "10de" priority = 8 diff --git a/tests/profiles/graphic_drivers-profiles-test.toml b/tests/profiles/graphic_drivers-profiles-test.toml index 4af07f4..5c28bf4 100644 --- a/tests/profiles/graphic_drivers-profiles-test.toml +++ b/tests/profiles/graphic_drivers-profiles-test.toml @@ -29,7 +29,6 @@ device_name_pattern = '(AD)\w+' [nvidia-dkms] desc = 'Closed source NVIDIA drivers for Linux (Latest)' -nonfree = true class_ids = "0300 0380 0302" vendor_ids = "10de" priority = 8 diff --git a/tests/profiles/profile-raw-escaped-strings-test.toml b/tests/profiles/profile-raw-escaped-strings-test.toml index 24a36f3..f88f121 100644 --- a/tests/profiles/profile-raw-escaped-strings-test.toml +++ b/tests/profiles/profile-raw-escaped-strings-test.toml @@ -5,7 +5,6 @@ desc = "Test profile" device_ids = "1435 163f" device_name_pattern = '(AD)\w+' hwd_product_name_pattern = '(Ally)\w+' -nonfree = false packages = "opencl-rusticl-mesa lib32-opencl-rusticl-mesa rocm-opencl-runtime" post_install = ''' echo "Steam Deck chwd installing..."