diff --git a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs index 9caddae..0f81983 100644 --- a/AM2RLauncher/AM2RLauncher.Wpf/Program.cs +++ b/AM2RLauncher/AM2RLauncher.Wpf/Program.cs @@ -25,7 +25,7 @@ namespace AM2RLauncher.Wpf // Configure logger XmlConfigurator.Configure(new FileInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/log4net.config")); - //try catch in case it ever crashes before actually getting to the Eto application + // Try catch in case it ever crashes before actually getting to the Eto application try { Application WinLauncher = new Application(Eto.Platforms.WinForms); diff --git a/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj b/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj index d6f5e8c..1b5f15e 100644 --- a/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj +++ b/AM2RLauncher/AM2RLauncher/AM2RLauncher.csproj @@ -6,7 +6,7 @@ Lojemiru, Miepee AM2R-Community-Developers This is a Launcher for AM2R and its Community Updates. - https://github.com/AM2R-Community-Developers/AM2RLauncherRewrite/ + https://github.com/AM2R-Community-Developers/AM2RLauncher/ diff --git a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs index fbd3b52..e6fa7c1 100644 --- a/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs +++ b/AM2RLauncher/AM2RLauncher/CrossPlatformOperations.cs @@ -74,34 +74,34 @@ namespace AM2RLauncher { if (currentPlatform.IsWinForms) { - //we use the configuration manager in order to read `property` from the app.config and then return it + // We use the configuration manager in order to read `property` from the app.config and then return it ConnectionStringSettings appConfig = ConfigurationManager.ConnectionStrings[property]; if (appConfig == null) throw new ArgumentException("The property " + property + " could not be found."); return appConfig.ConnectionString; } if (currentPlatform.IsGtk) { - //config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) + // Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) string homePath = Environment.GetEnvironmentVariable("HOME"); string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher"; string launcherConfigFilePath = launcherConfigPath + "/config.xml"; XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML(); - //if folder doesn't exist, create it and the config file + // If folder doesn't exist, create it and the config file if (!Directory.Exists(launcherConfigPath) || !File.Exists(launcherConfigFilePath)) { Directory.CreateDirectory(launcherConfigPath); File.WriteAllText(launcherConfigFilePath, XML.Serializer.Serialize(launcherConfig)); } - //deserialize the config xml into launcherConfig + // Deserialize the config xml into launcherConfig launcherConfig = XML.Serializer.Deserialize(File.ReadAllText(launcherConfigFilePath)); if (launcherConfig[property] == null) return null; - //this uses the indexer, which means, we can use the variable in order to get the property. Look at LauncherConfigXML for more info + // This uses the indexer, which means, we can use the variable in order to get the property. Look at LauncherConfigXML for more info return launcherConfig[property]?.ToString(); } return null; @@ -116,12 +116,12 @@ namespace AM2RLauncher { if (currentPlatform.IsWinForms) { - //we use the configuration manager in order to read from the app.config, change the value and save it + // We use the configuration manager in order to read from the app.config, change the value and save it Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 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 == null || connectionStringsSection.ConnectionStrings[property]?.ConnectionString == null) throw new ArgumentException("The property " + property + " could not be found."); connectionStringsSection.ConnectionStrings[property].ConnectionString = value.ToString(); appConfig.Save(); @@ -129,26 +129,26 @@ namespace AM2RLauncher } else if (currentPlatform.IsGtk) { - //config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) + // Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) string homePath = Environment.GetEnvironmentVariable("HOME"); string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher"; string launcherConfigFilePath = launcherConfigPath + "/config.xml"; XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML(); - //if folder doesn't exist, create it and the config file + // If folder doesn't exist, create it and the config file if (!Directory.Exists(launcherConfigPath) || !File.Exists(launcherConfigFilePath)) { Directory.CreateDirectory(launcherConfigPath); File.WriteAllText(launcherConfigFilePath, XML.Serializer.Serialize(launcherConfig)); } - //deserialize the config xml into launcherConfig + // Deserialize the config xml into launcherConfig launcherConfig = XML.Serializer.Deserialize(File.ReadAllText(launcherConfigFilePath)); - //uses indexer. Look at LauncherConfigXML for more info + // Uses indexer. Look at LauncherConfigXML for more info launcherConfig[property] = value; - //serialize back into the file + // Serialize back into the file File.WriteAllText(launcherConfigFilePath, XML.Serializer.Serialize(launcherConfig)); } } @@ -158,7 +158,7 @@ namespace AM2RLauncher /// public static void CopyOldConfigToNewConfig() { - if(currentPlatform.IsWinForms) + if (currentPlatform.IsWinForms) { string oldConfigPath = LAUNCHERNAME + ".oldCfg"; string newConfigPath = LAUNCHERNAME + ".config"; @@ -176,16 +176,16 @@ namespace AM2RLauncher File.WriteAllText(newConfigPath, newConfigText); } - else if(currentPlatform.IsGtk) + else if (currentPlatform.IsGtk) { - //config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) + // Config for nix systems will be saved in XDG_CONFIG_HOME/AM2RLauncher (or if empty, ~/.config) string homePath = Environment.GetEnvironmentVariable("HOME"); string xdgConfigHome = Environment.GetEnvironmentVariable("XDG_CONFIG_HOME"); string launcherConfigPath = (String.IsNullOrWhiteSpace(xdgConfigHome) ? (homePath + "/.config") : xdgConfigHome) + "/AM2RLauncher"; string launcherConfigFilePath = launcherConfigPath + "/config.xml"; XML.LauncherConfigXML launcherConfig = new XML.LauncherConfigXML(); - //for some reason deserializing and saving back again works, not exactly sure why, but I'll take it + // For some reason deserializing and saving back again works, not exactly sure why, but I'll take it launcherConfig = XML.Serializer.Deserialize(File.ReadAllText(launcherConfigFilePath)); File.WriteAllText(launcherConfigFilePath, XML.Serializer.Serialize(launcherConfig)); } @@ -197,9 +197,9 @@ namespace AM2RLauncher /// The URL of the website to be opened. public static void OpenURL(string url) { - if(currentPlatform.IsWinForms) + if (currentPlatform.IsWinForms) Process.Start(url); - else if(currentPlatform.IsGtk) + else if (currentPlatform.IsGtk) Process.Start("xdg-open", url); } @@ -219,11 +219,11 @@ namespace AM2RLauncher Directory.CreateDirectory(realPath); } - //needs quotes otherwise paths with space wont open + // Needs quotes otherwise paths with space wont open if (currentPlatform.IsWinForms) // And we're using explorer.exe to prevent people from stuffing system commands in here wholesale. That would be bad. Process.Start("explorer.exe", $"\"{realPath}\""); - // linux only opens the directory bc opening and selecting a file is pain + // Linux only opens the directory bc opening and selecting a file is pain else if (currentPlatform.IsGtk) Process.Start("xdg-open", $"\"{realPath}\""); } @@ -245,7 +245,7 @@ namespace AM2RLauncher return; } - //needs quotes otherwise paths with spaces wont open + // Needs quotes otherwise paths with spaces wont open if (currentPlatform.IsWinForms) // And we're using explorer.exe to prevent people from stuffing system commands in here wholesale. That would be bad. Process.Start("explorer.exe", $"/select, \"{realPath}\""); @@ -284,7 +284,7 @@ namespace AM2RLauncher java.StartInfo = javaStart; - //this is primarily for linux, but could be happening on windows as well + // This is primarily for linux, but could be happening on windows as well try { java.Start(); @@ -342,7 +342,7 @@ namespace AM2RLauncher /// Full Path to the output file. public static void ApplyXdeltaPatch(string original, string patch, string output) { - // for *whatever reason* **sometimes** xdelta patching doesn't work, if output = original. So I'm fixing that here. + // For *whatever reason* **sometimes** xdelta patching doesn't work, if output = original. So I'm fixing that here. string originalOutput = output; if (original == output) output = output += "_"; @@ -395,7 +395,7 @@ namespace AM2RLauncher /// Figures out what the AM2RLauncher's should be.
/// Determination is as follows: /// - /// AM2RLAUNCHERDATA environment variable is read and folders are recursively generated. + /// $AM2RLAUNCHERDATA environment variable is read and folders are recursively generated. /// The current OS is checked. For Windows, the path where the executable is located will be returned.
/// For Linux, $XDG_DATA_HOME/AM2RLauncher will be returned. /// Should $XDG_DATA_HOME be empty, it will default to $HOME/.local/share.
diff --git a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs index a16e86a..789f5dd 100644 --- a/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs +++ b/AM2RLauncher/AM2RLauncher/LauncherUpdater.cs @@ -23,8 +23,8 @@ namespace AM2RLauncher static readonly public string VERSION = "2.1.2"; /// The current Running platform. - static readonly private Platform currentPlatform = Platform.Instance; //needs to be declared here as well, because I can't access the one from eto - //since it's not loaded at this point + static readonly private 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 static readonly private string oldConfigPath = CrossPlatformOperations.CURRENTPATH + "/" + CrossPlatformOperations.LAUNCHERNAME + ".oldCfg"; @@ -47,9 +47,9 @@ namespace AM2RLauncher string version = VERSION.Replace(".", ""); - //update section + // Update section - //delete old files that have been left + // Clean old files that have been left if (File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2RLauncher.bak")) { log.Info("AM2RLauncher.bak detected. Removing file."); @@ -86,15 +86,15 @@ namespace AM2RLauncher } } - //check settings if autoUpdateLauncher is set to true + // Check settings if autoUpdateLauncher is set to true bool autoUpdate = bool.Parse(CrossPlatformOperations.ReadFromConfig("AutoUpdateLauncher")); if (autoUpdate) { log.Info("AutoUpdate Launcher set to true!"); - //this is supposed to fix the updater throwing an exception on windows 7 and earlier(?) - //see this for information: https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel and https://stackoverflow.com/a/50977774 + // 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) { ServicePointManager.Expect100Continue = true; @@ -177,7 +177,7 @@ namespace AM2RLauncher log.Info("Moving " + file.FullName + " to " + CrossPlatformOperations.CURRENTPATH + "/" + file.Name); 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")) { // So, because Windows behavior is dumb... @@ -198,8 +198,8 @@ namespace AM2RLauncher } // Yes, the above calls could be recursive. No, I can't be bothered to make them as such. - - HelperMethods.DirectoryCopy(tmpUpdatePath + "lib", CrossPlatformOperations.CURRENTPATH + "/lib", true); + if (Directory.Exists(tmpUpdatePath + "lib")) + HelperMethods.DirectoryCopy(tmpUpdatePath + "lib", CrossPlatformOperations.CURRENTPATH + "/lib", true); } Directory.Delete(tmpUpdatePath, true); diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs index d0179e3..642abc6 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Events.cs @@ -61,7 +61,7 @@ namespace AM2RLauncher { await Task.Run(() => PullPatchData()); - // thank you druid, for this case that should never happen + // Thank you druid, for this case that should never happen if (!File.Exists(CrossPlatformOperations.CURRENTPATH + "/PatchData/profile.xml")) { log.Error("Druid PatchData corruption occurred!"); @@ -70,10 +70,10 @@ namespace AM2RLauncher return; } } - catch (UserCancelledException) { } //we deliberately cancelled this! - catch (LibGit2SharpException ex) //this is for any exceptions from libgit + catch (UserCancelledException) { } // We deliberately cancelled this! + catch (LibGit2SharpException ex) // This is for any exceptions from libgit { - //libgit2sharp error messages are always in english! + // Libgit2sharp error messages are always in english! if (ex.Message.ToLower().Contains("failed to send request") || ex.Message.ToLower().Contains("connection with the server was terminated") || ex.Message.ToLower().Contains("failed to resolve address")) { @@ -89,7 +89,7 @@ namespace AM2RLauncher MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Language.Text.ErrorWindowTitle, MessageBoxType.Error); } } - catch (Exception ex) //this is if somehow any other exception might get thrown as well. + catch (Exception ex) // This is if somehow any other exception might get thrown as well. { log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Language.Text.ErrorWindowTitle, MessageBoxType.Error); @@ -191,7 +191,7 @@ namespace AM2RLauncher OnTransferProgress = new TransferProgressHandler(TransferProgressHandlerMethod) }; - // Everything after this is basically on a different thread, so the rest of the launcher isn't locked up. + // Everything after this is on a different thread, so the rest of the launcher isn't locked up. try { if (Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/PatchData")) @@ -204,11 +204,12 @@ namespace AM2RLauncher } catch (UserCancelledException) { + // We deliberately cancelled this! successful = false; - } //we deliberately cancelled this! - catch (LibGit2SharpException ex) //this is for any exceptions from libgit + } + catch (LibGit2SharpException ex) // This is for any exceptions from libgit { - //libgit2sharp error messages are always in english! + // Libgit2sharp error messages are always in english! if (ex.Message.ToLower().Contains("failed to send request") || ex.Message.ToLower().Contains("connection with the server was terminated") || ex.Message.ToLower().Contains("failed to resolve address")) { @@ -224,12 +225,12 @@ namespace AM2RLauncher } successful = false; } - catch(Exception ex) //this is if somehow any other exception might get thrown as well. + catch(Exception ex) // This is if somehow any other exception might get thrown as well. { log.Error(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace); MessageBox.Show(ex.Message + "\n*****Stack Trace*****\n\n" + ex.StackTrace, Language.Text.ErrorWindowTitle, MessageBoxType.Error); - if(Directory.Exists(CrossPlatformOperations.CURRENTPATH + " / PatchData")) + if (Directory.Exists(CrossPlatformOperations.CURRENTPATH + " / PatchData")) HelperMethods.DeleteDirectory(CrossPlatformOperations.CURRENTPATH + "/PatchData"); successful = false; } @@ -268,7 +269,7 @@ namespace AM2RLauncher isGitProcessGettingCancelled = true; } // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :) - // but we should probably wait a bit before proceeding, since cleanup can take a while + // But we should probably wait a bit before proceeding, since cleanup can take a while Thread.Sleep(1000); isGitProcessGettingCancelled = false; break; @@ -299,7 +300,7 @@ namespace AM2RLauncher { if (Directory.Exists(fileFinder.FileName)) { - // this can happen on linux, and maybe windows as well + // This can happen on linux, and maybe windows as well log.Error("User selected a Directory. Cancelling import."); return; } @@ -312,15 +313,15 @@ namespace AM2RLauncher return; } - //if either a directory was selected or the file somehow went missing, cancel + // If either a directory was selected or the file somehow went missing, cancel if (!File.Exists(fileFinder.FileName)) { log.Error("Selected AM2R_11.zip file not found! Cancelling import."); break; } - //we check if it exists first, because someone coughDRUIDcough might've copied it into here while on the showDialog - if(!File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip")) + // We check if it exists first, because someone coughDRUIDcough might've copied it into here while on the showDialog + if (!File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip")) File.Copy(fileFinder.FileName, CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip"); log.Info("AM2R_11.zip successfully imported."); @@ -346,7 +347,7 @@ namespace AM2RLauncher await Task.Run(() => { - //if the file cannot be launched due to anti-virus shenanigans or any other reason, we try catch here + // If the file cannot be launched due to anti-virus shenanigans or any other reason, we try catch here try { InstallProfile(profileList[profileIndex.Value]); @@ -414,8 +415,8 @@ namespace AM2RLauncher /// private bool TransferProgressHandlerMethod(TransferProgress transferProgress) { - //thank you random issue on the gitlib2sharp repo!!!! - //also tldr; rtfm + // Thank you random issue on the gitlib2sharp repo!!!! + // Also tldr; rtfm if (isGitProcessGettingCancelled) return false; // This needs to be in an Invoke, in order to access the variables from the main thread @@ -527,7 +528,7 @@ namespace AM2RLauncher { log.Info("User selected \"" + fileFinder.FileName + "\""); - //if either a directory was selected or the file somehow went missing, cancel + // If either a directory was selected or the file somehow went missing, cancel if (!File.Exists(fileFinder.FileName)) { log.Error("Selected mod .zip file not found! Cancelling import."); @@ -536,17 +537,12 @@ namespace AM2RLauncher FileInfo modFile = new FileInfo(fileFinder.FileName); - //we check if it exists first, because it might've copied it into here while on the showDialog - // This is irrelevant - we don't need to copy the zip over - // if (!File.Exists(CrossPlatformOperations.CURRENTPATH + "/Mods/" + modFile.Name)) - // File.Copy(fileFinder.FileName, CrossPlatformOperations.CURRENTPATH + "/Mods/" + modFile.Name); - string modsDir = new DirectoryInfo(CrossPlatformOperations.CURRENTPATH + "/Mods").FullName; string extractedName = modFile.Name.Replace(".zip", ""); - //extract it and see if it contains a profile.xml. If not, this is invalid + // Extract it and see if it contains a profile.xml. If not, this is invalid - // check first, if the directory is already there, if yes, throw a message + // Check first, if the directory is already there, if yes, throw a message if (Directory.Exists(modsDir + "/" + extractedName)) { ProfileXML profile2 = Serializer.Deserialize(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml")); @@ -559,7 +555,7 @@ namespace AM2RLauncher ZipFile.ExtractToDirectory(fileFinder.FileName, modsDir + "/" + extractedName); log.Info("Imported and extracted mod .zip as " + extractedName); - // let's check if profile.xml exists in there! If it doesn't throw an error and cleanup + // Let's check if profile.xml exists in there! If it doesn't throw an error and cleanup if (!File.Exists(modsDir + "/" + extractedName + "/profile.xml")) { log.Error(fileFinder.FileName + " does not contain profile.xml! Cancelling mod import."); @@ -572,12 +568,12 @@ 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")) + // Check if the OS versions match + if ((Platform.IsWinForms && profile.OperatingSystem != "Windows") || (Platform.IsGtk && profile.OperatingSystem != "Linux")) { 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.IsGtk) currentOS = "Linux"; // Teeeeechnically, any OS could run GTK applications as well but it'd break a lot and is thus unsupported. log.Error("Mod is for " + profile.OperatingSystem + " while current OS is " + Platform + ". Cancelling mod import."); @@ -588,7 +584,7 @@ namespace AM2RLauncher return; } - // check by *name*, if the mod was installed already + // Check by *name*, if the mod was installed already if (profileList.Where(p => p.Name == profile.Name).FirstOrDefault() != null || Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profile.Name)) { log.Error(profile.Name + " is already installed."); @@ -681,9 +677,9 @@ namespace AM2RLauncher /// private void ProfileLayoutLoadComplete(object sender, EventArgs e) { - // safety check + // Safety check if (settingsProfileDropDown == null) return; - if(settingsProfileDropDown.Items.Count == 0) + if (settingsProfileDropDown.Items.Count == 0) { addModButton.Enabled = false; settingsProfileLabel.TextColor = colInactive; @@ -758,7 +754,7 @@ namespace AM2RLauncher profileAuthorLabel.Text = Language.Text.Author + " " + profileList[profileDropDown.SelectedIndex].Author; profileVersionLabel.Text = Language.Text.VersionLabel + " " + profileList[profileDropDown.SelectedIndex].Version; - CrossPlatformOperations.WriteToConfig("ProfileIndex", profileIndex + ""); //Loj, tell me a better way to do this + CrossPlatformOperations.WriteToConfig("ProfileIndex", profileIndex + ""); // Loj, tell me a better way to do this if (profileDropDown.SelectedIndex != 0 && (profileList[profileDropDown.SelectedIndex].SaveLocation == "%localappdata%/AM2R" || profileList[profileDropDown.SelectedIndex].SaveLocation == "default")) @@ -830,12 +826,12 @@ namespace AM2RLauncher CrossPlatformOperations.WriteToConfig("MirrorIndex",mirrorDropDown.SelectedIndex); - //don't overwrite the git config while we download!!! + // Don't overwrite the git config while we download!!! if (updateState == UpdateState.Downloading) return; log.Info("Overwriting mirror in gitconfig."); - //check if the gitConfig exists, if yes regex the gitURL, and replace it with the new current Mirror. + // Check if the gitConfig exists, if yes regex the gitURL, and replace it with the new current Mirror. string gitConfigPath = CrossPlatformOperations.CURRENTPATH + "/PatchData/.git/config"; if (!File.Exists(gitConfigPath)) return; string gitConfig = File.ReadAllText(gitConfigPath); @@ -865,7 +861,7 @@ namespace AM2RLauncher log.Info("Overwriting mirror in gitconfig."); - //check if the gitConfig exists, if yes regex the gitURL, and replace it with the new current Mirror. + // Check if the gitConfig exists, if yes regex the gitURL, and replace it with the new current Mirror. string gitConfigPath = CrossPlatformOperations.CURRENTPATH + "/PatchData/.git/config"; if (!File.Exists(gitConfigPath)) return; string gitConfig = File.ReadAllText(gitConfigPath); @@ -952,7 +948,7 @@ namespace AM2RLauncher { log.Info("User selected \"" + fileFinder.FileName + "\""); - //if either a directory was selected or the file somehow went missing, cancel + // If either a directory was selected or the file somehow went missing, cancel if (!File.Exists(fileFinder.FileName)) { log.Error("Selected mod .zip file not found! Cancelling mod update."); @@ -964,12 +960,12 @@ namespace AM2RLauncher string modsDir = new DirectoryInfo(CrossPlatformOperations.CURRENTPATH + "/Mods").FullName; string extractedName = modFile.Name.Replace(".zip", "_new"); - //extract it and see if it contains a profile.xml. If not, this is invalid + // Extract it and see if it contains a profile.xml. If not, this is invalid // Directory doesn't exist -> extract! ZipFile.ExtractToDirectory(fileFinder.FileName, modsDir + "/" + extractedName); - // let's check if profile.xml exists in there! If it doesn't throw an error and cleanup + // Let's check if profile.xml exists in there! If it doesn't throw an error and cleanup if (!File.Exists(modsDir + "/" + extractedName + "/profile.xml")) { log.Error(fileFinder.FileName + " does not contain profile.xml! Cancelling mod update."); @@ -979,7 +975,7 @@ namespace AM2RLauncher return; } - // check by *name*, if the mod was installed already + // Check by *name*, if the mod was installed already ProfileXML profile = Serializer.Deserialize(File.ReadAllText(modsDir + "/" + extractedName + "/profile.xml")); if (profileList.Where(p => p.Name == profile.Name).FirstOrDefault() != null || Directory.Exists(CrossPlatformOperations.CURRENTPATH + "/Profiles/" + profile.Name)) @@ -1016,7 +1012,7 @@ namespace AM2RLauncher if (abort) { - // file cleanup + // File cleanup HelperMethods.DeleteDirectory(modsDir + "/" + extractedName); LoadProfiles(); return; @@ -1057,7 +1053,7 @@ namespace AM2RLauncher } else isGitProcessGettingCancelled = true; - //We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :) + // We don't need to delete any folders here, the cancelled gitClone will do that automatically for us :) } else if (updateState == UpdateState.Installing) @@ -1066,7 +1062,7 @@ namespace AM2RLauncher e.Cancel = true; } - //this needs to be made invisible, otherwise a tray indicator will be visible (on linux?) that clicking crashes the application + // 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) diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs index 3ce346f..248dc82 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.Methods.cs @@ -27,7 +27,7 @@ namespace AM2RLauncher /// if yes, if not. private bool IsPatchDataCloned() { - //isValid seems to only check for a .git folder, and there are cases where that exists, but not the profile.xml + // 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"); } @@ -37,7 +37,7 @@ namespace AM2RLauncher /// if yes, if not. private bool Is11Installed() { - // return safely if file doesn't exist + // Return safely if file doesn't exist if (!File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip")) return false; var returnCode = CheckIfZipIsAM2R11(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip"); // Check if it's valid, if not log it, rename it and silently leave @@ -129,9 +129,9 @@ namespace AM2RLauncher } // Delete the zip file in Mods - if(File.Exists(CrossPlatformOperations.CURRENTPATH + profile.DataPath + ".zip")) + if (File.Exists(CrossPlatformOperations.CURRENTPATH + profile.DataPath + ".zip")) { - File.SetAttributes(CrossPlatformOperations.CURRENTPATH + profile.DataPath + ".zip", FileAttributes.Normal); // for some reason, it was set at read only, so we undo that here + File.SetAttributes(CrossPlatformOperations.CURRENTPATH + profile.DataPath + ".zip", FileAttributes.Normal); // For some reason, it was set at read only, so we undo that here File.Delete(CrossPlatformOperations.CURRENTPATH + profile.DataPath + ".zip"); } @@ -186,7 +186,7 @@ namespace AM2RLauncher prof.DataPath = "/Mods/" + dir.Name; profileList.Add(prof); } - else if (!IsProfileInstalled(prof)) // if not installable and isn't installed, remove it + else if (!IsProfileInstalled(prof)) // If not installable and isn't installed, remove it { prof.DataPath = "/Mods/" + dir.Name; DeleteProfile(prof, false); @@ -205,19 +205,19 @@ namespace AM2RLauncher profileDropDown.Items.Add(profile.Name); } - // read the value from the config + // Read the value from the config string profIndexString = CrossPlatformOperations.ReadFromConfig("ProfileIndex"); - //check if either no profile was found or the setting says that the last current profile didn't exist + // Check if either no profile was found or the setting says that the last current profile didn't exist if (profileDropDown.Items.Count == 0) profileIndex = null; else { - // we know that profiles exist at this point, so we're going to point it to 0 instead so the following code doesn't fail + // We know that profiles exist at this point, so we're going to point it to 0 instead so the following code doesn't fail if (profIndexString == "null") profIndexString = "0"; - // we parse from the settings, and check if profiles got deleted from the last time the launcher has been selected. if yes, we revert the last selection to 0; + // We parse from the settings, and check if profiles got deleted from the last time the launcher has been selected. if yes, we revert the last selection to 0; int intParseResult = Int32.Parse(profIndexString); profileIndex = intParseResult; if (profileIndex >= profileDropDown.Items.Count) @@ -232,7 +232,7 @@ namespace AM2RLauncher log.Info("Profiles loaded."); - // refresh the author and version label on the main tab + // Refresh the author and version label on the main tab if (profileList.Count > 0) { profileAuthorLabel.Text = Language.Text.Author + " " + profileList[profileDropDown.SelectedIndex].Author; @@ -250,7 +250,7 @@ namespace AM2RLauncher { log.Info("Installing profile " + profile.Name + "..."); - // check if xdelta is installed on linux, by searching all folders in PATH + // Check if xdelta is installed on linux, by searching all folders in PATH if (Platform.IsGtk && !CrossPlatformOperations.CheckIfXdeltaIsInstalled()) { Application.Instance.Invoke(new Action(() => @@ -312,7 +312,7 @@ namespace AM2RLauncher else if (Platform.IsGtk) { datawin = "game.unx"; - // use the exe name based on the desktop file in the appimage, rather than hardcoding it. + // Use the exe name based on the desktop file in the appimage, rather than hardcoding it. string desktopContents = File.ReadAllText(CrossPlatformOperations.CURRENTPATH + "/PatchData/data/AM2R.AppDir/AM2R.desktop"); exe = Regex.Match(desktopContents, @"(?<=Exec=).*").Value; log.Info("According to AppImage desktop file, using \"" + exe + "\" as game name."); @@ -340,9 +340,10 @@ namespace AM2RLauncher { CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/data.win", dataPath + "/game.xdelta", profilePath + "/" + datawin); CrossPlatformOperations.ApplyXdeltaPatch(profilePath + "/AM2R.exe", dataPath + "/AM2R.xdelta", profilePath + "/" + exe); - Process.Start("chmod", "+x \"" + profilePath + "/" + exe + "\"").WaitForExit(); //just in case the resulting file isn't chmoddded, we do it here. + // Just in case the resulting file isn't chmoddded... + Process.Start("chmod", "+x \"" + profilePath + "/" + exe + "\"").WaitForExit(); - //these are not needed by linux at all, so we delete them + // These are not needed by linux at all, so we delete them File.Delete(profilePath + "/data.win"); File.Delete(profilePath + "/AM2R.exe"); File.Delete(profilePath + "/D3DX9_43.dll"); @@ -353,7 +354,7 @@ namespace AM2RLauncher // Applied patch if (Platform.IsWinForms) UpdateProgressBar(66); - else if (Platform.IsGtk) UpdateProgressBar(44); //linux will take a bit longer, due to appimage creation + else if (Platform.IsGtk) UpdateProgressBar(44); // Linux will take a bit longer, due to appimage creation log.Info("xdelta patch(es) applied."); // Install new datafiles @@ -372,24 +373,24 @@ namespace AM2RLauncher // Rename all songs to lowercase foreach (var file in new DirectoryInfo(assetsPath).GetFiles()) - if(file.Name.EndsWith(".ogg") && !File.Exists(file.DirectoryName + "/" + file.Name.ToLower())) + if (file.Name.EndsWith(".ogg") && !File.Exists(file.DirectoryName + "/" + file.Name.ToLower())) File.Move(file.FullName, file.DirectoryName + "/" + file.Name.ToLower()); - //Copy AppImage template to here + // Copy AppImage template to here HelperMethods.DirectoryCopy(CrossPlatformOperations.CURRENTPATH + "/PatchData/data/AM2R.AppDir", profilePath + "/AM2R.AppDir/"); - // safety checks, in case the folders don't exist + // Safety checks, in case the folders don't exist Directory.CreateDirectory(profilePath + "/AM2R.AppDir/usr/bin/"); Directory.CreateDirectory(profilePath + "/AM2R.AppDir/usr/bin/assets/"); - // copy game assets to the appimageDir + // Copy game assets to the appimageDir HelperMethods.DirectoryCopy(assetsPath, profilePath + "/AM2R.AppDir/usr/bin/assets/"); File.Copy(profilePath + "/" + exe, profilePath + "/AM2R.AppDir/usr/bin/" + exe); UpdateProgressBar(66); log.Info("Gtk-specific formatting finished."); - // temp save the currentWorkingDirectory and console.error, change it to profilePath and null, call the script, and change it back. + // Temp save the currentWorkingDirectory and console.error, change it to profilePath and null, call the script, and change it back. string workingDir = Directory.GetCurrentDirectory(); TextWriter cliError = Console.Error; Directory.SetCurrentDirectory(profilePath); @@ -399,7 +400,7 @@ namespace AM2RLauncher Directory.SetCurrentDirectory(workingDir); Console.SetError(cliError); - //Clean files + // Clean files Directory.Delete(profilePath + "/AM2R.AppDir", true); Directory.Delete(assetsPath, true); File.Delete(profilePath + "/" +exe); @@ -409,7 +410,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"); @@ -436,7 +437,7 @@ namespace AM2RLauncher // Check for java, exit safely with a warning if not found! if (!CrossPlatformOperations.IsJavaInstalled()) { - //message box show needs to be done on main thread + // Message box show needs to be done on main thread Application.Instance.Invoke(new Action(() => { MessageBox.Show(Language.Text.JavaNotFound, Language.Text.WarningWindowTitle, MessageBoxButtons.OK); @@ -447,10 +448,10 @@ namespace AM2RLauncher return; } - // check if xdelta is installed on linux, by searching all folders in PATH + // Check if xdelta is installed on linux, by searching all folders in PATH if (Platform.IsGtk && !CrossPlatformOperations.CheckIfXdeltaIsInstalled()) { - //message box show needs to be done on main thread + // Message box show needs to be done on main thread Application.Instance.Invoke(new Action(() => { MessageBox.Show(Language.Text.XdeltaNotFound, Language.Text.WarningWindowTitle, MessageBoxButtons.OK); @@ -498,7 +499,7 @@ namespace AM2RLauncher ProcessStartInfo apktoolStart = new ProcessStartInfo { FileName = proc, - // for an explanation on the .replace look in CreateXdeltaPatch method + // For an explanation on the .replace look in CreateXdeltaPatch method Arguments = args + "\"" + apktoolPath.Replace(CrossPlatformOperations.CURRENTPATH + "/","../") + "\" d \"" + dataPath.Replace(CrossPlatformOperations.CURRENTPATH + "/", "../") + "/android/AM2RWrapper.apk\"", WorkingDirectory = tempDir, UseShellExecute = false, @@ -653,7 +654,7 @@ namespace AM2RLauncher if (Platform.IsWinForms) { - // sets the arguments to empty, or to the profiles save path/logs and create time based logs. Creates the folder if necessary. + // Sets the arguments to empty, or to the profiles save path/logs and create time based logs. Creates the folder if necessary. string arguments = ""; // Game logging @@ -699,26 +700,26 @@ namespace AM2RLauncher log.Info("Is the environment textbox null or whitespace = " + string.IsNullOrWhiteSpace(customEnvVarTextBox.Text)); - if(!string.IsNullOrWhiteSpace(customEnvVarTextBox.Text)) + if (!string.IsNullOrWhiteSpace(customEnvVarTextBox.Text)) { string envVars = customEnvVarTextBox.Text; for(int i = 0; i < customEnvVarTextBox.Text.Count(f => f == '='); i++) { - // env var variable + // Env var variable string variable = envVars.Substring(0, envVars.IndexOf('=')); envVars = envVars.Replace(variable + "=", ""); - // this thing here is the value parser. Since values are sometimes "like this", i need to compensate for them. + // This thing here is the value parser. Since values are sometimes in quotes, i need to compensate for them. int valueSubstringLength = 0; - if(envVars[0] != '"') // if value is not embedded in "", check if there are spaces left. If yes, get the index of the space, if not that was the last + if (envVars[0] != '"') // If value is not embedded in "", check if there are spaces left. If yes, get the index of the space, if not that was the last { if (envVars.IndexOf(' ') >= 0) valueSubstringLength = envVars.IndexOf(' ')+1; else valueSubstringLength = envVars.Length; } - else // if value is embedded in "", check if there are spaces after the "". if yes, get index of that, if not that was the last + else // If value is embedded in "", check if there are spaces after the "". if yes, get index of that, if not that was the last { int secondQuoteIndex = envVars.IndexOf('"', envVars.IndexOf('"')+1); if (envVars.IndexOf(' ', secondQuoteIndex) >= 0) @@ -726,7 +727,7 @@ namespace AM2RLauncher else valueSubstringLength = envVars.Length; } - // env var value + // Env var value string value = envVars.Substring(0, valueSubstringLength); envVars = envVars.Substring(value.Length); @@ -735,7 +736,7 @@ namespace AM2RLauncher } } - // IF we're supposed to log profiles, add events that track those and append them to this var. otherwise keep it null + // If we're supposed to log profiles, add events that track those and append them to this var. otherwise keep it null string terminalOutput = null; startInfo.UseShellExecute = false; @@ -782,10 +783,10 @@ namespace AM2RLauncher StreamWriter stream = File.AppendText(logDir.FullName + "/" + profile.Name + ".txt"); - // write general info + // Write general info stream.WriteLine("AM2RLauncher " + VERSION + " log generated at " + date); - //write what was in the terminal + // Write what was in the terminal stream.WriteLine(terminalOutput); stream.Flush(); @@ -1087,13 +1088,13 @@ namespace AM2RLauncher string tmpPath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(zipPath); - // clean up in case folder exists already + // Clean up in case folder exists already if (Directory.Exists(tmpPath)) Directory.Delete(tmpPath, true); Directory.CreateDirectory(tmpPath); - //open archive + // Open archive ZipArchive am2rZip = ZipFile.OpenRead(zipPath); // Check if exe exists anywhere @@ -1124,10 +1125,10 @@ namespace AM2RLauncher if (HelperMethods.CalculateMD5(tmpPath + "/" + d3dx.FullName) != d3dHash) return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll; - // clean up + // Clean up Directory.Delete(tmpPath, true); - // if we didn't exit before, everything is fine + // If we didn't exit before, everything is fine return IsZipAM2R11ReturnCodes.Successful; } } diff --git a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs index df90e03..0838351 100644 --- a/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs +++ b/AM2RLauncher/AM2RLauncher/MainForm/MainForm.UI.cs @@ -153,7 +153,7 @@ namespace AM2RLauncher // But log actual folder location nonetheless log.Info("Actual Launcher location: " + Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)); - //Set the language to what User wanted or choose local language + // 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(); @@ -164,7 +164,7 @@ namespace AM2RLauncher #region VARIABLE INITIALIZATION log.Info("Beginning UI initialization..."); - // system tray indicator + // System tray indicator showButton = new ButtonMenuItem() { Text = Language.Text.TrayButtonShow }; trayIndicator = new TrayIndicator() { @@ -209,8 +209,8 @@ namespace AM2RLauncher // We do this as a List so we can add more dynamically on user input... if necessary. mirrorList = CrossPlatformOperations.GenerateMirrorList(); - //create mirror list - //we do this as a list for 1) make this dynamic and 2) make ETO happy + // Create mirror list + // We do this as a list for 1) make this dynamic and 2) make ETO happy mirrorDescriptionList = new List { new ListItem { Key = mirrorList[0], Text = Language.Text.MirrorGithubText }, @@ -503,14 +503,14 @@ namespace AM2RLauncher // [LAUNCHER SETTINGS] DynamicLayout settingsLayout = new DynamicLayout(); - //languageLabel + // LanguageLabel languageLabel = new Label { Text = Language.Text.LanguageNotice, TextColor = colGreen }; - //language DropDown menu + // Language DropDown menu List languageList = new List() { @@ -578,7 +578,7 @@ namespace AM2RLauncher TextColor = colGreen }; - // create game debug logs + // Create game debug logs profileDebugLogCheck = new CheckBox { Checked = bool.Parse(CrossPlatformOperations.ReadFromConfig("ProfileDebugLog")), @@ -586,9 +586,9 @@ namespace AM2RLauncher TextColor = colGreen }; - // custom environment variables label + // Custom environment variables label customEnvVarLabel = new Label(); - if(Platform.IsGtk) + if (Platform.IsGtk) { customEnvVarLabel = new Label { @@ -597,9 +597,9 @@ namespace AM2RLauncher }; } - // custom environment variables textbox + // Custom environment variables textbox customEnvVarTextBox = null; - if(Platform.IsGtk) + if (Platform.IsGtk) { customEnvVarTextBox = new TextBox { @@ -624,7 +624,7 @@ namespace AM2RLauncher if (Platform.IsGtk) 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 = (int.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) < mirrorDropDown.Items.Count) ? int.Parse(CrossPlatformOperations.ReadFromConfig("MirrorIndex")) : 0; mirrorDropDown.SelectedIndex = mirrorIndex; @@ -821,7 +821,7 @@ namespace AM2RLauncher deleteModButton.Click += DeleteModButtonClicked; updateModButton.Click += UpdateModButtonClicked; profileDebugLogCheck.CheckedChanged += ProfileDebugLogCheckedChanged; - if(Platform.IsGtk) + if (Platform.IsGtk) customEnvVarTextBox.LostFocus += CustomEnvVarTextBoxLostFocus; newsWebView.DocumentLoaded += NewsWebViewDocumentLoaded; @@ -834,7 +834,7 @@ namespace AM2RLauncher #region CONTROL VARIABLES - //Visual studio does it like this for normal winforms projects, so I just used the same format. + // Visual studio does it like this for normal winforms projects, so I just used the same format. /// The tray indicator TrayIndicator trayIndicator; @@ -846,7 +846,7 @@ namespace AM2RLauncher /// of s so that Eto's annoying interface is appeased. Used for profile name display in DropDowns. List profileNames; - //Bitmaps + // Bitmaps /// The Reddit icon. private Bitmap redditIcon; /// The Github icon. diff --git a/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs b/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs index 25f8b19..54dbd5b 100644 --- a/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs +++ b/AM2RLauncher/AM2RLauncher/XML/LauncherConfigXML.cs @@ -72,12 +72,12 @@ namespace AM2RLauncher.XML public bool IsMaximized { get; set; } - //huge help from James for all of this!!! - //here's a short explanation of this. Basically, what we do is create an indexer. This makes it possible for this class to be indexed, like this LauncherConfigXML[i] - //the indexer here has a get and set "submethod". And both use Reflection to get the current class as something that can be used with lambda values - //so for get we just lambda the properties and search for something that can be read and has the same name as the input property. After that, we just get the value and return it as a string - //set is basiaclly the same, but instead of returning it, we set the prtoperty value, which would be followed after the `='. - //So LauncherConfigXML[property] = hellWorld would set the value of `property` to `hellWorld` + // Huge help from James for all of this!!! + // Here's a short explanation of this. Basically, what we do is create an indexer. This makes it possible for this class to be indexed, like this LauncherConfigXML[i] + // The indexer here has a get and set "submethod". And both use Reflection to get the current class as something that can be used with lambda values + // So for get we just lambda the properties and search for something that can be read and has the same name as the input property. After that, we just get the value and return it as a string + // Set is basiaclly the same, but instead of returning it, we set the prtoperty value, which would be followed after the `='. + // So LauncherConfigXML[property] = hellWorld would set the value of `property` to `hellWorld` /// /// An Indexer for . Not to be used directly, use /// or instead! @@ -88,7 +88,7 @@ namespace AM2RLauncher.XML { get { - //this is gonna throw an exception, if the property can't be found. because of null.GetValue(this) + // This is gonna throw an exception, if the property can't be found. because of null.GetValue(this) return typeof(LauncherConfigXML).GetProperties().Where(p => p.CanRead && p.Name == property).First().GetValue(this).ToString(); } set