public Configuration(IEnumerable <string> args) { Arguments = new ApplicationArguments(); Localization = new ApplicationLocalization(); LocalizationsList = new Dictionary <string, ApplicationLocalization>(); Parser.Default.ParseArguments <ApplicationArguments>(args).WithParsed(arguments => Arguments = arguments); McDirectory = Path.Combine(Application.StartupPath, ".minecraft"); McLauncher = Path.Combine(McDirectory, "Launcher"); McVersions = Path.Combine(McDirectory, "versions"); McLibs = Path.Combine(McDirectory, "libraries"); _configurationFile = McLauncher + @"\configuration.json"; ApplicationConfiguration = GetConfiguration(); LoadLocalization(); }
public Configuration(IEnumerable <string> args) { Arguments = new ApplicationArguments(); Localization = new ApplicationLocalization(); LocalizationsList = new Dictionary <string, ApplicationLocalization>(); Parser.Default.ParseArguments <ApplicationArguments>(args).WithParsed(arguments => Arguments = arguments); McDirectory = Arguments.WorkingDirectory ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft"); McLauncher = Path.Combine(McDirectory, "freelauncher"); McVersions = Path.Combine(McDirectory, "versions"); McLibs = Path.Combine(McDirectory, "libraries"); _configurationFile = McLauncher + @"\configuration.json"; ApplicationConfiguration = GetConfiguration(); LoadLocalization(); }
private static void VersionCheck(string[] args) { Configuration configuration = new Configuration(args); _configuration = configuration; ApplicationConfiguration _cfg = _configuration.ApplicationConfiguration; ApplicationLocalization localization = _configuration.Localization; string Updatefoundtext = localization.Updatefound; string Updateinfotext = localization.UpdateInfo; string Updatelangtext = localization.UpdateLang; ServicePointManager.Expect100Continue = true; //win7 fix ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //win7 fix //Thanks stackoverflow: https://stackoverflow.com/a/32421479 SplashScreen = new Forms.Splash.SplashForm(); var splashThread = new System.Threading.Thread(new System.Threading.ThreadStart( () => Application.Run(SplashScreen))); splashThread.SetApartmentState(System.Threading.ApartmentState.STA); splashThread.Start(); MainForm = new LauncherForm(configuration); MainForm.Load += MainForm_LoadCompleted; using (WebClient client = new WebClient()) { client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); XmlUpdateFileDoc.LoadXml(client.DownloadString("https://raw.githubusercontent.com/rakion99/minecraftlauncher/gh-pages/Updater.xml"));//for some reason if i use https://rakion99.github.io/minecraftlauncher/Updater.xml takes ages to get the file } if ((WindowsCurrentUILang == "en" && !File.Exists("./Launcher-langs/en_UK.json")) || (_configuration.ApplicationConfiguration.SelectedLanguage == "en_UK" && !File.Exists("./Launcher-langs/en_UK.json"))) { UpdateLang = "en_UK"; Langnotfound = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } if ((WindowsCurrentUILang == "es" && !File.Exists("./Launcher-langs/es_MX.json")) || (_configuration.ApplicationConfiguration.SelectedLanguage == "es_MX" && !File.Exists("./Launcher-langs/es_MX.json"))) { UpdateLang = "es_MX"; Langnotfound = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } if (File.Exists("./Launcher-langs/en_UK.json")) { langen_UK = true; } if (File.Exists("./Launcher-langs/es_MX.json")) { langes_MX = true; } if (!_configuration.Arguments.OfflineMode) { _configuration.Arguments.OfflineMode = !CheckForInternetConnection; } if (_cfg.CheckforLauncherUpdates && !_configuration.Arguments.OfflineMode) { try { string UICurrentVerion = Application.ProductVersion; string LauncherXmlVersion = XmlGetSingleNode("/Launcher/version"); if (LauncherXmlVersion != UICurrentVerion) { string UIUpdateFound = string.Format(Updateinfotext, UICurrentVerion, LauncherXmlVersion); DialogResult UIUpdaterChecker = CustomRadMessagebox(UIUpdateFound, Updatefoundtext, MessageBoxButtons.YesNo, RadMessageIcon.Info, MessageBoxDefaultButton.Button1); if (UIUpdaterChecker == DialogResult.Yes) { UpdateLauncher = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } if (langen_UK) { string localen_UKSHA384 = GetSHA384("./Launcher-langs/en_UK.json"); if (XmlGetSingleNode("/Launcher/Languages/en_UK/SHA384") != localen_UKSHA384) { string Updatelangen_UK = string.Format(Updatelangtext, "en_UK"); DialogResult DLLUpdaterChecker = CustomRadMessagebox(Updatelangen_UK, Updatefoundtext, MessageBoxButtons.YesNo, RadMessageIcon.Info, MessageBoxDefaultButton.Button1); if (DLLUpdaterChecker == DialogResult.Yes) { UpdateLang = "en_UK"; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } } if (langes_MX) { string locales_MXSHA384 = GetSHA384("./Launcher-langs/es_MX.json"); if (XmlGetSingleNode("/Launcher/Languages/es_MX/SHA384") != locales_MXSHA384) { string Updatelanges_MX = string.Format(Updatelangtext, "es_MX"); DialogResult DLLUpdaterChecker = CustomRadMessagebox(Updatelanges_MX, Updatefoundtext, MessageBoxButtons.YesNo, RadMessageIcon.Info, MessageBoxDefaultButton.Button1); if (DLLUpdaterChecker == DialogResult.Yes) { UpdateLang = "es_MX"; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } } } catch (WebException wex) { if (wex.Status == WebExceptionStatus.ProtocolError) { if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound) { CustomRadMessagebox("Something happened and updater got error 404", "Update Checker Web 404", MessageBoxButtons.OK, RadMessageIcon.Error); } } else if (wex.Response == null) { CustomRadMessagebox("Can't connect because the update server is down, you dont have an internet connection or something is blocking it", "Update Checker Can't connect", MessageBoxButtons.OK, RadMessageIcon.Error); } else { CustomRadMessagebox($"{wex.Message}", "Update Checker Web Exception", MessageBoxButtons.OK, RadMessageIcon.Error); } } catch (Exception ex) { CustomRadMessagebox($"{ex.Message}\n{ex.StackTrace}", "Update Checker Fatal Exception", MessageBoxButtons.OK, RadMessageIcon.Error); } } Application.Run(MainForm); configuration.SaveConfiguration(); }
private static void VersionCheck(string[] args) { Configuration configuration = new Configuration(args); _configuration = configuration; ApplicationConfiguration _cfg = _configuration.ApplicationConfiguration; ApplicationLocalization localization = _configuration.Localization; string Updatefoundtext = localization.Updatefound; string Updateinfotext = localization.UpdateInfo; string Updatelangtext = localization.UpdateLang; string Javanotfound = localization.Javanotfound; string Javadownloadexit = localization.Javadownloadexit; string Javaupdatefound = localization.Javaupdatefound; string Javaupdateinfo = localization.Javaupdateinfo; ServicePointManager.Expect100Continue = true; //win7 fix ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //win7 fix using (WebClient client = new WebClient()) { client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore); XmlUpdateFileDoc.LoadXml(client.DownloadString("https://raw.githubusercontent.com/rakion99/minecraftlauncher/gh-pages/Updater.xml"));//for some reason if i use https://rakion99.github.io/minecraftlauncher/Updater.xml takes ages to get the file } if ((WindowsCurrentUILang == "en" && !File.Exists("./Launcher-langs/en_UK.json")) || (_configuration.ApplicationConfiguration.SelectedLanguage == "en_UK" && !File.Exists("./Launcher-langs/en_UK.json"))) { UpdateLang = "en_UK"; Langnotfound = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } if ((WindowsCurrentUILang == "es" && !File.Exists("./Launcher-langs/es_MX.json")) || (_configuration.ApplicationConfiguration.SelectedLanguage == "es_MX" && !File.Exists("./Launcher-langs/es_MX.json"))) { UpdateLang = "es_MX"; Langnotfound = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } if (File.Exists("./Launcher-langs/en_UK.json")) { langen_UK = true; } if (File.Exists("./Launcher-langs/es_MX.json")) { langes_MX = true; } if (!_configuration.Arguments.OfflineMode) { _configuration.Arguments.OfflineMode = !CheckForInternetConnection; } if (!Java.IsJavaDownloaded) { if (Environment.Is64BitOperatingSystem) { DialogResult WantDownloadJava64 = MessageBox.Show(Javadownloadexit, Javanotfound, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (WantDownloadJava64 == DialogResult.OK) { DownloadJava64bit = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } else { Environment.Exit(0); } } else { DialogResult WantDownloadJava32 = MessageBox.Show(Javadownloadexit, Javanotfound, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (WantDownloadJava32 == DialogResult.OK) { DownloadJava32bit = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } else { Environment.Exit(0); } } } if (_cfg.CheckforLauncherUpdates && !_configuration.Arguments.OfflineMode) { try { string UICurrentVerion = Application.ProductVersion; string LauncherXmlVersion = XmlGetSingleNode("/Launcher/version"); if (LauncherXmlVersion != UICurrentVerion) { string UIUpdateFound = string.Format(Updateinfotext, UICurrentVerion, LauncherXmlVersion); DialogResult UIUpdaterChecker = MessageBox.Show(UIUpdateFound, Updatefoundtext, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (UIUpdaterChecker == DialogResult.Yes) { UpdateLauncher = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } if (langen_UK) { string localen_UKSHA384 = GetSHA384("./Launcher-langs/en_UK.json"); if (XmlGetSingleNode("/Launcher/Languages/en_UK/SHA384") != localen_UKSHA384) { string Updatelangen_UK = string.Format(Updatelangtext, "en_UK"); DialogResult DLLUpdaterChecker = MessageBox.Show(Updatelangen_UK, Updatefoundtext, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (DLLUpdaterChecker == DialogResult.Yes) { UpdateLang = "en_UK"; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } } if (langes_MX) { string locales_MXSHA384 = GetSHA384("./Launcher-langs/es_MX.json"); if (XmlGetSingleNode("/Launcher/Languages/es_MX/SHA384") != locales_MXSHA384) { string Updatelanges_MX = string.Format(Updatelangtext, "es_MX"); DialogResult DLLUpdaterChecker = MessageBox.Show(Updatelanges_MX, Updatefoundtext, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (DLLUpdaterChecker == DialogResult.Yes) { UpdateLang = "es_MX"; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } } string JavaXmlVersion = XmlGetSingleNode("/Launcher/Java/JavaVersion"); if (Environment.Is64BitOperatingSystem) { string[] JAVA64_VERSION = File.ReadAllLines("./jre_64bit/release")[0].Split('='); if (JAVA64_VERSION[1] != JavaXmlVersion) { string Java64Updateinfostring = string.Format(Javaupdateinfo, JAVA64_VERSION[1], JavaXmlVersion); DialogResult WantUpdateJava64 = MessageBox.Show(Java64Updateinfostring, Javaupdatefound, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (WantUpdateJava64 == DialogResult.OK) { DownloadJava64bit = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } } else { string[] JAVA32_VERSION = File.ReadAllLines("./jre_32bit/release")[0].Split('='); if (JAVA32_VERSION[1] != JavaXmlVersion) { string Java32Updateinfostring = string.Format(Javaupdateinfo, JAVA32_VERSION[1], JavaXmlVersion); DialogResult WantUpdateJava32 = MessageBox.Show(Java32Updateinfostring, Javaupdatefound, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (WantUpdateJava32 == DialogResult.OK) { DownloadJava64bit = true; new Forms.UpdateForm.UpdaterForm().ShowDialog(); } } } } catch (WebException wex) { if (wex.Status == WebExceptionStatus.ProtocolError) { if (((HttpWebResponse)wex.Response).StatusCode == HttpStatusCode.NotFound) { MessageBox.Show("Something happened and updater got error 404", "Update Checker Web 404", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (wex.Response == null) { MessageBox.Show("Can't connect because the update server is down, you dont have an internet connection or something is blocking it", "Update Checker Can't connect", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show($"{wex.Message.ToString()}", "Update Checker Web Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show($"{ex.Message.ToString()}\n{ex.StackTrace}", "Update Checker Fatal Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Application.Run(new LauncherForm(configuration)); configuration.SaveConfiguration(); }