From 3f10dff371551147915cf092ba8d17e4a5460038 Mon Sep 17 00:00:00 2001 From: MatuxGG Date: Sun, 20 Nov 2022 19:08:00 +0100 Subject: [PATCH] Version 5.3.2 --- MakeExecutableDotnet6.iss | 2 +- ModManager5/Classes/Config.cs | 27 ++++++++++ ModManager5/Classes/ConfigManager.cs | 3 ++ ModManager5/Classes/ModList.cs | 9 ++-- ModManager5/Classes/ModManagerUI.cs | 26 +++++----- ModManager5/Classes/ModWorker.cs | 75 ++++++++++++++++----------- ModManager5/Classes/Utils.cs | 26 ++++++++++ ModManager5/Classes/VersionUpdater.cs | 29 +++++++++++ ModManager5/ModManager.cs | 3 ++ ModManager5/ModManager5.csproj | 4 +- ModManager5/Program.cs | 7 +++ 11 files changed, 162 insertions(+), 49 deletions(-) create mode 100644 ModManager5/Classes/VersionUpdater.cs diff --git a/MakeExecutableDotnet6.iss b/MakeExecutableDotnet6.iss index 0098a7ed..ad994e10 100644 --- a/MakeExecutableDotnet6.iss +++ b/MakeExecutableDotnet6.iss @@ -5,7 +5,7 @@ #include "Installer\CodeDependencies.iss" #define MyAppName "ModManager" -#define MyAppVersion "5.3.1" +#define MyAppVersion "5.3.2" #define MyAppPublisher "Matux" #define MyAppURL "https://goodloss.fr" #define MyAppExeName "ModManager5.exe" diff --git a/ModManager5/Classes/Config.cs b/ModManager5/Classes/Config.cs index fffcd371..fe234885 100644 --- a/ModManager5/Classes/Config.cs +++ b/ModManager5/Classes/Config.cs @@ -18,6 +18,7 @@ public class Config public bool miniEnabled; public bool multipleGames; public List availableAmongUsPaths; + public string supportId; public Config(string modManagerVersion, List installedMods, List installedVanilla, string amongUsPath, string launcher, List faroriteMods, bool miniEnabled, bool multipleGames) { @@ -30,6 +31,9 @@ public Config(string modManagerVersion, List installedMods, List() { }; + Random random = new Random(); + this.supportId = new string(Enumerable.Repeat(ModManager.supportIdChars, 10) + .Select(s => s[random.Next(s.Length)]).ToArray()); } public Config(string modManagerVersion, List installedMods, List installedVanilla, string amongUsPath, string launcher, List faroriteMods, bool miniEnabled) @@ -43,6 +47,9 @@ public Config(string modManagerVersion, List installedMods, List() { }; + Random random = new Random(); + this.supportId = new string(Enumerable.Repeat(ModManager.supportIdChars, 10) + .Select(s => s[random.Next(s.Length)]).ToArray()); } public Config(string modManagerVersion, List installedMods, List installedVanilla, string amongUsPath, string launcher, List faroriteMods, bool miniEnabled, List availableAmongUsPaths) @@ -56,6 +63,23 @@ public Config(string modManagerVersion, List installedMods, List s[random.Next(s.Length)]).ToArray()); + } + + public Config(string modManagerVersion, List installedMods, List installedVanilla, string amongUsPath, string launcher, List faroriteMods, bool miniEnabled, List availableAmongUsPaths, string supportId) + { + this.ModManagerVersion = modManagerVersion; + this.installedMods = installedMods; + this.installedVanilla = installedVanilla; + this.amongUsPath = amongUsPath; + this.launcher = launcher; + this.favoriteMods = faroriteMods; + this.miniEnabled = miniEnabled; + this.multipleGames = false; + this.availableAmongUsPaths = availableAmongUsPaths; + this.supportId = supportId; } public Config() @@ -70,6 +94,9 @@ public Config() this.miniEnabled = true; this.multipleGames = false; this.availableAmongUsPaths = new List() { }; + Random random = new Random(); + this.supportId = new string(Enumerable.Repeat(ModManager.supportIdChars, 10) + .Select(s => s[random.Next(s.Length)]).ToArray()); } } diff --git a/ModManager5/Classes/ConfigManager.cs b/ModManager5/Classes/ConfigManager.cs index 90576944..d468dbf6 100644 --- a/ModManager5/Classes/ConfigManager.cs +++ b/ModManager5/Classes/ConfigManager.cs @@ -301,6 +301,7 @@ public static void logConfig() { Utils.logE("Loading MM Config FAIL", "ConfigManager"); Utils.logEx(e, "ConfigManager"); + Utils.logToServ(e, "ConfigManager"); } } public static void logGlobalConfig() @@ -329,6 +330,7 @@ public static void logGlobalConfig() { Utils.logE("Loading computer info FAIL", "ConfigManager"); Utils.logEx(e, "ConfigManager"); + Utils.logToServ(e, "ConfigManager"); } Utils.log("MM Global Config", "ConfigManager"); @@ -343,6 +345,7 @@ public static void logGlobalConfig() { Utils.logE("Loading MM Global Config FAIL", "ConfigManager"); Utils.logEx(e, "ConfigManager"); + Utils.logToServ(e, "ConfigManager"); } } diff --git a/ModManager5/Classes/ModList.cs b/ModManager5/Classes/ModList.cs index 852ca7ff..4c511785 100644 --- a/ModManager5/Classes/ModList.cs +++ b/ModManager5/Classes/ModList.cs @@ -28,6 +28,8 @@ public static void load() ModManagerUI.StatusLabel.Text = Translator.get("Loading Mods..."); string modlistURL = ModManager.apiURL + "/mod"; string modlist = ""; + challengerClient = null; + challengerClientBeta = null; try { using (var client = new WebClient()) @@ -141,10 +143,10 @@ public static async Task loadRelease(Mod m) { await m.getGithubRelease(); } - else if (m.id == "Challenger") + else if (m.id == "Challenger" && challengerClient == null) { await getChallengerReleases(m, true); - } else if (m.id == "ChallengerBeta") + } else if (m.id == "ChallengerBeta" && challengerClientBeta == null) { await getChallengerReleases(m, false); } @@ -159,8 +161,6 @@ public static async Task getChallengerReleases(Mod m, Boolean live) IReadOnlyList releases = await client.Repository.Release.GetAll(m.author, m.github); m.release = releases.First(); // There is no management of Challenger down because we assume that it will be always up - challengerClient = null; - challengerClientBeta = null; Release challengerMod = null; foreach (Release r in releases) { @@ -218,6 +218,7 @@ public static void createShortcut(Mod m) } catch (Exception e) { Utils.logEx(e, "ModList"); + Utils.logToServ(e, "ModList"); } shortcut.Save(); diff --git a/ModManager5/Classes/ModManagerUI.cs b/ModManager5/Classes/ModManagerUI.cs index 6e71c5b1..ad896d9d 100644 --- a/ModManager5/Classes/ModManagerUI.cs +++ b/ModManager5/Classes/ModManagerUI.cs @@ -855,18 +855,10 @@ public static void refreshModForm(Form f) { ModWorker.startTransaction(); StatusLabel.Text = Translator.get("Adding local mod..."); - string newPath = ModManager.appDataPath + @"\localMods\" + ModTitle.Text; - Directory.CreateDirectory(newPath); - string tempPath = ModManager.tempPath + @"\ModZip"; - Utils.DirectoryDelete(tempPath); - Directory.CreateDirectory(tempPath); - string vanillaDestPath = ModManager.appDataPath + @"\vanilla\" + ModVersion.Text; - ZipFile.ExtractToDirectory(FileButton.Text, tempPath); - tempPath = ModWorker.getBepInExInsideRec(tempPath); - Utils.DirectoryCopy(vanillaDestPath, newPath, true); - Utils.DirectoryCopy(tempPath, newPath, true); + string newPath = ModManager.appDataPath + @"\localMods\" + ModTitle.Text + ".zip"; + Utils.FileCopy(FileButton.Text, newPath); - Mod newLocalMod = new Mod(ModTitle.Name, ModTitle.Text, "local", "local", ModVersion.Text, new List() { }, "", @"localMods\"+ModTitle.Text, "0", "", "", "", "") ; + Mod newLocalMod = new Mod(ModTitle.Name, ModTitle.Text, "local", "local", ModVersion.Text, new List() { }, "", @"localMods\"+ModTitle.Text+".zip", "0", "", "", "", "") ; ModList.localMods.Add(newLocalMod); @@ -890,7 +882,8 @@ public static void refreshModForm(Form f) Mod m = ModList.getLocalModById(modId); string path = m.github.Replace(@"localMods\", ModManager.appDataPath + @"\localMods\"); - Utils.DirectoryDelete(path); + + Utils.FileDelete(path); ModList.localMods.Remove(m); ModList.updateLocalMods(); @@ -1243,6 +1236,15 @@ public static void loadSettings() SettingsForm.Controls.Add(Visuals.SettingsButton(ResetButton, Translator.get("Reset"))); + // Support Id + MMButton SupportIdButton = new MMButton("trans"); + SupportIdButton.Click += new EventHandler((object sender, EventArgs e) => + { + Clipboard.SetText(ConfigManager.config.supportId); + }); + + SettingsForm.Controls.Add(Visuals.SettingsButton(SupportIdButton, Translator.get("Copy Support Id"))); + // Send log MMButton LogButton = new MMButton("trans"); LogButton.Click += new EventHandler((object sender, EventArgs e) => diff --git a/ModManager5/Classes/ModWorker.cs b/ModManager5/Classes/ModWorker.cs index 63e2d8c9..cc2dcf9e 100644 --- a/ModManager5/Classes/ModWorker.cs +++ b/ModManager5/Classes/ModWorker.cs @@ -115,52 +115,66 @@ public static void startMod(Mod m) //startSteam(); if (m.type == "local") { - string dirPath = ModManager.appDataPath + @"\localMods\" + m.name; + string dirPath = ModManager.appDataPath + @"\localMods\" + m.name + ".zip"; if (!ModManager.silent) ModManagerUI.StatusLabel.Text = Translator.get("Starting MODNAME ... Please wait...").Replace("MODNAME", m.name); + if (!ConfigManager.config.multipleGames && isGameOpen()) return; + if (ConfigManager.config.launcher != "Steam") { cleanGame(); - Utils.DirectoryCopy(dirPath, ConfigManager.config.amongUsPath, true); + + string newPath = ModManager.tempPath + @"\ModZip"; + Utils.DirectoryDelete(newPath); + Directory.CreateDirectory(newPath); + try + { + ZipFile.ExtractToDirectory(dirPath, newPath); + } + catch (Exception ex) + { + Utils.logE("Local mod zip extraction FAIL", "ModWorker"); + Utils.logEx(ex, "ModWorker"); + Utils.logToServ(ex, "ModWorker"); + return; + } + newPath = getBepInExInsideRec(newPath); + + Utils.DirectoryCopy(newPath, ConfigManager.config.amongUsPath, true); Process.Start("explorer", ConfigManager.config.amongUsPath + @"\Among Us.exe"); } else { - string dirPathLocal = ModManager.appDataPath + @"\localMods\" + m.name + @"-work"; - string vanillaDestPath = ModManager.appDataPath + @"\vanilla\" + m.gameVersion; - - if (!ConfigManager.containsGameVersion(m.gameVersion)) + string vanillaPath = ModManager.appDataPath + @"\vanilla\" + m.gameVersion; + string playPath = ModManager.appDataPath + @"\epicplay"; + Utils.DirectoryDelete(playPath); + Utils.DirectoryCreate(playPath); + + string newPath = ModManager.tempPath + @"\ModZip"; + Utils.DirectoryDelete(newPath); + Directory.CreateDirectory(newPath); + try { - string tempPath = ModManager.tempPath + @"\" + m.gameVersion + ".zip"; - Utils.FileDelete(tempPath); - - DownloadWorker.download(ModManager.fileURL + @"/client/" + m.gameVersion + @".zip", tempPath, Translator.get("Installing MODNAME, please wait...").Replace("MODNAME", m.name) + "\n(PERCENT)", 0, 100); - - Utils.DirectoryDelete(vanillaDestPath); - Directory.CreateDirectory(vanillaDestPath); - try - { - ZipFile.ExtractToDirectory(tempPath, vanillaDestPath); - } - catch (Exception ex) - { - Utils.logE("Client zip extraction FAIL", "ModWorker"); - Utils.logEx(ex, "ModWorker"); - return; - } - ConfigManager.config.installedVanilla.Add(new InstalledVanilla(m.gameVersion)); - ConfigManager.update(); + ZipFile.ExtractToDirectory(dirPath, newPath); } + catch (Exception ex) + { + Utils.logE("Local mod zip extraction FAIL", "ModWorker"); + Utils.logEx(ex, "ModWorker"); + Utils.logToServ(ex, "ModWorker"); + return; + } + newPath = getBepInExInsideRec(newPath); - Utils.DirectoryDelete(dirPathLocal); - Utils.DirectoryCreate(dirPathLocal); - Utils.DirectoryCopy(vanillaDestPath, dirPathLocal, true); - Utils.DirectoryCopy(dirPath, dirPathLocal, true); - Process.Start("explorer", dirPathLocal + @"\Among Us.exe"); + Utils.DirectoryCopy(vanillaPath, playPath, true); + Utils.DirectoryCopy(newPath, playPath, true); + + Process.Start("explorer", playPath + @"\Among Us.exe"); } + if (!ModManager.silent) ModManagerUI.StatusLabel.Text = Translator.get("MODNAME started.").Replace("MODNAME", m.name); @@ -758,6 +772,7 @@ private static void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Utils.logE("Client zip extraction FAIL", "ModWorker"); Utils.logEx(ex, "ModWorker"); + Utils.logToServ(ex, "ModWorker"); backgroundWorker.ReportProgress(100); } ConfigManager.config.installedVanilla.Add(new InstalledVanilla(m.gameVersion)); diff --git a/ModManager5/Classes/Utils.cs b/ModManager5/Classes/Utils.cs index 7613cddd..ea833db9 100644 --- a/ModManager5/Classes/Utils.cs +++ b/ModManager5/Classes/Utils.cs @@ -1,6 +1,9 @@ using System; +using System.Collections.Specialized; using System.IO; using System.Linq; +using System.Net; +using System.Text; using System.Windows.Forms; namespace ModManager5.Classes @@ -79,6 +82,29 @@ public static void logEx(Exception e, string className) Utils.logE("Source: " + e.Source, className); } + public static void logToServ(Exception e, string className) + { + logToServ("Mod Manager " + ModManager.visibleVersion + " - Client id: " + ConfigManager.config.supportId + " - Class: " + className + " - Message: " + e.Message + " - Source = " + e.Source); + } + + public static void logToServ(string text) + { + if (!String.IsNullOrEmpty(text)) + { + using (var client = new WebClient()) + { + var values = new NameValueCollection(); + values["text"] = text; + + var response = client.UploadValues(ModManager.apiURL + "/log", values); + + var responseString = Encoding.Default.GetString(response); + + } + } + + } + // Spec : str <= 15 public static string getTabs(string str) { diff --git a/ModManager5/Classes/VersionUpdater.cs b/ModManager5/Classes/VersionUpdater.cs new file mode 100644 index 00000000..965606c6 --- /dev/null +++ b/ModManager5/Classes/VersionUpdater.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ModManager5.Classes +{ + public static class VersionUpdater + { + public static void applyUpdates(string oldVersion, string newVersion) + { + if (Version.Parse(oldVersion) < Version.Parse("5.3.2")) + { + ModList.localMods = new List() { }; + string localPath = ModManager.appDataPath + @"\localMods\"; + Utils.DirectoryDelete(localPath); + Utils.DirectoryCreate(localPath); + ModList.updateLocalMods(); + } + + if (oldVersion != newVersion) + { + ConfigManager.config.ModManagerVersion = newVersion; + ConfigManager.update(); + } + } + } +} diff --git a/ModManager5/ModManager.cs b/ModManager5/ModManager.cs index b6e0a52b..5de077d7 100644 --- a/ModManager5/ModManager.cs +++ b/ModManager5/ModManager.cs @@ -26,6 +26,7 @@ public partial class ModManager : Form public static Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; public static string visibleVersion = version.ToString().Substring(0, version.ToString().Length - 2); public static string token = System.IO.File.ReadAllText(appPath + @"\token.txt"); + public static string supportIdChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789"; public static bool debug = false; @@ -152,6 +153,8 @@ public async Task Start(string[] args) ConfigManager.updateGlobalConfig(); } + VersionUpdater.applyUpdates(ConfigManager.config.ModManagerVersion, visibleVersion); + if (args.Count() > 0) { Utils.log("Starting mod from a shortcut", "ModManager"); diff --git a/ModManager5/ModManager5.csproj b/ModManager5/ModManager5.csproj index 7bb3fddd..1325e79a 100644 --- a/ModManager5/ModManager5.csproj +++ b/ModManager5/ModManager5.csproj @@ -4,8 +4,8 @@ net6.0-windows true modmanager.ico - 5.3.1.0 - 5.3.1.0 + 5.3.2.0 + 5.3.2.0 diff --git a/ModManager5/Program.cs b/ModManager5/Program.cs index 147a498b..a3bda7de 100644 --- a/ModManager5/Program.cs +++ b/ModManager5/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -14,10 +15,16 @@ static class Program [STAThread] static void Main(string[] args) { + Application.ThreadException += new ThreadExceptionEventHandler(ThreadException); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ModManager(args)); } + static void ThreadException(object sender, ThreadExceptionEventArgs e) + { + MessageBox.Show(e.Exception.Message, "Unhandled Thread Exception"); + + } } }