/// <summary> /// Look inside folder for "XInput..." strings and return XInput mask. /// </summary> /// <returns>Thanks mrexodia (https://github.com/mrexodia) for suggestion</returns> public Dictionary <string, XInputMask> GetMasks(string path, SearchOption searchOption, bool is64bit) { // Check masks inside *.exe and *.dll files. var files = Directory.GetFiles(path, "*.exe", searchOption).ToList(); var dlls = Directory.GetFiles(path, "*.dll", searchOption).ToList(); files.AddRange(dlls); XInputMask mask = Engine.XInputMask.None; // Create list to store masks. var masks = new Dictionary <string, XInputMask>(); // If file doesn't exist in the game list then continue. var e = new XInputMaskScannerEventArgs(); e.Level = 1; e.Files = files.Select(x => new FileInfo(x)).ToList(); e.State = XInputMaskScannerState.FileUpdate; ReportProgress(e); for (int i = 0; i < files.Count; i++) { e.FileIndex = i; e.Message = string.Format("Scan file {0} of {1}. Please wait...", i + 1, files.Count); ReportProgress(e); var file = files[i]; // Pause or Stop. while (IsPaused && !IsStopping) { // Logical delay without blocking the current thread. System.Threading.Tasks.Task.Delay(500).Wait(); } if (IsStopping) { return(masks); } // Do tasks. // Skip XInput files. if (string.Compare(file, "xinput", true) == 00) { continue; } // Skip X360CE files. if (string.Compare(file, "x360ce", true) == 00) { continue; } var fileArchitecture = JocysCom.ClassLibrary.Win32.PEReader.GetProcessorArchitecture(file); var fileIs64bit = (fileArchitecture == System.Reflection.ProcessorArchitecture.Amd64); // Skip wrong architecture. if (is64bit != fileIs64bit) { continue; } // Get XInput mask for the file. mask = GetMask(file); if (mask != Engine.XInputMask.None) { masks.Add(file, mask); } } return(masks); }
private void ReportProgress(XInputMaskScannerEventArgs e) { var ev = Progress; if (ev != null) { ev(this, e); } }
private void ff_FileFound(object sender, FileFinderEventArgs e) { var e2 = new XInputMaskScannerEventArgs(); e2.DirectoryIndex = e.DirectoryIndex; e2.Directories = e.Directories; e2.FileIndex = e.FileIndex; e2.Files = e.Files; e2.State = XInputMaskScannerState.DirectoryUpdate; e2.Message = string.Format("Step 1: {0} programs found. Searching path {1} of {2}. Please wait...", e.Files.Count, e.DirectoryIndex + 1, e.Directories.Count); ReportProgress(e2); }
public void ScanGames(string[] paths, IList <UserGame> games, IList <Program> programs, string fileName = null) { IsStopping = false; IsPaused = false; // Step 1: Get list of executables inside the folder. var e = new XInputMaskScannerEventArgs(); e.State = XInputMaskScannerState.Started; ReportProgress(e); var skipped = 0; var added = 0; var updated = 0; var winFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows); var dirs = paths .Select(x => x) // Except win folders. .Where(x => !x.StartsWith(winFolder, StringComparison.OrdinalIgnoreCase)) .ToArray(); // Create list to store file to scan. var exes = string.IsNullOrEmpty(fileName) // Scan all executables. ? ff.GetFiles("*.exe", true, dirs) // Scan specific executable. : ff.GetFiles(fileName, false, dirs); // Step 2: Scan files. for (int i = 0; i < exes.Count; i++) { var exe = exes[i]; var exeName = exe.Name.ToLower(); var program = programs.FirstOrDefault(x => x.FileName.ToLower() == exeName); // If file doesn't exist in the game list then continue. e = new XInputMaskScannerEventArgs(); e.Message = string.Format("Step 2: Scan file {0} of {1}. Please wait...", i + 1, exes.Count); e.FileIndex = i; e.Files = exes; e.State = XInputMaskScannerState.FileUpdate; e.Added = added; e.Skipped = skipped; e.Updated = updated; ReportProgress(e); // If specific file name was not specifield and program not found then... if (string.IsNullOrEmpty(fileName) && program == null) { skipped++; } else { e = new XInputMaskScannerEventArgs(); e.Program = program; e.GameFileInfo = exe; // Get game by executable name. var game = games.FirstOrDefault(x => x.FileName.ToLower() == exeName); // If file doesn't exist in the game list then... if (game == null) { game = FromDisk(exe.FullName, SearchOption.AllDirectories); game.LoadDefault(program, true); e.State = XInputMaskScannerState.GameFound; e.Game = game; added++; } else { e.Game = game; e.State = XInputMaskScannerState.GameUpdated; updated++; } ReportProgress(e); } } e = new XInputMaskScannerEventArgs(); e.State = XInputMaskScannerState.Completed; ReportProgress(e); }