public override void DownloadComplete(System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null) { Sys.Message(new WMessage($"[{StringKey.ErrorUpdating}] {Mod.Name}") { TextTranslationKey = StringKey.ErrorUpdating, LoggedException = e.Error }); Sys.RevertStatus(Mod.ID); } else { // update the cached mod details by re-reading the mod.xml string sourceFileName = Install.LatestInstalled.InstalledLocation; string sourcePath = Path.Combine(Sys.Settings.LibraryLocation, sourceFileName); Mod updatedMod = new ModImporter().ParseModXmlFromSource(sourcePath, Mod); Install.CachedDetails = updatedMod; Install.Versions.Clear(); Install.Versions.Add(new InstalledVersion() { VersionDetails = updatedMod.LatestVersion, InstalledLocation = sourceFileName }); Sys.Message(new WMessage($"[{StringKey.Updated}] {Mod.Name}") { TextTranslationKey = StringKey.Updated }); Sys.SetStatus(Mod.ID, ModStatus.Installed); } Sys.SaveLibrary(); }
private bool TryBatchImport() { if (string.IsNullOrWhiteSpace(PathToBatchFolderInput)) { MessageDialogWindow.Show("Enter a path to a folder containing .iro files and/or mod folders.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!Directory.Exists(PathToBatchFolderInput)) { MessageDialogWindow.Show("Directory does not exist.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } ModImporter importer = null; try { importer = new ModImporter(); importer.ImportProgressChanged += Importer_ImportProgressChanged; int modImportCount = 0; foreach (string iro in Directory.GetFiles(PathToBatchFolderInput, "*.iro")) { string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(iro)); importer.Import(iro, modName, true, false); modImportCount++; } foreach (string dir in Directory.GetDirectories(PathToBatchFolderInput)) { string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(dir)); importer.Import(dir, modName, false, false); modImportCount++; } Sys.Message(new WMessage($"Successfully imported {modImportCount} mod(s)!", true)); return(true); } catch (DuplicateModException de) { Logger.Error(de); MessageDialogWindow.Show($"Can not import mod(s). {de.Message}", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Logger.Error(e); MessageDialogWindow.Show("Failed to import mod(s). The error has been logged.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } finally { importer.ImportProgressChanged -= Importer_ImportProgressChanged; } }
private bool TryBatchImport() { if (string.IsNullOrWhiteSpace(PathToBatchFolderInput)) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.EnterPathToFolderContainingIroFilesOrModFolders), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!Directory.Exists(PathToBatchFolderInput)) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.DirectoryDoesNotExist), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } ModImporter importer = null; try { importer = new ModImporter(); importer.ImportProgressChanged += Importer_ImportProgressChanged; int modImportCount = 0; foreach (string iro in Directory.GetFiles(PathToBatchFolderInput, "*.iro")) { string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(iro)); importer.Import(iro, modName, true, false); modImportCount++; } foreach (string dir in Directory.GetDirectories(PathToBatchFolderInput)) { string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(dir)); importer.Import(dir, modName, false, false); modImportCount++; } Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.SuccessfullyImported)} {modImportCount} mod(s)!", true)); return(true); } catch (DuplicateModException de) { Logger.Error(de); MessageDialogWindow.Show($"{ResourceHelper.Get(StringKey.CanNotImportMod)}(s). {de.Message}", ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Logger.Error(e); MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } finally { importer.ImportProgressChanged -= Importer_ImportProgressChanged; } }
public void Start() { // Are mods enabled? if (!IsModsEnabled()) { return; } ModImporter.ImportLocalMods(); }
public override void DownloadComplete(System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null) { Sys.Message(new WMessage($"[{StringKey.ErrorDownloading}] {Mod.Name}") { TextTranslationKey = StringKey.ErrorDownloading, LoggedException = e.Error }); Sys.RevertStatus(Mod.ID); return; } InstalledItem inst = Sys.Library.GetItem(Mod.ID); bool isIro = Path.GetExtension(_dest) == ".iro"; string modName = Mod?.Name; if (string.IsNullOrWhiteSpace(modName)) { modName = ModImporter.ParseNameFromFileOrFolder(_dest); } try { Mod = ModImporter.ImportMod(_dest, modName, isIro, noCopy: true); // noCopy set to true because ProcessDownload() already copied the downloaded mod to the 'mods' library folder } catch (Exception ex) { base.Error(ex); return; } if (inst == null) { Sys.Message(new WMessage($"[{StringKey.Installed}] {Mod.Name}") { TextTranslationKey = StringKey.Installed }); } else { Sys.Message(new WMessage($"[{StringKey.Updated}] {Mod.Name}") { TextTranslationKey = StringKey.Updated }); } Sys.SetStatus(Mod.ID, ModStatus.Installed); Sys.SaveLibrary(); }
private bool TryImportFromFolder() { if (string.IsNullOrWhiteSpace(PathToModFolderInput)) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.EnterPathToFolderContainingModFiles), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!Directory.Exists(PathToModFolderInput)) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.DirectoryDoesNotExist), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } ModImporter importer = null; try { string folderName = new DirectoryInfo(PathToModFolderInput).Name; importer = new ModImporter(); importer.ImportProgressChanged += Importer_ImportProgressChanged; importer.Import(PathToModFolderInput, ModImporter.ParseNameFromFileOrFolder(folderName), false, false); Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.SuccessfullyImported)} {folderName}!", true)); return(true); } catch (DuplicateModException de) { Logger.Error(de); MessageDialogWindow.Show($"{ResourceHelper.Get(StringKey.CanNotImportMod)} {de.Message}", ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Logger.Error(e); MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } finally { importer.ImportProgressChanged -= Importer_ImportProgressChanged; } }
private bool TryImportFromFolder() { if (string.IsNullOrWhiteSpace(PathToModFolderInput)) { MessageDialogWindow.Show("Enter a path to a folder containing mod files.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!Directory.Exists(PathToModFolderInput)) { MessageDialogWindow.Show("Directory does not exist.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } ModImporter importer = null; try { string folderName = new DirectoryInfo(PathToModFolderInput).Name; importer = new ModImporter(); importer.ImportProgressChanged += Importer_ImportProgressChanged; importer.Import(PathToModFolderInput, ModImporter.ParseNameFromFileOrFolder(folderName), false, false); Sys.Message(new WMessage($"Successfully imported {folderName}!", true)); return(true); } catch (DuplicateModException de) { Logger.Error(de); MessageDialogWindow.Show($"Can not import mod. {de.Message}", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Logger.Error(e); MessageDialogWindow.Show("Failed to import mod. The error has been logged.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } finally { importer.ImportProgressChanged -= Importer_ImportProgressChanged; } }
private bool TryImportFromIroArchive() { if (string.IsNullOrWhiteSpace(PathToIroArchiveInput)) { MessageDialogWindow.Show("Enter a path to an .iro file.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!File.Exists(PathToIroArchiveInput)) { MessageDialogWindow.Show(".iro file does not exist.", "Validation Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } ModImporter importer = null; try { string fileName = Path.GetFileNameWithoutExtension(PathToIroArchiveInput); importer = new ModImporter(); importer.ImportProgressChanged += Importer_ImportProgressChanged; importer.Import(PathToIroArchiveInput, ModImporter.ParseNameFromFileOrFolder(fileName), true, false); Sys.Message(new WMessage($"Successfully imported {fileName}!")); return(true); } catch (DuplicateModException de) { Logger.Error(de); MessageDialogWindow.Show($"Can not import mod. {de.Message}", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Logger.Error(e); MessageDialogWindow.Show("Failed to import mod. The error has been logged.", "Import Error", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } finally { importer.ImportProgressChanged -= Importer_ImportProgressChanged; } }
internal void LoadModXmlFromIro(string pathToIroFile) { try { Mod parsedMod = new ModImporter().ParseModXmlFromSource(pathToIroFile); if (parsedMod == null) { Sys.Message(new WMessage(ResourceHelper.Get(StringKey.CouldNotLoadModXmlFromIroFile), true)); return; } IDInput = parsedMod.ID.ToString(); NameInput = parsedMod.Name; CategoryInput = ResourceHelper.Get(ModLoadOrder.GetCategoryKey(parsedMod.Category)); AuthorInput = parsedMod.Author; DescriptionInput = parsedMod.Description; VersionInput = parsedMod.LatestVersion.Version.ToString(); MetaVersionInput = "1.00"; PreviewImageInput = ""; TagsInput = ""; InfoLinkInput = parsedMod.Link; ReleaseNotesInput = parsedMod.LatestVersion.ReleaseNotes; ReleaseDateInput = parsedMod.LatestVersion.ReleaseDate.ToString("MM/dd/yyyy"); if (string.IsNullOrWhiteSpace(CategoryInput)) { CategoryInput = ResourceHelper.Get(StringKey.Unknown); } DownloadLinkList.Clear(); AddEmptyDownloadLink(); _modToEdit = null; } catch (Exception e) { Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.CouldNotLoadModXmlFromIroFile)}: {e.Message}", true) { LoggedException = e }); } }
private void LoadModIntoGame(PublishedFileId_t publishedFileId, bool owner) { ulong sizeOnDisk = 0; uint folderSize = 512; char[] temp = new char[folderSize]; string folder = new string(temp); uint timeStamp = 0; uint retval = SteamUGC.GetItemState(publishedFileId); EItemState state = (EItemState)retval; Debug.Log("Item state: " + state.ToString()); if (SteamUGC.GetItemInstallInfo(publishedFileId, out sizeOnDisk, out folder, folderSize, out timeStamp)) { try { foreach (Mod m in ModManager.importedMods) { if (m.path.Contains(folder)) { // Don't load twice return; } } // Register new mod in the ModManager ModImporter.ImportMod(folder, false, owner); } catch (System.Exception e) { Debug.LogWarning($"Failed to import {folder}: {e.Message}"); } } else { Debug.LogWarning("Attempted to load non-installed Steam Workshop item ID " + publishedFileId); } }
private async Task <Library> LoadLibrary(string path) { continueButton.Enabled = false; var versioninfo = new FileInfo(Path.Combine(path, "data", "changelog.txt")); if (!versioninfo.Exists) { statusLabel.Text = Resources.LocationSelector_LoadLibrary_FactorioNotFound; continueButton.Enabled = true; return(null); } browseButton.Enabled = false; locationInput.Enabled = false; var file = versioninfo.OpenText(); file.ReadLine(); var version = file.ReadLine(); File.WriteAllText(FactorioPathPath, path); statusLabel.Text = string.Format(Resources.LocationSelector_LoadLibrary_FactorioFound_Loading, version); var importer = new ModImporter(path); await Task.Run((Action)importer.Load); statusLabel.Text = string.Format(Resources.LocationSelector_LoadLibrary_FactorioFound_Loaded, version); continueButton.Enabled = true; browseButton.Enabled = true; locationInput.Enabled = true; continueButton.Focus(); return(importer.Library); }
internal static void ProcessCommandLineArgs(string[] args, bool closeAfterProcessing = false) { bool hasLaunchCommand = args.Any(s => s.Equals("/LAUNCH", StringComparison.InvariantCultureIgnoreCase)); foreach (string parm in args) { if (parm.StartsWith("iros://", StringComparison.InvariantCultureIgnoreCase)) { App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.AddIrosUrlToSubscriptions(parm); }); } else if (parm.Equals("/MINI", StringComparison.InvariantCultureIgnoreCase)) { App.Current.Dispatcher.Invoke(() => { App.Current.MainWindow.WindowState = WindowState.Minimized; }); } else if (parm.StartsWith("/PROFILE:", StringComparison.InvariantCultureIgnoreCase)) { try { string profileToLoad = Path.Combine(Sys.PathToProfiles, $"{parm.Substring(9)}.xml"); Profile profile = Util.Deserialize <Profile>(profileToLoad); Sys.Settings.CurrentProfile = parm.Substring(9); Sys.ActiveProfile = profile; Sys.Message(new WMessage($"Loaded profile {Sys.Settings.CurrentProfile}")); Sys.ActiveProfile.RemoveDeletedItems(doWarn: true); App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.RefreshProfile(); }); } catch (Exception e) { Sys.Message(new WMessage($"Could not load profile {parm.Substring(9)}", WMessageLogLevel.Error, e)); } } else if (parm.Equals("/LAUNCH", StringComparison.InvariantCultureIgnoreCase)) { App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.LaunchGame(); }); } else if (parm.Equals("/QUIT", StringComparison.InvariantCultureIgnoreCase)) { if (hasLaunchCommand) { bool isGameLaunching = false; App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; isGameLaunching = window.ViewModel.IsGameLaunching; }); while (isGameLaunching || GameLauncher.IsFF7Running()) { Thread.Sleep(10000); // sleep 10 seconds and check again until ff7 not running if (isGameLaunching) { // only need to invoke this until game launcher is finished launching the game App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; isGameLaunching = window.ViewModel.IsGameLaunching; }); } } // wait for ff7 to close before closing down 7th Heaven } ShutdownApp(); } else if (parm.StartsWith("/OPENIRO:", StringComparison.InvariantCultureIgnoreCase)) { string irofile = null; string irofilenoext = null; try { irofile = parm.Substring(9); irofilenoext = Path.GetFileNameWithoutExtension(irofile); Logger.Info("Importing IRO from Windows " + irofile); ModImporter.ImportMod(irofile, ModImporter.ParseNameFromFileOrFolder(irofilenoext), true, false); } catch (Exception ex) { Sys.Message(new WMessage("Mod " + irofilenoext + " failed to import: " + ex.ToString(), true) { LoggedException = ex }); continue; } Sys.Message(new WMessage($"Auto imported mod {irofilenoext}", true)); } else if (parm.StartsWith("/PACKIRO:", StringComparison.InvariantCultureIgnoreCase)) { string pathToFolder; try { pathToFolder = parm.Substring(9); string folderName = new DirectoryInfo(pathToFolder).Name; string parentDir = new DirectoryInfo(pathToFolder).Parent.FullName; PackIroViewModel packViewModel = new PackIroViewModel() { PathToSourceFolder = pathToFolder, PathToOutputFile = Path.Combine(parentDir, $"{folderName}.iro"), }; Sys.Message(new WMessage($"Packing {folderName} into .iro ...", true)); Task packTask = packViewModel.PackIro(); packTask.ContinueWith((result) => { Sys.Message(new WMessage(packViewModel.StatusText, true)); if (closeAfterProcessing) { ShutdownApp(); } }); } catch (Exception e) { Sys.Message(new WMessage($"Failed to pack into .iro", WMessageLogLevel.Error, e) { IsImportant = true }); } } else if (parm.StartsWith("/UNPACKIRO:", StringComparison.InvariantCultureIgnoreCase)) { string pathToIro; try { pathToIro = parm.Substring(11); string fileName = Path.GetFileNameWithoutExtension(pathToIro); string pathToDir = Path.GetDirectoryName(pathToIro); UnpackIroViewModel unpackViewModel = new UnpackIroViewModel() { PathToIroFile = pathToIro, PathToOutputFolder = Path.Combine(pathToDir, fileName), }; Sys.Message(new WMessage($"Unpacking {fileName}.iro into subfolder '{fileName}' ...", true)); Task unpackTask = unpackViewModel.UnpackIro(); unpackTask.ContinueWith((result) => { Sys.Message(new WMessage(unpackViewModel.StatusText, true)); if (closeAfterProcessing) { ShutdownApp(); } }); } catch (Exception e) { Sys.Message(new WMessage($"Failed to unpack .iro", WMessageLogLevel.Error, e) { IsImportant = true }); } } } }
public override void DownloadComplete(System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null) { Sys.Message(new WMessage() { Text = $"Error downloading {Mod.Name}\r\n{e.Error.ToString()}", LoggedException = e.Error }); Sys.RevertStatus(Mod.ID); return; } InstalledItem inst = Sys.Library.GetItem(Mod.ID); if (inst == null) { try { Mod = new ModImporter().ParseModXmlFromSource(_dest, Mod); Sys.Library.AddInstall(new InstalledItem() { ModID = Mod.ID, CachedDetails = Mod, UpdateType = Sys.Library.DefaultUpdate, Versions = new List <InstalledVersion>() { new InstalledVersion() { InstalledLocation = System.IO.Path.GetFileName(_dest), VersionDetails = Mod.LatestVersion } } }); } catch (Exception ex) { base.Error(ex); return; } Sys.Message(new WMessage() { Text = "Installed " + Mod.Name, Link = "iros://" + Mod.ID.ToString() }); Sys.SetStatus(Mod.ID, ModStatus.Installed); } else { try { inst.CachedDetails = new ModImporter().ParseModXmlFromSource(_dest, Mod); // 7H 2.0 NOTE: GeneralOptions.KeepOldVersions is always FALSE and is hidden from the user.. The conditional is kept in-case we ever want to try re-enabling it. if (!Sys.Settings.HasOption(GeneralOptions.KeepOldVersions)) { foreach (string ivfile in inst.Versions.Select(v => v.InstalledLocation)) { string ifile = System.IO.Path.Combine(Sys.Settings.LibraryLocation, ivfile); if (ifile == _dest) { continue; // skip file that was just copied as the new version may have overwritten the old version file so they have the same file name } if (System.IO.File.Exists(ifile)) { System.IO.File.Delete(ifile); } else if (System.IO.Directory.Exists(ifile)) { System.IO.Directory.Delete(ifile, true); } } inst.Versions.Clear(); } inst.Versions.Add(new InstalledVersion() { InstalledLocation = System.IO.Path.GetFileName(_dest), VersionDetails = Mod.LatestVersion }); } catch (Exception ex) { base.Error(ex); return; } Sys.Message(new WMessage() { Text = "Updated " + Mod.Name, Link = "iros://" + Mod.ID.ToString() }); Sys.SetStatus(Mod.ID, ModStatus.Installed); } Sys.Save(); }
public override void DownloadComplete(System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Error != null) { Sys.Message(new WMessage() { Text = "Error downloading " + Mod.Name + "\r\n" + e.Error.ToString() }); Sys.RevertStatus(Mod.ID); } else { //ProcessDownload(file); var inst = Sys.Library.GetItem(Mod.ID); if (inst == null) { Mod = new ModImporter().ParseModXmlFromSource(_dest, Mod); Sys.Library.AddInstall(new InstalledItem() { ModID = Mod.ID, CachedDetails = Mod, UpdateType = Sys.Library.DefaultUpdate, Versions = new List <InstalledVersion>() { new InstalledVersion() { InstalledLocation = System.IO.Path.GetFileName(_dest), VersionDetails = Mod.LatestVersion } } }); Sys.Message(new WMessage() { Text = "Installed " + Mod.Name, Link = "iros://" + Mod.ID.ToString() }); Sys.SetStatus(Mod.ID, ModStatus.Installed); } else { inst.CachedDetails = new ModImporter().ParseModXmlFromSource(_dest, Mod); if (!Sys.Settings.HasOption(GeneralOptions.KeepOldVersions)) { foreach (string ivfile in inst.Versions.Select(v => v.InstalledLocation)) { string ifile = System.IO.Path.Combine(Sys.Settings.LibraryLocation, ivfile); if (System.IO.File.Exists(ifile)) { System.IO.File.Delete(ifile); } else if (System.IO.Directory.Exists(ifile)) { System.IO.Directory.Delete(ifile, true); } } inst.Versions.Clear(); } inst.Versions.Add(new InstalledVersion() { InstalledLocation = System.IO.Path.GetFileName(_dest), VersionDetails = Mod.LatestVersion }); Sys.Message(new WMessage() { Text = "Updated " + Mod.Name, Link = "iros://" + Mod.ID.ToString() }); Sys.SetStatus(Mod.ID, ModStatus.Installed); } Sys.Save(); } }
private bool TryImportFromIroArchive() { if (string.IsNullOrWhiteSpace(PathToIroArchiveInput)) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.EnterPathToAnIroFile), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } if (!File.Exists(PathToIroArchiveInput)) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.IroFileDoesNotExist), ResourceHelper.Get(StringKey.ValidationError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } bool isPatchFile = Path.GetExtension(PathToIroArchiveInput) == ".irop"; ModImporter importer = null; try { importer = new ModImporter(); importer.ImportProgressChanged += Importer_ImportProgressChanged; string fileName = Path.GetFileNameWithoutExtension(PathToIroArchiveInput); if (isPatchFile) { bool didPatch = importer.ImportModPatch(PathToIroArchiveInput); if (!didPatch) { MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } Sys.Message(new WMessage($"Successfully applied patch {fileName}!")); } else { importer.Import(PathToIroArchiveInput, ModImporter.ParseNameFromFileOrFolder(fileName), true, false); Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.SuccessfullyImported)} {fileName}!")); } return(true); } catch (DuplicateModException de) { Logger.Error(de); MessageDialogWindow.Show($"{ResourceHelper.Get(StringKey.CanNotImportMod)} {de.Message}", ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } catch (Exception e) { Logger.Error(e); MessageDialogWindow.Show(ResourceHelper.Get(StringKey.FailedToImportModTheErrorHasBeenLogged), ResourceHelper.Get(StringKey.ImportError), MessageBoxButton.OK, MessageBoxImage.Error); return(false); } finally { importer.ImportProgressChanged -= Importer_ImportProgressChanged; } }
internal static void ProcessCommandLineArgs(string[] args, bool closeAfterProcessing = false) { bool hasLaunchCommand = args.Any(s => s.Equals("/LAUNCH", StringComparison.InvariantCultureIgnoreCase)); foreach (string parm in args) { if (parm.StartsWith("iros://", StringComparison.InvariantCultureIgnoreCase)) { // check if its a catalog url or a mod download url if (parm.StartsWith("iros://mod/")) { App.Current.Dispatcher.Invoke(() => { Mod newMod = new Mod() { Name = Path.GetFileName(parm), ID = Guid.NewGuid(), LatestVersion = new ModVersion() { Links = new System.Collections.Generic.List <string>() { parm.Replace("iros://mod/", "iros://") }, Version = 1, }, }; Install.DownloadAndInstall(newMod); MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.SelectedTabIndex = 1; }); } else { App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.AddIrosUrlToSubscriptions(parm); }); } } else if (parm.Equals("/MINI", StringComparison.InvariantCultureIgnoreCase)) { App.Current.Dispatcher.Invoke(() => { App.Current.MainWindow.WindowState = WindowState.Minimized; }); } else if (parm.StartsWith("/PROFILE:", StringComparison.InvariantCultureIgnoreCase)) { try { string profileToLoad = Path.Combine(Sys.PathToProfiles, $"{parm.Substring(9)}.xml"); Profile profile = Util.Deserialize <Profile>(profileToLoad); Sys.Settings.CurrentProfile = parm.Substring(9); Sys.ActiveProfile = profile; Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.LoadedProfile)} {Sys.Settings.CurrentProfile}")); Sys.ActiveProfile.RemoveDeletedItems(doWarn: true); App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.RefreshProfile(); }); } catch (Exception e) { Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.CouldNotLoadProfile)} {parm.Substring(9)}", WMessageLogLevel.Error, e)); } } else if (parm.Equals("/LAUNCH", StringComparison.InvariantCultureIgnoreCase)) { App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; window.ViewModel.LaunchGame(); }); } else if (parm.Equals("/QUIT", StringComparison.InvariantCultureIgnoreCase)) { if (hasLaunchCommand) { bool isGameLaunching = false; App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; isGameLaunching = window.ViewModel.IsGameLaunching; }); while (isGameLaunching || GameLauncher.IsFF7Running()) { Thread.Sleep(10000); // sleep 10 seconds and check again until ff7 not running if (isGameLaunching) { // only need to invoke this until game launcher is finished launching the game App.Current.Dispatcher.Invoke(() => { MainWindow window = App.Current.MainWindow as MainWindow; isGameLaunching = window.ViewModel.IsGameLaunching; }); } } // wait for ff7 to close before closing down 7th Heaven } ShutdownApp(); } else if (parm.StartsWith("/OPENIRO:", StringComparison.InvariantCultureIgnoreCase)) { string irofile = null; string irofilenoext = null; try { irofile = parm.Substring(9); irofilenoext = Path.GetFileNameWithoutExtension(irofile); Logger.Info("Importing IRO from Windows " + irofile); ModImporter.ImportMod(irofile, ModImporter.ParseNameFromFileOrFolder(irofilenoext), true, false); } catch (Exception ex) { Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.FailedToImportMod)} {irofilenoext}: {ex.Message}", true) { LoggedException = ex }); continue; } Sys.Message(new WMessage($"{ResourceHelper.Get(StringKey.AutoImportedMod)} {irofilenoext}", true)); } else if (parm.StartsWith("/OPENIROP:", StringComparison.InvariantCultureIgnoreCase)) { string iropFile = null; var importer = new ModImporter(); try { iropFile = parm.Substring(10); Sys.Message(new WMessage($"Applying patch file {iropFile}", true)); importer.ImportProgressChanged += ModPatchImportProgressChanged; bool didPatch = importer.ImportModPatch(iropFile); if (didPatch) { Sys.Message(new WMessage($"Applied patch {iropFile}", true)); } else { Sys.Message(new WMessage($"Failed to apply patch {iropFile}. Check applog for details.", true)); } } catch (Exception ex) { Sys.Message(new WMessage($"Failed to apply patch {iropFile}: {ex.Message}", true) { LoggedException = ex }); continue; } finally { importer.ImportProgressChanged -= ModPatchImportProgressChanged; } } else if (parm.StartsWith("/PACKIRO:", StringComparison.InvariantCultureIgnoreCase)) { string pathToFolder; try { pathToFolder = parm.Substring(9); string folderName = new DirectoryInfo(pathToFolder).Name; string parentDir = new DirectoryInfo(pathToFolder).Parent.FullName; PackIroViewModel packViewModel = new PackIroViewModel() { PathToSourceFolder = pathToFolder, PathToOutputFile = Path.Combine(parentDir, $"{folderName}.iro"), }; Sys.Message(new WMessage(string.Format(ResourceHelper.Get(StringKey.PackingIntoIro), folderName), true)); Task packTask = packViewModel.PackIro(); packTask.ContinueWith((result) => { Sys.Message(new WMessage(packViewModel.StatusText, true)); if (closeAfterProcessing) { ShutdownApp(); } }); } catch (Exception e) { Sys.Message(new WMessage(ResourceHelper.Get(StringKey.FailedToPackIntoIro), WMessageLogLevel.Error, e) { IsImportant = true }); } } else if (parm.StartsWith("/UNPACKIRO:", StringComparison.InvariantCultureIgnoreCase)) { string pathToIro; try { pathToIro = parm.Substring(11); string fileName = Path.GetFileNameWithoutExtension(pathToIro); string pathToDir = Path.GetDirectoryName(pathToIro); UnpackIroViewModel unpackViewModel = new UnpackIroViewModel() { PathToIroFile = pathToIro, PathToOutputFolder = Path.Combine(pathToDir, fileName), }; Sys.Message(new WMessage(string.Format(ResourceHelper.Get(StringKey.UnpackingIroIntoSubfolder), fileName), true)); Task unpackTask = unpackViewModel.UnpackIro(); unpackTask.ContinueWith((result) => { Sys.Message(new WMessage(unpackViewModel.StatusText, true)); if (closeAfterProcessing) { ShutdownApp(); } }); } catch (Exception e) { Sys.Message(new WMessage(ResourceHelper.Get(StringKey.FailedToUnpackIro), WMessageLogLevel.Error, e) { IsImportant = true }); } } } }
public static void ExportBundle(string source) { string dest = Path.Combine(ModManager.GetModsfolderPath(), $"modfile_{Path.GetFileName(source)}"); Debug.Log($"Exporting Mod: Source: \"{source}\", Target: \"{dest}\""); // Get Files and convert absolute paths to relative paths (required by the buildmap) string[] absolute_files = Directory.GetFiles(source).Where(name => !name.EndsWith(".meta") && !name.EndsWith(".cs")).ToArray(); string[] files = new string[absolute_files.Length]; if (files.Length > 0) { int index = absolute_files[0].IndexOf("Assets"); for (int i = 0; i < files.Length; i++) { files[i] = absolute_files[i].Substring(index); } } if (!CheckHasHolder(files)) { throw new System.Exception($"Failed to export \"{Path.GetDirectoryName(source)}\". Make sure you have an appropriate holder included!"); } // Prepare Bundle AssetBundleBuild[] build_map = new AssetBundleBuild[1]; build_map[0].assetNames = files; // Build Folder / Bundle Directory.CreateDirectory(dest); foreach (var target in new Dictionary <OperatingSystemFamily, BuildTarget> { { OperatingSystemFamily.Windows, BuildTarget.StandaloneWindows64 }, { OperatingSystemFamily.Linux, BuildTarget.StandaloneLinux64 }, { OperatingSystemFamily.MacOSX, BuildTarget.StandaloneOSX } }) { build_map[0].assetBundleName = $"{Path.GetFileName(source)}_{target.Key}"; BuildPipeline.BuildAssetBundles(dest, build_map, BuildAssetBundleOptions.None, target.Value); } // Clean out manifest files and bundle holder try { if (Directory.GetFiles(dest).Count() > 10) // FAILSAFE { throw new System.ArgumentException($"failsafe triggered: too many files found in mod folder! Skipping deletion of unneeded files!"); } File.Delete(Path.Combine(dest, Path.GetFileName(dest))); foreach (var manifest in Directory.GetFiles(dest, "*.manifest", SearchOption.TopDirectoryOnly)) { File.Delete(Path.Combine(dest, manifest)); } } catch (System.UnauthorizedAccessException) { Debug.LogWarning("Unauthorized to delete obsolete files in the exported mod. These files are not needed and don't need to be removed manually."); } catch (System.ArgumentException e) { Debug.LogError(e); } // Make Thumbnail GameObject thumbnailMakerPrefab = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>("Assets/ThumbnailMaker.prefab"); if (thumbnailMakerPrefab) { Mod mod = ModImporter.ImportModNow(dest, true); string lastScene = EditorSceneManager.GetActiveScene().path; int lastBuildIndex = EditorSceneManager.GetActiveScene().buildIndex; // Create scene Scene thumbnailScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); ThumbnailMaker thumbnailMaker = Instantiate(thumbnailMakerPrefab).GetComponent <ThumbnailMaker>(); File.WriteAllBytes(mod.GetThumbnailPath(), thumbnailMaker.CreateThumbnail(mod).EncodeToJPG(90)); // Cleanup if (lastBuildIndex >= 0) { EditorSceneManager.OpenScene(lastScene, OpenSceneMode.Single); } else { EditorSceneManager.OpenScene(EditorSceneManager.GetSceneByBuildIndex(0).path); } } Debug.Log($"Export Completed. Name: \"{Path.GetFileName(source)}\" with {files.Length} files"); }
public static void TryAutoImportMods() { if (Sys.Settings.HasOption(GeneralOptions.AutoImportMods) && Directory.Exists(Sys.Settings.LibraryLocation)) { foreach (string folder in Directory.GetDirectories(Sys.Settings.LibraryLocation)) { string name = Path.GetFileName(folder); if (!name.EndsWith("temp", StringComparison.InvariantCultureIgnoreCase) && !Sys.Library.PendingDelete.Contains(name, StringComparer.InvariantCultureIgnoreCase)) { if (!Sys.Library.Items.SelectMany(ii => ii.Versions).Any(v => v.InstalledLocation.Equals(name, StringComparison.InvariantCultureIgnoreCase))) { Sys.Message(new WMessage("Trying to auto-import file " + folder, WMessageLogLevel.LogOnly)); try { string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(folder)); ModImporter.ImportMod(folder, modName, false, true); } catch (Exception ex) { Sys.Message(new WMessage($"[{StringKey.FailedToImportMod}] {name}: " + ex.ToString(), true) { TextTranslationKey = StringKey.FailedToImportMod, LoggedException = ex }); continue; } Sys.Message(new WMessage() { Text = $"[{StringKey.AutoImportedMod}] {name}", TextTranslationKey = StringKey.AutoImportedMod }); } } } foreach (string iro in Directory.GetFiles(Sys.Settings.LibraryLocation, "*.iro")) { string name = Path.GetFileName(iro); if (!name.EndsWith("temp", StringComparison.InvariantCultureIgnoreCase) && !Sys.Library.PendingDelete.Contains(name, StringComparer.InvariantCultureIgnoreCase)) { if (!Sys.Library.Items.SelectMany(ii => ii.Versions).Any(v => v.InstalledLocation.Equals(name, StringComparison.InvariantCultureIgnoreCase))) { Sys.Message(new WMessage($"Trying to auto-import file {iro}", WMessageLogLevel.LogOnly)); try { string modName = ModImporter.ParseNameFromFileOrFolder(Path.GetFileNameWithoutExtension(iro)); ModImporter.ImportMod(iro, modName, true, true); } catch (_7thWrapperLib.IrosArcException ae) { Sys.Message(new WMessage($"[{StringKey.CouldNotImportIroFileIsCorrupt}] - {Path.GetFileNameWithoutExtension(iro)}", true) { TextTranslationKey = StringKey.CouldNotImportIroFileIsCorrupt, LoggedException = ae }); continue; } catch (Exception ex) { Sys.Message(new WMessage($"[{StringKey.FailedToImportMod}] {name}: " + ex.ToString(), true) { TextTranslationKey = StringKey.FailedToImportMod, LoggedException = ex }); continue; } Sys.Message(new WMessage() { Text = $"[{StringKey.AutoImportedMod}] {name}", TextTranslationKey = StringKey.AutoImportedMod }); } } } } // validate imported mod files exist - remove them if they do not exist ValidateAndRemoveDeletedMods(); Sys.Library.AttemptDeletions(); }