From 398a44e92d017e7dd9c8945e7baa9e7b7ccd1d69 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Thu, 27 Jan 2022 15:21:03 +0100 Subject: [PATCH] Fix todos, replace platform with OS, add splashes, documentation --- AM2RLauncher/AM2RLauncher/LauncherUpdater.cs | 25 +++--- .../AM2RLauncher/MainForm/MainForm.Events.cs | 33 +++---- .../MainForm/MainForm.StateMachine.cs | 6 +- .../AM2RLauncher/MainForm/MainForm.UI.cs | 65 +++++++------- AM2RLauncher/AM2RLauncherCore/Core.cs | 9 +- .../CrossPlatformOperations.cs | 2 +- .../AM2RLauncherCore/HelperMethods.cs | 85 +------------------ AM2RLauncher/AM2RLauncherCore/OS.cs | 23 ++++- AM2RLauncher/AM2RLauncherCore/Profile.cs | 85 ++++++++++++++++++- AM2RLauncher/AM2RLauncherCore/Splash.cs | 29 ++++++- 10 files changed, 203 insertions(+), 159 deletions(-) diff --git a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs index 7e0f22d..95acdd5 100644 --- a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs +++ b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs @@ -20,16 +20,13 @@ namespace AM2RLauncher /// The Version that identifies this current release. public const string VERSION = Core.Core.VERSION; - /// The current Running platform. - private static readonly Platform CurrentPlatform = Platform.Instance; // Needs to be declared here as well, because I can't access the one from eto, - // Since isn't loaded at this point - /// The Path of the oldConfig. Only gets used Windows-only private static readonly string OldConfigPath = CrossPlatformOperations.CURRENTPATH + "/" + CrossPlatformOperations.LAUNCHERNAME + ".oldCfg"; /// The actual Path where the executable is stored, only used for updating. //TODO: for mac, this reports the path of the mac runner, not the actual .app - private static readonly string UpdatePath = CurrentPlatform.IsWinForms ? CrossPlatformOperations.CURRENTPATH : Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); + private static readonly string UpdatePath = OS.IsWindows ? CrossPlatformOperations.CURRENTPATH : Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); + //TODO: Mac support for this in general /// /// Our log object, that handles logging the current execution to a file. @@ -51,19 +48,19 @@ namespace AM2RLauncher Log.Info("AM2RLauncher.bak detected. Removing file."); File.Delete(CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak"); } - if (CurrentPlatform.IsWinForms && File.Exists(OldConfigPath)) + if (OS.IsWindows && File.Exists(OldConfigPath)) { Log.Info(CrossPlatformOperations.LAUNCHERNAME + ".oldCfg detected. Removing file."); File.Delete(OldConfigPath); } - if (CurrentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/oldLib")) + if (OS.IsWindows && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/oldLib")) { Log.Info("Old lib folder detected, removing folder."); Directory.Delete(CrossPlatformOperations.CURRENTPATH + "/oldLib", true); } // Clean up old update libs - if (CurrentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib")) + if (OS.IsWindows && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib")) { foreach (FileInfo file in new DirectoryInfo(CrossPlatformOperations.CURRENTPATH + "/lib").GetFiles()) { @@ -91,7 +88,7 @@ namespace AM2RLauncher // This is supposed to fix the updater throwing an exception on windows 7 and earlier(?) // See this for information: https://stackoverflow.com/q/2859790 and https://stackoverflow.com/a/50977774 - if (CurrentPlatform.IsWinForms) + if (OS.IsWindows) { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; @@ -152,8 +149,8 @@ namespace AM2RLauncher using (var client = new WebClient()) { string platformSuffix = ""; - if (CurrentPlatform.IsWinForms) platformSuffix = "_win"; - else if (CurrentPlatform.IsGtk) platformSuffix = "_lin"; + if (OS.IsWindows) platformSuffix = "_win"; + else if (OS.IsLinux) platformSuffix = "_lin"; Log.Info("Downloading https://github.com/AM2R-Community-Developers/AM2RLauncher/releases/latest/download/AM2RLauncher_" + onlineVersion + platformSuffix + ".zip to " + zipPath + "."); @@ -174,7 +171,7 @@ namespace AM2RLauncher File.Delete(zipPath); File.Move(UpdatePath + "/" + CrossPlatformOperations.LAUNCHERNAME, CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak"); - if (CurrentPlatform.IsWinForms) File.Move(CrossPlatformOperations.LAUNCHERNAME + ".config", CrossPlatformOperations.LAUNCHERNAME + ".oldCfg"); + if (OS.IsWindows) File.Move(CrossPlatformOperations.LAUNCHERNAME + ".config", CrossPlatformOperations.LAUNCHERNAME + ".oldCfg"); foreach (var file in new DirectoryInfo(tmpUpdatePath).GetFiles()) { @@ -182,7 +179,7 @@ namespace AM2RLauncher File.Copy(file.FullName, UpdatePath + "/" + file.Name, true); } // For windows, the actual application is in "AM2RLauncher.dll". Which means, we need to update the lib folder as well. - if (CurrentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib")) + if (OS.IsWindows && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib")) { // So, because Windows behavior is dumb... @@ -212,7 +209,7 @@ namespace AM2RLauncher Log.Info("Files extracted. Preparing to restart executable..."); - if (CurrentPlatform.IsGtk) System.Diagnostics.Process.Start("chmod", "+x ./AM2RLauncher.Gtk"); + if (OS.IsLinux) System.Diagnostics.Process.Start("chmod", "+x ./AM2RLauncher.Gtk"); System.Diagnostics.Process.Start(UpdatePath + "/" + CrossPlatformOperations.LAUNCHERNAME); Environment.Exit(0); diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs index d617828..8ac3fc9 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs @@ -33,7 +33,7 @@ namespace AM2RLauncher private async void PlayButtonLoadComplete(object sender, EventArgs e) { LoadProfiles(); - if (!HelperMethods.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked) + if (!Profile.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked) return; SetPlayButtonState(UpdateState.Downloading); @@ -297,7 +297,7 @@ namespace AM2RLauncher return; } - IsZipAM2R11ReturnCodes errorCode = HelperMethods.CheckIfZipIsAM2R11(fileFinder.FileName); + IsZipAM2R11ReturnCodes errorCode = Profile.CheckIfZipIsAM2R11(fileFinder.FileName); if (errorCode != IsZipAM2R11ReturnCodes.Successful) { Log.Error("User tried to input invalid AM2R_11.zip file (" + errorCode + "). Cancelling import."); @@ -350,7 +350,6 @@ namespace AM2RLauncher Log.Error("Xdelta not found. Aborting installing a profile..."); break; } - //TODO: handle this until progress is set to 100 var progressIndicator = new Progress(UpdateProgressBar); bool useHqMusic = hqMusicPCCheck.Checked.Value; await Task.Run(() => Profile.InstallProfile(profileList[profileIndex.Value], useHqMusic, progressIndicator)); @@ -377,7 +376,6 @@ namespace AM2RLauncher #region Play case UpdateState.Play: - //TODO: put this block where this method would be called if (!IsProfileIndexValid()) return; @@ -401,7 +399,6 @@ namespace AM2RLauncher string envVarText = customEnvVarTextBox?.Text; bool createDebugLogs = profileDebugLogCheck.Checked.Value; - //TODO: handle this with the env var text box await Task.Run(() => Profile.RunGame(profile, createDebugLogs, envVarText)); this.ShowInTaskbar = true; @@ -485,7 +482,6 @@ namespace AM2RLauncher progressBar.Visible = true; bool useHqMusic = hqMusicAndroidCheck.Checked.Value; - //TODO: handle this until progress is set to 100 var progressIndicator = new Progress(UpdateProgressBar); await Task.Run(() => Profile.CreateAPK(profileList[profileIndex.Value], useHqMusic, progressIndicator)); @@ -604,16 +600,11 @@ namespace AM2RLauncher ProfileXML profile = Serializer.Deserialize(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml")); // Check if the OS versions match - if ((Platform.IsWinForms && profile.OperatingSystem != "Windows") || (Platform.IsGtk && profile.OperatingSystem != "Linux") || (Platform.IsMac && profile.OperatingSystem != "Mac")) + if (OS.Name != profile.OperatingSystem) { - string currentOS = ""; - if (Platform.IsWinForms) currentOS = "Windows"; - else if (Platform.IsGtk) currentOS = "Linux"; // Teeeeechnically, any OS could run GTK applications as well but it'd break a lot and is thus unsupported. - else if (Platform.IsMac) currentOS = "Mac"; + Log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + OS.Name + ". Cancelling mod import."); - Log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + Platform + ". Cancelling mod import."); - - MessageBox.Show(Language.Text.ModIsForWrongOS.Replace("$NAME", profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", currentOS), + MessageBox.Show(Language.Text.ModIsForWrongOS.Replace("$NAME", profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", OS.Name), Language.Text.ErrorWindowTitle, MessageBoxType.Error); HelperMethods.DeleteDirectory(modsDir + "/" + extractedName); return; @@ -675,10 +666,9 @@ namespace AM2RLauncher /// private void SettingsProfileDropDownSelectedIndexChanged(object sender, EventArgs e) { - //TODO: Eto bug, staying here until it gets fixed. - if (Platform.IsMac && settingsProfileDropDown.SelectedIndex == -1 && settingsProfileDropDown.Items.Count == 0) return; - Log.Info("SettingsProfileDropDown.SelectedIndex has been changed to " + settingsProfileDropDown.SelectedIndex + "."); + if (settingsProfileDropDown.SelectedIndex == -1 && settingsProfileDropDown.Items.Count == 0) return; + Log.Info("SettingsProfileDropDown.SelectedIndex has been changed to " + settingsProfileDropDown.SelectedIndex + "."); if (settingsProfileDropDown.SelectedIndex <= 0 || settingsProfileDropDown.Items.Count == 0) { deleteModButton.Enabled = false; @@ -733,7 +723,7 @@ namespace AM2RLauncher // Get drawing variables int height = drawable.Height; int width = drawable.Width; - float scaleDivisor = Platform.IsWinForms ? 955f : 715f; // Magic brute-forced values. Don't ask questions, because we don't have answers >_> + float scaleDivisor = OS.IsWindows ? 955f : 715f; // Magic brute-forced values. Don't ask questions, because we don't have answers >_> // Also, seems like nix systems share the same scaleDivisor. Again, don't ask. float scale = height / scaleDivisor; @@ -783,8 +773,7 @@ namespace AM2RLauncher /// Gets called when user selects a different item from and changes accordingly. private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e) { - //TODO: Eto bug, staying here until it gets fixed. - if (Platform.IsMac && profileDropDown.SelectedIndex == -1 && profileDropDown.Items.Count == 0) return; + if (profileDropDown.SelectedIndex == -1 && profileDropDown.Items.Count == 0) return; profileIndex = profileDropDown.SelectedIndex; Log.Info("profileDropDown.SelectedIndex has been changed to " + profileIndex + "."); @@ -835,7 +824,7 @@ namespace AM2RLauncher customMirrorTextBox.Enabled = enabled; mirrorDropDown.Enabled = !enabled; // Not sure why the dropdown menu needs this hack, but the textBox does not. - if (Platform.IsWinForms) + if (OS.IsWindows) mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; mirrorLabel.TextColor = !enabled ? colGreen : colInactive; @@ -934,7 +923,7 @@ namespace AM2RLauncher bool enabled = (bool)customMirrorCheck.Checked; customMirrorTextBox.Enabled = enabled; mirrorDropDown.Enabled = !enabled; - if (Platform.IsWinForms) + if (OS.IsWindows) mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; } diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs index 96552ce..9f96efd 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.StateMachine.cs @@ -36,7 +36,7 @@ namespace AM2RLauncher { playButton.Enabled = true; // If PatchData is cloned... - if (HelperMethods.IsPatchDataCloned()) + if (Profile.IsPatchDataCloned()) { // If 1.1 is installed or if the current profile is invalid... if (Profile.Is11Installed()) @@ -142,7 +142,7 @@ namespace AM2RLauncher Color col = profileDropDown.Enabled ? colGreen : colInactive; - if (Platform.IsWinForms) + if (OS.IsWindows) profileDropDown.TextColor = col; profileAuthorLabel.TextColor = col; profileVersionLabel.TextColor = col; @@ -190,7 +190,7 @@ namespace AM2RLauncher Color col = enabled ? colGreen : colInactive; - if (Platform.IsWinForms) + if (OS.IsWindows) settingsProfileDropDown.TextColor = col; settingsProfileLabel.TextColor = col; diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs index 7b2b0b8..4b57ce9 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs @@ -1,4 +1,5 @@ -using AM2RLauncher.Core.XML; +using AM2RLauncher.Core; +using AM2RLauncher.Core.XML; using Eto.Drawing; using Eto.Forms; using log4net; @@ -35,7 +36,6 @@ namespace AM2RLauncher /// private static readonly Bitmap am2rIcon = new Bitmap(AM2RLauncher.Properties.Resources.AM2RIcon); - //TODO: this should be part of GUI /// /// An enum, that has possible states for our Launcher. /// @@ -99,7 +99,7 @@ namespace AM2RLauncher if (!singleInstance) { // If on Windows, set the original app to the foreground window to prevent confusion - if (Platform.IsWinForms) + if (OS.IsWindows) { Process current = Process.GetCurrentProcess(); foreach (Process process in Process.GetProcessesByName(current.ProcessName)) @@ -116,14 +116,17 @@ namespace AM2RLauncher Log.Info("Mutex check passed. Entering main thread."); Log.Info("Current Launcher Version: " + VERSION); Log.Info("Current Platform-ID is: " + Platform.ID); + Log.Info("Current OS is: " + OS.Name); //Log Wine + //TODO: move this to WPF project? if (isThisRunningFromWine) { Log.Info("Currently running from WINE!"); } // Log distro and version (if it exists) - else if (Platform.IsGtk) + //TODO: move this to GTK project? + else if (OS.IsLinux) { if (File.Exists("/etc/os-release")) { @@ -139,7 +142,7 @@ namespace AM2RLauncher } // Set the Current Directory to the path the Launcher is located. Fixes some relative path issues. - Environment.CurrentDirectory = Core.CrossPlatformOperations.CURRENTPATH; + Environment.CurrentDirectory = CrossPlatformOperations.CURRENTPATH; Log.Info("Set Launcher CWD to " + Environment.CurrentDirectory); // But log actual folder location nonetheless @@ -166,7 +169,7 @@ namespace AM2RLauncher }; // Create menubar with defaults for mac - if (Platform.IsMac) + if (OS.IsMac) Menu = new MenuBar(); // Create array from validCount @@ -195,7 +198,7 @@ namespace AM2RLauncher colInactive = Color.FromArgb(109, 109, 109); colBGNoAlpha = Color.FromArgb(10, 10, 10); colBG = Color.FromArgb(10, 10, 10, 80); - if (Platform.IsGtk) colBG = colBGNoAlpha; // XORG can't display alpha anyway, and Wayland breaks with it. + if (OS.IsLinux) colBG = colBGNoAlpha; // XORG can't display alpha anyway, and Wayland breaks with it. colBGHover = Color.FromArgb(17, 28, 13); Font smallButtonFont = new Font(SystemFont.Default, 10); @@ -234,7 +237,7 @@ namespace AM2RLauncher // Drawable paint event drawable.Paint += DrawablePaintEvent; // Some systems don't call the paintEvent by default and only do so after actual resizing - if (Platform.IsMac) + if (OS.IsMac) LoadComplete += (sender, e) => { Size = new Size(Size.Width + 1, Size.Height); Size = new Size(Size.Width - 1, Size.Height);}; #region MAIN WINDOW @@ -263,7 +266,7 @@ namespace AM2RLauncher centerInterface.AddRow(playButton); // 2px spacer between playButton and apkButton (Windows only) - if (Platform.IsWinForms) centerInterface.AddRow(new Label { BackgroundColor = colBG, Height = 2 }); + if (OS.IsWindows) centerInterface.AddRow(new Label { BackgroundColor = colBG, Height = 2 }); // APK button apkButton = new ColorButton @@ -286,7 +289,7 @@ namespace AM2RLauncher }; // 4px spacer between APK button and progressBar (Windows only) - if (Platform.IsWinForms) centerInterface.AddRow(new Label { BackgroundColor = colBG, Height = 4 }); + if (OS.IsWindows) centerInterface.AddRow(new Label { BackgroundColor = colBG, Height = 4 }); centerInterface.AddRow(progressBar); @@ -302,7 +305,7 @@ namespace AM2RLauncher centerInterface.AddRow(progressLabel); // 3px spacer between progressBar and profile label (Windows only) - if (Platform.IsWinForms) centerInterface.AddRow(new Label { BackgroundColor = colBG, Height = 3 }); + if (OS.IsWindows) centerInterface.AddRow(new Label { BackgroundColor = colBG, Height = 3 }); profileLabel = new Label { @@ -322,10 +325,10 @@ namespace AM2RLauncher profileDropDown = new DropDown { TextColor = colGreen, - BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color() + BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color() }; // In order to not have conflicting theming, we just always respect the users theme for dropdown on GTK. - if (Platform.IsGtk) + if (OS.IsLinux) profileDropDown = new DropDown(); profileDropDown.Items.AddRange(profileNames); // It's actually more comfortable if it's outside, because of GTK shenanigans @@ -426,7 +429,8 @@ namespace AM2RLauncher changelogWebView = new WebView { Url = changelogUri }; - if (Platform.IsGtk && !isInternetThere) + //TODO: what happens if one would make this on unix instead of linux? + if (OS.IsLinux && !isInternetThere) changelogWebView = new WebView(); changelogNoConnectionLabel = new Label @@ -454,7 +458,8 @@ namespace AM2RLauncher newsUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/news.html"); newsWebView = new WebView { Url = newsUri }; - if (Platform.IsGtk && !isInternetThere) + //TODO: see todo above + if (OS.IsLinux && !isInternetThere) newsWebView = new WebView(); newsNoConnectionLabel = new Label @@ -477,8 +482,8 @@ namespace AM2RLauncher } }; - - if (Platform.IsGtk && !isInternetThere) + //TODO: see todo above + if (OS.IsLinux && !isInternetThere) { changelogPage.Content = new TableLayout { @@ -529,9 +534,9 @@ namespace AM2RLauncher languageDropDown = new DropDown { TextColor = colGreen, - BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color() + BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color() }; - if (Platform.IsGtk) + if (OS.IsLinux) languageDropDown = new DropDown(); languageDropDown.Items.AddRange(languageList); @@ -581,14 +586,14 @@ namespace AM2RLauncher // Create game debug logs profileDebugLogCheck = new CheckBox { - Checked = bool.Parse(Core.CrossPlatformOperations.ReadFromConfig("ProfileDebugLog")), + Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("ProfileDebugLog")), Text = Language.Text.ProfileDebugCheckBox, TextColor = colGreen }; // Custom environment variables label customEnvVarLabel = new Label(); - if (Platform.IsGtk) + if (OS.IsLinux) { customEnvVarLabel = new Label { @@ -599,11 +604,11 @@ namespace AM2RLauncher // Custom environment variables textbox customEnvVarTextBox = null; - if (Platform.IsGtk) + if (OS.IsLinux) { customEnvVarTextBox = new TextBox { - Text = Core.CrossPlatformOperations.ReadFromConfig("CustomEnvVar"), + Text = CrossPlatformOperations.ReadFromConfig("CustomEnvVar"), BackgroundColor = colBGNoAlpha, TextColor = colGreen }; @@ -619,14 +624,14 @@ namespace AM2RLauncher mirrorDropDown = new DropDown { TextColor = colGreen, - BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color() + BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color() }; - if (Platform.IsGtk) + if (OS.IsLinux) mirrorDropDown = new DropDown(); mirrorDropDown.Items.AddRange(mirrorDescriptionList); // As above, find a way to get this inside the dropDown definition - mirrorIndex = (Int32.Parse(Core.CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? Int32.Parse(Core.CrossPlatformOperations.ReadFromConfig("MirrorIndex")) - : 0; + mirrorIndex = (Int32.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? Int32.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) + : 0; mirrorDropDown.SelectedIndex = mirrorIndex; currentMirror = mirrorList[mirrorDropDown.SelectedIndex]; @@ -691,11 +696,11 @@ namespace AM2RLauncher settingsProfileDropDown = new DropDown { TextColor = colGreen, - BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color() + BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color() }; // In order to not have conflicting theming, we just always respect the users theme for dropdown on GTK. - if (Platform.IsGtk) + if (OS.IsLinux) settingsProfileDropDown = new DropDown(); settingsProfileDropDown.Items.AddRange(profileNames); // It's actually more comfortable if it's outside, because of GTK shenanigans @@ -822,7 +827,7 @@ namespace AM2RLauncher deleteModButton.Click += DeleteModButtonClicked; updateModButton.Click += UpdateModButtonClicked; profileDebugLogCheck.CheckedChanged += ProfileDebugLogCheckedChanged; - if (Platform.IsGtk) + if (OS.IsLinux) customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus; //TODO: These don't work properly on mac? Maybe on other platforms too? diff --git a/AM2RLauncher/AM2RLauncherCore/Core.cs b/AM2RLauncher/AM2RLauncherCore/Core.cs index 2afe034..7d648f7 100644 --- a/AM2RLauncher/AM2RLauncherCore/Core.cs +++ b/AM2RLauncher/AM2RLauncherCore/Core.cs @@ -7,10 +7,11 @@ using System.Runtime.InteropServices; namespace AM2RLauncher.Core { - //TODO: document a ton of these new movings + /// + /// Class that has core stuff that doesn't fit anywhere else + /// public static class Core { - // Load reference to logger /// /// Our log object, that handles logging the current execution to a file. /// @@ -29,6 +30,10 @@ namespace AM2RLauncher.Core /// public static readonly bool isInternetThere = HelperMethods.IsConnectedToInternet(); + /// + /// Checks if this is ran from WINE + /// + /// if run from WINE, if not. private static bool CheckIfRunFromWINE() { if (OS.IsWindows && Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null) diff --git a/AM2RLauncher/AM2RLauncherCore/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncherCore/CrossPlatformOperations.cs index c716186..dd09f2f 100644 --- a/AM2RLauncher/AM2RLauncherCore/CrossPlatformOperations.cs +++ b/AM2RLauncher/AM2RLauncherCore/CrossPlatformOperations.cs @@ -10,7 +10,7 @@ using System.Text.RegularExpressions; namespace AM2RLauncher.Core { /// - /// Class that does Operations that work cross-platform. + /// Class that does operations that work cross-platform. /// public static class CrossPlatformOperations { diff --git a/AM2RLauncher/AM2RLauncherCore/HelperMethods.cs b/AM2RLauncher/AM2RLauncherCore/HelperMethods.cs index caae192..4f00e85 100644 --- a/AM2RLauncher/AM2RLauncherCore/HelperMethods.cs +++ b/AM2RLauncher/AM2RLauncherCore/HelperMethods.cs @@ -12,19 +12,7 @@ using System.Text; namespace AM2RLauncher.Core { /// - /// An enum, that has possible return codes for . - /// - public enum IsZipAM2R11ReturnCodes - { - Successful, - MissingOrInvalidAM2RExe, - MissingOrInvalidD3DX9_43Dll, - MissingOrInvalidDataWin, - GameIsInASubfolder - } - - /// - /// Class that has various Helper functions. Basically anything that could be used outside the Launcher GUI resides here. + /// Class that has various Helper functions. Basically anything that could be used outside the Launcher resides here. /// public static class HelperMethods { @@ -155,7 +143,7 @@ namespace AM2RLauncher.Core RecursiveRollover(fileName, max); } - //TODO: this can fail + //TODO: this can fail if one doesnt have permissions to move or delete the file // If index is less than max, rename file. if (index < max) { @@ -185,74 +173,5 @@ namespace AM2RLauncher.Core Log.Info("Internet connection established!"); return true; } - - /// - /// Checks if the repository has been validly cloned already. - /// - /// if yes, if not. - public static bool IsPatchDataCloned() - { - // isValid seems to only check for a .git folder, and there are cases where that exists, but not the profile.xml - return Repository.IsValid(CrossPlatformOperations.CURRENTPATH + "/PatchData") && File.Exists(CrossPlatformOperations.CURRENTPATH + "/PatchData/profile.xml"); - } - - /// - /// Checks if a Zip file is a valid AM2R_1.1 zip. - /// - /// Full Path to the Zip file to check. - /// detailing the result - public static IsZipAM2R11ReturnCodes CheckIfZipIsAM2R11(string zipPath) - { - const string d3dHash = "86e39e9161c3d930d93822f1563c280d"; - const string dataWinHash = "f2b84fe5ba64cb64e284be1066ca08ee"; - const string am2rHash = "15253f7a66d6ea3feef004ebbee9b438"; - - string tmpPath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(zipPath); - - // Clean up in case folder exists already - if (Directory.Exists(tmpPath)) - Directory.Delete(tmpPath, true); - - Directory.CreateDirectory(tmpPath); - - // Open archive - ZipArchive am2rZip = ZipFile.OpenRead(zipPath); - - // Check if exe exists anywhere - ZipArchiveEntry am2rExe = am2rZip.Entries.FirstOrDefault(x => x.FullName.Contains("AM2R.exe")); - if (am2rExe == null) - return IsZipAM2R11ReturnCodes.MissingOrInvalidAM2RExe; - // Check if it's not in a subfolder. if it'd be in a subfolder, fullname would be "folder/AM2R.exe" - if (am2rExe.FullName != "AM2R.exe") - return IsZipAM2R11ReturnCodes.GameIsInASubfolder; - // Check validity - am2rExe.ExtractToFile(tmpPath + "/" + am2rExe.FullName); - if (HelperMethods.CalculateMD5(tmpPath + "/" + am2rExe.FullName) != am2rHash) - return IsZipAM2R11ReturnCodes.MissingOrInvalidAM2RExe; - - // Check if data.win exists / is valid - ZipArchiveEntry dataWin = am2rZip.Entries.FirstOrDefault(x => x.FullName == "data.win"); - if (dataWin == null) - return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin; - dataWin.ExtractToFile(tmpPath + "/" + dataWin.FullName); - if (HelperMethods.CalculateMD5(tmpPath + "/" + dataWin.FullName) != dataWinHash) - return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin; - - // Check if d3d.dll exists / is valid - ZipArchiveEntry d3dx = am2rZip.Entries.FirstOrDefault(x => x.FullName == "D3DX9_43.dll"); - if (d3dx == null) - return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll; - d3dx.ExtractToFile(tmpPath + "/" + d3dx.FullName); - if (HelperMethods.CalculateMD5(tmpPath + "/" + d3dx.FullName) != d3dHash) - return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll; - - // Clean up - Directory.Delete(tmpPath, true); - - // If we didn't exit before, everything is fine - Log.Info("AM2R_11 check successful!"); - return IsZipAM2R11ReturnCodes.Successful; - } - } } diff --git a/AM2RLauncher/AM2RLauncherCore/OS.cs b/AM2RLauncher/AM2RLauncherCore/OS.cs index a4fd421..23e581a 100644 --- a/AM2RLauncher/AM2RLauncherCore/OS.cs +++ b/AM2RLauncher/AM2RLauncherCore/OS.cs @@ -5,18 +5,39 @@ using System.Text; namespace AM2RLauncher.Core { + /// + /// Class that has information about the current running operating system. + /// public class OS { + /// + /// Determines if the current OS is Windows. + /// public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + /// + /// Determines if the current OS is Linux. + /// public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + /// + /// Determines if the current OS is Mac. + /// public static readonly bool IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + /// + /// Determines if the current OS is a unix based system (Mac or Linux). + /// public static readonly bool IsUnix = IsLinux || IsMac; + /// + /// Gets a string representation of the current OS. + /// public static readonly string Name = DetermineOSName(); + /// + /// Generates a string representation of the current OS + /// private static string DetermineOSName() { if (IsWindows) @@ -24,7 +45,7 @@ namespace AM2RLauncher.Core else if (IsLinux) return "Linux"; else if (IsMac) - return "MacOS"; + return "Mac"; else return "Unknown OS"; } diff --git a/AM2RLauncher/AM2RLauncherCore/Profile.cs b/AM2RLauncher/AM2RLauncherCore/Profile.cs index c0eb68a..181ed0d 100644 --- a/AM2RLauncher/AM2RLauncherCore/Profile.cs +++ b/AM2RLauncher/AM2RLauncherCore/Profile.cs @@ -13,6 +13,21 @@ using System.Threading; namespace AM2RLauncher.Core { + /// + /// An enum, that has possible return codes for . + /// + public enum IsZipAM2R11ReturnCodes + { + Successful, + MissingOrInvalidAM2RExe, + MissingOrInvalidD3DX9_43Dll, + MissingOrInvalidDataWin, + GameIsInASubfolder + } + + /// + /// Class that has methods related to AM2RLauncher profiles. + /// public static class Profile { @@ -47,7 +62,7 @@ namespace AM2RLauncher.Core // Return safely if file doesn't exist if (!File.Exists(am2r11file)) return false; lastAM2R11ZipMD5 = HelperMethods.CalculateMD5(am2r11file); - var returnCode = HelperMethods.CheckIfZipIsAM2R11(am2r11file); + var returnCode = Profile.CheckIfZipIsAM2R11(am2r11file); // Check if it's valid, if not log it, rename it and silently leave if (returnCode != IsZipAM2R11ReturnCodes.Successful) { @@ -620,5 +635,73 @@ namespace AM2RLauncher.Core Log.Info("Profile " + profile.Name + " process exited."); } + + /// + /// Checks if the repository has been validly cloned already. + /// + /// if yes, if not. + public static bool IsPatchDataCloned() + { + // isValid seems to only check for a .git folder, and there are cases where that exists, but not the profile.xml + return Repository.IsValid(CrossPlatformOperations.CURRENTPATH + "/PatchData") && File.Exists(CrossPlatformOperations.CURRENTPATH + "/PatchData/profile.xml"); + } + + /// + /// Checks if a Zip file is a valid AM2R_1.1 zip. + /// + /// Full Path to the Zip file to check. + /// detailing the result + public static IsZipAM2R11ReturnCodes CheckIfZipIsAM2R11(string zipPath) + { + const string d3dHash = "86e39e9161c3d930d93822f1563c280d"; + const string dataWinHash = "f2b84fe5ba64cb64e284be1066ca08ee"; + const string am2rHash = "15253f7a66d6ea3feef004ebbee9b438"; + + string tmpPath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(zipPath); + + // Clean up in case folder exists already + if (Directory.Exists(tmpPath)) + Directory.Delete(tmpPath, true); + + Directory.CreateDirectory(tmpPath); + + // Open archive + ZipArchive am2rZip = ZipFile.OpenRead(zipPath); + + // Check if exe exists anywhere + ZipArchiveEntry am2rExe = am2rZip.Entries.FirstOrDefault(x => x.FullName.Contains("AM2R.exe")); + if (am2rExe == null) + return IsZipAM2R11ReturnCodes.MissingOrInvalidAM2RExe; + // Check if it's not in a subfolder. if it'd be in a subfolder, fullname would be "folder/AM2R.exe" + if (am2rExe.FullName != "AM2R.exe") + return IsZipAM2R11ReturnCodes.GameIsInASubfolder; + // Check validity + am2rExe.ExtractToFile(tmpPath + "/" + am2rExe.FullName); + if (HelperMethods.CalculateMD5(tmpPath + "/" + am2rExe.FullName) != am2rHash) + return IsZipAM2R11ReturnCodes.MissingOrInvalidAM2RExe; + + // Check if data.win exists / is valid + ZipArchiveEntry dataWin = am2rZip.Entries.FirstOrDefault(x => x.FullName == "data.win"); + if (dataWin == null) + return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin; + dataWin.ExtractToFile(tmpPath + "/" + dataWin.FullName); + if (HelperMethods.CalculateMD5(tmpPath + "/" + dataWin.FullName) != dataWinHash) + return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin; + + // Check if d3d.dll exists / is valid + ZipArchiveEntry d3dx = am2rZip.Entries.FirstOrDefault(x => x.FullName == "D3DX9_43.dll"); + if (d3dx == null) + return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll; + d3dx.ExtractToFile(tmpPath + "/" + d3dx.FullName); + if (HelperMethods.CalculateMD5(tmpPath + "/" + d3dx.FullName) != d3dHash) + return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll; + + // Clean up + Directory.Delete(tmpPath, true); + + // If we didn't exit before, everything is fine + Log.Info("AM2R_11 check successful!"); + return IsZipAM2R11ReturnCodes.Successful; + } } } diff --git a/AM2RLauncher/AM2RLauncherCore/Splash.cs b/AM2RLauncher/AM2RLauncherCore/Splash.cs index 2243105..1c511ce 100644 --- a/AM2RLauncher/AM2RLauncherCore/Splash.cs +++ b/AM2RLauncher/AM2RLauncherCore/Splash.cs @@ -45,6 +45,15 @@ namespace AM2RLauncher.Core "Did you know that games take time to develop?" }; + /// + /// Windows only splash strings + /// + private static readonly string[] windowsSplash = + { + ":(", + "All your machine are belong to MS" + }; + /// /// Linux only splash strings /// @@ -71,6 +80,19 @@ namespace AM2RLauncher.Core "Did you find the penguin yet?" }; + /// + /// Mac only splash strings + /// + private static readonly string[] macSplash = + { + "Does this even work?", + "You weren't supposed to do that!", + "Another Mac 2 Remake", + "This shouldn't even be possible", + "How long until this breaks?", + "Have fun trying to convince modders to support this!" + }; + /// /// Combined splash strings /// @@ -95,9 +117,12 @@ namespace AM2RLauncher.Core private static string[] combineSplashes() { string[] totalSplashes; - if (OS.IsLinux) + if (OS.IsWindows) + totalSplashes = generalSplash.Concat(windowsSplash).ToArray(); + else if (OS.IsLinux) totalSplashes = generalSplash.Concat(linuxSplash).ToArray(); - // else if (Platform.Instance.IsMac) combinedSplash = GeneralSplash.Concat(MacSplash).ToArray(); + else if (OS.IsMac) + totalSplashes = generalSplash.Concat(macSplash).ToArray(); else totalSplashes = generalSplash; return totalSplashes;