Example #1
0
        private void SelectWindowStartup()
        {
            //switch into application modes based on mode enum
            Logging.Debug("Starting application in {0} mode", CommandLineSettings.ApplicationMode.ToString());
            switch (CommandLineSettings.ApplicationMode)
            {
            case ApplicationMode.Updater:
                ModpackToolbox updater = new ModpackToolbox(modpackSettings)
                {
                    CommandLineSettings = CommandLineSettings
                };

                //close application log if open
                if (Logging.IsLogOpen(Logfiles.Application))
                {
                    CloseApplicationLog(true);
                }

                //start updater logging
                if (!Logging.Init(Logfiles.Updater, modpackSettings.VerboseLogging, true))
                {
                    MessageBox.Show("Failed to initialize logfile for updater");
                    Current.Shutdown((int)ReturnCodes.LogfileError);
                    return;
                }
                Logging.WriteHeader(Logfiles.Updater);

                //redirect application log file to the modpack toolbox
                if (!Logging.RedirectLogOutput(Logfiles.Application, Logfiles.Updater))
                {
                    Logging.Error(Logfiles.Updater, LogOptions.MethodName, "Failed to redirect messages from application to modpack toolbox");
                }

                //show window
                updater.Show();
                break;

            case ApplicationMode.Editor:
                DatabaseEditor editor = new DatabaseEditor(modpackSettings)
                {
                    CommandLineSettings = CommandLineSettings
                };

                //close application log if open
                if (Logging.IsLogOpen(Logfiles.Application))
                {
                    CloseApplicationLog(true);
                }

                //start updater logging
                if (!Logging.Init(Logfiles.Editor, modpackSettings.VerboseLogging, true))
                {
                    MessageBox.Show("Failed to initialize logfile for editor");
                    Current.Shutdown((int)ReturnCodes.LogfileError);
                    return;
                }
                Logging.WriteHeader(Logfiles.Editor);

                //redirect application log file to the editor
                if (!Logging.RedirectLogOutput(Logfiles.Application, Logfiles.Editor))
                {
                    Logging.Error(Logfiles.Editor, LogOptions.MethodName, "Failed to redirect messages from application to editor");
                }

                //show window
                editor.Show();
                break;

            case ApplicationMode.PatchDesigner:
                PatchDesigner patcher = new PatchDesigner(modpackSettings)
                {
                    CommandLineSettings = CommandLineSettings
                };

                //close application log if open
                if (Logging.IsLogOpen(Logfiles.Application))
                {
                    CloseApplicationLog(true);
                }

                //start updater logging
                if (!Logging.Init(Logfiles.PatchDesigner, modpackSettings.VerboseLogging, true))
                {
                    MessageBox.Show("Failed to initialize logfile for patcher");
                    Current.Shutdown((int)ReturnCodes.LogfileError);
                    return;
                }
                Logging.WriteHeader(Logfiles.PatchDesigner);

                //redirect application log file to the patch designer
                if (!Logging.RedirectLogOutput(Logfiles.Application, Logfiles.PatchDesigner))
                {
                    Logging.Error(Logfiles.PatchDesigner, LogOptions.MethodName, "Failed to redirect messages from application to patch designer");
                }

                //show window
                patcher.Show();
                break;

            case ApplicationMode.AutomationRunner:
                DatabaseAutomationRunner automationRunner = new DatabaseAutomationRunner(modpackSettings)
                {
                    CommandLineSettings = CommandLineSettings
                };

                //close application log if open
                if (Logging.IsLogOpen(Logfiles.Application))
                {
                    CloseApplicationLog(true);
                }

                //start DatabaseAutomationRunner logging
                if (!Logging.Init(Logfiles.AutomationRunner, modpackSettings.VerboseLogging, true))
                {
                    MessageBox.Show("Failed to initialize logfile for DatabaseAutomationRunner");
                    Current.Shutdown((int)ReturnCodes.LogfileError);
                    return;
                }
                Logging.WriteHeader(Logfiles.AutomationRunner);

                //redirect application log file to the automation runner
                if (!Logging.RedirectLogOutput(Logfiles.Application, Logfiles.AutomationRunner))
                {
                    Logging.Error(Logfiles.AutomationRunner, LogOptions.MethodName, "Failed to redirect messages from application to automation runner");
                }

                //show window
                automationRunner.Show();
                break;

            case ApplicationMode.Patcher:
                //check that at least one patch file was specified from command line
                if (CommandLineSettings.PatchFilenames.Count == 0)
                {
                    Logging.Error("0 patch files parsed from command line!");
                    Current.Shutdown((int)ReturnCodes.PatcherNoSpecifiedFiles);
                    Environment.Exit((int)ReturnCodes.PatcherNoSpecifiedFiles);
                }
                else
                {
                    //parse patch objects from command line file list
                    List <Instruction> patchList = new List <Instruction>();
                    InstructionLoader  loader    = new InstructionLoader();
                    foreach (string file in CommandLineSettings.PatchFilenames)
                    {
                        if (!File.Exists(file))
                        {
                            Logging.Warning("Skipping file path {0}, not found", file);
                            continue;
                        }
                        Logging.Info("Adding patches from file {0}", file);
                        loader.AddInstructionObjectsToList(file, patchList, InstructionsType.Patch, Patch.PatchXmlSearchPath);
                    }

                    //check for at least one patchfile was parsed
                    if (patchList.Count == 0)
                    {
                        Logging.Error("0 patches parsed from files!");
                        Current.Shutdown((int)ReturnCodes.PatcherNoPatchesParsed);
                        Environment.Exit((int)ReturnCodes.PatcherNoPatchesParsed);
                    }

                    //set default patch return code
                    PatcherExitCode = PatchExitCode.Success;

                    //always return on worst condition
                    int i = 1;
                    //TODO: does WoTDirectory get set later? maybe tm?
                    Patcher thePatcher = new Patcher()
                    {
                        WoTDirectory = null
                    };
                    foreach (Patch p in patchList)
                    {
                        Logging.Info("Running patch {0} of {1}", i++, patchList.Count);
                        PatchExitCode exitCodeTemp = thePatcher.RunPatchFromCommandline(p);
                        if ((int)exitCodeTemp < (int)PatcherExitCode)
                        {
                            PatcherExitCode = exitCodeTemp;
                        }
                    }
                }
                break;

            case ApplicationMode.Default:
                MainWindow window = new MainWindow(modpackSettings)
                {
                    CommandLineSettings = CommandLineSettings
                };
                window.Show();
                break;
            }
        }
Example #2
0
        private void FinishApplicationInit()
        {
            Logging.WriteHeader(Logfiles.Application);
            Logging.Info(string.Format("| Relhax Modpack version {0}", CommonUtils.GetApplicationVersion()));
            Logging.Info(string.Format("| Build version {0}, from date {1}", ApplicationConstants.ApplicationVersion.ToString(), CommonUtils.GetCompileTime()));
            Logging.Info(string.Format("| Running on OS {0}", Environment.OSVersion.ToString()));

            //parse command line arguments given to the application
            Logging.Info("Parsing command line switches");
            CommandLineSettings.ParseCommandLineSwitches();

            //load the ModpackSettings from xml file
            SettingsParser settingsParser = new SettingsParser();

            settingsParser.LoadSettings(modpackSettings);

            //set verbose logging option
            bool verboseSettingForLogfile = modpackSettings.VerboseLogging;

            if (ApplicationConstants.ApplicationVersion != ApplicationVersions.Stable)
            {
                verboseSettingForLogfile = true;
            }
            Logging.GetLogfile(Logfiles.Application).VerboseLogging = verboseSettingForLogfile;

            //run a check for a valid .net framework version, only if we're opening MainWindow, and the version
            //of the .net framework installed has not yet been detected to be 4.8
            if ((!CommandLineSettings.ArgsOpenCustomWindow()) && (!modpackSettings.ValidFrameworkVersion))
            {
                //https://github.com/Willster419/RelhaxModpack/issues/90
                //try getting .net framework information
                //https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
                //https://docs.microsoft.com/en-us/dotnet/api/system.environment.version?view=netcore-3.1
                //https://stackoverflow.com/questions/19096841/how-to-get-the-version-of-the-net-framework-being-targeted
                Logging.Debug(".NET Framework version information");
                int frameworkVersion = -1;
                try
                {
                    RegistryKey key = RegistryUtils.GetRegistryKeys(new RegistrySearch()
                    {
                        Root = Registry.LocalMachine, Searchpath = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
                    });
                    Logging.Debug("Registry: {0}", key.Name);
                    foreach (string subkey in key.GetValueNames())
                    {
                        object value = key.GetValue(subkey);
                        Logging.Debug("Registry: Subkey={0}, Value={1}", subkey, value.ToString());
                        if (subkey.ToLower().Equals("release"))
                        {
                            if (int.TryParse(value.ToString(), out int result))
                            {
                                frameworkVersion = result;
                            }
                            else
                            {
                                Logging.Error("Unable to parse release value: {0}", value);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.Exception(ex.ToString());
                }

                Logging.Info("Minimum required .NET Framework version: {0}, Installed: {1}", ApplicationConstants.MinimumDotNetFrameworkVersionRequired, frameworkVersion);

                if (frameworkVersion == -1)
                {
                    Logging.Error("Failed to get .NET Framework version from the registry");
                    MessageBox.Show("failedToGetDotNetFrameworkVersion");
                }
                else if (frameworkVersion < ApplicationConstants.MinimumDotNetFrameworkVersionRequired)
                {
                    Logging.Error("Invalid .NET Framework version (less then 4.8)");
                    if (MessageBox.Show("invalidDotNetFrameworkVersion", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        CommonUtils.StartProcess(ApplicationConstants.DotNetFrameworkLatestDownloadURL);
                    }
                }
                else
                {
                    Logging.Info("Valid .NET Framework version");
                    modpackSettings.ValidFrameworkVersion = true;
                }
            }
        }