diff --git a/AddonLoader.lua b/AddonLoader.lua index 1234fd6..e3743dc 100644 --- a/AddonLoader.lua +++ b/AddonLoader.lua @@ -156,4 +156,4 @@ _G.CSScript_OnLoadCharacter=OnLoadCharacter _G.CSScript_OnPlayerAdded=OnPlayerAdded _G.CSScript_OnPlayerRemoved=OnPlayerRemoved _G.CSScript_OnPlayerKicked=OnPlayerKicked -_G.CSScript_OnPrePlayerKicked=OnPrePlayerKicked \ No newline at end of file +_G.CSScript_OnPrePlayerKicked=OnPrePlayerKicked diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs index 436bb17..63e508a 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs @@ -21,6 +21,8 @@ public class GlobalPaths public static readonly string DataDir = BinDir + @"\\data"; public static readonly string ClientDir = BasePath + @"\\clients"; public static readonly string MapsDir = BasePath + @"\\maps"; + public static readonly string AddonDir = BasePath + @"\\addons"; + public static readonly string AddonCoreDir = AddonDir + @"\\core"; public static readonly string MapsDirCustom = MapsDir + @"\\Custom"; public static readonly string MapsDirBase = "maps"; public static readonly string BaseGameDir = "rbxasset://../../../"; @@ -109,6 +111,7 @@ public class GlobalPaths public static readonly string ServerInfoFileName = "serverinfo.txt"; public static readonly string ConsoleHelpFileName = "consolehelp.txt"; public static readonly string ClientScriptDocumentationFileName = "documentation.txt"; + public static readonly string AddonLoaderFileName = "AddonLoader.lua"; #endregion } #endregion diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs index 83ccae7..9136ff4 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs @@ -10,6 +10,7 @@ #region Usings using System; using System.Collections.Generic; +using System.Diagnostics; using System.Windows.Forms; #endregion diff --git a/Novetus/NovetusCore/StorageAndFunctions/Util.cs b/Novetus/NovetusCore/StorageAndFunctions/Util.cs index 0fc6dfe..581e76d 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/Util.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/Util.cs @@ -330,6 +330,8 @@ public static class Util File.Copy(src, dest, overwrite); File.SetAttributes(dest, FileAttributes.Normal); + + return; } public static void FixedFileDelete(string src) diff --git a/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs b/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs index dcae6a6..6b16092 100644 --- a/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs +++ b/Novetus/NovetusLauncher/Classes/Launcher/ModManager.cs @@ -1,6 +1,7 @@ #region Usings using Ionic.Zip; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -17,7 +18,14 @@ public class ModManager ModCreation } + public enum ModType + { + ModPackage, + AddonScript + } + private ModMode globalMode; + private ModType globalType; private OpenFileDialog openFileDialog1; private SaveFileDialog saveFileDialog1; private string installOutcome = ""; @@ -49,8 +57,8 @@ public class ModManager default: openFileDialog1 = new OpenFileDialog() { - FileName = "Select a mod .zip file", - Filter = "Compressed zip files (*.zip)|*.zip", + FileName = "Select a mod .zip or addon *.lua file", + Filter = "Compressed zip files (*.zip)|*.zip|LUA Script (*.lua)|*.lua", Title = "Open mod .zip" }; break; @@ -79,52 +87,93 @@ public class ModManager if (openFileDialog1.ShowDialog() == DialogResult.OK) { - MessageBox.Show("Your mod is loading. You will recieve a notification when it is installed. Please keep the launcher open. You can see the installation progress in the Console.", "Novetus - Mod Loading"); - try { - int filecount = 0; - StringBuilder filelistbuilder = new StringBuilder(); - StringBuilder filelistcutdown = new StringBuilder(); + globalType = (ModType)(openFileDialog1.FilterIndex - 1); - using (Stream str = openFileDialog1.OpenFile()) + if (globalType == ModType.ModPackage) { - using (var zipFile = ZipFile.Read(str)) + MessageBox.Show("Your mod is loading. You will recieve a notification when it is installed. Please keep the launcher open. You can see the installation progress in the Console.", "Novetus - Mod Loading"); + + int filecount = 0; + StringBuilder filelistbuilder = new StringBuilder(); + StringBuilder filelistcutdown = new StringBuilder(); + + using (Stream str = openFileDialog1.OpenFile()) { - zipFile.ExtractProgress += ExtractProgress; - ZipEntry[] entries = zipFile.Entries.ToArray(); - - foreach (ZipEntry entry in entries) + using (var zipFile = ZipFile.Read(str)) { - filelistbuilder.Append(!entry.IsDirectory ? (entry.FileName + " (" + entry.UncompressedSize + " KB)" + Environment.NewLine) : ""); + zipFile.ExtractProgress += ExtractProgress; + ZipEntry[] entries = zipFile.Entries.ToArray(); - if (filecount < fileListDisplay) + foreach (ZipEntry entry in entries) { - filelistcutdown.Append(!entry.IsDirectory ? (entry.FileName + " (" + entry.UncompressedSize + " KB)" + Environment.NewLine) : ""); + filelistbuilder.Append(!entry.IsDirectory ? (entry.FileName + " (" + entry.UncompressedSize + " KB)" + Environment.NewLine) : ""); + + if (filecount < fileListDisplay) + { + filelistcutdown.Append(!entry.IsDirectory ? (entry.FileName + " (" + entry.UncompressedSize + " KB)" + Environment.NewLine) : ""); + } + + if (!entry.IsDirectory) + { + filecount++; + } } - if (!entry.IsDirectory) - { - filecount++; - } + tokenSource = new CancellationTokenSource(); + var token = tokenSource.Token; + await Task.Factory.StartNew(() => zipFile.ExtractAll(GlobalPaths.BasePath, ExtractExistingFileAction.OverwriteSilently), token); + zipFile.Dispose(); } + } - tokenSource = new CancellationTokenSource(); - var token = tokenSource.Token; - await Task.Factory.StartNew(() => zipFile.ExtractAll(GlobalPaths.BasePath, ExtractExistingFileAction.OverwriteSilently), token); - zipFile.Dispose(); + string filelist = filelistbuilder.ToString(); + + if (filecount > fileListDisplay) + { + installOutcome = "Mod " + openFileDialog1.SafeFileName + " installed! " + filecount + " files copied!" + Environment.NewLine + "Files added/modified:" + Environment.NewLine + Environment.NewLine + filelistcutdown + Environment.NewLine + "and " + (filecount - fileListDisplay) + " more files!"; + } + else + { + installOutcome = "Mod " + openFileDialog1.SafeFileName + " installed! " + filecount + " files copied!" + Environment.NewLine + "Files added/modified:" + Environment.NewLine + Environment.NewLine + filelist; } } - - string filelist = filelistbuilder.ToString(); - - if (filecount > fileListDisplay) + else if (globalType == ModType.AddonScript) { - installOutcome = "Mod " + openFileDialog1.SafeFileName + " installed! " + filecount + " files copied!" + Environment.NewLine + "Files added/modified:" + Environment.NewLine + Environment.NewLine + filelistcutdown + Environment.NewLine + "and " + (filecount - fileListDisplay) + " more files!"; - } - else - { - installOutcome = "Mod " + openFileDialog1.SafeFileName + " installed! " + filecount + " files copied!" + Environment.NewLine + "Files added/modified:" + Environment.NewLine + Environment.NewLine + filelist; + try + { + Util.FixedFileCopy(openFileDialog1.FileName, GlobalPaths.AddonDir + @"\" + openFileDialog1.SafeFileName, false); + + string AddonPath = GlobalPaths.AddonCoreDir + "\\" + GlobalPaths.AddonLoaderFileName; + var lines = File.ReadLines(AddonPath); + List FileLines = lines.ToList(); + for (var i = 0; i < FileLines.Count; i++) + { + if (FileLines[i].Contains("Addons")) + { + if (FileLines[i].Contains(Path.GetFileNameWithoutExtension(openFileDialog1.SafeFileName))) + { + installOutcome = "Error: Script has already been added."; + break; + } + + string[] list = FileLines[i].Replace("Addons", "").Replace("=", "").Replace("{", "").Replace("}", "").Replace(" ", "").Split(','); + List Addons = list.ToList(); + Addons.Add("\"" + Path.GetFileNameWithoutExtension(openFileDialog1.SafeFileName) + "\""); + string newline = "Addons = {" + string.Join(", ", Addons) + "}"; + FileLines[i] = newline; + File.WriteAllLines(AddonPath, FileLines.ToArray()); + installOutcome = "Addon Script " + openFileDialog1.SafeFileName + " installed!"; + break; + } + } + } + catch (Exception ex) + { + Util.LogExceptions(ex); + installOutcome = "Error: Script has already been added."; + } } } catch (Exception ex) diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index 926ac4c..77b5b86 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -63,8 +63,6 @@ namespace NovetusLauncher private ToolTip contextToolTip; #endregion - - #region Form Event Functions public void InitForm() { @@ -183,7 +181,7 @@ namespace NovetusLauncher { DiscordRPC.Shutdown(); } - + if (!GlobalVars.AppClosed) { GlobalVars.AppClosed = true; @@ -433,7 +431,7 @@ namespace NovetusLauncher Parent.Visible = true; } - if (GlobalVars.isConsoleOnly && !GlobalVars.isConsoleOnly) + if (GlobalVars.isConsoleOnly) { CloseEventInternal(); } diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml index 9ffe03a..3fa25d3 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml @@ -777,14 +777,14 @@