public UnpackIroUserControl()
        {
            InitializeComponent();

            ViewModel        = new UnpackIroViewModel();
            this.DataContext = ViewModel;
        }
Beispiel #2
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
                        });
                    }
                }
            }
        }
Beispiel #3
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
                        });
                    }
                }
            }
        }