private void InitSettingsAndLogging() { CommandLineSettings = new CommandLineSettings(Environment.GetCommandLineArgs().Skip(1).ToArray()); modpackSettings = new ModpackSettings(); if (!Logging.Init(Logfiles.Application, false, !CommandLineSettings.ArgsOpenCustomWindow())) { //check if it's because the file already exists, or some other actual reason //if the file exists, and it's locked (init failed), then check if also the command line is creating a new window if (File.Exists(Logging.GetLogfile(Logfiles.Application).Filepath) && CommandLineSettings.ArgsOpenCustomWindow()) { //getting here means the main window is open, but in this instance, a custom window will be open. We can temporarily //open the log in a custom name (with the application mode), and when opening the 'real' logfile for the custom window, //we'll transfer the text over then Logging.DisposeLogging(Logfiles.Application); if (!Logging.Init(Logfiles.Application, false, false, Logging.ApplicationTempLogFilename)) { MessageBox.Show(string.Format("Failed to initialize logfile {0}, check file permissions", Logging.ApplicationTempLogFilename)); Shutdown((int)ReturnCodes.LogfileError); return; } } else { if (!Translations.TranslationsLoaded) { Translations.LoadTranslations(false); } //old message from Logging.Init //MessageBox.Show(string.Format("Failed to initialize logfile {0}, check file permissions", logfilePath)); MessageBox.Show(Translations.GetTranslatedString("appFailedCreateLogfile")); Shutdown((int)ReturnCodes.LogfileError); return; } } }
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; } } }