public void FullRefresh() { if (ModManager != null) { Directory.CreateDirectory(ModManager.DownloadPath); Directory.CreateDirectory(ModManager.InstallPath); ModManager.SyncModsFromDisk(); ModManager.SyncConfigFromDisk(); ModManager.UpdateReadOnlyStatus(); ModManager.SortMods(); if (!autoUpdater.IsBusy) { autoUpdater.RunWorkerAsync(); } } AMLUtils.InvokeUI(() => { if (TableManager != null) { TableManager.Refresh(); } AMLPalette.RefreshTheme(this); RefreshModInfoLabel(); }); }
private void Form1_Load(object sender, EventArgs e) { dataGridView1.ClearSelection(); if (!string.IsNullOrEmpty(Program.CommandLineOptions.NextLaunchPath)) { ModManager.LaunchCommand = Program.CommandLineOptions.NextLaunchPath; Program.CommandLineOptions.NextLaunchPath = null; ModManager.SyncConfigToDisk(); } // Fetch the latest version from github Task.Run(() => { latestOnlineVersion = GitHubAPI.GetLatestVersionFromGitHub(GitHubRepo); }).ContinueWith(res => { if (latestOnlineVersion != null && latestOnlineVersion.IsAMLVersionLower()) { BasicButtonPopup resultButton = this.GetBasicButton("A new version of AstroModLoader (v" + latestOnlineVersion + ") is available!", "OK", "Open in browser", null); resultButton.PageToVisit = GitHubAPI.GetLatestVersionURL(GitHubRepo); resultButton.ShowDialog(); } }, TaskScheduler.FromCurrentSynchronizationContext()); // Initial resize of the menu to fit the table if necessary AMLUtils.InvokeUI(ForceTableToFit); AMLUtils.InvokeUI(ForceResize); AMLUtils.InvokeUI(ForceResize); UpdateVersionLabel(); RefreshModInfoLabel(); }
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (TableManager != null) { AMLUtils.InvokeUI(() => TableManager.PaintCell(sender, e)); } }
private void SetDebugText(string txt) { AMLUtils.InvokeUI(() => { debugLabel.Text = txt; }); }
public static void RefreshTheme(Form frm) { AMLUtils.InvokeUI(() => { RefreshThemeInternal(frm); }); }
private void refuseMismatchedConnectionsCheckbox_CheckedChanged(object sender, EventArgs e) { ModHandler.OurIntegrator.RefuseMismatchedConnections = refuseMismatchedConnectionsCheckbox.Checked; BaseForm.ModManager.SyncDependentConfigToDisk(); AMLUtils.InvokeUI(BaseForm.TableManager.Refresh); this.UpdateLabels(); }
public void SyncConfigToDisk() { AMLUtils.InvokeUI(() => { SyncDependentConfigToDisk(); SyncIndependentConfigToDisk(); }); }
private void waitingTimer_Tick(object sender, EventArgs e) { AMLUtils.InvokeUI(() => { numDots++; if (numDots > 3) { numDots = 1; } this.label1.Text = "Working" + new string('.', numDots); }); }
private async Task ForceUpdateCells() { await Task.Run(() => { if (ModManager.IsReadOnly) { return; } if (!updateCellsSemaphore.WaitOne(5000)) { return; } foreach (DataGridViewRow row in this.dataGridView1.Rows) { if (row.Tag is Mod taggedMod) { if (taggedMod.CannotCurrentlyUpdate) { continue; } taggedMod.Enabled = (bool)row.Cells[0].Value; if (TableHandler.ShouldContainOptionalColumn()) { taggedMod.IsOptional = (bool)row.Cells[5].Value; } if (row.Cells[2].Value is string strVal) { Version changingVer = null; if (strVal.Contains("Latest")) { taggedMod.ForceLatest = true; changingVer = taggedMod.AvailableVersions[0]; } else { taggedMod.ForceLatest = false; changingVer = new Version(strVal); } SwitchVersionSync(taggedMod, changingVer); } } } ModManager.FullUpdate(); updateCellsSemaphore.Release(); }).ContinueWith(res => { AMLUtils.InvokeUI(TableManager.Refresh); }); }
private void DataGridView1_SelectionChanged(object sender, EventArgs e) { Mod selectedMod = TableManager.GetCurrentlySelectedMod(); if (dataGridView1.SelectedRows.Count == 1 && !ModManager.IsReadOnly) { DataGridViewRow selectedRow = dataGridView1.SelectedRows[0]; int newModIndex = selectedRow.Index; // If shift is held, that means we are changing the order if (canAdjustOrder && ModifierKeys == Keys.Shift && selectedMod != null && previouslySelectedMod != null && previouslySelectedMod != selectedMod) { AMLUtils.InvokeUI(() => { ModManager.SwapMod(previouslySelectedMod, newModIndex, false); previouslySelectedMod = null; canAdjustOrder = false; TableManager.Refresh(); canAdjustOrder = true; dataGridView1.ClearSelection(); dataGridView1.Rows[newModIndex].Selected = true; dataGridView1.CurrentCell = dataGridView1.Rows[newModIndex].Cells[0]; selectedMod = ModManager.Mods[newModIndex]; foreach (Mod mod in ModManager.Mods) { mod.Dirty = true; // Update all the priorities on disk to be safe } ModManager.FullUpdate(); }); } } previouslySelectedMod = selectedMod; RefreshModInfoLabel(); }
public void UpdateAvailableVersionsFromIndexFiles() { IsUpdatingAvailableVersionsFromIndexFilesWaitHandler.Reset(); Dictionary <Mod, Version> switchVersionInstructions = new Dictionary <Mod, Version>(); foreach (Mod mod in Mods) { Version latestVersion = null; if (mod.AvailableVersions.Count > 0) { latestVersion = mod.AvailableVersions[0]; } if (GlobalIndexFile.ContainsKey(mod.CurrentModData.ModID)) { IndexMod indexMod = GlobalIndexFile[mod.CurrentModData.ModID]; mod.AvailableVersions.AddRange(indexMod.AllVersions.Keys.Except(mod.AvailableVersions)); mod.AvailableVersions.Sort(); mod.AvailableVersions.Reverse(); latestVersion = mod.AvailableVersions[0]; //if (indexMod.LatestVersion != null) latestVersion = indexMod.LatestVersion; } if (mod.ForceLatest && latestVersion != null) { switchVersionInstructions.Add(mod, latestVersion); } } AMLUtils.InvokeUI(BaseForm.TableManager.Refresh); foreach (KeyValuePair <Mod, Version> entry in switchVersionInstructions) { BaseForm.SwitchVersionSync(entry.Key, entry.Value); } IsUpdatingAvailableVersionsFromIndexFilesWaitHandler.Set(); }
private void RefreshModInfoLabel() { AMLUtils.InvokeUI(() => { Mod selectedMod = TableManager?.GetCurrentlySelectedMod(); if (selectedMod == null) { AdjustModInfoText(""); return; } string kosherDescription = selectedMod.CurrentModData.Description; if (!string.IsNullOrEmpty(kosherDescription) && kosherDescription.Length > 200) { kosherDescription = kosherDescription.Substring(0, 200) + "..."; } string kosherSync = "N/A"; switch (selectedMod.CurrentModData.Sync) { case SyncMode.None: kosherSync = "None"; break; case SyncMode.ClientOnly: kosherSync = "Client only"; break; case SyncMode.ServerOnly: kosherSync = "Server only"; break; case SyncMode.ServerAndClient: kosherSync = "Server and client"; break; } long knownSize = -1; try { knownSize = ModManager.GetSizeOnDisk(selectedMod); } catch (Exception ex) { if (!(ex is IOException) && !(ex is FileNotFoundException)) { throw; } } string additionalData = ""; if (knownSize >= 0) { additionalData += "\nSize: " + AMLUtils.FormatFileSize(knownSize); } bool hasHomepage = !string.IsNullOrEmpty(selectedMod.CurrentModData.Homepage) && AMLUtils.IsValidUri(selectedMod.CurrentModData.Homepage); string realText = "Name: " + selectedMod.CurrentModData.Name; if (!string.IsNullOrEmpty(kosherDescription)) { realText += "\nDescription: " + kosherDescription; } realText += "\nSync: " + kosherSync; realText += additionalData; realText += hasHomepage ? "\nWebsite: " : ""; AdjustModInfoText(realText, hasHomepage ? selectedMod.CurrentModData.Homepage : ""); }); }
private async void Form1_DragDrop(object sender, DragEventArgs e) { string[] installingModPaths = (string[])e.Data.GetData(DataFormats.FileDrop); if (installingModPaths.Length > 0) { Dictionary <string, List <Version> > newMods = new Dictionary <string, List <Version> >(); int clientOnlyCount = 0; int malformattedCount = 0; int newProfileCount = 0; int invalidExtensionCount = 0; int wasFolderCount = 0; foreach (string newInstallingMod in installingModPaths) { if (!File.Exists(newInstallingMod)) { wasFolderCount++; continue; } if (!AllowedModExtensions.Contains(Path.GetExtension(newInstallingMod))) { invalidExtensionCount++; continue; } List <Mod> resMods = InstallModFromPath(newInstallingMod, out int thisClientOnlyCount, out int thisNumMalformatted, out int thisNumNewProfiles); if (resMods == null) { continue; } foreach (Mod resMod in resMods) { if (resMod == null) { continue; } if (!newMods.ContainsKey(resMod.CurrentModData.ModID)) { newMods[resMod.CurrentModData.ModID] = new List <Version>(); } newMods[resMod.CurrentModData.ModID].AddRange(resMod.AvailableVersions); } clientOnlyCount += thisClientOnlyCount; malformattedCount += thisNumMalformatted; newProfileCount += thisNumNewProfiles; } //ModManager.SyncModsFromDisk(true); ModManager.SortMods(); ModManager.SortVersions(); ModManager.RefreshAllPriorites(); if (!autoUpdater.IsBusy) { autoUpdater.RunWorkerAsync(); } foreach (Mod mod in ModManager.Mods) { if (mod == null) { continue; } mod.Dirty = true; if (newMods.ContainsKey(mod.CurrentModData.ModID)) { // We switch the installed version to the newest version that has just been added newMods[mod.CurrentModData.ModID].Sort(); newMods[mod.CurrentModData.ModID].Reverse(); mod.InstalledVersion = newMods[mod.CurrentModData.ModID][0]; // If this is a new mod, we enable it or disable it automatically, but if it's not new then we respect the user's pre-existing setting if (mod.AvailableVersions.Count == 1) { mod.Enabled = ModManager.InstalledAstroBuild.AcceptablySimilar(mod.CurrentModData.AstroBuild) && (!Program.CommandLineOptions.ServerMode || mod.CurrentModData.Sync != SyncMode.ClientOnly); } } } await ModManager.FullUpdate(); AMLUtils.InvokeUI(() => { TableManager.Refresh(); if (wasFolderCount > 0) { this.ShowBasicButton("You cannot drag in a folder!", "OK", null, null); } if (invalidExtensionCount > 0) { this.ShowBasicButton(invalidExtensionCount + " file" + (invalidExtensionCount == 1 ? " had an invalid extension" : "s had invalid extensions") + " and " + (invalidExtensionCount == 1 ? "was" : "were") + " ignored.\nAcceptable mod extensions are: " + string.Join(", ", AllowedModExtensions), "OK", null, null); } if (clientOnlyCount > 0) { this.ShowBasicButton(clientOnlyCount + " mod" + (clientOnlyCount == 1 ? " is" : "s are") + " designated as \"Client only\" and " + (clientOnlyCount == 1 ? "was" : "were") + " ignored.", "OK", null, null); } if (malformattedCount > 0) { this.ShowBasicButton(malformattedCount + " mod" + (malformattedCount == 1 ? " was" : "s were") + " malformatted, and could not be installed.\nThe file name may be invalid, the metadata may be invalid, or both.\nPlease ensure that this mod meets the community-made standards.", "OK", null, null); } if (newProfileCount > 0) { this.ShowBasicButton(newProfileCount + " new profile" + (newProfileCount == 1 ? " was" : "s were") + " included with the file" + (installingModPaths.Length == 1 ? "" : "s") + " you installed.\n" + (newProfileCount == 1 ? "It has" : "They have") + " been added to your list of profiles.", "OK", null, null); } }); } }
public void Refresh() { AMLUtils.InvokeUI(RefreshInternal); }