Cleanup commit nr 2

pull/32/head
Miepee 5 years ago
parent c0cdd1799d
commit 8e34b55398

@ -5,6 +5,7 @@
<TargetFramework>net5.0</TargetFramework>
<ApplicationIcon>icon64.ico</ApplicationIcon>
<RollForward>LatestMajor</RollForward>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>

@ -4,8 +4,8 @@ using log4net.Config;
using System;
using System.IO;
namespace AM2RLauncher.Gtk
{
namespace AM2RLauncher.Gtk;
/// <summary>
/// The main class for the GTK project.
/// </summary>
@ -19,7 +19,7 @@ namespace AM2RLauncher.Gtk
/// The main method for the GTK project.
/// </summary>
[STAThread]
public static void Main(string[] args)
public static void Main()
{
string launcherDataPath = GenerateCurrentPath();
@ -82,7 +82,7 @@ namespace AM2RLauncher.Gtk
// First check if XDG_DATA_HOME is set, if not we'll use ~/.local/share
string xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
if (string.IsNullOrWhiteSpace(xdgDataHome))
if (String.IsNullOrWhiteSpace(xdgDataHome))
xdgDataHome = nixHome + "/.local/share";
// Add AM2RLauncher to the end of the dataPath
@ -101,4 +101,4 @@ namespace AM2RLauncher.Gtk
return Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
}
}
}

@ -4,8 +4,8 @@ using log4net.Config;
using System;
using System.IO;
namespace AM2RLauncher.Mac
{
namespace AM2RLauncher.Mac;
/// <summary>
/// The main class for the Mac project.
/// </summary>
@ -20,7 +20,7 @@ namespace AM2RLauncher.Mac
/// The main method for the Mac project.
/// </summary>
[STAThread]
public static void Main(string[] args)
public static void Main()
{
string launcherDataPath = GenerateCurrentPath();
@ -37,10 +37,10 @@ namespace AM2RLauncher.Mac
try
{
Application MacLauncher = new Application(Eto.Platforms.Mac64);
Application macLauncher = new Application(Eto.Platforms.Mac64);
LauncherUpdater.Main();
MacLauncher.UnhandledException += MacLauncher_UnhandledException;
MacLauncher.Run(new MainForm());
macLauncher.UnhandledException += MacLauncher_UnhandledException;
macLauncher.Run(new MainForm());
}
catch (Exception e)
{
@ -48,7 +48,6 @@ namespace AM2RLauncher.Mac
Console.WriteLine(Language.Text.UnhandledException + "\n" + e.Message + "\n*****Stack Trace*****\n\n" + e.StackTrace);
Console.WriteLine("Check the logs at " + launcherDataPath + " for more info!");
}
//new Application(Eto.Platforms.Mac64).Run(new MainForm());
}
/// <summary>
@ -79,4 +78,3 @@ namespace AM2RLauncher.Mac
return Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
}
}
}

@ -17,6 +17,7 @@
<PackageProjectUrl>https://github.com/AM2R-Community-Developers/AM2RLauncherRewrite/</PackageProjectUrl>
<PackageLicenseExpression>GNU General Public License v3.0</PackageLicenseExpression>
<Description>A Launcher for AM2R that with mod capabilities.</Description>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

@ -5,8 +5,8 @@ using System;
using System.IO;
using System.Reflection;
namespace AM2RLauncher.Wpf
{
namespace AM2RLauncher.Wpf;
/// <summary>
/// The main class for the WinForms project.
/// </summary>
@ -20,7 +20,7 @@ namespace AM2RLauncher.Wpf
/// The main method for the WinForms project.
/// </summary>
[STAThread]
public static void Main(string[] args)
public static void Main()
{
string launcherDataPath = GenerateCurrentPath();
@ -81,4 +81,4 @@ namespace AM2RLauncher.Wpf
return Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
}
}
}

@ -45,8 +45,8 @@ namespace AM2RLauncher
/// Linux: Will point to XDG_CONFIG_HOME/AM2RLauncher <br/>
/// Mac: Will point to ~/Library/Preferences/AM2RLauncher
/// </summary>
private static readonly string NIXLAUNCHERCONFIGPATH = CurrentPlatform.IsGtk ? ((String.IsNullOrWhiteSpace(LINUXXDGCONFIG) ? (NIXHOME + "/.config")
: LINUXXDGCONFIG) + "/AM2RLauncher")
private static readonly string NIXLAUNCHERCONFIGPATH = CurrentPlatform.IsGtk ? (String.IsNullOrWhiteSpace(LINUXXDGCONFIG) ? NIXHOME + "/.config"
: LINUXXDGCONFIG) + "/AM2RLauncher"
: NIXHOME + "/Library/Preferences/AM2RLauncher";
/// <summary>
@ -154,7 +154,7 @@ namespace AM2RLauncher
if (appConfig == null)
throw new NullReferenceException("Could not find the Config file! Please make sure it exists!");
ConnectionStringsSection connectionStringsSection = (ConnectionStringsSection)appConfig.GetSection("connectionStrings");
if (connectionStringsSection == null || connectionStringsSection.ConnectionStrings[property]?.ConnectionString == null)
if (connectionStringsSection?.ConnectionStrings[property]?.ConnectionString == null)
throw new ArgumentException("The property " + property + " could not be found.");
connectionStringsSection.ConnectionStrings[property].ConnectionString = value.ToString();
appConfig.Save();
@ -512,7 +512,7 @@ namespace AM2RLauncher
{
// First check if XDG_DATA_HOME is set, if not we'll use ~/.local/share
string xdgDataHome = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
if (string.IsNullOrWhiteSpace(xdgDataHome))
if (String.IsNullOrWhiteSpace(xdgDataHome))
{
Log.Info("Using default Linux CurrentPath.");
xdgDataHome = NIXHOME + "/.local/share";

@ -18,18 +18,18 @@ namespace AM2RLauncher
// Auto updating is fun!
/// <summary>The Version that identifies this current release.</summary>
public static readonly string VERSION = "2.2.0";
public const string VERSION = "2.2.0";
/// <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,
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>
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>
//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 = CurrentPlatform.IsWinForms ? CrossPlatformOperations.CURRENTPATH : Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
/// <summary>
/// Our log object, that handles logging the current execution to a file.
@ -51,19 +51,19 @@ namespace AM2RLauncher
Log.Info("AM2RLauncher.bak detected. Removing file.");
File.Delete(CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak");
}
if (currentPlatform.IsWinForms && File.Exists(oldConfigPath))
if (CurrentPlatform.IsWinForms && File.Exists(OldConfigPath))
{
Log.Info(CrossPlatformOperations.LAUNCHERNAME + ".oldCfg detected. Removing file.");
File.Delete(oldConfigPath);
File.Delete(OldConfigPath);
}
if (currentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/oldLib"))
if (CurrentPlatform.IsWinForms && 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 (CurrentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib"))
{
foreach (FileInfo file in new DirectoryInfo(CrossPlatformOperations.CURRENTPATH + "/lib").GetFiles())
{
@ -91,7 +91,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 (CurrentPlatform.IsWinForms)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
@ -132,8 +132,10 @@ namespace AM2RLauncher
Log.Info((isCurrentVersionOutdated ? "Updating" : "Not Updating") + " from " + VERSION + " to " + onlineVersion);
if (isCurrentVersionOutdated)
{
// No new update, exiting
if (!isCurrentVersionOutdated)
return;
Log.Info("Current version (" + VERSION + ") is outdated! Initiating update for version " + onlineVersion + ".");
string tmpUpdatePath = CrossPlatformOperations.CURRENTPATH + "/tmpupdate/";
@ -150,8 +152,8 @@ namespace AM2RLauncher
using (var client = new WebClient())
{
string platformSuffix = "";
if (currentPlatform.IsWinForms) platformSuffix = "_win";
else if (currentPlatform.IsGtk) platformSuffix = "_lin";
if (CurrentPlatform.IsWinForms) platformSuffix = "_win";
else if (CurrentPlatform.IsGtk) platformSuffix = "_lin";
Log.Info("Downloading https://github.com/AM2R-Community-Developers/AM2RLauncher/releases/latest/download/AM2RLauncher_" + onlineVersion + platformSuffix + ".zip to " + zipPath + ".");
@ -171,16 +173,16 @@ namespace AM2RLauncher
Log.Info("Updates successfully extracted to " + tmpUpdatePath);
File.Delete(zipPath);
File.Move(updatePath + "/" + CrossPlatformOperations.LAUNCHERNAME, CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak");
if (currentPlatform.IsWinForms) File.Move(CrossPlatformOperations.LAUNCHERNAME + ".config", CrossPlatformOperations.LAUNCHERNAME + ".oldCfg");
File.Move(UpdatePath + "/" + CrossPlatformOperations.LAUNCHERNAME, CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak");
if (CurrentPlatform.IsWinForms) File.Move(CrossPlatformOperations.LAUNCHERNAME + ".config", CrossPlatformOperations.LAUNCHERNAME + ".oldCfg");
foreach (var file in new DirectoryInfo(tmpUpdatePath).GetFiles())
{
Log.Info("Moving " + file.FullName + " to " + CrossPlatformOperations.CURRENTPATH + "/" + file.Name);
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.
if (currentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib"))
if (CurrentPlatform.IsWinForms && Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/lib"))
{
// So, because Windows behavior is dumb...
@ -210,12 +212,11 @@ namespace AM2RLauncher
Log.Info("Files extracted. Preparing to restart executable...");
if (currentPlatform.IsGtk) System.Diagnostics.Process.Start("chmod", "+x ./AM2RLauncher.Gtk");
if (CurrentPlatform.IsGtk) 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);
}
}
else
{
Log.Info("AutoUpdate Launcher set to false. Exiting update check.");

@ -67,14 +67,15 @@ namespace AM2RLauncher.Helpers
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
if (!copySubDirs)
return;
foreach (DirectoryInfo subDir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, tempPath, overwriteFiles, copySubDirs);
}
string tempPath = Path.Combine(destDirName, subDir.Name);
DirectoryCopy(subDir.FullName, tempPath, overwriteFiles);
}
}
@ -170,10 +171,9 @@ namespace AM2RLauncher.Helpers
{
Log.Info("Checking internet connection...");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://github.com");
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
}
catch (WebException)
{

@ -30,7 +30,7 @@ namespace AM2RLauncher
/// <param name="hWnd">Pointer to the process you want to have in the foreground.</param>
/// <returns></returns>
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
private static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// After the <see cref="playButton"/> has bee loaded, git pull if a repo has been cloned already.
@ -38,8 +38,9 @@ namespace AM2RLauncher
private async void PlayButtonLoadComplete(object sender, EventArgs e)
{
LoadProfiles();
if (HelperMethods.IsPatchDataCloned() && (bool)autoUpdateAM2RCheck.Checked)
{
if (!HelperMethods.IsPatchDataCloned() || !(bool)autoUpdateAM2RCheck.Checked)
return;
SetPlayButtonState(UpdateState.Downloading);
progressBar.Visible = true;
@ -152,7 +153,6 @@ namespace AM2RLauncher
SetPlayButtonState(UpdateState.Install);
UpdateStateMachine();
}
}
/// <summary>
/// Does a bunch of stuff, depending on the current state of <see cref="updateState"/>.
@ -282,7 +282,7 @@ namespace AM2RLauncher
Title = Language.Text.Select11FileDialog
};
fileFinder.Filters.Add(new FileFilter(Language.Text.ZipArchiveText, new[] { ".zip" }));
fileFinder.Filters.Add(new FileFilter(Language.Text.ZipArchiveText, ".zip"));
if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{
@ -290,7 +290,7 @@ namespace AM2RLauncher
return;
}
if (!string.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default
if (!String.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default
{
if (Directory.Exists(fileFinder.FileName))
{
@ -416,13 +416,11 @@ namespace AM2RLauncher
{
progressBar.MinValue = 0;
progressBar.MaxValue = transferProgress.TotalObjects;
if (currentGitObject < transferProgress.ReceivedObjects)
{
if (currentGitObject >= transferProgress.ReceivedObjects)
return;
progressLabel.Text = Language.Text.ProgressbarProgress + " " + transferProgress.ReceivedObjects + " (" + (int)transferProgress.ReceivedBytes / 1000000 + "MB) / " + transferProgress.TotalObjects + " objects";
currentGitObject = transferProgress.ReceivedObjects;
progressBar.Value = transferProgress.ReceivedObjects;
}
});
return true;
@ -507,7 +505,7 @@ namespace AM2RLauncher
Title = Language.Text.SelectModFileDialog
};
fileFinder.Filters.Add(new FileFilter(Language.Text.ZipArchiveText, new[] { ".zip" }));
fileFinder.Filters.Add(new FileFilter(Language.Text.ZipArchiveText, ".zip"));
if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{
@ -515,7 +513,7 @@ namespace AM2RLauncher
return;
}
if (!string.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default
if (!String.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default
{
Log.Info("User selected \"" + fileFinder.FileName + "\"");
@ -607,13 +605,12 @@ namespace AM2RLauncher
/// </summary>
private void ProfilesButtonClickEvent(object sender, EventArgs e)
{
if (IsProfileIndexValid())
{
if (!IsProfileIndexValid())
return;
Log.Info("User opened the profile directory for profile " + profileList[settingsProfileDropDown.SelectedIndex].Name +
", which is " + profileList[settingsProfileDropDown.SelectedIndex].SaveLocation);
CrossPlatformOperations.OpenFolder(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profileList[settingsProfileDropDown.SelectedIndex].Name);
}
}
/// <summary>
/// This opens the save directory for the current profile.
@ -657,11 +654,10 @@ namespace AM2RLauncher
saveButton.Enabled = true;
saveButton.ToolTip = Language.Text.OpenSaveFolderToolTip.Replace("$NAME", settingsProfileDropDown.Items[settingsProfileDropDown.SelectedIndex].Text);
if (!(settingsProfileDropDown.SelectedIndex < 0 || settingsProfileDropDown.Items.Count == 0))
{
if (settingsProfileDropDown.SelectedIndex < 0 || settingsProfileDropDown.Items.Count == 0)
return;
profileNotesTextArea.TextColor = colGreen;
profileNotesTextArea.Text = Language.Text.ProfileNotes + "\n" + profileList[settingsProfileDropDown.SelectedIndex].ProfileNotes;
}
}
@ -673,8 +669,8 @@ namespace AM2RLauncher
{
// Safety check
if (settingsProfileDropDown == null) return;
if (settingsProfileDropDown.Items.Count == 0)
{
if (settingsProfileDropDown.Items.Count != 0)
return;
addModButton.Enabled = false;
settingsProfileLabel.TextColor = colInactive;
settingsProfileDropDown.Enabled = false;
@ -684,7 +680,6 @@ namespace AM2RLauncher
deleteModButton.Enabled = false;
profileNotesTextArea.TextColor = colInactive;
}
}
/// <summary>
/// The <see cref="MainForm"/> calls this when you're resizing, in order to resize and scale the application accordingly.
@ -942,7 +937,7 @@ namespace AM2RLauncher
Title = Language.Text.SelectModFileDialog
};
fileFinder.Filters.Add(new FileFilter(Language.Text.ZipArchiveText, new[] { ".zip" }));
fileFinder.Filters.Add(new FileFilter(Language.Text.ZipArchiveText, ".zip"));
if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{
@ -950,7 +945,7 @@ namespace AM2RLauncher
return;
}
if (!string.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default
if (!String.IsNullOrWhiteSpace(fileFinder.FileName)) // This is default
{
Log.Info("User selected \"" + fileFinder.FileName + "\"");
@ -1047,9 +1042,11 @@ namespace AM2RLauncher
CrossPlatformOperations.WriteToConfig("Width", ClientSize.Width);
CrossPlatformOperations.WriteToConfig("Height", ClientSize.Height);
CrossPlatformOperations.WriteToConfig("IsMaximized", (this.WindowState == WindowState.Maximized));
CrossPlatformOperations.WriteToConfig("IsMaximized", this.WindowState == WindowState.Maximized);
if (updateState == UpdateState.Downloading)
switch (updateState)
{
case UpdateState.Downloading:
{
var result = MessageBox.Show(Language.Text.CloseOnCloningText, Language.Text.WarningWindowTitle, MessageBoxButtons.YesNo,
MessageBoxType.Warning, MessageBoxDefaultButton.No);
@ -1060,19 +1057,19 @@ namespace AM2RLauncher
else
isGitProcessGettingCancelled = true;
// We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :)
break;
}
else if (updateState == UpdateState.Installing)
{
case UpdateState.Installing:
MessageBox.Show(Language.Text.CloseOnInstallingText, Language.Text.WarningWindowTitle, MessageBoxButtons.OK, MessageBoxType.Warning);
e.Cancel = true;
break;
}
// This needs to be made invisible, otherwise a tray indicator will be visible (on linux?) that clicking crashes the application
trayIndicator.Visible = false;
if (e.Cancel)
Log.Info("Cancelled MainForm closing event during UpdateState." + updateState.ToString() + ".");
Log.Info("Cancelled MainForm closing event during UpdateState." + updateState + ".");
else
Log.Info("Successfully closed MainForm. Exiting main thread.");
}

@ -131,7 +131,7 @@ namespace AM2RLauncher
if (reloadProfileList)
LoadProfiles();
Log.Info("Succesfully deleted profile " + profile.Name + ".");
Log.Info("Successfully deleted profile " + profile.Name + ".");
}
/// <summary>
@ -165,8 +165,8 @@ namespace AM2RLauncher
{
foreach (FileInfo file in dir.GetFiles())
{
if (file.Name == "profile.xml")
{
if (file.Name != "profile.xml")
continue;
ProfileXML prof = Serializer.Deserialize<ProfileXML>(File.ReadAllText(dir.FullName + "/profile.xml"));
if (prof.Installable || IsProfileInstalled(prof)) // Safety check for non-installable profiles
{
@ -180,7 +180,6 @@ namespace AM2RLauncher
}
}
}
}
// Add profile names to the profileDropDown
foreach (ProfileXML profile in profileList)
@ -284,7 +283,7 @@ namespace AM2RLauncher
Directory.CreateDirectory(profilePath + "/Resources");
profilePath += "/Resources";
Log.Info("ProfileInstallstion: Created folder structure.");
Log.Info("ProfileInstallation: Created folder structure.");
}
// Extract 1.1
@ -345,7 +344,7 @@ namespace AM2RLauncher
CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/data.win", dataPath + "/game.xdelta", profilePath + "/" + datawin);
CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/AM2R.exe", dataPath + "/AM2R.xdelta", profilePath + "/" + exe);
// Just in case the resulting file isn't chmoddded...
Process.Start("chmod", "+x \"" + profilePath + "/" + exe + "\"").WaitForExit();
Process.Start("chmod", "+x \"" + profilePath + "/" + exe + "\"")?.WaitForExit();
// These are not needed by linux or Mac at all, so we delete them
File.Delete(profilePath + "/data.win");
@ -409,7 +408,7 @@ namespace AM2RLauncher
Directory.SetCurrentDirectory(profilePath);
Console.SetError(new StreamWriter(Stream.Null));
Environment.SetEnvironmentVariable("ARCH", "x86_64");
Process.Start(CrossPlatformOperations.CURRENTPATH + "/PatchData/utilities/appimagetool-x86_64.AppImage", "-n AM2R.AppDir").WaitForExit();
Process.Start(CrossPlatformOperations.CURRENTPATH + "/PatchData/utilities/appimagetool-x86_64.AppImage", "-n AM2R.AppDir")?.WaitForExit();
Directory.SetCurrentDirectory(workingDir);
Console.SetError(cliError);
@ -439,7 +438,7 @@ namespace AM2RLauncher
// Copy profile.xml so we can grab data to compare for updates later!
// tldr; check if we're in PatchData or not
if (new DirectoryInfo(dataPath).Parent.Name == "PatchData")
if (new DirectoryInfo(dataPath)?.Parent?.Name == "PatchData")
File.Copy(dataPath + "/../profile.xml", profilePath + "/profile.xml");
else File.Copy(dataPath + "/profile.xml", profilePath + "/profile.xml");
@ -567,15 +566,16 @@ namespace AM2RLauncher
/// </summary>
private void RunGame()
{
if (IsProfileIndexValid())
{
if (!IsProfileIndexValid())
return;
ProfileXML profile = profileList[profileIndex.Value];
// These are used on both windows and linux for game logging
string savePath = Platform.IsWinForms ? profile.SaveLocation.Replace("%localappdata%", Environment.GetEnvironmentVariable("LOCALAPPDATA"))
: profile.SaveLocation.Replace("~", CrossPlatformOperations.NIXHOME);
DirectoryInfo logDir = new DirectoryInfo(savePath + "/logs");
string date = string.Join("-", DateTime.Now.ToString().Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries));
string date = String.Join("-", DateTime.Now.ToString().Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries));
Log.Info("Launching game profile " + profile.Name + ".");
@ -635,9 +635,9 @@ namespace AM2RLauncher
string envVars = "";
Application.Instance.Invoke(new Action(() => envVars = customEnvVarTextBox.Text));
Log.Info("Is the environment textbox null or whitespace = " + string.IsNullOrWhiteSpace(envVars));
Log.Info("Is the environment textbox null or whitespace = " + String.IsNullOrWhiteSpace(envVars));
if (!string.IsNullOrWhiteSpace(envVars))
if (!String.IsNullOrWhiteSpace(envVars))
{
for (int i = 0; i < envVars.Count(f => f == '='); i++)
{
@ -780,4 +780,3 @@ namespace AM2RLauncher
}
}
}
}

@ -79,8 +79,8 @@ namespace AM2RLauncher
private void UpdateApkState()
{
// Safety check
if (apkButton != null)
{
if (apkButton == null)
return;
// If profile supports Android...
if (IsProfileIndexValid() && profileList[profileIndex.Value].SupportsAndroid && profileList[profileIndex.Value].Installable)
{
@ -111,7 +111,6 @@ namespace AM2RLauncher
apkButton.ToolTip = Language.Text.ApkButtonDisabledToolTip;
}
}
}
/// <summary>
/// Determines current conditions and enables or disables the <see cref="profileDropDown"/> and related controls accordingly.
@ -119,8 +118,8 @@ namespace AM2RLauncher
private void UpdateProfileState()
{
// Safety check
if (profileDropDown != null)
{
if (profileDropDown == null)
return;
switch (updateState)
{
case UpdateState.Download: profileDropDown.Enabled = false; break;
@ -144,7 +143,6 @@ namespace AM2RLauncher
profileVersionLabel.TextColor = col;
profileLabel.TextColor = col;
}
}
/// <summary>
/// Determines current conditions and enables or disables <see cref="profilePage"/> controls accordingly.
@ -152,9 +150,8 @@ namespace AM2RLauncher
private void UpdateProfileSettingsState()
{
// Safety check
if (settingsProfileDropDown == null) return;
if (settingsProfileDropDown.Items.Count > 0)
{
if (settingsProfileDropDown == null || settingsProfileDropDown.Items.Count <= 0) return;
bool enabled = false;
switch (updateState)
{
@ -198,7 +195,6 @@ namespace AM2RLauncher
settingsProfileDropDown.SelectedIndex = profileDropDown.SelectedIndex;
}
}
}
/// <summary>
/// Sets the global <see cref="updateState"/> and then changes the state of <see cref="playButton"/> accordingly.
@ -255,8 +251,8 @@ namespace AM2RLauncher
case UpdateState.Installing: return Language.Text.Installing;
case UpdateState.Play: return Language.Text.Play;
case UpdateState.Playing: return Language.Text.Playing;
default: return null;
}
return null;
}
/// <summary>
@ -269,8 +265,8 @@ namespace AM2RLauncher
{
case ApkButtonState.Create: return Language.Text.CreateAPK;
case ApkButtonState.Creating: return Language.Text.CreatingAPK;
default: return null;
}
return null;
}
/// <summary>
/// Checks if AM2R 1.1 has been installed already, aka if a valid AM2R 1.1 Zip exists.

@ -28,7 +28,7 @@ namespace AM2RLauncher
/// <summary>
/// An enum, that has possible states for our Launcher.
/// </summary>
enum UpdateState
private enum UpdateState
{
Download,
Downloading,
@ -42,7 +42,7 @@ namespace AM2RLauncher
/// <summary>
/// An enum, that has different states for <see cref="apkButton"/>.
/// </summary>
enum ApkButtonState
private enum ApkButtonState
{
Create,
Creating
@ -52,11 +52,10 @@ namespace AM2RLauncher
/// <summary>
/// A <see cref="string"/>-<see cref="Array"/> of custom splashes.
/// </summary>
/// <summary>
/// The current Launcher version.
/// </summary>
private static readonly string VERSION = LauncherUpdater.VERSION;
private const string VERSION = LauncherUpdater.VERSION;
/// <summary>
/// A <see cref="Bitmap"/> of the AM2R icon.
@ -124,13 +123,12 @@ namespace AM2RLauncher
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
if (process.Id == current.Id)
continue;
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
Environment.Exit(0);
}
@ -173,7 +171,7 @@ namespace AM2RLauncher
// Set the language to what User wanted or choose local language
string userLanguage = CrossPlatformOperations.ReadFromConfig("Language").ToLower();
if (!userLanguage.Equals("default"))
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => c.NativeName.ToLower().Contains(userLanguage)).First();
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultures(CultureTypes.AllCultures).First(c => c.NativeName.ToLower().Contains(userLanguage));
Log.Info("Language has been set to: " + Thread.CurrentThread.CurrentUICulture.EnglishName);
@ -181,8 +179,8 @@ namespace AM2RLauncher
Log.Info("Beginning UI initialization...");
// System tray indicator
showButton = new ButtonMenuItem() { Text = Language.Text.TrayButtonShow };
trayIndicator = new TrayIndicator()
showButton = new ButtonMenuItem { Text = Language.Text.TrayButtonShow };
trayIndicator = new TrayIndicator
{
Menu = new ContextMenu(showButton),
Title = "AM2RLauncher",
@ -198,9 +196,9 @@ namespace AM2RLauncher
profileList = new List<ProfileXML>();
profileNames = new List<ListItem>();
for (int i = 0; i < profileList.Count; i++)
foreach (var profile in profileList)
{
profileNames.Add(profileList[i].Name);
profileNames.Add(profile.Name);
}
// Custom splash texts
@ -243,15 +241,15 @@ namespace AM2RLauncher
Title = "AM2RLauncher " + VERSION + ": " + splash;
MinimumSize = new Size(500, 400);
// TODO: for some reason, this sometimes doesn't work on Linux. Was reported at eto, stays here until its fixed
ClientSize = new Size(int.Parse(CrossPlatformOperations.ReadFromConfig("Width")), int.Parse(CrossPlatformOperations.ReadFromConfig("Height")));
ClientSize = new Size(Int32.Parse(CrossPlatformOperations.ReadFromConfig("Width")), Int32.Parse(CrossPlatformOperations.ReadFromConfig("Height")));
if (ClientSize.Width < 500)
ClientSize = new Size(500, ClientSize.Height);
if (ClientSize.Height < 400)
ClientSize = new Size(ClientSize.Width, 400);
Log.Info("Start the launcher with Size: " + ClientSize.Width + ", " + ClientSize.Height);
if (bool.Parse(CrossPlatformOperations.ReadFromConfig("IsMaximized"))) Maximize();
if (Boolean.Parse(CrossPlatformOperations.ReadFromConfig("IsMaximized"))) Maximize();
drawable = new Drawable() { BackgroundColor = colBGNoAlpha };
drawable = new Drawable { BackgroundColor = colBGNoAlpha };
// Drawable paint event
drawable.Paint += DrawablePaintEvent;
@ -318,7 +316,7 @@ namespace AM2RLauncher
Height = 15,
Text = "",
TextColor = colGreen,
Visible = false,
Visible = false
};
centerInterface.AddRow(progressLabel);
@ -331,7 +329,7 @@ namespace AM2RLauncher
BackgroundColor = colBG,
Height = 15,
Text = Language.Text.CurrentProfile,
TextColor = colGreen,
TextColor = colGreen
};
centerInterface.AddRow(profileLabel);
@ -344,7 +342,7 @@ namespace AM2RLauncher
profileDropDown = new DropDown
{
TextColor = colGreen,
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color(),
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color()
};
// In order to not have conflicting theming, we just always respect the users theme for dropdown on GTK.
if (Platform.IsGtk)
@ -382,23 +380,23 @@ namespace AM2RLauncher
Width = 20,
Height = 55,
Text = Language.Text.SaveLocationWarning,
TextColor = colRed,
TextColor = colRed
};
centerInterface.AddRow(saveWarningLabel);
// Social buttons
var redditButton = new ImageButton() { ToolTip = Language.Text.RedditToolTip, Image = redditIcon };
var redditButton = new ImageButton { ToolTip = Language.Text.RedditToolTip, Image = redditIcon };
redditButton.Click += RedditIconOnClick;
var githubButton = new ImageButton() { ToolTip = Language.Text.GithubToolTip, Image = githubIcon };
var githubButton = new ImageButton { ToolTip = Language.Text.GithubToolTip, Image = githubIcon };
githubButton.Click += GithubIconOnClick;
var youtubeButton = new ImageButton() { ToolTip = Language.Text.YoutubeToolTip, Image = youtubeIcon };
var youtubeButton = new ImageButton { ToolTip = Language.Text.YoutubeToolTip, Image = youtubeIcon };
youtubeButton.Click += YoutubeIconOnClick;
var discordButton = new ImageButton() { ToolTip = Language.Text.DiscordToolTip, Image = discordIcon };
var discordButton = new ImageButton { ToolTip = Language.Text.DiscordToolTip, Image = discordIcon };
discordButton.Click += DiscordIconOnClick;
@ -534,7 +532,7 @@ namespace AM2RLauncher
// Language DropDown menu
List<ListItem> languageList = new List<ListItem>()
List<ListItem> languageList = new List<ListItem>
{
Language.Text.SystemLanguage,
"Deutsch",
@ -551,7 +549,7 @@ namespace AM2RLauncher
languageDropDown = new DropDown
{
TextColor = colGreen,
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color(),
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color()
};
if (Platform.IsGtk)
languageDropDown = new DropDown();
@ -559,7 +557,7 @@ namespace AM2RLauncher
languageDropDown.Items.AddRange(languageList);
var tmpLanguage = CrossPlatformOperations.ReadFromConfig("Language");
languageDropDown.SelectedIndex = tmpLanguage == "Default" ? 0 : languageDropDown.Items.IndexOf(languageDropDown.Items.Where(x => x.Text.Equals(tmpLanguage)).FirstOrDefault());
languageDropDown.SelectedIndex = tmpLanguage == "Default" ? 0 : languageDropDown.Items.IndexOf(languageDropDown.Items.FirstOrDefault(x => x.Text.Equals(tmpLanguage)));
if (languageDropDown.SelectedIndex == -1)
{
@ -570,7 +568,7 @@ namespace AM2RLauncher
// autoUpdateAM2R checkbox
autoUpdateAM2RCheck = new CheckBox
{
Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateAM2R")),
Checked = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateAM2R")),
Text = Language.Text.AutoUpdateAM2R,
TextColor = colGreen
};
@ -579,7 +577,7 @@ namespace AM2RLauncher
// autoUpdateLauncher checkbox
autoUpdateLauncherCheck = new CheckBox
{
Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateLauncher")),
Checked = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateLauncher")),
Text = Language.Text.AutoUpdateLauncher,
TextColor = colGreen
};
@ -587,7 +585,7 @@ namespace AM2RLauncher
// HQ music, PC
hqMusicPCCheck = new CheckBox
{
Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("MusicHQPC")),
Checked = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("MusicHQPC")),
Text = Language.Text.HighQualityPC,
TextColor = colGreen
};
@ -595,7 +593,7 @@ namespace AM2RLauncher
// HQ music, Android
hqMusicAndroidCheck = new CheckBox
{
Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("MusicHQAndroid")),
Checked = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("MusicHQAndroid")),
Text = Language.Text.HighQualityAndroid,
TextColor = colGreen
};
@ -641,13 +639,14 @@ namespace AM2RLauncher
mirrorDropDown = new DropDown
{
TextColor = colGreen,
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color(),
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color()
};
if (Platform.IsGtk)
mirrorDropDown = new DropDown();
mirrorDropDown.Items.AddRange(mirrorDescriptionList); // As above, find a way to get this inside the dropDown definition
mirrorIndex = (int.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? int.Parse(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];
@ -655,7 +654,7 @@ namespace AM2RLauncher
// Custom mirror
customMirrorCheck = new CheckBox
{
Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("CustomMirrorEnabled")),
Checked = Boolean.Parse(CrossPlatformOperations.ReadFromConfig("CustomMirrorEnabled")),
Text = Language.Text.CustomMirrorCheck,
TextColor = colGreen
};
@ -712,7 +711,7 @@ namespace AM2RLauncher
settingsProfileDropDown = new DropDown
{
TextColor = colGreen,
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color(),
BackgroundColor = Platform.IsWinForms ? colBGNoAlpha : new Color()
};
// In order to not have conflicting theming, we just always respect the users theme for dropdown on GTK.
@ -815,7 +814,7 @@ namespace AM2RLauncher
};
#region EVENTS
Log.Info("All UI objects have been initalized, UI has been set up.");
Log.Info("All UI objects have been initialized, UI has been set up.");
Log.Info("Beginning event linkage...");
Closing += MainformClosing;

@ -12,7 +12,7 @@ namespace AM2RLauncher
/// <summary>
/// Cross-Platform splash strings
/// </summary>
static readonly string[] GeneralSplash =
private static readonly string[] GeneralSplash =
{
"The real Ridley is the friends we made along the way.",
"Now with 100% more Septoggs!",
@ -48,7 +48,7 @@ namespace AM2RLauncher
/// <summary>
/// Linux only splash strings
/// </summary>
static readonly string[] LinuxSplash =
private static readonly string[] LinuxSplash =
{
"Sorry this is ugly, but at least it works.",
"GTK + QT = 💣",
@ -75,7 +75,7 @@ namespace AM2RLauncher
/// Get a random splash string, according to the current OS.
/// </summary>
/// <returns>The randomly chosen splash as a <see cref="string"/>.</returns>
static public string GetSplash()
public static string GetSplash()
{
string[] combinedSplash;
Random rng = new Random();

@ -7,7 +7,7 @@ namespace AM2RLauncher.XML
/// <summary>
/// The <c>Serializer</c> class, that serializes to and deserializes from XML files.
/// </summary>
public class Serializer
public static class Serializer
{
/// <summary>
/// Serializes <paramref name="item"/> as a <typeparamref name="T"/> to XML.

Loading…
Cancel
Save