public static async Task LoadProfileMods(SortedDictionary <int, Mod> mods) { MainForm MainForm_Control = Application.OpenForms.OfType <MainForm>().First(); DataGridView modsGridView = (DataGridView)MainForm_Control.Controls.Find("modsListDataGridView", true).First(); modsGridView.Rows.Clear(); foreach (KeyValuePair <int, Mod> modsPair in mods) { Mod mod = modsPair.Value; string index = modsPair.Key.ToString(); string modSize; string modPath = Profiles.currentProfile.path + "\\ShooterGame\\Content\\Mods\\" + mod.Id.ToString(); if (System.IO.Directory.Exists(modPath)) { modSize = SpaceUsage.SizeSuffix(SpaceUsage.DirectorySize(new System.IO.DirectoryInfo(modPath), true), 2); } else { modSize = "N/A"; } string[] row = new string[] { index, mod.Id.ToString(), mod.Name, mod.LastDownload.ToString(), mod.LastUpdate.ToString(), modSize }; modsGridView.Rows.Add(row); } }
private void refreshSpaceUsageButton_Click(object sender, EventArgs e) { serverSpaceUsageLabel.Text = "Server Space Usage: Calculating..."; Task.Factory.StartNew(async() => { string serverSpaceUsageString = "Server Space Usage: " + SpaceUsage.SizeSuffix(SpaceUsage.DirectorySize(new System.IO.DirectoryInfo(Utilities.Profiles.currentProfile.path), true), 2); if (serverSpaceUsageLabel.InvokeRequired) { this.Invoke(new MethodInvoker(delegate { serverSpaceUsageLabel.Text = serverSpaceUsageString; })); } else { serverSpaceUsageLabel.Text = serverSpaceUsageString; } }); }