コード例 #1
0
        private void btn_search_Click(object sender, EventArgs e)
        {
            if (searching)
            {
                return;
            }

            if (GameManager.Instance.User.InstalledHandlers.Count == 0)
            {
                MessageBox.Show("You have no game handlers installed. No games to search for.");
                return;
            }

            btn_search.Enabled      = false;
            searching               = true;
            drivesFinishedSearching = 0;

            drivesToSearch = new List <SearchStorageInfo>();
            CheckedListBox checkedBox = list_storage;

            for (int i = 0; i < checkedBox.CheckedItems.Count; i++)
            {
                SearchStorageInfo info = (SearchStorageInfo)checkedBox.CheckedItems[i];
                drivesToSearch.Add(info);
            }

            SearchDrives();
        }
コード例 #2
0
        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;
                }

                SearchStorageInfo d = new SearchStorageInfo(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);
                }
            }
        }
コード例 #3
0
        private void ScanGames_Click(object sender, EventArgs e)
        {
            MainForm.Instance.ChangeTitle("Scan Storage for Games", scanGames.Image);

            panel_disks.Visible          = true;
            panel_installedGames.Visible = false;
            panel_gameData.Visible       = false;

            list_storage.Controls.Clear();
            diskControls = new List <CheckedTextControl>();
            GC.Collect();

            DriveInfo[] drives = DriveInfo.GetDrives();
            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;
                }

                SearchStorageInfo  d   = new SearchStorageInfo(drive);
                CheckedTextControl con = null;
                if (drive.IsReady)
                {
                    if (drive.DriveFormat != "NTFS")
                    {
                        // ignore non-NTFS drives
                        continue;
                    }

                    con            = new CheckedTextControl();
                    con.Width      = list_installedGames.Width;
                    con.Checked    = true;
                    con.SharedData = d;
                    list_storage.Controls.Add(con);
                    diskControls.Add(con);

                    Control sep = new Control();
                    sep.Height = 2;
                    list_storage.Controls.Add(sep);

                    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);
                }

                if (con != null)
                {
                    con.UpdateTitleText(d.Info);
                }
            }

            DPI.DPIManager.ForceUpdate();
            DPI.DPIManager.ForceUpdate();
        }
コード例 #4
0
        private void SearchDrive(object state)
        {
            int driveIndex         = (int)state;
            SearchStorageInfo 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!");
                }));
            }
        }