From 7df557baa8057c3b0556efa7003fb01091ece520 Mon Sep 17 00:00:00 2001 From: Bitl Date: Tue, 31 Aug 2021 12:28:05 -0700 Subject: [PATCH] fix certain bugs --- .../StorageAndFunctions/GlobalFuncs.cs | 57 +++++++++++++------ .../Forms/LauncherForm/LauncherFormShared.cs | 15 +++-- Novetus/NovetusLauncher/NovetusLauncher.cs | 1 + Novetus/NovetusURI/Forms/QuickConfigure.cs | 7 +-- changelog.txt | 2 + 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs index fa4076e..79d3297 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs @@ -211,8 +211,9 @@ public class GlobalFuncs GlobalVars.UserConfiguration.DiscordPresence = Convert.ToBoolean(discord); GlobalVars.UserConfiguration.MapPathSnip = mapsnip; + string oldMapath = Path.GetDirectoryName(GlobalVars.UserConfiguration.MapPath); //update the map path if the file doesn't exist and write to config. - if (File.Exists(mappath)) + if (oldMapath.Equals(GlobalPaths.MapsDir.Replace(@"\\", @"\")) && File.Exists(mappath)) { GlobalVars.UserConfiguration.MapPath = mappath; } @@ -1760,28 +1761,50 @@ public class GlobalFuncs SizeSuffixes[mag]); } - //https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm - public static DateTime GetLinkerTimestampUtc(Assembly assembly) + //https://stackoverflow.com/questions/11927116/getting-files-recursively-skip-files-directories-that-cannot-be-read + public static string[] FindAllFiles(string rootDir) { - var location = assembly.Location; - return GetLinkerTimestampUtc(location); - } + var pathsToSearch = new Queue(); + var foundFiles = new List(); - public static DateTime GetLinkerTimestampUtc(string filePath) - { - const int peHeaderOffset = 60; - const int linkerTimestampOffset = 8; - var bytes = new byte[2048]; + pathsToSearch.Enqueue(rootDir); - using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + while (pathsToSearch.Count > 0) { - file.Read(bytes, 0, bytes.Length); + var dir = pathsToSearch.Dequeue(); + + try + { + var files = Directory.GetFiles(dir); + foreach (var file in Directory.GetFiles(dir)) + { + foundFiles.Add(file); + } + + foreach (var subDir in Directory.GetDirectories(dir)) + { + pathsToSearch.Enqueue(subDir); + } + + } + catch (Exception /* TODO: catch correct exception */) + { + // Swallow. Gulp! + } } - var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset); - var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset); - var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - return dt.AddSeconds(secondsSince1970); + return foundFiles.ToArray(); + } + + //https://stackoverflow.com/questions/66667263/i-want-to-remove-special-characters-from-file-name-without-affecting-extension-i + //https://stackoverflow.com/questions/3218910/rename-a-file-in-c-sharp + public static void RenameFileWithInvalidChars(string path) + { + string pathWithoutFilename = Path.GetDirectoryName(path); + string fileName = Path.GetFileName(path); + fileName = Regex.Replace(fileName, @"[^\w-.'_! ]", ""); + + File.Move(path, pathWithoutFilename + "\\" + fileName); } } #endregion diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index 43552b8..17aedc6 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -322,12 +322,7 @@ namespace NovetusLauncher PortBox.Items.Clear(); break; case TabPage pg4 when pg4 == Tabs.TabPages[TabPageMaps]: - string mapdir = GlobalPaths.MapsDir; - string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; - TreeNodeHelper.ListDirectory(Tree, mapdir, fileexts); - TreeNodeHelper.CopyNodes(Tree.Nodes, _TreeCache.Nodes); - Tree.SelectedNode = TreeNodeHelper.SearchTreeView(GlobalVars.UserConfiguration.Map, Tree.Nodes); - Tree.Focus(); + RefreshMaps(); ServerInfo.Text = ""; ClientBox.Items.Clear(); ServerBox.Items.Clear(); @@ -903,6 +898,13 @@ namespace NovetusLauncher Tree.Nodes.Clear(); _TreeCache.Nodes.Clear(); string mapdir = GlobalPaths.MapsDir; + string[] filePaths = GlobalFuncs.FindAllFiles(GlobalPaths.MapsDir); + + foreach (string path in filePaths) + { + GlobalFuncs.RenameFileWithInvalidChars(path); + } + string[] fileexts = new string[] { ".rbxl", ".rbxlx" }; TreeNodeHelper.ListDirectory(Tree, mapdir, fileexts); TreeNodeHelper.CopyNodes(Tree.Nodes, _TreeCache.Nodes); @@ -1181,6 +1183,7 @@ namespace NovetusLauncher try { + GlobalFuncs.RenameFileWithInvalidChars(mapname); GlobalFuncs.FixedFileCopy(ofd.FileName, GlobalPaths.MapsDirCustom + @"\\" + mapname, true, true); } catch (Exception ex) diff --git a/Novetus/NovetusLauncher/NovetusLauncher.cs b/Novetus/NovetusLauncher/NovetusLauncher.cs index b22f0bb..2c73266 100644 --- a/Novetus/NovetusLauncher/NovetusLauncher.cs +++ b/Novetus/NovetusLauncher/NovetusLauncher.cs @@ -44,6 +44,7 @@ namespace NovetusLauncher case Settings.UIOptions.Style.Compact: Application.Run(new LauncherFormCompact()); break; + case Settings.UIOptions.Style.Extended: default: Application.Run(new LauncherFormExtended()); break; diff --git a/Novetus/NovetusURI/Forms/QuickConfigure.cs b/Novetus/NovetusURI/Forms/QuickConfigure.cs index 59506a2..448f542 100644 --- a/Novetus/NovetusURI/Forms/QuickConfigure.cs +++ b/Novetus/NovetusURI/Forms/QuickConfigure.cs @@ -71,15 +71,14 @@ namespace NovetusURI { switch(GlobalVars.UserConfiguration.LauncherStyle) { - case Settings.UIOptions.Style.Extended: - CharacterCustomizationExtended ccustom = new CharacterCustomizationExtended(); - ccustom.Show(); - break; case Settings.UIOptions.Style.Compact: CharacterCustomizationCompact ccustom2 = new CharacterCustomizationCompact(); ccustom2.Show(); break; + case Settings.UIOptions.Style.Extended: default: + CharacterCustomizationExtended ccustom = new CharacterCustomizationExtended(); + ccustom.Show(); break; } } diff --git a/changelog.txt b/changelog.txt index 5eb6f9b..5b76fad 100644 --- a/changelog.txt +++ b/changelog.txt @@ -19,6 +19,8 @@ - Item Creation SDK: If a character customization window is open, it will now close the window and open a new one to update the contents. - Item Creation SDK: Added the optional ability to replace existing item icons. - Added the XML Content Editor: a Excel-like editor that allows you to edit and add content providers and part colors. +- The Novetus Launcher will now remove any invalid characters from a map's file name. +- Fixed an issue with the Launcher where the internal map file path wouldn't automatically change if the directory changed. Portable installations should work properly now. Added the following T-Shirts: Blue Ring of Fire Ring of Fire