public void ReloadMods() { Logging.LogMessage("Loading Mods...", Logging.LogSeverity.Info); this.ModLoadWarningShown = false; this.AvailableMods = ModLoaderUtility.LoadMods(Settings.AvailableMods, ModLoadResults); foreach (var mod in this.ModLoadResults) { if (mod.loadErrors.Count() == 0) { continue; } foreach (var error in mod.loadErrors) { Logging.LogMessage($"{mod.modFileName} - {error}", Logging.LogSeverity.Error); } } if (ModLoadResults.All(m => m.status == ModLoadStatus.Success)) { Logging.LogMessage("Loaded all mods successfully!", Logging.LogSeverity.Info); } }
public ModLoadStatus TryAddMod(string fileName, byte[] fileBytes) { var modInstallPath = Path.Combine(ModLoaderUtility.GetModPath(), fileName); if (File.Exists(modInstallPath)) { modInstallPath = FileWriterUtility.GetUniqueFilePath(modInstallPath); } var fileInfo = new FileInfo(modInstallPath); File.WriteAllBytes(modInstallPath, fileBytes); // Add this mod to the mod list, so it will attemp to be loaded Settings.AvailableMods.Add(fileInfo.Name); ReloadMods(); var result = ModLoadResults.First(r => r.modFileName == fileInfo.Name).status; var success = result == ModLoadStatus.Success; if (!success) { // If this mod failed to load, File.Delete(modInstallPath); Settings.AvailableMods.Remove(fileInfo.Name); ReloadMods(); } else { SaveSettings(); } return(result); }
public void DeleteMod(string modID) { var loadedMod = ModLoadResults.First(m => m.modID == modID); ModLoaderUtility.DeleteMod(loadedMod); Settings.AvailableMods.Remove(loadedMod.modFileName); ReloadMods(); SaveSettings(); }