private static void Initialize() { Config.LoadConfig(); if (GithubBridge.CheckForLauncherUpdate()) { Application.Exit(); return; } if (!Directory.Exists(Path.Combine(Config.InstallPath, "Versions"))) { Directory.CreateDirectory(Path.Combine(Config.InstallPath, "Versions")); if (Config.CurrentVersion?.ToString().Equals("ALPHA 0.0") != false) { Config.CurrentVersion = VersionGameFiles.FromString("ALPHA 0.0"); } } try { NetworkConnected = DownloadVersionManifests(); } catch (WebException) { NetworkConnected = false; } return; }
/// <summary> /// Load underlying configuration file to memory. /// </summary> public static void LoadConfig() { if (!File.Exists(Filepath)) { CreateConfig(); } foreach (string line in File.ReadAllLines(Filepath)) { if (line.Length == 0 || new[] { '\n', ' ', '#' }.Contains(line[0]) || !line.Contains('=')) { continue; } string[] split = line.Split('='); string param = split[0].Trim(); string value = split[1].Trim(); foreach (PropertyInfo pi in typeof(Config).GetProperties()) { if (pi.Name.ToLower(Program.Culture) == param.ToLower(Program.Culture)) { try { object v = null; if (pi.PropertyType.GetInterfaces().Contains(typeof(IDownloadable))) { if (pi.PropertyType == typeof(VersionGameFiles)) { v = VersionGameFiles.FromString(value); } if (pi.PropertyType == typeof(VersionAudio)) { v = VersionAudio.FromString(value); } } else { v = Convert.ChangeType(value, pi.PropertyType); } pi.SetValue(null, v); } catch (FormatException) { pi.SetValue(null, default); } break; } } } loaded = true; }
private void LaunchButton_Click(object sender, EventArgs e) { if (Program.Downloading) { MessageBox.Show("A download is currently in progress. Please cancel your download or wait until it finishes.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } VersionGameFiles currentVersion = Config.CurrentVersion; if (currentVersion is null) { if (MessageBox.Show("No installed version found. Would you like to download now?", "No Version Found", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } Program.InstallLatestVersion(); return; } string launchpath = Path.Combine(Config.InstallPath, "Versions", currentVersion.ToString(), "Game.exe"); if (Program.ForceUpdate) { string path = Path.Combine(Config.InstallPath, "Versions", currentVersion.ToString()); if (File.Exists(path + ".zip")) { File.Delete(path + ".zip"); } if (Directory.Exists(path)) { Directory.Delete(path, true); } if (currentVersion.IsPatch) { string previousPath = Path.Combine(Config.InstallPath, "Versions", currentVersion.Prerequisite.ToString()); if (File.Exists(previousPath + ".zip")) { File.Delete(previousPath + ".zip"); } if (Directory.Exists(previousPath)) { Directory.Delete(previousPath, true); } Config.CurrentVersion = VersionGameFiles.FromString("ALPHA 0.0"); } Program.DownloadVersion(VersionGameFiles.GetMostRecentVersion()); Program.ForceUpdate = false; } else if (!File.Exists(launchpath)) { DialogResult res = MessageBox.Show( $"Cannot find the game in your install path. It might be moved or deleted.\nCheck \n{launchpath}\nfor your files, or redownload them.\nWould you like to redownload?", "Game not found", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { Program.InstallLatestVersion(); } else { return; } } if (File.Exists(launchpath)) { Process.Start(launchpath); if (!Config.KeepLauncherOpen) { Close(); } } }