private void Btn_addSelection_Click(object sender, EventArgs e) { if (checkboxFoundGames.CheckedItems.Count == 0) { DialogResult dialogResult = MessageBox.Show("No games have been selected. Do you wish to add any?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { return; } } if (checkboxFoundGames.CheckedItems.Count > 0) { List <string> gamesToAdd = new List <string>(); int numAdded = 0; for (int i = 0; i < checkboxFoundGames.CheckedItems.Count; i++) { string checkBoxFullname = checkboxFoundGames.CheckedItems[i].ToString(); string exePath = checkBoxFullname.Substring(checkBoxFullname.IndexOf(" | ") + " | ".Length); gamesToAdd.Add(exePath); } foreach (string gameToAdd in gamesToAdd) { UserGameInfo uinfo = GameManager.Instance.TryAddGame(gameToAdd); if (uinfo != null) { main.NewUserGame(uinfo); numAdded++; } } MessageBox.Show(string.Format("{0}/{1} selected games added!", numAdded, checkboxFoundGames.CheckedItems.Count), "Games added"); main.RefreshGames(); } btnSearch.Enabled = true; btn_customPath.Enabled = true; btn_delPath.Enabled = true; btn_addSelection.Enabled = false; btn_selectAll.Enabled = false; btn_deselectAll.Enabled = false; checkboxFoundGames.Enabled = false; checkboxFoundGames.Items.Clear(); disksBox.Enabled = true; progressBar1.Value = 0; progress = 0; lastProgress = 0; label2.Enabled = false; label1.Enabled = true; txt_Path.Text = ""; txt_Stage.Text = ""; }
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!"); })); } }