private void btnSearch_Click(object sender, EventArgs e) { if (searching) { return; } if (GameManager.Instance.User.InstalledHandlers.Count == 0) { MessageBox.Show("You have no game handlers installed."); return; } btnSearch.Enabled = false; searching = true; done = 0; toSearch = new List <SearchDriveInfo>(); CheckedListBox checkedBox = disksBox; for (int i = 0; i < checkedBox.CheckedItems.Count; i++) { SearchDriveInfo info = (SearchDriveInfo)checkedBox.CheckedItems[i]; toSearch.Add(info); } SearchDrives(); }
public SearchDisksForm(MainForm main) { this.main = main; InitializeComponent(); DriveInfo[] drives = DriveInfo.GetDrives(); CheckedListBox checkedBox = disksBox; for (int i = 0; i < drives.Length; i++) { DriveInfo drive = drives[i]; if (drive.DriveType == DriveType.CDRom) { // CDs cannot use ntfs continue; } SearchDriveInfo d = new SearchDriveInfo(); d.drive = drive; if (drive.IsReady) { if (drive.DriveFormat != "NTFS") { // ignore non-NTFS drives continue; } try { long free = drive.AvailableFreeSpace / 1024 / 1024 / 1024; long total = drive.TotalSize / 1024 / 1024 / 1024; long used = total - free; d.text = drive.Name + " " + used + " GB used"; checkedBox.Items.Add(d, true); } catch { // notify user of crash d.text = drive.Name + " (Not authorized)"; checkedBox.Items.Add(d, CheckState.Indeterminate); } } else { // user might want to get that drive ready d.text = drive.Name + " (Drive not ready)"; checkedBox.Items.Add(d, CheckState.Indeterminate); } } }
public SearchStorageForm() { InitializeComponent(); titleBarControl.Text = "Search Storage"; DriveInfo[] drives = DriveInfo.GetDrives(); CheckedListBox checkedBox = list_storage; for (int i = 0; i < drives.Length; i++) { DriveInfo drive = drives[i]; if (drive.DriveType == DriveType.CDRom || drive.DriveType == DriveType.Network) { // CDs cannot use NTFS // and network I'm not even trying continue; } SearchDriveInfo d = new SearchDriveInfo(drive); if (drive.IsReady) { if (drive.DriveFormat != "NTFS") { // ignore non-NTFS drives continue; } try { long free = drive.AvailableFreeSpace / 1024 / 1024 / 1024; long total = drive.TotalSize / 1024 / 1024 / 1024; long used = total - free; d.SetInfo(drive.Name + " " + used + " GB used"); checkedBox.Items.Add(d, true); } catch { // notify user of crash d.SetInfo(drive.Name + " (Not authorized)"); checkedBox.Items.Add(d, CheckState.Indeterminate); } } else { // user might want to get that drive ready d.SetInfo(drive.Name + " (Drive not ready)"); checkedBox.Items.Add(d, CheckState.Indeterminate); } } }
public SearchDisksForm(MainForm main) { this.main = main; InitializeComponent(); DriveInfo[] drives = DriveInfo.GetDrives(); CheckedListBox checkedBox = disksBox; for (int i = 0; i < drives.Length; i++) { DriveInfo drive = drives[i]; SearchDriveInfo d = new SearchDriveInfo(); d.drive = drive; if (drive.IsReady) { if (drive.DriveFormat != "NTFS") { // ignore non-NTFS drives continue; } try { long free = drive.AvailableFreeSpace / 1024 / 1024 / 1024; long total = drive.TotalSize / 1024 / 1024 / 1024; long used = total - free; d.text = drive.Name + " " + used + " GB used"; checkedBox.Items.Add(d, true); } catch { // notify user of crash d.text = drive.Name + " (Not authorized)"; checkedBox.Items.Add(d, CheckState.Indeterminate); } } else { // user might want to get that drive ready d.text = drive.Name + " (Drive not ready)"; checkedBox.Items.Add(d, CheckState.Indeterminate); } } }
private void btnSearch_Click(object sender, EventArgs e) { if (searching) { return; } btnSearch.Enabled = false; searching = true; done = 0; toSearch = new List <SearchDriveInfo>(); CheckedListBox checkedBox = disksBox; for (int i = 0; i < checkedBox.CheckedItems.Count; i++) { SearchDriveInfo info = (SearchDriveInfo)checkedBox.CheckedItems[i]; toSearch.Add(info); } SearchDrives(); }
private void SearchDrive(object state) { int i = (int)state; SearchDriveInfo info = toSearch[i]; if (!info.drive.IsReady) { done++; return; } float totalDiskPc = 1 / (float)toSearch.Count; float thirdDiskPc = totalDiskPc / 3.0f; // 1/3 done, we started the operation UpdateProgress(thirdDiskPc); LogManager.Log("> Searching drive {0} for game executables", info.drive.Name); Dictionary <ulong, FileNameAndParentFrn> mDict = new Dictionary <ulong, FileNameAndParentFrn>(); MFTReader mft = new MFTReader(); mft.Drive = info.drive.RootDirectory.FullName; mft.EnumerateVolume(out mDict, new string[] { ".exe" }); progress += thirdDiskPc; // 2/3 done UpdateProgress(thirdDiskPc); float increment = thirdDiskPc / (float)mDict.Count; foreach (KeyValuePair <UInt64, FileNameAndParentFrn> entry in mDict) { if (closed) { return; } UpdateProgress(increment); FileNameAndParentFrn file = (FileNameAndParentFrn)entry.Value; string name = file.Name; string lower = name.ToLower(); if (GameManager.Instance.AnyGame(lower)) { string path = mft.GetFullPath(file); if (path.Contains("$Recycle.Bin") || path.Contains(@"\Instance")) { // noope continue; } UserGameInfo uinfo = GameManager.Instance.TryAddGame(path); if (uinfo != null) { #if RELEASE if (uinfo.Game.Debug) { continue; } #endif LogManager.Log("> Found new game {0} on drive {1}", uinfo.Game.GameName, info.drive.Name); Invoke(new Action(delegate { listGames.Items.Add(uinfo.Game.GameName + " - " + path); listGames.Invalidate(); main.NewUserGame(uinfo); })); } } } if (closed) { return; } done++; if (done == toSearch.Count) { searching = false; Invoke(new Action(delegate { progress = 1; UpdateProgress(0); btnSearch.Enabled = true; main.RefreshGames(); MessageBox.Show("Finished searching!"); })); } }
private void SearchDrive(object state) { int driveIndex = (int)state; SearchDriveInfo info = drivesToSearch[driveIndex]; if (!info.Drive.IsReady) { drivesFinishedSearching++; return; } float totalDiskPc = 1 / (float)drivesToSearch.Count; float thirdDiskPc = totalDiskPc / 3.0f; // 1/3 done, we started the operation UpdateProgress(thirdDiskPc); Log.WriteLine($"> Searching drive {info.Drive.Name} for game executables"); Dictionary <ulong, FileNameAndParentFrn> allExes = new Dictionary <ulong, FileNameAndParentFrn>(); MFTReader mft = new MFTReader(); mft.Drive = info.Drive.RootDirectory.FullName; // TODO: search only for specific games? mft.EnumerateVolume(out allExes, new string[] { ".exe" }); UpdateProgress(thirdDiskPc); // 2/3 done float perFilePCIncrement = thirdDiskPc / (float)allExes.Count; bool shouldUpdate = false; foreach (KeyValuePair <UInt64, FileNameAndParentFrn> entry in allExes) { UpdateProgress(perFilePCIncrement); FileNameAndParentFrn file = (FileNameAndParentFrn)entry.Value; string name = file.Name; string lower = name.ToLower(); if (GameManager.Instance.AnyGame(lower)) { string path = mft.GetFullPath(file); if (path.Contains("$Recycle.Bin") || path.Contains(@"\Instance")) { // noope continue; } UserGameInfo uinfo = GameManager.Instance.TryAddGame(path); if (uinfo != null) { Log.WriteLine($"> Found new game ID {uinfo.GameID} on drive {info.Drive.Name}"); Invoke(new Action(delegate { list_games.Items.Add(GameManager.Instance.MetadataManager.GetGameName(uinfo.GameID) + " - " + path); list_games.Invalidate(); shouldUpdate = true; })); } } } if (shouldUpdate) { MainForm.Instance.Invoke((Action)MainForm.Instance.RefreshGames); } drivesFinishedSearching++; if (drivesFinishedSearching == drivesToSearch.Count) { searching = false; Invoke(new Action(delegate { progress = 1; UpdateProgress(0); btn_search.Enabled = true; // TODO make it better MainForm.Instance.RefreshGames(); MessageBox.Show("Finished searching!"); })); } }