mirror of
				https://github.com/PancakeTAS/lsfg-vk.git
				synced 2025-10-30 07:01:10 +00:00 
			
		
		
		
	feat(exe): present exe files in ui
This commit is contained in:
		
							parent
							
								
									7ddf1bdbde
								
							
						
					
					
						commit
						e09d590f2d
					
				
					 1 changed files with 20 additions and 36 deletions
				
			
		|  | @ -1,61 +1,45 @@ | |||
| use procfs::{process, ProcResult}; | ||||
| use std::path::Path; | ||||
| 
 | ||||
| pub fn find_vulkan_processes() -> ProcResult<Vec<(String, String)>> { | ||||
|     let mut processes = Vec::new(); | ||||
|     let apps = process::all_processes()?; | ||||
| 
 | ||||
|     for app in apps { | ||||
|         let Ok(process) = app else { continue; }; | ||||
|         let Ok(prc) = app else { continue; }; | ||||
| 
 | ||||
|         // ensure vulkan is loaded
 | ||||
|         let Ok(maps) = proc_maps::get_process_maps(process.pid()) else { | ||||
|         let Ok(maps) = proc_maps::get_process_maps(prc.pid()) else { | ||||
|             continue; | ||||
|         }; | ||||
| 
 | ||||
|         let result = maps.iter() | ||||
|             .filter_map(|map| map.filename()) | ||||
|             .map(|filename| filename.to_string_lossy().to_string()) | ||||
|             .any(|filename| filename.to_lowercase().contains("vulkan")); | ||||
| 
 | ||||
|         if !result { | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
|         // Format process information
 | ||||
|         // find executed binary
 | ||||
|         let mut exe = prc.exe()?.to_string_lossy().to_string(); | ||||
| 
 | ||||
|         let pid = process.pid(); | ||||
|         // replace binary with exe for wine apps
 | ||||
|         if exe.contains("wine") || exe.contains("proton") { | ||||
|             let result = maps.iter() | ||||
|                 .filter_map(|map| map.filename()) | ||||
|                 .map(|filename| filename.to_string_lossy().to_string()) | ||||
|                 .find(|filename| filename.ends_with(".exe")); | ||||
| 
 | ||||
|         // By default, assume Linux process, and use /proc/self/comm
 | ||||
|         let mut name = process.stat()?.comm; | ||||
| 
 | ||||
|         // Solely just for checking if it's a Proton or Wine process
 | ||||
|         // Not sure if there's a more efficient way to do this
 | ||||
|         let cmdline = process.cmdline()?.join(" "); | ||||
|         
 | ||||
| 
 | ||||
|         // If this is a Proton or Wine process with .exe,
 | ||||
|         // then just get filename from /proc/self/maps
 | ||||
|         if cmdline.contains(".exe") { | ||||
|             for map in &maps { | ||||
|                 if let Some(path) = map.filename() { | ||||
|                     let path_str = path.to_string_lossy().to_lowercase(); | ||||
|                     if path_str.contains(".exe") && | ||||
|                        !path_str.contains("wine") && // Make sure .exe is not from Wine
 | ||||
|                        path_str.contains('/') || | ||||
|                        path_str.contains('\\') { | ||||
| 
 | ||||
|                         name = Path::new(&path_str).file_name() | ||||
|                                                              .unwrap_or_default() | ||||
|                                                              .to_string_lossy() | ||||
|                                                              .to_string(); | ||||
|                         break; | ||||
|             if let Some(exe_name) = result { | ||||
|                 exe = exe_name; | ||||
|             } | ||||
|         } | ||||
|             } | ||||
|         } | ||||
|         let process_info = format!("PID {pid}: {name}"); | ||||
|         processes.push((process_info, name)); | ||||
| 
 | ||||
|         // split off last part of the path
 | ||||
|         exe = exe.split('/').last().unwrap_or(&exe).to_string(); | ||||
| 
 | ||||
|         // format process information
 | ||||
|         let pid = prc.pid(); | ||||
|         let process_info = format!("PID {}: {}", pid, exe); | ||||
|         processes.push((process_info, exe)); | ||||
|     } | ||||
| 
 | ||||
|     Ok(processes) | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 PancakeTAS
						PancakeTAS