private void RefreshContents(bool plugins, bool sideloader) { if (plugins) { PluginLoader.StartReload(); } if (sideloader) { SideloaderModLoader.StartReload(); } foreach (var window in GetWindows <DockContent>()) { if (window is PluginsWindow pw) { if (plugins) { pw.RefreshList(); } } else if (window is SideloaderModsWindow sm) { if (sideloader) { sm.RefreshList(); } } } }
private static string GetEnabledName(FileInfo file) { if (SideloaderModLoader.IsValidZipmodExtension(file.Extension)) { return(SideloaderModInfo.EnabledLocation(file).Name); } else if (PluginLoader.IsValidPluginExtension(file.Extension)) { return(PluginInfo.EnabledLocation(file).Name); } else { return(file.Name); } }
private async Task ShowModUpdateDialog() { try { try { Enabled = false; _checkForUpdatesCancel?.Cancel(); PluginLoader.CancelReload(); SideloaderModLoader.CancelReload(); await PluginLoader.Plugins.LastOrDefaultAsync().Timeout(TimeSpan.FromSeconds(30)); await SideloaderModLoader.Zipmods.LastOrDefaultAsync().Timeout(TimeSpan.FromSeconds(30)); var updateSources = GetUpdateSources(); if (!updateSources.Any()) { throw new IOException("No update sources are available"); } ModUpdateProgressDialog.StartUpdateDialog(this, updateSources); } catch (Exception ex) { var errorMsg = "Failed to start update - " + ex.ToStringDemystified(); Console.WriteLine(errorMsg); MessageBox.Show(errorMsg, "Update failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } SideloaderModLoader.StartReload(); PluginLoader.StartReload(); var contentWindows = GetWindows <DockContent>().OfType <IContentWindow>().ToList(); foreach (var window in contentWindows) { window.RefreshList(); } updateSideloaderModpackToolStripMenuItem.BackColor = DefaultBackColor; updateSideloaderModpackToolStripMenuItem.ForeColor = DefaultForeColor; } finally { Enabled = true; } }
public void ReloadList() { CancelListReload(); objectListView1.ClearObjects(); _cancellationTokenSource = new CancellationTokenSource(); var token = _cancellationTokenSource.Token; var observable = SideloaderModLoader.TryReadSideloaderMods(InstallDirectoryHelper.GetModsPath().FullName, token); observable .Buffer(TimeSpan.FromSeconds(3)) .ObserveOn(this) .Subscribe(list => objectListView1.AddObjects((ICollection)list), () => { objectListView1.FastAutoResizeColumns(); MainWindow.SetStatusText("Done loading zipmods"); }, token); }
private static void SideloaderCleanupByManifest(IEnumerable <string> allMods) { try { var mods = new List <SideloaderModInfo>(); foreach (var mod in allMods) { try { mods.Add(SideloaderModLoader.LoadFromFile(mod)); } catch (SystemException ex) { Console.WriteLine($"Deleting zipmod file: {mod} | Reason: {ex.Message}"); // Kill it with fire SafeFileDelete(mod); } } foreach (var modGroup in mods.GroupBy(x => x.Guid)) { //todo don't prioritize mods inside the modpacks? var orderedMods = modGroup.All(x => !string.IsNullOrWhiteSpace(x.Version)) ? modGroup.OrderByDescending(x => x.Location.FullName.ToLower().Contains("mods\\sideloader modpack")).ThenByDescending(x => x.Version, new SideloaderVersionComparer()) : modGroup.OrderByDescending(x => x.Location.FullName.ToLower().Contains("mods\\sideloader modpack")).ThenByDescending(x => x.Location.LastWriteTimeUtc); // Prefer .zipmod extension and then longer paths (so the mod has either longer name or is arranged in a subdirectory) orderedMods = orderedMods.ThenByDescending(x => FileHasZipmodExtension(x.FileName)).ThenByDescending(x => x.Location.FullName.Length); var orederedModsList = orderedMods.ToList(); foreach (var oldMod in orederedModsList.Skip(1)) { Console.WriteLine($"Deleting zipmod file: {oldMod.Location.FullName} | Reason: Duplicate GUID, older than {orederedModsList.First().Location.FullName}"); SafeFileDelete(oldMod.Location.FullName); } } } catch (Exception ex) { Console.WriteLine(ex); } }
public static void InstallFromUnknownFile(string fileName) { var file = new FileInfo(fileName); Exception toThrow = null; if (SideloaderModLoader.IsValidZipmodExtension(file.Extension)) { try { // This will throw NotSupportedException on hardmods so no need to check it later InstallZipmod(fileName); return; } catch (InvalidDataException ex) { // Not a zipmod toThrow = ex; } } if (PluginLoader.IsValidPluginExtension(file.Extension)) { // If it throws, there's a good reason InstallPlugin(fileName); return; } /* todo fix and reenable * if (ZipFile.IsZipFile(fileName)) * { * InstallFromArchive(fileName); * return; * }*/ if (toThrow != null) { throw toThrow; } throw new InvalidDataException("The file format is not supported, or the file is broken"); }
private static void InstallZipmod(string fileName) { SideloaderModInfo newMod; try { newMod = SideloaderModLoader.LoadFromFile(fileName); } catch (NotSupportedException) { throw; } catch (SystemException ex) { throw new InvalidDataException("The file is not a zipmod or is broken - " + ex.Message, ex); } if (newMod != null) { try { var modDirectory = InstallDirectoryHelper.GetModsPath().FullName; var mods = SideloaderModLoader.TryReadSideloaderMods(modDirectory, CancellationToken.None); var oldMod = mods.ToList().Wait().FirstOrDefault(x => x.Guid == newMod.Guid); if (oldMod != null) { switch (SideloaderVersionComparer.CompareVersions(newMod.Version, oldMod.Version)) { case -1: throw new InvalidOperationException("You already have a newer version of this zipmod installed"); case 0: throw new InvalidOperationException("You already have this zipmod installed"); case 1: oldMod.Location.Delete(); var newPath = oldMod.Location.Directory?.FullName; if (!string.IsNullOrWhiteSpace(newPath)) { newMod.Location.CopyTo(Path.Combine(newPath, newMod.Location.Name)); return; } break; } } var installModDir = Path.Combine(modDirectory, "Installed by KKManager"); Directory.CreateDirectory(installModDir); newMod.Location.CopyTo(Path.Combine(installModDir, newMod.Location.Name)); return; } catch (SystemException e) { Console.WriteLine(e); throw new InvalidOperationException("Failed to install zipmod file - " + e.Message, e); } } throw new InvalidOperationException("Failed to install zipmod file for an unknown reason"); }
private void toolStripButton1_Click(object sender, EventArgs e) { SideloaderModLoader.StartReload(); RefreshList(); }