Fix todos, replace platform with OS, add splashes, documentation

pull/32/head
Miepee 5 years ago
parent 7a72c8fdcc
commit 398a44e92d

@ -20,16 +20,13 @@ namespace AM2RLauncher
/// <summary>The Version that identifies this current release.</summary> /// <summary>The Version that identifies this current release.</summary>
public const string VERSION = Core.Core.VERSION; public const string VERSION = Core.Core.VERSION;
/// <summary>The current Running platform.</summary>
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
/// <summary>The Path of the oldConfig. Only gets used Windows-only</summary> /// <summary>The Path of the oldConfig. Only gets used Windows-only</summary>
private static readonly string OldConfigPath = CrossPlatformOperations.CURRENTPATH + "/" + CrossPlatformOperations.LAUNCHERNAME + ".oldCfg"; private static readonly string OldConfigPath = CrossPlatformOperations.CURRENTPATH + "/" + CrossPlatformOperations.LAUNCHERNAME + ".oldCfg";
/// <summary>The actual Path where the executable is stored, only used for updating.</summary> /// <summary>The actual Path where the executable is stored, only used for updating.</summary>
//TODO: for mac, this reports the path of the mac runner, not the actual .app //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
/// <summary> /// <summary>
/// Our log object, that handles logging the current execution to a file. /// 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."); Log.Info("AM2RLauncher.bak detected. Removing file.");
File.Delete(CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak"); 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."); Log.Info(CrossPlatformOperations.LAUNCHERNAME + ".oldCfg detected. Removing file.");
File.Delete(OldConfigPath); 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."); Log.Info("Old lib folder detected, removing folder.");
Directory.Delete(CrossPlatformOperations.CURRENTPATH + "/oldLib", true); Directory.Delete(CrossPlatformOperations.CURRENTPATH + "/oldLib", true);
} }
// Clean up old update libs // 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()) 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(?) // 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 // 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.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
@ -152,8 +149,8 @@ namespace AM2RLauncher
using (var client = new WebClient()) using (var client = new WebClient())
{ {
string platformSuffix = ""; string platformSuffix = "";
if (CurrentPlatform.IsWinForms) platformSuffix = "_win"; if (OS.IsWindows) platformSuffix = "_win";
else if (CurrentPlatform.IsGtk) platformSuffix = "_lin"; 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 + "."); 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.Delete(zipPath);
File.Move(UpdatePath + "/" + CrossPlatformOperations.LAUNCHERNAME, CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak"); 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()) foreach (var file in new DirectoryInfo(tmpUpdatePath).GetFiles())
{ {
@ -182,7 +179,7 @@ namespace AM2RLauncher
File.Copy(file.FullName, UpdatePath + "/" + file.Name, true); 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. // 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... // So, because Windows behavior is dumb...
@ -212,7 +209,7 @@ namespace AM2RLauncher
Log.Info("Files extracted. Preparing to restart executable..."); 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); System.Diagnostics.Process.Start(UpdatePath + "/" + CrossPlatformOperations.LAUNCHERNAME);
Environment.Exit(0); Environment.Exit(0);

@ -33,7 +33,7 @@ namespace AM2RLauncher
private async void PlayButtonLoadComplete(object sender, EventArgs e) private async void PlayButtonLoadComplete(object sender, EventArgs e)
{ {
LoadProfiles(); LoadProfiles();
if (!HelperMethods.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked) if (!Profile.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked)
return; return;
SetPlayButtonState(UpdateState.Downloading); SetPlayButtonState(UpdateState.Downloading);
@ -297,7 +297,7 @@ namespace AM2RLauncher
return; return;
} }
IsZipAM2R11ReturnCodes errorCode = HelperMethods.CheckIfZipIsAM2R11(fileFinder.FileName); IsZipAM2R11ReturnCodes errorCode = Profile.CheckIfZipIsAM2R11(fileFinder.FileName);
if (errorCode != IsZipAM2R11ReturnCodes.Successful) if (errorCode != IsZipAM2R11ReturnCodes.Successful)
{ {
Log.Error("User tried to input invalid AM2R_11.zip file (" + errorCode + "). Cancelling import."); 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..."); Log.Error("Xdelta not found. Aborting installing a profile...");
break; break;
} }
//TODO: handle this until progress is set to 100
var progressIndicator = new Progress<int>(UpdateProgressBar); var progressIndicator = new Progress<int>(UpdateProgressBar);
bool useHqMusic = hqMusicPCCheck.Checked.Value; bool useHqMusic = hqMusicPCCheck.Checked.Value;
await Task.Run(() => Profile.InstallProfile(profileList[profileIndex.Value], useHqMusic, progressIndicator)); await Task.Run(() => Profile.InstallProfile(profileList[profileIndex.Value], useHqMusic, progressIndicator));
@ -377,7 +376,6 @@ namespace AM2RLauncher
#region Play #region Play
case UpdateState.Play: case UpdateState.Play:
//TODO: put this block where this method would be called
if (!IsProfileIndexValid()) if (!IsProfileIndexValid())
return; return;
@ -401,7 +399,6 @@ namespace AM2RLauncher
string envVarText = customEnvVarTextBox?.Text; string envVarText = customEnvVarTextBox?.Text;
bool createDebugLogs = profileDebugLogCheck.Checked.Value; bool createDebugLogs = profileDebugLogCheck.Checked.Value;
//TODO: handle this with the env var text box
await Task.Run(() => Profile.RunGame(profile, createDebugLogs, envVarText)); await Task.Run(() => Profile.RunGame(profile, createDebugLogs, envVarText));
this.ShowInTaskbar = true; this.ShowInTaskbar = true;
@ -485,7 +482,6 @@ namespace AM2RLauncher
progressBar.Visible = true; progressBar.Visible = true;
bool useHqMusic = hqMusicAndroidCheck.Checked.Value; bool useHqMusic = hqMusicAndroidCheck.Checked.Value;
//TODO: handle this until progress is set to 100
var progressIndicator = new Progress<int>(UpdateProgressBar); var progressIndicator = new Progress<int>(UpdateProgressBar);
await Task.Run(() => Profile.CreateAPK(profileList[profileIndex.Value], useHqMusic, progressIndicator)); await Task.Run(() => Profile.CreateAPK(profileList[profileIndex.Value], useHqMusic, progressIndicator));
@ -604,16 +600,11 @@ namespace AM2RLauncher
ProfileXML profile = Serializer.Deserialize<ProfileXML>(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml")); ProfileXML profile = Serializer.Deserialize<ProfileXML>(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml"));
// Check if the OS versions match // 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 = ""; Log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + OS.Name + ". Cancelling mod import.");
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 " + Platform + ". Cancelling mod import."); MessageBox.Show(Language.Text.ModIsForWrongOS.Replace("$NAME", profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", OS.Name),
MessageBox.Show(Language.Text.ModIsForWrongOS.Replace("$NAME", profile.Name).Replace("$OS", profile.OperatingSystem).Replace("$CURRENTOS", currentOS),
Language.Text.ErrorWindowTitle, MessageBoxType.Error); Language.Text.ErrorWindowTitle, MessageBoxType.Error);
HelperMethods.DeleteDirectory(modsDir + "/" + extractedName); HelperMethods.DeleteDirectory(modsDir + "/" + extractedName);
return; return;
@ -675,10 +666,9 @@ namespace AM2RLauncher
/// </summary> /// </summary>
private void SettingsProfileDropDownSelectedIndexChanged(object sender, EventArgs e) private void SettingsProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{ {
//TODO: Eto bug, staying here until it gets fixed. if (settingsProfileDropDown.SelectedIndex == -1 && settingsProfileDropDown.Items.Count == 0) return;
if (Platform.IsMac && settingsProfileDropDown.SelectedIndex == -1 && settingsProfileDropDown.Items.Count == 0) return;
Log.Info("SettingsProfileDropDown.SelectedIndex has been changed to " + settingsProfileDropDown.SelectedIndex + ".");
Log.Info("SettingsProfileDropDown.SelectedIndex has been changed to " + settingsProfileDropDown.SelectedIndex + ".");
if (settingsProfileDropDown.SelectedIndex <= 0 || settingsProfileDropDown.Items.Count == 0) if (settingsProfileDropDown.SelectedIndex <= 0 || settingsProfileDropDown.Items.Count == 0)
{ {
deleteModButton.Enabled = false; deleteModButton.Enabled = false;
@ -733,7 +723,7 @@ namespace AM2RLauncher
// Get drawing variables // Get drawing variables
int height = drawable.Height; int height = drawable.Height;
int width = drawable.Width; 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. // Also, seems like nix systems share the same scaleDivisor. Again, don't ask.
float scale = height / scaleDivisor; float scale = height / scaleDivisor;
@ -783,8 +773,7 @@ namespace AM2RLauncher
/// <summary>Gets called when user selects a different item from <see cref="profileDropDown"/> and changes <see cref="profileAuthorLabel"/> accordingly.</summary> /// <summary>Gets called when user selects a different item from <see cref="profileDropDown"/> and changes <see cref="profileAuthorLabel"/> accordingly.</summary>
private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e) private void ProfileDropDownSelectedIndexChanged(object sender, EventArgs e)
{ {
//TODO: Eto bug, staying here until it gets fixed. if (profileDropDown.SelectedIndex == -1 && profileDropDown.Items.Count == 0) return;
if (Platform.IsMac && profileDropDown.SelectedIndex == -1 && profileDropDown.Items.Count == 0) return;
profileIndex = profileDropDown.SelectedIndex; profileIndex = profileDropDown.SelectedIndex;
Log.Info("profileDropDown.SelectedIndex has been changed to " + profileIndex + "."); Log.Info("profileDropDown.SelectedIndex has been changed to " + profileIndex + ".");
@ -835,7 +824,7 @@ namespace AM2RLauncher
customMirrorTextBox.Enabled = enabled; customMirrorTextBox.Enabled = enabled;
mirrorDropDown.Enabled = !enabled; mirrorDropDown.Enabled = !enabled;
// Not sure why the dropdown menu needs this hack, but the textBox does not. // 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; mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive;
mirrorLabel.TextColor = !enabled ? colGreen : colInactive; mirrorLabel.TextColor = !enabled ? colGreen : colInactive;
@ -934,7 +923,7 @@ namespace AM2RLauncher
bool enabled = (bool)customMirrorCheck.Checked; bool enabled = (bool)customMirrorCheck.Checked;
customMirrorTextBox.Enabled = enabled; customMirrorTextBox.Enabled = enabled;
mirrorDropDown.Enabled = !enabled; mirrorDropDown.Enabled = !enabled;
if (Platform.IsWinForms) if (OS.IsWindows)
mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive; mirrorDropDown.TextColor = mirrorDropDown.Enabled ? colGreen : colInactive;
} }

@ -36,7 +36,7 @@ namespace AM2RLauncher
{ {
playButton.Enabled = true; playButton.Enabled = true;
// If PatchData is cloned... // If PatchData is cloned...
if (HelperMethods.IsPatchDataCloned()) if (Profile.IsPatchDataCloned())
{ {
// If 1.1 is installed or if the current profile is invalid... // If 1.1 is installed or if the current profile is invalid...
if (Profile.Is11Installed()) if (Profile.Is11Installed())
@ -142,7 +142,7 @@ namespace AM2RLauncher
Color col = profileDropDown.Enabled ? colGreen : colInactive; Color col = profileDropDown.Enabled ? colGreen : colInactive;
if (Platform.IsWinForms) if (OS.IsWindows)
profileDropDown.TextColor = col; profileDropDown.TextColor = col;
profileAuthorLabel.TextColor = col; profileAuthorLabel.TextColor = col;
profileVersionLabel.TextColor = col; profileVersionLabel.TextColor = col;
@ -190,7 +190,7 @@ namespace AM2RLauncher
Color col = enabled ? colGreen : colInactive; Color col = enabled ? colGreen : colInactive;
if (Platform.IsWinForms) if (OS.IsWindows)
settingsProfileDropDown.TextColor = col; settingsProfileDropDown.TextColor = col;
settingsProfileLabel.TextColor = col; settingsProfileLabel.TextColor = col;

@ -1,4 +1,5 @@
using AM2RLauncher.Core.XML; using AM2RLauncher.Core;
using AM2RLauncher.Core.XML;
using Eto.Drawing; using Eto.Drawing;
using Eto.Forms; using Eto.Forms;
using log4net; using log4net;
@ -35,7 +36,6 @@ namespace AM2RLauncher
/// </summary> /// </summary>
private static readonly Bitmap am2rIcon = new Bitmap(AM2RLauncher.Properties.Resources.AM2RIcon); private static readonly Bitmap am2rIcon = new Bitmap(AM2RLauncher.Properties.Resources.AM2RIcon);
//TODO: this should be part of GUI
/// <summary> /// <summary>
/// An enum, that has possible states for our Launcher. /// An enum, that has possible states for our Launcher.
/// </summary> /// </summary>
@ -99,7 +99,7 @@ namespace AM2RLauncher
if (!singleInstance) if (!singleInstance)
{ {
// If on Windows, set the original app to the foreground window to prevent confusion // If on Windows, set the original app to the foreground window to prevent confusion
if (Platform.IsWinForms) if (OS.IsWindows)
{ {
Process current = Process.GetCurrentProcess(); Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName)) foreach (Process process in Process.GetProcessesByName(current.ProcessName))
@ -116,14 +116,17 @@ namespace AM2RLauncher
Log.Info("Mutex check passed. Entering main thread."); Log.Info("Mutex check passed. Entering main thread.");
Log.Info("Current Launcher Version: " + VERSION); Log.Info("Current Launcher Version: " + VERSION);
Log.Info("Current Platform-ID is: " + Platform.ID); Log.Info("Current Platform-ID is: " + Platform.ID);
Log.Info("Current OS is: " + OS.Name);
//Log Wine //Log Wine
//TODO: move this to WPF project?
if (isThisRunningFromWine) if (isThisRunningFromWine)
{ {
Log.Info("Currently running from WINE!"); Log.Info("Currently running from WINE!");
} }
// Log distro and version (if it exists) // 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")) 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. // 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); Log.Info("Set Launcher CWD to " + Environment.CurrentDirectory);
// But log actual folder location nonetheless // But log actual folder location nonetheless
@ -166,7 +169,7 @@ namespace AM2RLauncher
}; };
// Create menubar with defaults for mac // Create menubar with defaults for mac
if (Platform.IsMac) if (OS.IsMac)
Menu = new MenuBar(); Menu = new MenuBar();
// Create array from validCount // Create array from validCount
@ -195,7 +198,7 @@ namespace AM2RLauncher
colInactive = Color.FromArgb(109, 109, 109); colInactive = Color.FromArgb(109, 109, 109);
colBGNoAlpha = Color.FromArgb(10, 10, 10); colBGNoAlpha = Color.FromArgb(10, 10, 10);
colBG = Color.FromArgb(10, 10, 10, 80); 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); colBGHover = Color.FromArgb(17, 28, 13);
Font smallButtonFont = new Font(SystemFont.Default, 10); Font smallButtonFont = new Font(SystemFont.Default, 10);
@ -234,7 +237,7 @@ namespace AM2RLauncher
// Drawable paint event // Drawable paint event
drawable.Paint += DrawablePaintEvent; drawable.Paint += DrawablePaintEvent;
// Some systems don't call the paintEvent by default and only do so after actual resizing // 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);}; LoadComplete += (sender, e) => { Size = new Size(Size.Width + 1, Size.Height); Size = new Size(Size.Width - 1, Size.Height);};
#region MAIN WINDOW #region MAIN WINDOW
@ -263,7 +266,7 @@ namespace AM2RLauncher
centerInterface.AddRow(playButton); centerInterface.AddRow(playButton);
// 2px spacer between playButton and apkButton (Windows only) // 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 // APK button
apkButton = new ColorButton apkButton = new ColorButton
@ -286,7 +289,7 @@ namespace AM2RLauncher
}; };
// 4px spacer between APK button and progressBar (Windows only) // 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); centerInterface.AddRow(progressBar);
@ -302,7 +305,7 @@ namespace AM2RLauncher
centerInterface.AddRow(progressLabel); centerInterface.AddRow(progressLabel);
// 3px spacer between progressBar and profile label (Windows only) // 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 profileLabel = new Label
{ {
@ -322,10 +325,10 @@ namespace AM2RLauncher
profileDropDown = new DropDown profileDropDown = new DropDown
{ {
TextColor = colGreen, 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. // 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 = new DropDown();
profileDropDown.Items.AddRange(profileNames); // It's actually more comfortable if it's outside, because of GTK shenanigans 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 }; 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(); changelogWebView = new WebView();
changelogNoConnectionLabel = new Label changelogNoConnectionLabel = new Label
@ -454,7 +458,8 @@ namespace AM2RLauncher
newsUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/news.html"); newsUri = new Uri("https://am2r-community-developers.github.io/DistributionCenter/news.html");
newsWebView = new WebView { Url = newsUri }; newsWebView = new WebView { Url = newsUri };
if (Platform.IsGtk && !isInternetThere) //TODO: see todo above
if (OS.IsLinux && !isInternetThere)
newsWebView = new WebView(); newsWebView = new WebView();
newsNoConnectionLabel = new Label newsNoConnectionLabel = new Label
@ -477,8 +482,8 @@ namespace AM2RLauncher
} }
}; };
//TODO: see todo above
if (Platform.IsGtk && !isInternetThere) if (OS.IsLinux && !isInternetThere)
{ {
changelogPage.Content = new TableLayout changelogPage.Content = new TableLayout
{ {
@ -529,9 +534,9 @@ namespace AM2RLauncher
languageDropDown = new DropDown languageDropDown = new DropDown
{ {
TextColor = colGreen, TextColor = colGreen,
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color() BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color()
}; };
if (Platform.IsGtk) if (OS.IsLinux)
languageDropDown = new DropDown(); languageDropDown = new DropDown();
languageDropDown.Items.AddRange(languageList); languageDropDown.Items.AddRange(languageList);
@ -581,14 +586,14 @@ namespace AM2RLauncher
// Create game debug logs // Create game debug logs
profileDebugLogCheck = new CheckBox profileDebugLogCheck = new CheckBox
{ {
Checked = bool.Parse(Core.CrossPlatformOperations.ReadFromConfig("ProfileDebugLog")), Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("ProfileDebugLog")),
Text = Language.Text.ProfileDebugCheckBox, Text = Language.Text.ProfileDebugCheckBox,
TextColor = colGreen TextColor = colGreen
}; };
// Custom environment variables label // Custom environment variables label
customEnvVarLabel = new Label(); customEnvVarLabel = new Label();
if (Platform.IsGtk) if (OS.IsLinux)
{ {
customEnvVarLabel = new Label customEnvVarLabel = new Label
{ {
@ -599,11 +604,11 @@ namespace AM2RLauncher
// Custom environment variables textbox // Custom environment variables textbox
customEnvVarTextBox = null; customEnvVarTextBox = null;
if (Platform.IsGtk) if (OS.IsLinux)
{ {
customEnvVarTextBox = new TextBox customEnvVarTextBox = new TextBox
{ {
Text = Core.CrossPlatformOperations.ReadFromConfig("CustomEnvVar"), Text = CrossPlatformOperations.ReadFromConfig("CustomEnvVar"),
BackgroundColor = colBGNoAlpha, BackgroundColor = colBGNoAlpha,
TextColor = colGreen TextColor = colGreen
}; };
@ -619,14 +624,14 @@ namespace AM2RLauncher
mirrorDropDown = new DropDown mirrorDropDown = new DropDown
{ {
TextColor = colGreen, TextColor = colGreen,
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color() BackgroundColor = OS.IsWindows ? colBGNoAlpha : new Color()
}; };
if (Platform.IsGtk) if (OS.IsLinux)
mirrorDropDown = new DropDown(); mirrorDropDown = new DropDown();
mirrorDropDown.Items.AddRange(mirrorDescriptionList); // As above, find a way to get this inside the dropDown definition 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")) mirrorIndex = (Int32.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? Int32.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex"))
: 0; : 0;
mirrorDropDown.SelectedIndex = mirrorIndex; mirrorDropDown.SelectedIndex = mirrorIndex;
currentMirror = mirrorList[mirrorDropDown.SelectedIndex]; currentMirror = mirrorList[mirrorDropDown.SelectedIndex];
@ -691,11 +696,11 @@ namespace AM2RLauncher
settingsProfileDropDown = new DropDown settingsProfileDropDown = new DropDown
{ {
TextColor = colGreen, 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. // 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 = new DropDown();
settingsProfileDropDown.Items.AddRange(profileNames); // It's actually more comfortable if it's outside, because of GTK shenanigans 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; deleteModButton.Click += DeleteModButtonClicked;
updateModButton.Click += UpdateModButtonClicked; updateModButton.Click += UpdateModButtonClicked;
profileDebugLogCheck.CheckedChanged += ProfileDebugLogCheckedChanged; profileDebugLogCheck.CheckedChanged += ProfileDebugLogCheckedChanged;
if (Platform.IsGtk) if (OS.IsLinux)
customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus; customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus;
//TODO: These don't work properly on mac? Maybe on other platforms too? //TODO: These don't work properly on mac? Maybe on other platforms too?

@ -7,10 +7,11 @@ using System.Runtime.InteropServices;
namespace AM2RLauncher.Core namespace AM2RLauncher.Core
{ {
//TODO: document a ton of these new movings /// <summary>
/// Class that has core stuff that doesn't fit anywhere else
/// </summary>
public static class Core public static class Core
{ {
// Load reference to logger
/// <summary> /// <summary>
/// Our log object, that handles logging the current execution to a file. /// Our log object, that handles logging the current execution to a file.
/// </summary> /// </summary>
@ -29,6 +30,10 @@ namespace AM2RLauncher.Core
/// </summary> /// </summary>
public static readonly bool isInternetThere = HelperMethods.IsConnectedToInternet(); public static readonly bool isInternetThere = HelperMethods.IsConnectedToInternet();
/// <summary>
/// Checks if this is ran from WINE
/// </summary>
/// <returns><see langword="true"/> if run from WINE, <see langword="false"/> if not.</returns>
private static bool CheckIfRunFromWINE() private static bool CheckIfRunFromWINE()
{ {
if (OS.IsWindows && Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null) if (OS.IsWindows && Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null)

@ -10,7 +10,7 @@ using System.Text.RegularExpressions;
namespace AM2RLauncher.Core namespace AM2RLauncher.Core
{ {
/// <summary> /// <summary>
/// Class that does Operations that work cross-platform. /// Class that does operations that work cross-platform.
/// </summary> /// </summary>
public static class CrossPlatformOperations public static class CrossPlatformOperations
{ {

@ -12,19 +12,7 @@ using System.Text;
namespace AM2RLauncher.Core namespace AM2RLauncher.Core
{ {
/// <summary> /// <summary>
/// An enum, that has possible return codes for <see cref="HelperMethods.CheckIfZipIsAM2R11"/>. /// Class that has various Helper functions. Basically anything that could be used outside the Launcher resides here.
/// </summary>
public enum IsZipAM2R11ReturnCodes
{
Successful,
MissingOrInvalidAM2RExe,
MissingOrInvalidD3DX9_43Dll,
MissingOrInvalidDataWin,
GameIsInASubfolder
}
/// <summary>
/// Class that has various Helper functions. Basically anything that could be used outside the Launcher GUI resides here.
/// </summary> /// </summary>
public static class HelperMethods public static class HelperMethods
{ {
@ -155,7 +143,7 @@ namespace AM2RLauncher.Core
RecursiveRollover(fileName, max); 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 is less than max, rename file.
if (index < max) if (index < max)
{ {
@ -185,74 +173,5 @@ namespace AM2RLauncher.Core
Log.Info("Internet connection established!"); Log.Info("Internet connection established!");
return true; return true;
} }
/// <summary>
/// Checks if the repository has been validly cloned already.
/// </summary>
/// <returns><see langword="true"/> if yes, <see langword="false"/> if not.</returns>
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");
}
/// <summary>
/// Checks if a Zip file is a valid AM2R_1.1 zip.
/// </summary>
/// <param name="zipPath">Full Path to the Zip file to check.</param>
/// <returns><see cref="IsZipAM2R11ReturnCodes"/> detailing the result</returns>
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;
}
} }
} }

@ -5,18 +5,39 @@ using System.Text;
namespace AM2RLauncher.Core namespace AM2RLauncher.Core
{ {
/// <summary>
/// Class that has information about the current running operating system.
/// </summary>
public class OS public class OS
{ {
/// <summary>
/// Determines if the current OS is Windows.
/// </summary>
public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); public static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
/// <summary>
/// Determines if the current OS is Linux.
/// </summary>
public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); public static readonly bool IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
/// <summary>
/// Determines if the current OS is Mac.
/// </summary>
public static readonly bool IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); public static readonly bool IsMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
/// <summary>
/// Determines if the current OS is a unix based system (Mac or Linux).
/// </summary>
public static readonly bool IsUnix = IsLinux || IsMac; public static readonly bool IsUnix = IsLinux || IsMac;
/// <summary>
/// Gets a string representation of the current OS.
/// </summary>
public static readonly string Name = DetermineOSName(); public static readonly string Name = DetermineOSName();
/// <summary>
/// Generates a string representation of the current OS
/// </summary>
private static string DetermineOSName() private static string DetermineOSName()
{ {
if (IsWindows) if (IsWindows)
@ -24,7 +45,7 @@ namespace AM2RLauncher.Core
else if (IsLinux) else if (IsLinux)
return "Linux"; return "Linux";
else if (IsMac) else if (IsMac)
return "MacOS"; return "Mac";
else else
return "Unknown OS"; return "Unknown OS";
} }

@ -13,6 +13,21 @@ using System.Threading;
namespace AM2RLauncher.Core namespace AM2RLauncher.Core
{ {
/// <summary>
/// An enum, that has possible return codes for <see cref="HelperMethods.CheckIfZipIsAM2R11"/>.
/// </summary>
public enum IsZipAM2R11ReturnCodes
{
Successful,
MissingOrInvalidAM2RExe,
MissingOrInvalidD3DX9_43Dll,
MissingOrInvalidDataWin,
GameIsInASubfolder
}
/// <summary>
/// Class that has methods related to AM2RLauncher profiles.
/// </summary>
public static class Profile public static class Profile
{ {
@ -47,7 +62,7 @@ namespace AM2RLauncher.Core
// Return safely if file doesn't exist // Return safely if file doesn't exist
if (!File.Exists(am2r11file)) return false; if (!File.Exists(am2r11file)) return false;
lastAM2R11ZipMD5 = HelperMethods.CalculateMD5(am2r11file); 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 // Check if it's valid, if not log it, rename it and silently leave
if (returnCode != IsZipAM2R11ReturnCodes.Successful) if (returnCode != IsZipAM2R11ReturnCodes.Successful)
{ {
@ -620,5 +635,73 @@ namespace AM2RLauncher.Core
Log.Info("Profile " + profile.Name + " process exited."); Log.Info("Profile " + profile.Name + " process exited.");
} }
/// <summary>
/// Checks if the repository has been validly cloned already.
/// </summary>
/// <returns><see langword="true"/> if yes, <see langword="false"/> if not.</returns>
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");
}
/// <summary>
/// Checks if a Zip file is a valid AM2R_1.1 zip.
/// </summary>
/// <param name="zipPath">Full Path to the Zip file to check.</param>
/// <returns><see cref="IsZipAM2R11ReturnCodes"/> detailing the result</returns>
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;
}
} }
} }

@ -45,6 +45,15 @@ namespace AM2RLauncher.Core
"Did you know that games take time to develop?" "Did you know that games take time to develop?"
}; };
/// <summary>
/// Windows only splash strings
/// </summary>
private static readonly string[] windowsSplash =
{
":(",
"All your machine are belong to MS"
};
/// <summary> /// <summary>
/// Linux only splash strings /// Linux only splash strings
/// </summary> /// </summary>
@ -71,6 +80,19 @@ namespace AM2RLauncher.Core
"Did you find the penguin yet?" "Did you find the penguin yet?"
}; };
/// <summary>
/// Mac only splash strings
/// </summary>
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!"
};
/// <summary> /// <summary>
/// Combined splash strings /// Combined splash strings
/// </summary> /// </summary>
@ -95,9 +117,12 @@ namespace AM2RLauncher.Core
private static string[] combineSplashes() private static string[] combineSplashes()
{ {
string[] totalSplashes; string[] totalSplashes;
if (OS.IsLinux) if (OS.IsWindows)
totalSplashes = generalSplash.Concat(windowsSplash).ToArray();
else if (OS.IsLinux)
totalSplashes = generalSplash.Concat(linuxSplash).ToArray(); 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 else
totalSplashes = generalSplash; totalSplashes = generalSplash;
return totalSplashes; return totalSplashes;

Loading…
Cancel
Save