From 3e200879ef10b5f98e8229f3f84790438f89270f Mon Sep 17 00:00:00 2001 From: Sarah Hawthorne Date: Thu, 3 Sep 2020 16:43:06 -0400 Subject: [PATCH] Finalized Audio split Redid config system --- Apex Launcher/Apex Launcher.csproj | 11 +- Apex Launcher/Config.cs | 104 +++++++++++++++ Apex Launcher/Forms/DownloadForm.cs | 128 +++++++++++-------- Apex Launcher/Forms/ErrorCatcher.Designer.cs | 6 +- Apex Launcher/Forms/ErrorCatcher.cs | 14 +- Apex Launcher/Forms/Launcher.cs | 17 +-- Apex Launcher/Forms/SaveManagementForm.cs | 2 +- Apex Launcher/Forms/SettingsForm.cs | 16 +-- Apex Launcher/Forms/TextEntryForm.cs | 4 +- Apex Launcher/Program.cs | 108 ++++++---------- Apex Launcher/Properties/AssemblyInfo.cs | 4 +- Apex Launcher/Properties/Resources.resx | 13 +- Apex Launcher/Version/VersionAudio.cs | 15 ++- Apex Launcher/Version/VersionGameFiles.cs | 23 ++-- Apex Launcher/VersionManifest.xml | 10 +- Apex Launcher/VersionManifestAudio.xml | 2 +- Apex Launcher/config.txt | 2 +- 17 files changed, 298 insertions(+), 181 deletions(-) create mode 100644 Apex Launcher/Config.cs diff --git a/Apex Launcher/Apex Launcher.csproj b/Apex Launcher/Apex Launcher.csproj index 2629026..6267e4c 100644 --- a/Apex Launcher/Apex Launcher.csproj +++ b/Apex Launcher/Apex Launcher.csproj @@ -56,11 +56,10 @@ giratina.ico - false + true - - + Properties\LauncherKey.pfx @@ -78,6 +77,7 @@ + Form @@ -148,6 +148,7 @@ TextEntryForm.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -165,11 +166,9 @@ + - - Designer - diff --git a/Apex Launcher/Config.cs b/Apex Launcher/Config.cs new file mode 100644 index 0000000..ef538d3 --- /dev/null +++ b/Apex Launcher/Config.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace Apex_Launcher { + public static class Config { + private static string Filepath => Path.Combine(Directory.GetCurrentDirectory(), "config.txt"); + + private static VersionGameFiles _currentVersion; + public static VersionGameFiles CurrentVersion { + get { + return _currentVersion; + } + set { + _currentVersion = value; + SaveConfig(); + } + } + + private static VersionAudio _currentVersionAudio; + public static VersionAudio CurrentAudioVersion { + get { + return _currentVersionAudio; + } + set { + _currentVersionAudio = value; + SaveConfig(); + } + } + + private static string _installPath; + public static string InstallPath { + get { + if (string.IsNullOrEmpty(_installPath)) return Directory.GetCurrentDirectory(); + return _installPath; + } + set { + _installPath = value; + SaveConfig(); + } + } + + private static bool _keepLauncherOpen; + public static bool KeepLauncherOpen { + get { + return _keepLauncherOpen; + } + set { + _keepLauncherOpen = value; + SaveConfig(); + } + } + + private static bool _disableAudioDownload; + public static bool DisableAudioDownload { + get { + return _disableAudioDownload; + } + set { + _disableAudioDownload = value; + SaveConfig(); + } + } + + 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() == param) { + try { + object v = null; + if (pi.PropertyType.IsAssignableFrom(typeof(IDownloadable))) { + if (pi.PropertyType == typeof(VersionGameFiles)) v = VersionGameFiles.FromString(value); + if (pi.PropertyType == typeof(VersionAudio)) v = VersionAudio.FromString(value); + } else pi.SetValue(null, Convert.ChangeType(value, pi.PropertyType)); + } catch (Exception) { + pi.SetValue(null, default); + } + break; + } + } + } + } + + public static void SaveConfig() { + List lines = new List(); + foreach (PropertyInfo pi in typeof(Config).GetProperties()) lines.Add($"{pi.Name}={pi.GetValue(null)}"); + File.WriteAllLines(Filepath, lines); + } + + public static void CreateConfig() { + using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Apex_Launcher.config.txt"); + using FileStream fileStream = new FileStream(Filepath, FileMode.CreateNew); + for (int i = 0; i < stream.Length; i++) fileStream.WriteByte((byte)stream.ReadByte()); + } + } +} diff --git a/Apex Launcher/Forms/DownloadForm.cs b/Apex Launcher/Forms/DownloadForm.cs index c245369..b7c7de9 100644 --- a/Apex Launcher/Forms/DownloadForm.cs +++ b/Apex Launcher/Forms/DownloadForm.cs @@ -11,20 +11,39 @@ namespace Apex_Launcher { public partial class DownloadForm : Form { private readonly List downloadQueue; private Thread dlThread = null; + private string currentFilepath; + private readonly VersionGameFiles BaseVersion; + private readonly VersionGameFiles MostRecent; public bool Downloading { get; private set; } - [Obsolete("Switch to download queueing")] - public DownloadForm(IDownloadable v) : this(new List() { v }) { } - public DownloadForm(List downloads) { InitializeComponent(); + downloadQueue = new List(); foreach (IDownloadable d in downloads) { + if (d is VersionGameFiles) { + if (MostRecent == null || d.GreaterThan(MostRecent)) MostRecent = d as VersionGameFiles; + } if (d.Prerequisite != null && d.Prerequisite.NewerThanDownloaded()) downloadQueue.Add(d.Prerequisite); + else if (d is VersionGameFiles) { + VersionGameFiles vgf = d as VersionGameFiles; + if (!vgf.IsPatch) BaseVersion = vgf; + } downloadQueue.Add(d); } Aborted += DownloadForm_Aborted; + QueueComplete += DownloadForm_QueueComplete; + } + + private void DownloadForm_QueueComplete(object sender, EventArgs e) { + if (MostRecent != null) { + Config.CurrentVersion = MostRecent; + Config.CurrentAudioVersion = MostRecent.MinimumAudioVersion; + } + + Program.Launcher.SetGameVersion(MostRecent); + Program.Launcher.UpdateStatus("Ready to launch"); } private void DownloadForm_Aborted(object sender, EventArgs e) { @@ -37,8 +56,9 @@ private void DownloadForm_Aborted(object sender, EventArgs e) { public void StartDownload() { Downloading = true; - dlThread = new Thread(Download); - dlThread.IsBackground = true; + dlThread = new Thread(Download) { + IsBackground = true + }; dlThread.SetApartmentState(ApartmentState.STA); dlThread.Start(); } @@ -48,13 +68,14 @@ public void Download() { bool allFinished = true; foreach (IDownloadable download in downloadQueue) { string Source = download.Location; - string Destination = Path.Combine(Program.GetInstallPath(), "Versions", download.ToString()); - string filepath = Destination + ".zip"; + string Destination = Path.Combine(Config.InstallPath, "Versions", download.ToString()); + currentFilepath = Destination + ".zip"; Program.Launcher.UpdateStatus("Downloading " + download.ToString()); Directory.CreateDirectory(Destination); bool succeeded = true; + // Download HttpWebRequest filereq = (HttpWebRequest)WebRequest.Create(Source); HttpWebResponse fileresp = null; try { @@ -69,23 +90,24 @@ public void Download() { return; } if (filereq.ContentLength > 0) fileresp.ContentLength = filereq.ContentLength; + if (fileresp.ContentLength <= 0) { + MessageBox.Show($"Could not access file {download}. Package skipped."); + continue; + } using (Stream dlstream = fileresp.GetResponseStream()) { - using FileStream outputStream = new FileStream(filepath, FileMode.OpenOrCreate); + using FileStream outputStream = new FileStream(currentFilepath, FileMode.OpenOrCreate); int buffersize = 10000; try { long bytesRead = 0; int length = 1; while (length > 0) { - byte[] buffer = new Byte[buffersize]; + byte[] buffer = new byte[buffersize]; length = dlstream.Read(buffer, 0, buffersize); bytesRead += length; outputStream.Write(buffer, 0, length); - UpdateProgress((int)(100 * bytesRead / fileresp.ContentLength)); + UpdateProgress(Convert.ToInt32(100F * bytesRead / fileresp.ContentLength)); UpdateProgressText( - "Downloading " + download.ToString() + - " (Package " + (downloadQueue.IndexOf(download) + 1) + "/" + downloadQueue.Count + ") " + - (bytesRead / 1048576) + "/" + (fileresp.ContentLength / 1048576) + - " MB (" + Convert.ToInt16(100 * (double)bytesRead / fileresp.ContentLength, Program.Culture) + "%)..." + $"Downloading {download} (Package {downloadQueue.IndexOf(download) + 1}/{downloadQueue.Count}) {(bytesRead / 1048576)}/{(fileresp.ContentLength / 1048576)} MB (" + Convert.ToInt16(100 * (double)bytesRead / fileresp.ContentLength, Program.Culture) + "%)..." ); } } catch (WebException e) { @@ -105,47 +127,52 @@ public void Download() { } } - if (succeeded) { - Program.Launcher.UpdateStatus("Extracting version " + download.ToString()); - try { - if (Directory.Exists(Destination)) Directory.Delete(Destination, true); - UpdateProgressText("Download " + (downloadQueue.IndexOf(download) + 1) + "/" + downloadQueue.Count + - " completed. Extracting..."); - ZipFile.ExtractToDirectory(filepath, Destination); - - if (download is VersionGameFiles) { - VersionGameFiles vgf = download as VersionGameFiles; - if (vgf.IsPatch) { - UpdateProgressText("Patching..."); - string versionpath = Program.GetInstallPath() + "\\Versions\\" + download.Prerequisite.ToString(); - RecursiveCopy(versionpath, Destination, false); - } - } - } catch (InvalidDataException) { - MessageBox.Show( - "Could not unzip file\n" + Destination + ".zip.\nThe file appears to be invalid. Please report this issue. In the meantime, try a manual download.", - "Apex Launcher Error", - MessageBoxButtons.OK, - MessageBoxIcon.Warning - ); - } - File.Delete(filepath); - } else { + if (!succeeded) { allFinished = false; MessageBox.Show( "The download couldn't be completed. Check your internet connection. If you think this is a program error, please report this to the Launcher's GitHub page." ); break; } + + // Extraction + Program.Launcher.UpdateStatus("Extracting " + download.ToString()); + try { + if (Directory.Exists(Destination)) Directory.Delete(Destination, true); + UpdateProgressText("Download " + (downloadQueue.IndexOf(download) + 1) + "/" + downloadQueue.Count + + " completed. Extracting..."); + ZipFile.ExtractToDirectory(currentFilepath, Destination); + } catch (InvalidDataException) { + MessageBox.Show( + "Could not unzip file\n" + Destination + ".zip.\nThe file appears to be invalid. Please report this issue. In the meantime, try a manual download.", + "Apex Launcher Error", + MessageBoxButtons.OK, + MessageBoxIcon.Warning + ); + + continue; + } + + // Patching + if (download is VersionGameFiles) { + VersionGameFiles vgf = download as VersionGameFiles; + if (vgf.IsPatch) { + UpdateProgressText("Patching..."); + string versionpath = Path.Combine(Config.InstallPath, "Versions", download.Prerequisite.ToString()); + RecursiveCopy(versionpath, Destination, false); + } + } else if (download is VersionAudio) { + VersionAudio va = download as VersionAudio; + string versionpath = Path.Combine(Config.InstallPath, "Versions", BaseVersion.ToString()); + RecursiveCopy(Destination, versionpath, true); + } + File.Delete(currentFilepath); } if (allFinished) { QueueComplete?.Invoke(this, new EventArgs()); - /*Program.SetParameter("currentversion", v.ToString()); - Program.Launcher.SetGameVersion(v); - Program.Launcher.UpdateStatus("Ready to launch");*/ } CloseForm(); - } catch (ThreadAbortException) { } catch (Exception e) { + } catch (ThreadAbortException) { } catch (ThreadInterruptedException) { } catch (Exception e) { new ErrorCatcher(e).ShowDialog(); CloseForm(); } @@ -155,8 +182,8 @@ public void Download() { public void UpdateProgress(int progress) { if (DownloadProgressBar.InvokeRequired) { UP d = UpdateProgress; - this.Invoke(d, new object[] { progress }); - } else DownloadProgressBar.Value = progress; + Invoke(d, new object[] { progress }); + } else if (progress >= 0) DownloadProgressBar.Value = progress; } public delegate void UPT(string message); @@ -164,7 +191,7 @@ public void UpdateProgressText(string message) { if (ProgressLabel.InvokeRequired) { UPT d = UpdateProgressText; try { - this.Invoke(d, new object[] { message }); + Invoke(d, new object[] { message }); } catch (ObjectDisposedException) { } } else ProgressLabel.Text = message; } @@ -185,7 +212,7 @@ private bool PromptCancelDownload() { DialogResult res = MessageBox.Show("There is a download in progress. Are you sure you want to cancel?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.Yes) { dlThread.Abort(); - try { File.Delete(filepath); } catch (Exception) { }; + try { File.Delete(currentFilepath); } catch (Exception) { }; Downloading = false; Program.Launcher.UpdateStatus("Download cancelled."); return true; @@ -193,10 +220,7 @@ private bool PromptCancelDownload() { return false; } - private static void RecursiveCopy(string SourceDirectory, string DestinationDirectory) { - RecursiveCopy(SourceDirectory, DestinationDirectory, true); - } - private static void RecursiveCopy(string SourceDirectory, string DestinationDirectory, bool overwriteFile) { + private static void RecursiveCopy(string SourceDirectory, string DestinationDirectory, bool overwriteFile = true) { if (!Directory.Exists(DestinationDirectory)) Directory.CreateDirectory(DestinationDirectory); foreach (string f in Directory.GetFiles(SourceDirectory)) { if (overwriteFile || !File.Exists(DestinationDirectory + "\\" + f.Split('\\').Last())) { diff --git a/Apex Launcher/Forms/ErrorCatcher.Designer.cs b/Apex Launcher/Forms/ErrorCatcher.Designer.cs index c406a1e..66ad7bb 100644 --- a/Apex Launcher/Forms/ErrorCatcher.Designer.cs +++ b/Apex Launcher/Forms/ErrorCatcher.Designer.cs @@ -36,9 +36,10 @@ private void InitializeComponent() { // YorickHead // this.YorickHead.Image = ((System.Drawing.Image)(resources.GetObject("YorickHead.Image"))); - this.YorickHead.Location = new System.Drawing.Point(13, 22); + this.YorickHead.Location = new System.Drawing.Point(-1, 12); this.YorickHead.Name = "YorickHead"; - this.YorickHead.Size = new System.Drawing.Size(34, 36); + this.YorickHead.Size = new System.Drawing.Size(52, 52); + this.YorickHead.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.YorickHead.TabIndex = 0; this.YorickHead.TabStop = false; // @@ -117,6 +118,7 @@ private void InitializeComponent() { this.Text = "Error Catcher"; ((System.ComponentModel.ISupportInitialize)(this.YorickHead)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } diff --git a/Apex Launcher/Forms/ErrorCatcher.cs b/Apex Launcher/Forms/ErrorCatcher.cs index 7fd3513..69b3219 100644 --- a/Apex Launcher/Forms/ErrorCatcher.cs +++ b/Apex Launcher/Forms/ErrorCatcher.cs @@ -8,12 +8,12 @@ namespace Apex_Launcher { public partial class ErrorCatcher : Form { - private Exception exception; + private readonly Exception exception; public ErrorCatcher(Exception e) { exception = e; InitializeComponent(); - + Enabled = true; Initialize(); } @@ -24,16 +24,16 @@ private void Initialize() { sb.AppendLine(); sb.AppendLine("# Configuration"); try { - sb.AppendLine("* Current Launcher Version: " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); - sb.AppendLine("* Current Game Version: " + Program.GetParameter("currentversion")); - sb.AppendLine("* Install Path: " + Program.GetParameter("installpath")); + sb.AppendLine($"* Current Launcher Version: {Assembly.GetExecutingAssembly().GetName().Version}"); + sb.AppendLine($"* Current Game Version: {Config.CurrentVersion}"); + sb.AppendLine($"* Install Path: {Config.InstallPath}"); } catch (Exception) { } try { sb.AppendLine(); sb.AppendLine("# Files"); if (File.Exists(Directory.GetCurrentDirectory() + "\\config.txt")) sb.AppendLine("* `config.txt`"); - string installpath = Program.GetParameter("installpath"); + string installpath = Config.InstallPath; if (Directory.Exists(installpath)) { sb.AppendLine("* " + installpath + ":"); if (Directory.Exists(installpath + "\\Versions")) { @@ -59,7 +59,7 @@ private void CopyButton_Click(object sender, EventArgs e) { } private void LinkButton_Click(object sender, EventArgs e) { - Process.Start("https://github.com/griffenx/Apex-Launcher/issues/new?title=" + exception.GetType().Name + " in " + exception.TargetSite.Name + "&body=" + exception.StackTrace); + Process.Start("https://github.com/griffenx/Apex-Launcher/issues/new" + $"?title={exception.GetType().Name} in {exception.TargetSite.Name}&body={Uri.EscapeDataString(DetailsBox.Text)}"); } private void ButtonViewIssues_Click(object sender, EventArgs e) { diff --git a/Apex Launcher/Forms/Launcher.cs b/Apex Launcher/Forms/Launcher.cs index cab44e2..877ee08 100644 --- a/Apex Launcher/Forms/Launcher.cs +++ b/Apex Launcher/Forms/Launcher.cs @@ -25,7 +25,8 @@ private void Launcher_Shown(object sender, EventArgs e) { TumblrBrowser.IsWebBrowserContextMenuEnabled = false; RedditBrowser.IsWebBrowserContextMenuEnabled = false; //GitHubBrowser.IsWebBrowserContextMenuEnabled = false; - SetGameVersion(Program.GetCurrentVersion()); + VersionGameFiles vgf = Config.CurrentVersion; + if (vgf != null) SetGameVersion(vgf); LauncherVersionLabel.Text = "Launcher v" + Program.GetLauncherVersion(); if (Program.NetworkConnected) { try { @@ -67,18 +68,18 @@ private void LaunchButton_Click(object sender, EventArgs e) { 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 = Program.GetCurrentVersion(); - string launchpath = Program.GetInstallPath() + "\\Versions\\" + CurrentVersion.ToString() + "\\Game.exe"; + VersionGameFiles CurrentVersion = Config.CurrentVersion; + string launchpath = Path.Combine(Config.InstallPath, "Versions", CurrentVersion.ToString(), "Game.exe"); if (Program.ForceUpdate) { - string path = Program.GetInstallPath() + "\\Versions\\" + CurrentVersion.ToString(); + string path = 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 = Program.GetInstallPath() + "\\Versions\\" + CurrentVersion.Prerequisite.ToString(); + string previousPath = Config.InstallPath + "\\Versions\\" + CurrentVersion.Prerequisite.ToString(); if (File.Exists(previousPath + ".zip")) File.Delete(previousPath + ".zip"); if (Directory.Exists(previousPath)) Directory.Delete(previousPath, true); - Program.SetParameter("currentversion", "ALPHA 0.0"); + Config.CurrentVersion = VersionGameFiles.FromString("ALPHA 0.0"); } Program.DownloadVersion(VersionGameFiles.GetMostRecentVersion()); @@ -95,7 +96,7 @@ private void LaunchButton_Click(object sender, EventArgs e) { if (File.Exists(launchpath)) { Process.Start(launchpath); - if (!Convert.ToBoolean(Program.GetParameter("keepLauncherOpen"), Program.Culture)) Close(); + if (!Config.KeepLauncherOpen) Close(); } } @@ -108,7 +109,7 @@ public void EnableLaunch() { public void UpdateStatus(string message) { if (StatusLabel.InvokeRequired) { US d = UpdateStatus; - this.Invoke(d, new object[] { message }); + Invoke(d, new object[] { message }); } else StatusLabel.Text = message; } diff --git a/Apex Launcher/Forms/SaveManagementForm.cs b/Apex Launcher/Forms/SaveManagementForm.cs index 425f8cf..88c7301 100644 --- a/Apex Launcher/Forms/SaveManagementForm.cs +++ b/Apex Launcher/Forms/SaveManagementForm.cs @@ -6,7 +6,7 @@ namespace Apex_Launcher { public partial class SaveManagementForm : Form { - private string savePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Saved Games\\Pokémon Apex\\"; + private readonly string savePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Saved Games\\Pokémon Apex\\"; private const string currentSaveName = "[Current Save]"; public SaveManagementForm() { diff --git a/Apex Launcher/Forms/SettingsForm.cs b/Apex Launcher/Forms/SettingsForm.cs index 6ba0ff0..502407d 100644 --- a/Apex Launcher/Forms/SettingsForm.cs +++ b/Apex Launcher/Forms/SettingsForm.cs @@ -6,8 +6,8 @@ public partial class SettingsForm : Form { public SettingsForm() { InitializeComponent(); - PathTextbox.Text = Program.GetInstallPath(); - KeepOpenCheckbox.Checked = Convert.ToBoolean(Program.GetParameter("keepLauncherOpen"), Program.Culture); + PathTextbox.Text = Config.InstallPath; + KeepOpenCheckbox.Checked = Convert.ToBoolean(Config.KeepLauncherOpen, Program.Culture); ForceUpdateCheckbox.Checked = Program.ForceUpdate; } @@ -17,7 +17,7 @@ private void CancelButton_Click(object sender, EventArgs e) { private void OKButton_Click(object sender, EventArgs e) { bool validated = true; - if (Program.GetParameter("installpath").Length > 0 && PathTextbox.Text != Program.GetParameter("installpath")) { + if (Config.InstallPath.Length > 0 && PathTextbox.Text != Config.InstallPath) { if ( MessageBox.Show( "If you change your install path, you will need to move your game data to the new path or redownload it before you will be able to play. Is this OK?", @@ -33,17 +33,17 @@ private void OKButton_Click(object sender, EventArgs e) { } if (validated) { - Program.SetParameter("installpath", PathTextbox.Text); - Program.SetParameter("keepLauncherOpen", KeepOpenCheckbox.Checked.ToString()); - //Program.SetParameter("disableGameFonts", DisableFontBox.Checked.ToString()); + Config.InstallPath = PathTextbox.Text; + Config.KeepLauncherOpen = KeepOpenCheckbox.Checked; Program.ForceUpdate = ForceUpdateCheckbox.Checked; Close(); } } private void BrowseButton_Click(object sender, EventArgs e) { - FolderBrowserDialog fbd = new FolderBrowserDialog(); - fbd.Description = "Choose a Folder"; + FolderBrowserDialog fbd = new FolderBrowserDialog { + Description = "Choose a Folder" + }; fbd.ShowDialog(); string selectedPath = fbd.SelectedPath; diff --git a/Apex Launcher/Forms/TextEntryForm.cs b/Apex Launcher/Forms/TextEntryForm.cs index d52ea7b..9a18004 100644 --- a/Apex Launcher/Forms/TextEntryForm.cs +++ b/Apex Launcher/Forms/TextEntryForm.cs @@ -3,8 +3,8 @@ namespace Apex_Launcher { public partial class TextEntryForm : Form { - private string Prompt; - private string Title; + private readonly string Prompt; + private readonly string Title; public string Result; diff --git a/Apex Launcher/Program.cs b/Apex Launcher/Program.cs index 2eac0c6..4450740 100644 --- a/Apex Launcher/Program.cs +++ b/Apex Launcher/Program.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using System.Net; using System.Reflection; using System.Windows.Forms; @@ -35,29 +34,28 @@ static void Main() { Launcher = new Launcher(); Application.Run(Launcher); } catch (Exception e) { - ErrorCatcher ec = new ErrorCatcher(e); + ErrorCatcher ec = new ErrorCatcher(e) { + Enabled = true + }; ec.ShowDialog(); } } public static void Initialize() { - if (!File.Exists(Directory.GetCurrentDirectory() + "\\config.txt")) { - using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Apex_Launcher.config.txt"); - using FileStream fileStream = new FileStream(Directory.GetCurrentDirectory() + "\\config.txt", FileMode.CreateNew); - for (int i = 0; i < stream.Length; i++) fileStream.WriteByte((byte)stream.ReadByte()); - } + Config.LoadConfig(); if (GithubBridge.CheckForLauncherUpdate()) { Application.Exit(); return; } - if (!Directory.Exists(GetInstallPath() + "\\Versions")) { - Directory.CreateDirectory(GetInstallPath() + "\\Versions"); - if (!GetParameter("currentversion").Equals("ALPHA 0.0")) SetParameter("currentversion", "ALPHA 0.0"); + if (!Directory.Exists(Path.Combine(Config.InstallPath, "Versions"))) { + Directory.CreateDirectory(Path.Combine(Config.InstallPath, "Versions")); + if (Config.CurrentVersion.ToString().Equals("ALPHA 0.0")) Config.CurrentVersion = VersionGameFiles.FromString("ALPHA 0.0"); } + try { - NetworkConnected = DownloadVersionManifest(); + NetworkConnected = DownloadVersionManifests(); } catch (WebException) { NetworkConnected = false; } @@ -83,51 +81,24 @@ public static void Initialize() { return; } - public static string GetParameter(string parameter) { - foreach (string line in File.ReadAllLines(Directory.GetCurrentDirectory() + "\\config.txt")) { - if (line.Length > 0 && !(new[] { '\n', ' ', '#' }.Contains(line[0])) && line.Contains('=')) { - if (line.Split('=')[0].ToLower().Equals(parameter.ToLower())) { - return line.Split('=')[1]; - } - } - } - return null; - } - - public static void SetParameter(string parameter, string value) { - if (GetParameter(parameter) == null) { - File.AppendAllText(Directory.GetCurrentDirectory() + "\\config.txt", parameter + "=" + value + "\n"); - } else { - string[] lines = File.ReadAllLines(Directory.GetCurrentDirectory() + "\\config.txt"); - int foundline = -1; - foreach (string line in lines) { - if (line.Length > 0 && !(new[] { '\n', ' ', '#' }.Contains(line[0])) && line.Contains('=')) { - if (line.Split('=')[0].ToLower().Equals(parameter.ToLower())) { - foundline = Array.IndexOf(lines, line); - break; - } - } - } - if (foundline > -1) { - lines[foundline] = parameter + "=" + value; - File.WriteAllLines(Directory.GetCurrentDirectory() + "\\config.txt", lines); - } - } - } - - public static bool DownloadVersionManifest() { + public static bool DownloadVersionManifests() { bool completed; + string[] files = new[] { + "http://www.mediafire.com/download/qkauu9oca3lcjw1/VersionManifest.xml", + "http://www.mediafire.com/download/zvooruhs1b3e4c9/VersionManifestAudio.xml" + }; try { - HttpWebRequest filereq = (HttpWebRequest)WebRequest.Create("http://www.mediafire.com/download/qkauu9oca3lcjw1/VersionManifest.xml"); - HttpWebResponse fileresp = (HttpWebResponse)filereq.GetResponse(); - if (filereq.ContentLength > 0) fileresp.ContentLength = filereq.ContentLength; - using (Stream dlstream = fileresp.GetResponseStream()) { - using FileStream outputStream = new FileStream(GetInstallPath() + "\\Versions\\VersionManifest.xml", FileMode.OpenOrCreate); + foreach (string file in files) { + HttpWebRequest filereq = (HttpWebRequest)WebRequest.Create(file); + HttpWebResponse fileresp = (HttpWebResponse)filereq.GetResponse(); + if (filereq.ContentLength > 0) fileresp.ContentLength = filereq.ContentLength; + using Stream dlstream = fileresp.GetResponseStream(); + using FileStream outputStream = new FileStream(Path.Combine(Config.InstallPath, "Versions", Path.GetFileName(file)), FileMode.OpenOrCreate); int buffersize = 1000; long bytesRead = 0; int length = 1; while (length > 0) { - byte[] buffer = new Byte[buffersize]; + byte[] buffer = new byte[buffersize]; length = dlstream.Read(buffer, 0, buffersize); bytesRead += length; outputStream.Write(buffer, 0, length); @@ -140,40 +111,41 @@ public static bool DownloadVersionManifest() { return completed; } - public static VersionGameFiles GetCurrentVersion() { - return VersionGameFiles.FromString(GetParameter("currentversion")); - } - public static bool InstallLatestVersion() { Launcher.UpdateStatus("Checking for new versions..."); VersionGameFiles mostRecent = VersionGameFiles.GetMostRecentVersion(); - if (mostRecent != null && mostRecent.GreaterThan(GetCurrentVersion())) { - DialogResult result = MessageBox.Show("New version found: " + mostRecent.Channel.ToString() + " " + mostRecent.Number + - "\nDownload and install this update?", "Update Found", MessageBoxButtons.YesNo); + if (mostRecent != null && mostRecent.GreaterThan(Config.CurrentVersion)) { + DialogResult result = MessageBox.Show($"New version found: {mostRecent.Channel} {mostRecent.Number}\nDownload and install this update?", "Update Found", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { DownloadVersion(mostRecent); return true; - } else return false; + } + } + + VersionAudio mostRecentAudio = VersionAudio.GetMostRecentVersion(); + if (!Config.DisableAudioDownload && mostRecentAudio.GreaterThan(Config.CurrentAudioVersion)) { + DialogResult result = MessageBox.Show($"New audio version found: {mostRecentAudio}.\nDownload and install this update?\n(Note, audio updates are often large downloads)", "Audio Update Found", MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) DownloadVersion(mostRecentAudio); } Launcher.UpdateStatus("No new version found."); return false; } - public static void DownloadVersion(VersionGameFiles v) { - DownloadForm = new DownloadForm(v); + public static void DownloadVersion(IDownloadable v) { + List queue = new List(new[] { v }); + VersionGameFiles vgf = v as VersionGameFiles; + if (!Config.DisableAudioDownload && vgf.MinimumAudioVersion != null && vgf.MinimumAudioVersion.GreaterThan(Config.CurrentVersion)) { + DialogResult result = MessageBox.Show($"New audio version found: {vgf.MinimumAudioVersion}.\nDownload and install this update?\n(Note, audio updates are often large downloads)", "Audio Update Found", MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) queue.Add(vgf.MinimumAudioVersion); + } + + DownloadForm = new DownloadForm(queue); DownloadForm.Show(); DownloadForm.StartDownload(); - - } - - public static string GetInstallPath() { - string installpath = GetParameter("installpath"); - if (installpath.Length == 0) installpath = Directory.GetCurrentDirectory(); - return installpath; } public static bool HasWriteAccess(string folderPath) { @@ -205,7 +177,7 @@ public static string GetNextAvailableFilePath(string path) { if (j == preExtension.Length - 1 && preExtension[j] != ')') break; if (j < preExtension.Length - 1) { if (preExtension[j] == '(') { - numbering = Convert.ToInt32(String.Join("", digits), Program.Culture); + numbering = Convert.ToInt32(string.Join("", digits), Program.Culture); } else { try { digits.Insert(0, Convert.ToInt16(preExtension[j].ToString(), Program.Culture)); diff --git a/Apex Launcher/Properties/AssemblyInfo.cs b/Apex Launcher/Properties/AssemblyInfo.cs index 2e757a6..f150a70 100644 --- a/Apex Launcher/Properties/AssemblyInfo.cs +++ b/Apex Launcher/Properties/AssemblyInfo.cs @@ -33,7 +33,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.5.0")] -[assembly: AssemblyFileVersion("1.4.5.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] [assembly: NeutralResourcesLanguage("en-US")] diff --git a/Apex Launcher/Properties/Resources.resx b/Apex Launcher/Properties/Resources.resx index af7dbeb..1af7de1 100644 --- a/Apex Launcher/Properties/Resources.resx +++ b/Apex Launcher/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file diff --git a/Apex Launcher/Version/VersionAudio.cs b/Apex Launcher/Version/VersionAudio.cs index 3014c41..b9585d4 100644 --- a/Apex Launcher/Version/VersionAudio.cs +++ b/Apex Launcher/Version/VersionAudio.cs @@ -17,6 +17,7 @@ public VersionAudio(double number, string location) { } public bool GreaterThan(IDownloadable other) { + if (other == null) return true; return Number > other.Number; } @@ -28,10 +29,14 @@ public override string ToString() { return "Audio v" + Number.ToString(); } + public static VersionAudio FromString(string str) { + return FromNumber(Convert.ToInt32(str.Replace("Audio v", ""))); + } + public static List GetAllVersions() { List versions = new List(); XmlDocument doc = new XmlDocument(); - doc.Load(Path.Combine(Program.GetInstallPath(), "Versions\\VersionManifestAudio.xml")); + doc.Load(Path.Combine(Config.InstallPath, "Versions\\VersionManifestAudio.xml")); foreach (XmlNode node in doc.GetElementsByTagName("version")) { string location = string.Empty; double number = 0; @@ -59,5 +64,13 @@ public static VersionAudio FromNumber(int number) { } return null; } + + public static VersionAudio GetMostRecentVersion() { + VersionAudio mostRecent = null; + foreach (VersionAudio va in GetAllVersions()) { + if (mostRecent == null || va.GreaterThan(mostRecent)) mostRecent = va; + } + return mostRecent; + } } } diff --git a/Apex Launcher/Version/VersionGameFiles.cs b/Apex Launcher/Version/VersionGameFiles.cs index 2ac4233..27d0f68 100644 --- a/Apex Launcher/Version/VersionGameFiles.cs +++ b/Apex Launcher/Version/VersionGameFiles.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Xml; namespace Apex_Launcher { @@ -28,15 +27,16 @@ public IDownloadable Prerequisite { } } - public VersionGameFiles(Channel channel, double number, string location) : this(channel, number, location, false) { } - public VersionGameFiles(Channel channel, double number, string location, bool ispatch) { + public VersionGameFiles(Channel channel, double number, string location, VersionAudio audioVersion, bool ispatch = false) { Channel = channel; Number = number; Location = location; IsPatch = ispatch; + MinimumAudioVersion = audioVersion; } public bool GreaterThan(IDownloadable other) { + if (other == null) return true; VersionGameFiles v = other as VersionGameFiles; if (Channel == v.Channel) return Number > v.Number; else return Channel > v.Channel; @@ -60,7 +60,7 @@ public override string ToString() { } public bool NewerThanDownloaded() { - return GreaterThan(Program.GetCurrentVersion()); + return GreaterThan(Config.CurrentVersion); } public static Channel GetChannelFromString(string name) { @@ -80,18 +80,17 @@ public static Channel GetChannelFromString(string name) { } public static VersionGameFiles FromString(string str) { - return new VersionGameFiles( - GetChannelFromString(str.Split(' ')[0]), - str.Last() != 'p' ? Convert.ToDouble(str.Split(' ')[1], Program.Culture) : Convert.ToDouble(str.Split(' ')[1].Replace('p', '\0'), Program.Culture), - "", - str[str.Length - 1] == 'p'); + foreach (VersionGameFiles vgf in GetAllVersions()) { + if (vgf.ToString() == str) return vgf; + } + return null; } public static List GetAllVersions() { List versions = new List(); XmlDocument doc = new XmlDocument(); - doc.Load(Program.GetInstallPath() + "\\Versions\\VersionManifest.xml"); + doc.Load(Config.InstallPath + "\\Versions\\VersionManifest.xml"); foreach (XmlNode node in doc.GetElementsByTagName("version")) { Channel channel = Channel.NONE; @@ -129,13 +128,13 @@ public static List GetAllVersions() { break; } } - versions.Add(new VersionGameFiles(channel, number, location, patch)); + versions.Add(new VersionGameFiles(channel, number, location, audioversion, patch)); } return versions; } public static VersionGameFiles GetMostRecentVersion() { - VersionGameFiles mostRecent = Program.GetCurrentVersion(); + VersionGameFiles mostRecent = Config.CurrentVersion; foreach (VersionGameFiles v in GetAllVersions()) if (mostRecent == null || v.GreaterThan(mostRecent) || v.Equals(mostRecent)) mostRecent = v; return mostRecent; } diff --git a/Apex Launcher/VersionManifest.xml b/Apex Launcher/VersionManifest.xml index e3662b7..361f6e4 100644 --- a/Apex Launcher/VersionManifest.xml +++ b/Apex Launcher/VersionManifest.xml @@ -1,4 +1,4 @@ - + a @@ -75,24 +75,24 @@ a 8 - https://www.mediafire.com/download/8durrekd79tpcml/Pok%E9mon_Apex_Alpha_Build_8.zip/file + https://www.mediafire.com/download/8durrekd79tpcml/Pok%E9mon_Apex_Alpha_Build_8.zip a 8.1 - https://www.mediafire.com/download/w3dsiitx7yk48fp/Pok%E9mon_Apex_Alpha_Build_8.1.zip/file + https://www.mediafire.com/download/w3dsiitx7yk48fp/Pok%E9mon_Apex_Alpha_Build_8.1.zip true a 8.2 - https://www.mediafire.com/download/ze8l977vy62zlka/Pok%E9mon_Apex_Alpha_Build_8.2.zip/file + https://www.mediafire.com/download/ze8l977vy62zlka/Pok%E9mon_Apex_Alpha_Build_8.2.zip true a 9 + http://www.mediafire.com/download/uibf9asdocyt2k6/Pokémon+Apex+Alpha+Build+9.zip 1 - http://www.mediafire.com/download/uibf9asdocyt2k6/Pokémon+Apex+Alpha+Build+9.zip/file diff --git a/Apex Launcher/VersionManifestAudio.xml b/Apex Launcher/VersionManifestAudio.xml index 46ed61a..e63f247 100644 --- a/Apex Launcher/VersionManifestAudio.xml +++ b/Apex Launcher/VersionManifestAudio.xml @@ -2,6 +2,6 @@ 1 - http://www.mediafire.com/file/pn5n0eu2r3j5mf9/Audio.zip/file + http://www.mediafire.com/download/pn5n0eu2r3j5mf9/Audio.zip diff --git a/Apex Launcher/config.txt b/Apex Launcher/config.txt index 34900d0..c951065 100644 --- a/Apex Launcher/config.txt +++ b/Apex Launcher/config.txt @@ -4,4 +4,4 @@ currentAudioVersion=0 installpath= keepLauncherOpen=false disableGameFonts=false -disableMusicDownload=false \ No newline at end of file +disableAudioDownload=false \ No newline at end of file