Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
            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();
            }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
        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;
            }
        }
Esempio n. 6
0
        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;
            }
        }
Esempio n. 7
0
        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
                        });
                    }
                }
            }
        }
Esempio n. 8
0
File: Sys.cs Progetto: Erendel/7h
        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();
        }
Esempio n. 9
0
        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;
            }
        }
Esempio n. 10
0
        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
                        });
                    }
                }
            }
        }