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 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); } }
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 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(); }
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 }); } } } }