diff --git a/Knossos.NET/App.axaml.cs b/Knossos.NET/App.axaml.cs index d94712c8..50f9296e 100644 --- a/Knossos.NET/App.axaml.cs +++ b/Knossos.NET/App.axaml.cs @@ -278,12 +278,12 @@ private NativeMenuItem CreateLaunchFSOButton(Mod mod, FsoExecType fsoExecType) private void OpenLog() { - if (File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "Knossos.log")) + if (File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "Knossos.log"))) { try { var cmd = new Process(); - cmd.StartInfo.FileName = KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "Knossos.log"; + cmd.StartInfo.FileName = Path.Combine(KnUtils.GetKnossosDataFolderPath(), "Knossos.log"); cmd.StartInfo.UseShellExecute = true; cmd.Start(); cmd.Dispose(); @@ -296,18 +296,18 @@ private void OpenLog() else { if (MainWindow.instance != null) - MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "Knossos.log not found.", "File not found", MessageBox.MessageBoxButtons.OK); + MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetKnossosDataFolderPath(), "Knossos.log") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } private void OpenFS2Log() { - if (File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log")) + if (File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log"))) { try { var cmd = new Process(); - cmd.StartInfo.FileName = KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log"; + cmd.StartInfo.FileName = Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log"); cmd.StartInfo.UseShellExecute = true; cmd.Start(); cmd.Dispose(); @@ -320,7 +320,7 @@ private void OpenFS2Log() else { if (MainWindow.instance != null) - MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log not found.", "File not found", MessageBox.MessageBoxButtons.OK); + MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } } diff --git a/Knossos.NET/Classes/FsoBuild.cs b/Knossos.NET/Classes/FsoBuild.cs index 1605a065..b7fcc397 100644 --- a/Knossos.NET/Classes/FsoBuild.cs +++ b/Knossos.NET/Classes/FsoBuild.cs @@ -437,10 +437,10 @@ public async Task RunFSO(FsoExecType executableType, string cmdline, catch (JsonException exJson) { //json failed try to see if it exported a binary - if(File.Exists(folderPath+Path.DirectorySeparatorChar+"flags.lch")) + if(File.Exists(Path.Combine(folderPath, "flags.lch"))) { Log.Add(Log.LogSeverity.Error, "FsoBuild.GetFlagsV1()", "FSO build "+ this +" seems to be below the minimum supported version (3.8.1) and does not support exporting flags as Json."); - File.Delete(folderPath + Path.DirectorySeparatorChar + "flags.lch"); + File.Delete(Path.Combine(folderPath, "flags.lch")); } else { @@ -544,7 +544,7 @@ private void LoadExecutables(Mod modJson) FsoExecType type = GetExecType(exec.label); FsoExecArch arch = GetExecArch(exec.properties); if(modJson.devMode) - executables.Add(new FsoFile(package.folder+Path.DirectorySeparatorChar+exec.file.Replace(@"./",""), folderPath, type, arch, env)); + executables.Add(new FsoFile(Path.Combine(package.folder ?? "", exec.file.Replace(@"./","")), folderPath, type, arch, env)); else executables.Add(new FsoFile(exec.file, folderPath, type, arch, env)); } diff --git a/Knossos.NET/Classes/KnUtils.cs b/Knossos.NET/Classes/KnUtils.cs index 5efdde2d..9d839f53 100644 --- a/Knossos.NET/Classes/KnUtils.cs +++ b/Knossos.NET/Classes/KnUtils.cs @@ -1402,7 +1402,7 @@ public static void CreateDesktopShortcut(string shortcutName, string destFileFul Arguments = arguments }; - shortcut.Save(@Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + shortcutName + ".lnk"); + shortcut.Save(Path.Combine(@Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), shortcutName + ".lnk")); } }catch(Exception ex) { diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index c18bc571..4f530b8d 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -97,11 +97,11 @@ public static async void StartUp(bool isQuickLaunch, bool forceUpdate) else { // Test if we can write to the data directory - using (StreamWriter writer = new StreamWriter(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "test.txt")) + using (StreamWriter writer = new StreamWriter(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "test.txt"))) { writer.WriteLine("test"); } - File.Delete(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "test.txt"); + File.Delete(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "test.txt")); } } catch (Exception ex) @@ -526,7 +526,7 @@ await Dispatcher.UIThread.Invoke(async () => { { extension = ".tar.gz"; } - var download = await Dispatcher.UIThread.InvokeAsync(async () => await TaskViewModel.Instance!.AddFileDownloadTask(releaseAsset.browser_download_url, KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "update"+ extension, "Downloading "+latest.tag_name+" "+releaseAsset.name, true, "This is a Knossos.NET update"), DispatcherPriority.Background).ConfigureAwait(false); + var download = await Dispatcher.UIThread.InvokeAsync(async () => await TaskViewModel.Instance!.AddFileDownloadTask(releaseAsset.browser_download_url, Path.Combine(KnUtils.GetKnossosDataFolderPath(), "update" + extension), "Downloading "+latest.tag_name+" "+releaseAsset.name, true, "This is a Knossos.NET update"), DispatcherPriority.Background).ConfigureAwait(false); if (download != null && download == true) { var appDirPath = Path.GetDirectoryName(Environment.ProcessPath); @@ -557,7 +557,7 @@ await Dispatcher.UIThread.Invoke(async () => { // set new filename to match old one, in case it was renamed by the user var newFileFullPath = Path.Combine(appFolder, Path.GetFileName(execFullPath)); - File.Move(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "update" + extension, newFileFullPath); + File.Move(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "update" + extension), newFileFullPath); //Start again KnUtils.Chmod(newFileFullPath, "+x"); @@ -609,12 +609,12 @@ await Dispatcher.UIThread.Invoke(async () => { await Dispatcher.UIThread.Invoke(async () => { - result = await TaskViewModel.Instance!.AddFileDecompressionTask( KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "update" + extension, updateFilesFolder, false); + result = await TaskViewModel.Instance!.AddFileDecompressionTask(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "update" + extension), updateFilesFolder, false); }).ConfigureAwait(false); if (!result) { - throw new Exception("Error while decompressing update file: " + KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "update" + extension); + throw new Exception("Error while decompressing update file: " + Path.Combine(KnUtils.GetKnossosDataFolderPath(), "update" + extension)); } if (forceUpdateDownload) @@ -623,8 +623,8 @@ await Dispatcher.UIThread.Invoke(async () => //Cleanup file try { - if (File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "update" + extension)) - File.Delete(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "update" + extension); + if (File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "update" + extension))) + File.Delete(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "update" + extension)); } catch { } } @@ -1147,11 +1147,11 @@ public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standalo { if (modFlag.Length > 0) { - modFlag += "," + Path.GetRelativePath(rootPath, mod.fullPath + Path.DirectorySeparatorChar + pkg.folder).TrimEnd('/').TrimEnd('\\'); + modFlag += "," + Path.GetRelativePath(rootPath, Path.Combine(mod.fullPath, pkg.folder ?? "")).TrimEnd('/').TrimEnd('\\'); } else { - modFlag += Path.GetRelativePath(rootPath, mod.fullPath + Path.DirectorySeparatorChar + pkg.folder).TrimEnd('/').TrimEnd('\\'); + modFlag += Path.GetRelativePath(rootPath, Path.Combine(mod.fullPath, pkg.folder ?? "")).TrimEnd('/').TrimEnd('\\'); } } } @@ -1198,11 +1198,11 @@ public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standalo { if (modFlag.Length > 0) { - modFlag += "," + Path.GetRelativePath(rootPath, depMod.fullPath + Path.DirectorySeparatorChar + pkg.folder).TrimEnd('/').TrimEnd('\\'); + modFlag += "," + Path.GetRelativePath(rootPath, Path.Combine(depMod.fullPath, pkg.folder ?? "")).TrimEnd('/').TrimEnd('\\'); } else { - modFlag += Path.GetRelativePath(rootPath, depMod.fullPath + Path.DirectorySeparatorChar + pkg.folder).TrimEnd('/').TrimEnd('\\'); + modFlag += Path.GetRelativePath(rootPath, Path.Combine(depMod.fullPath, pkg.folder ?? "")).TrimEnd('/').TrimEnd('\\'); } } } @@ -1239,11 +1239,11 @@ public static async void PlayMod(Mod mod, FsoExecType fsoExecType, bool standalo { if (modFlag.Length > 0) { - modFlag += "," + Path.GetRelativePath(rootPath, newerOpt.fullPath + Path.DirectorySeparatorChar + pkg.folder).TrimEnd('/').TrimEnd('\\'); + modFlag += "," + Path.GetRelativePath(rootPath, Path.Combine(newerOpt.fullPath, pkg.folder ?? "")).TrimEnd('/').TrimEnd('\\'); } else { - modFlag += Path.GetRelativePath(rootPath, newerOpt.fullPath + Path.DirectorySeparatorChar + pkg.folder).TrimEnd('/').TrimEnd('\\'); + modFlag += Path.GetRelativePath(rootPath, Path.Combine(newerOpt.fullPath, pkg.folder ?? "")).TrimEnd('/').TrimEnd('\\'); } } } @@ -1546,17 +1546,17 @@ private static async Task FolderSearchRecursive(string path, bool isQuickLaunch, } } - if(File.Exists(path + Path.DirectorySeparatorChar + "knossos_net_download.token")) + if(File.Exists(Path.Combine(path, "knossos_net_download.token"))) { /* This is a incomplete download, delete the folder */ Log.Add(Log.LogSeverity.Warning, "Knossos.FolderSearchRecursive()", "Deleting incomplete download found at "+path); Directory.Delete(path, true); } - else if (File.Exists(path + Path.DirectorySeparatorChar + "tool.json")) + else if (File.Exists(Path.Combine(path, "tool.json"))) { Knossos.AddTool(new Tool(path)); } - else if (File.Exists(path + Path.DirectorySeparatorChar + "mod.json")) + else if (File.Exists(Path.Combine(path, "mod.json"))) { try { @@ -1597,7 +1597,7 @@ private static async Task FolderSearchRecursive(string path, bool isQuickLaunch, Log.Add(Log.LogSeverity.Error, "Knossos.ModSearchRecursive", ex); } } - else if(File.Exists(path + Path.DirectorySeparatorChar + "mod.ini")) + else if(File.Exists(Path.Combine(path, "mod.ini"))) { var modLegacy = new Mod(path, di.Name, ModType.modlegacy); installedMods.Add(modLegacy); @@ -1751,11 +1751,11 @@ public async static void Tts(string text, int? voice_index = null, string? voice } if (text != string.Empty) { - if (!File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe")) + if (!File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "KSapi.exe"))) { if (KnUtils.CpuArch == "X86") { - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "KSapi.exe"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/win/KSapi_x86.exe")).CopyTo(fileStream); fileStream.Close(); @@ -1763,7 +1763,7 @@ public async static void Tts(string text, int? voice_index = null, string? voice } else { - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "KSapi.exe"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/win/KSapi.exe")).CopyTo(fileStream); fileStream.Close(); @@ -1785,7 +1785,7 @@ await Task.Run(async () => if (volume.HasValue) vol = volume.Value; using var ttsProcess = new Process(); - ttsProcess.StartInfo.FileName = KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "KSapi.exe"; + ttsProcess.StartInfo.FileName = Path.Combine(KnUtils.GetKnossosDataFolderPath(), "KSapi.exe"); ttsProcess.StartInfo.Arguments = "-text \"" + text + "\" -voice " + voice + " -vol " + vol; ttsProcess.StartInfo.UseShellExecute = false; ttsProcess.StartInfo.CreateNoWindow = true; diff --git a/Knossos.NET/Classes/SevenZipConsoleWrapper.cs b/Knossos.NET/Classes/SevenZipConsoleWrapper.cs index bd8cf337..ed784e38 100644 --- a/Knossos.NET/Classes/SevenZipConsoleWrapper.cs +++ b/Knossos.NET/Classes/SevenZipConsoleWrapper.cs @@ -344,7 +344,7 @@ private string UnpackExec() AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/win/7za.exe")).CopyTo(fileStream); fileStream.Close(); } - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "7z.License.txt")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "7z.License.txt"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/win/7z.License.txt")).CopyTo(fileStream); fileStream.Close(); @@ -366,7 +366,7 @@ private string UnpackExec() fileStream.Close(); KnUtils.Chmod(execPath, "+x"); } - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "7z.License.txt")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "7z.License.txt"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/linux-x64/7z.License.txt")).CopyTo(fileStream); fileStream.Close(); @@ -384,7 +384,7 @@ private string UnpackExec() fileStream.Close(); KnUtils.Chmod(execPath, "+x"); } - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "7z.License.txt")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "7z.License.txt"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/linux-arm64/7z.License.txt")).CopyTo(fileStream); fileStream.Close(); @@ -402,7 +402,7 @@ private string UnpackExec() fileStream.Close(); KnUtils.Chmod(execPath, "+x"); } - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "7z.License.txt")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "7z.License.txt"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/linux-riscv64/7z.License.txt")).CopyTo(fileStream); fileStream.Close(); @@ -423,7 +423,7 @@ private string UnpackExec() fileStream.Close(); KnUtils.Chmod(execPath, "+x"); } - using (var fileStream = File.Create(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "7z.License.txt")) + using (var fileStream = File.Create(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "7z.License.txt"))) { AssetLoader.Open(new Uri("avares://Knossos.NET.Desktop/Assets/utils/osx/7z.License.txt")).CopyTo(fileStream); fileStream.Close(); diff --git a/Knossos.NET/Classes/Tool.cs b/Knossos.NET/Classes/Tool.cs index 1ceb8b16..78602a91 100644 --- a/Knossos.NET/Classes/Tool.cs +++ b/Knossos.NET/Classes/Tool.cs @@ -44,7 +44,7 @@ public Tool(string folderpath) { try { - using(var jsonFile = File.OpenRead(folderpath + Path.DirectorySeparatorChar + "tool.json")) + using(var jsonFile = File.OpenRead(Path.Combine(folderpath, "tool.json"))) { var temptool = JsonSerializer.Deserialize(jsonFile)!; if (temptool != null) @@ -173,8 +173,8 @@ public void SaveJson(string? path = null) WriteIndented = true }; var json = JsonSerializer.Serialize(this, options); - File.WriteAllText(folderpath + Path.DirectorySeparatorChar + "tool.json", json, new UTF8Encoding(false)); - Log.Add(Log.LogSeverity.Information, "Tool.SaveJson", "tool.json has been saved to " + folderpath + Path.DirectorySeparatorChar + "tool.json"); + File.WriteAllText(Path.Combine(folderpath, "tool.json"), json, new UTF8Encoding(false)); + Log.Add(Log.LogSeverity.Information, "Tool.SaveJson", "tool.json has been saved to " + Path.Combine(folderpath, "tool.json")); } else { diff --git a/Knossos.NET/Models/GlobalSettings.cs b/Knossos.NET/Models/GlobalSettings.cs index e87de9af..5030dd7c 100644 --- a/Knossos.NET/Models/GlobalSettings.cs +++ b/Knossos.NET/Models/GlobalSettings.cs @@ -354,12 +354,12 @@ private void ReadFS2IniValues() { try { - if (!File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini")) + if (!File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini"))) { return; } var parser = new FileIniDataParser(); - var data = parser.ReadFile(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini"); + var data = parser.ReadFile(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini")); data.Configuration.AssigmentSpacer = string.Empty; //LEGACY ENTRIES, mostly read only by fso @@ -635,9 +635,9 @@ public void Load() { try { - if (File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "settings.json")) + if (File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "settings.json"))) { - using FileStream jsonFile = File.OpenRead(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "settings.json"); + using FileStream jsonFile = File.OpenRead(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "settings.json")); var tempSettings = JsonSerializer.Deserialize(jsonFile)!; jsonFile.Close(); if (tempSettings != null) @@ -744,13 +744,13 @@ public void WriteFS2IniValues(string? customFullPath = null) try { var parser = new FileIniDataParser(); - if(!File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini")) + if(!File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini"))) { Directory.CreateDirectory(KnUtils.GetFSODataFolderPath()); - File.Create(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini").Close(); + File.Create(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini")).Close(); } - var data = parser.ReadFile(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini"); + var data = parser.ReadFile(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini")); data.Configuration.AssigmentSpacer = string.Empty; /* Default Section */ @@ -895,8 +895,8 @@ public void WriteFS2IniValues(string? customFullPath = null) if (customFullPath == null) { - parser.WriteFile(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini", data, new UTF8Encoding(false)); - Log.Add(Log.LogSeverity.Information, "GlobalSettings.WriteFS2IniValues", "Writen ini: " + KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini"); + parser.WriteFile(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini"), data, new UTF8Encoding(false)); + Log.Add(Log.LogSeverity.Information, "GlobalSettings.WriteFS2IniValues", "Writen ini: " + Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini")); } else { @@ -937,7 +937,7 @@ public void Save(bool writeIni = true) }; var json = JsonSerializer.Serialize(this, options); - File.WriteAllText(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "settings.json", json, new UTF8Encoding(false)); + File.WriteAllText(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "settings.json"), json, new UTF8Encoding(false)); Log.Add(Log.LogSeverity.Information, "GlobalSettings.Save()", "Global settings have been saved."); pendingChangesOnAppClose = false; } diff --git a/Knossos.NET/Models/Mod.cs b/Knossos.NET/Models/Mod.cs index f9cdb6b2..7b0cf9a9 100644 --- a/Knossos.NET/Models/Mod.cs +++ b/Knossos.NET/Models/Mod.cs @@ -534,7 +534,7 @@ private void ParseJson(string modPath) { try { - using FileStream jsonFile = File.OpenRead(modPath + Path.DirectorySeparatorChar + "mod.json"); + using FileStream jsonFile = File.OpenRead(Path.Combine(modPath, "mod.json")); var tempMod = JsonSerializer.Deserialize(jsonFile)!; jsonFile.Close(); installed = tempMod.installed; @@ -580,7 +580,7 @@ private void ParseIni(string modPath) try { var iniParser = new FileIniDataParser(); - var iniFile = iniParser.ReadFile(modPath + Path.DirectorySeparatorChar + "mod.ini"); + var iniFile = iniParser.ReadFile(Path.Combine(modPath, "mod.ini")); var dir = new DirectoryInfo(modPath); if(dir.Name.Contains(" ")) @@ -588,7 +588,7 @@ private void ParseIni(string modPath) try { Log.Add(Log.LogSeverity.Warning, "Mod.ParseIni", "Local Mod Folder: " + dir.Name + ". Contains spaces in the folder name, this is not supported Knet will attempt to rename it to: " + dir.Name.Replace(" ", "_")); - dir.MoveTo(dir.Parent!.FullName+Path.DirectorySeparatorChar+dir.Name.Replace(" ", "_")); + dir.MoveTo(Path.Combine(dir.Parent!.FullName, dir.Name.Replace(" ", "_"))); fullPath = dir.FullName; folderName = dir.Name; } @@ -751,8 +751,8 @@ public void SaveJson() WriteIndented = true }; var json = JsonSerializer.Serialize(this, options); - File.WriteAllText(fullPath + Path.DirectorySeparatorChar + "mod.json", json, new UTF8Encoding(false)); - Log.Add(Log.LogSeverity.Information, "ModJson.SaveJson", "mod.json has been saved to " + fullPath + Path.DirectorySeparatorChar + "mod.json"); + File.WriteAllText(Path.Combine(fullPath, "mod.json"), json, new UTF8Encoding(false)); + Log.Add(Log.LogSeverity.Information, "ModJson.SaveJson", "mod.json has been saved to " + Path.Combine(fullPath, "mod.json")); } else { diff --git a/Knossos.NET/Models/ModSettings.cs b/Knossos.NET/Models/ModSettings.cs index c7615e41..79c9d00c 100644 --- a/Knossos.NET/Models/ModSettings.cs +++ b/Knossos.NET/Models/ModSettings.cs @@ -79,7 +79,7 @@ public bool IsDefaultConfig() public void SetInitialFilePath(string modFullPath) { if (filePath == null) - filePath = modFullPath + Path.DirectorySeparatorChar + "mod_settings.json"; + filePath = Path.Combine(modFullPath, "mod_settings.json"); } /// @@ -91,7 +91,7 @@ public void Load(string modFolderPath) { try { - this.filePath = modFolderPath + Path.DirectorySeparatorChar + "mod_settings.json"; + this.filePath = Path.Combine(modFolderPath, "mod_settings.json"); if(File.Exists(filePath)) { using FileStream jsonFile = File.OpenRead(filePath); diff --git a/Knossos.NET/Models/Nebula.cs b/Knossos.NET/Models/Nebula.cs index 53048ca0..f7e3e036 100644 --- a/Knossos.NET/Models/Nebula.cs +++ b/Knossos.NET/Models/Nebula.cs @@ -120,9 +120,9 @@ public static async Task Trinity() } cancellationToken = new CancellationTokenSource(); - if (File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "nebula.json")) + if (File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "nebula.json"))) { - string jsonString = File.ReadAllText(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "nebula.json"); + string jsonString = File.ReadAllText(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "nebula.json")); settings = JsonSerializer.Deserialize(jsonString); Log.Add(Log.LogSeverity.Information, "Nebula.Constructor()", "Nebula settings have been loaded"); } @@ -142,12 +142,12 @@ public static async Task Trinity() var neb_text_downloading = CustomLauncher.IsCustomMode ? CustomLauncher.NebulaTextDownloading : "Downloading repo_minimal.json"; var neb_text_uptodate = CustomLauncher.IsCustomMode ? CustomLauncher.NebulaTextUpToDate : "Nebula: repo_minimal.json is up to date!"; var neb_text_tooltip = CustomLauncher.IsCustomMode ? CustomLauncher.NebulaTextToolTip : "The repo_minimal.json file contains info on all the mods available in Nebula, without this you will not be able to install new mods or engine builds"; - if (!File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal.json") || settings.etag != webEtag) + if (!File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal.json")) || settings.etag != webEtag) { //Download the repo_minimal.json if (TaskViewModel.Instance != null) { - var result = await Dispatcher.UIThread.InvokeAsync(async()=>await TaskViewModel.Instance.AddFileDownloadTask(repoUrl, KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal_temp.json", neb_text_downloading, true, neb_text_tooltip), DispatcherPriority.Background).ConfigureAwait(false); + var result = await Dispatcher.UIThread.InvokeAsync(async()=>await TaskViewModel.Instance.AddFileDownloadTask(repoUrl, Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal_temp.json"), neb_text_downloading, true, neb_text_tooltip), DispatcherPriority.Background).ConfigureAwait(false); if (cancellationToken!.IsCancellationRequested) { @@ -157,8 +157,8 @@ public static async Task Trinity() { try { - File.Delete(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal.json"); - File.Move(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal_temp.json", KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal.json"); + File.Delete(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal.json")); + File.Move(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal_temp.json"), Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal.json")); settings.etag = webEtag; SaveSettings(); } @@ -386,13 +386,13 @@ private static bool IsModUpdate(Mod mod) { try { - await WaitForFileAccess(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal.json"); + await WaitForFileAccess(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal.json")); if (cancelToken != null && cancelToken!.IsCancellationRequested) { throw new TaskCanceledException(); } RepoData? repoData = null; - using (FileStream? fileStream = new FileStream(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "repo_minimal.json", FileMode.Open, FileAccess.ReadWrite)) + using (FileStream? fileStream = new FileStream(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "repo_minimal.json"), FileMode.Open, FileAccess.ReadWrite)) { JsonSerializerOptions serializerOptions = new JsonSerializerOptions(); try @@ -674,7 +674,7 @@ public static async void SaveSettings() { try { - await WaitForFileAccess(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "nebula.json"); + await WaitForFileAccess(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "nebula.json")); var encoderSettings = new TextEncoderSettings(); encoderSettings.AllowRange(UnicodeRanges.All); @@ -685,7 +685,7 @@ public static async void SaveSettings() }; var json = JsonSerializer.Serialize(settings, options); - File.WriteAllText(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "nebula.json", json, Encoding.UTF8); + File.WriteAllText(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "nebula.json"), json, Encoding.UTF8); Log.Add(Log.LogSeverity.Information, "Nebula.SaveSettings()", "Nebula settings have been saved."); } catch (Exception ex) diff --git a/Knossos.NET/ViewModels/CustomHomeViewModel.cs b/Knossos.NET/ViewModels/CustomHomeViewModel.cs index 6426be2c..473916aa 100644 --- a/Knossos.NET/ViewModels/CustomHomeViewModel.cs +++ b/Knossos.NET/ViewModels/CustomHomeViewModel.cs @@ -488,11 +488,11 @@ internal async void BrowseFolderCommand() { // Test if we can write to the new library directory - using (StreamWriter writer = new StreamWriter(result[0].Path.LocalPath.ToString() + Path.DirectorySeparatorChar + "test.txt")) + using (StreamWriter writer = new StreamWriter(Path.Combine(result[0].Path.LocalPath.ToString(), "test.txt"))) { writer.WriteLine("test"); } - File.Delete(Path.Combine(result[0].Path.LocalPath.ToString() + Path.DirectorySeparatorChar + "test.txt")); + File.Delete(Path.Combine(Path.Combine(result[0].Path.LocalPath.ToString(), "test.txt"))); NewBasePath = result[0].Path.LocalPath.ToString(); ChangeBasePathButtonVisible = true; } diff --git a/Knossos.NET/ViewModels/DebugViewModel.cs b/Knossos.NET/ViewModels/DebugViewModel.cs index cca2420f..34b6ed33 100644 --- a/Knossos.NET/ViewModels/DebugViewModel.cs +++ b/Knossos.NET/ViewModels/DebugViewModel.cs @@ -25,59 +25,59 @@ public void WriteToUIConsole(string message) /* Debug Section */ internal void OpenLog() { - if (File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "Knossos.log")) + if (File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "Knossos.log"))) { - KnUtils.OpenFileInOS(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "Knossos.log"); + KnUtils.OpenFileInOS(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "Knossos.log")); } else { - MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "Knossos.log not found.", "File not found", MessageBox.MessageBoxButtons.OK); + MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetKnossosDataFolderPath(), "Knossos.log") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } internal void OpenSettings() { - if (File.Exists(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "settings.json")) + if (File.Exists(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "settings.json"))) { - KnUtils.OpenFileInOS(KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "settings.json"); + KnUtils.OpenFileInOS(Path.Combine(KnUtils.GetKnossosDataFolderPath(), "settings.json")); } else { - MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetKnossosDataFolderPath() + Path.DirectorySeparatorChar + "settings.json not found.", "File not found", MessageBox.MessageBoxButtons.OK); + MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetKnossosDataFolderPath(), "settings.json") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } internal void OpenFS2Log() { - if (File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log")) + if (File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log"))) { - KnUtils.OpenFileInOS(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log"); + KnUtils.OpenFileInOS(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log")); } else { - MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log not found.", "File not found", MessageBox.MessageBoxButtons.OK); + MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } internal void OpenFS2Ini() { - if (File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini")) + if (File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini"))) { - KnUtils.OpenFileInOS(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini"); + KnUtils.OpenFileInOS(Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini")); } else { - MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "fs2_open.ini not found.", "File not found", MessageBox.MessageBoxButtons.OK); + MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetFSODataFolderPath(), "fs2_open.ini") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } internal async void UploadFS2Log() { - if (File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log")) + if (File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log"))) { try { - var logString = File.ReadAllText(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log", System.Text.Encoding.UTF8); + var logString = File.ReadAllText(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log"), System.Text.Encoding.UTF8); if (logString.Trim() != string.Empty) { var status = await Nebula.UploadLog(logString); @@ -98,7 +98,7 @@ internal async void UploadFS2Log() } else { - await MessageBox.Show(MainWindow.instance, "Log File " + KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log not found.", "File not found", MessageBox.MessageBoxButtons.OK); + await MessageBox.Show(MainWindow.instance, "Log File " + Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log") + " not found.", "File not found", MessageBox.MessageBoxButtons.OK); } } internal async void UploadKnossosConsole() diff --git a/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs b/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs index 315d28be..3d203fef 100644 --- a/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs +++ b/Knossos.NET/ViewModels/GlobalSettingsViewModel.cs @@ -628,11 +628,11 @@ internal async void UpdateBasePathAndroid() return; // Test if we can write to the new library directory Directory.CreateDirectory(path); - using (StreamWriter writer = new StreamWriter(path + Path.DirectorySeparatorChar + "test.txt")) + using (StreamWriter writer = new StreamWriter(Path.Combine(path, "test.txt"))) { writer.WriteLine("test"); } - File.Delete(Path.Combine(path + Path.DirectorySeparatorChar + "test.txt")); + File.Delete(Path.Combine(Path.Combine(path, "test.txt"))); Knossos.globalSettings.basePath = path; Knossos.globalSettings.Save(); @@ -1247,11 +1247,11 @@ internal async void BrowseFolderCommand() if (result != null && result.Count > 0) { // Test if we can write to the new library directory - using (StreamWriter writer = new StreamWriter(result[0].Path.LocalPath.ToString() + Path.DirectorySeparatorChar + "test.txt")) + using (StreamWriter writer = new StreamWriter(Path.Combine(result[0].Path.LocalPath.ToString(), "test.txt"))) { writer.WriteLine("test"); } - File.Delete(Path.Combine(result[0].Path.LocalPath.ToString() + Path.DirectorySeparatorChar + "test.txt")); + File.Delete(Path.Combine(Path.Combine(result[0].Path.LocalPath.ToString(), "test.txt"))); Knossos.globalSettings.basePath = result[0].Path.LocalPath.ToString(); Knossos.globalSettings.Save(); diff --git a/Knossos.NET/ViewModels/Templates/DevBuildPkgMgrViewModel.cs b/Knossos.NET/ViewModels/Templates/DevBuildPkgMgrViewModel.cs index 0aa630f7..5facb3cb 100644 --- a/Knossos.NET/ViewModels/Templates/DevBuildPkgMgrViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevBuildPkgMgrViewModel.cs @@ -363,9 +363,9 @@ internal void CreatePackage() { if (NewPackageFolder.Trim() != string.Empty && NewPackageName.Trim() != string.Empty) { - Directory.CreateDirectory(editor!.ActiveVersion.fullPath + Path.DirectorySeparatorChar + NewPackageFolder + Path.DirectorySeparatorChar + NewPackageFolder); - File.Create(editor!.ActiveVersion.fullPath + Path.DirectorySeparatorChar + NewPackageFolder + Path.DirectorySeparatorChar + "do_not_copy_the_build_files_here").Close(); - File.Create(editor!.ActiveVersion.fullPath + Path.DirectorySeparatorChar + NewPackageFolder + Path.DirectorySeparatorChar + NewPackageFolder + Path.DirectorySeparatorChar + "copy_the_build_files_here").Close(); + Directory.CreateDirectory(Path.Combine(editor!.ActiveVersion.fullPath, NewPackageFolder, NewPackageFolder)); + File.Create(Path.Combine(editor!.ActiveVersion.fullPath, NewPackageFolder, "do_not_copy_the_build_files_here")).Close(); + File.Create(Path.Combine(editor!.ActiveVersion.fullPath, NewPackageFolder, NewPackageFolder, "copy_the_build_files_here")).Close(); var newPkg = new ModPackage(); newPkg.folder = NewPackageFolder; newPkg.name = NewPackageName; @@ -384,9 +384,9 @@ internal async void DeletePkg(EditorPackageItem editorPackageItem) { try { - if (editor != null) + if (editor != null && editorPackageItem.Package.folder != null) { - var folderPath = Path.Combine(editor.ActiveVersion.fullPath, editorPackageItem.Package.folder != null ? editorPackageItem.Package.folder : string.Empty); + var folderPath = Path.Combine(editor.ActiveVersion.fullPath, editorPackageItem.Package.folder); var resp = await MessageBox.Show(MainWindow.instance!, "This will delete the package: " + editorPackageItem.Package.name + " and ALL FILES on this folder: " + folderPath + " of the build and version " + editor.ActiveVersion + "\n Do you really want to do this? This action cannot be undone.", "Confirm package deletion", MessageBox.MessageBoxButtons.YesNo); if (resp == MessageBox.MessageBoxResult.Yes) { diff --git a/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs b/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs index 57c8efd4..eda66da4 100644 --- a/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevModDetailsViewModel.cs @@ -35,7 +35,7 @@ public DevModScreenshot(string modPath, string path, DevModDetailsViewModel deta { if (!path.ToLower().Contains("http")) { - Bitmap = new Bitmap(modPath + Path.DirectorySeparatorChar + path); + Bitmap = new Bitmap(Path.Combine(modPath, path)); } else { @@ -218,14 +218,14 @@ internal async void ChangeTileImage() var extension = Path.GetExtension(filepath); - using (FileStream? dest = new FileStream(editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + filename + extension, FileMode.Create, FileAccess.ReadWrite)) + using (FileStream? dest = new FileStream(Path.Combine(editor.ActiveVersion.fullPath, "kn_images", filename + extension), FileMode.Create, FileAccess.ReadWrite)) { file.Position = 0; await file.CopyToAsync(dest); dest.Close(); } file.Close(); - TileImagePath = "kn_images" + Path.DirectorySeparatorChar + filename + extension; + TileImagePath = Path.Combine("kn_images", filename + extension); LoadTileImage(); } } @@ -283,14 +283,14 @@ internal async void ChangeBannerImage() var extension = Path.GetExtension(filepath); - using (FileStream? dest = new FileStream(editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + filename + extension, FileMode.Create, FileAccess.ReadWrite)) + using (FileStream? dest = new FileStream(Path.Combine(editor.ActiveVersion.fullPath, "kn_images", filename + extension), FileMode.Create, FileAccess.ReadWrite)) { file.Position = 0; await file.CopyToAsync(dest); dest.Close(); } file.Close(); - BannerImagePath = "kn_images" + Path.DirectorySeparatorChar + filename + extension; + BannerImagePath = Path.Combine("kn_images", filename + extension); LoadBannerImage(); } } @@ -316,7 +316,7 @@ private void LoadBannerImage() { if (!BannerImagePath.ToLower().Contains("http") && editor != null) { - BannerImage = new Bitmap(editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + BannerImagePath); + BannerImage = new Bitmap(Path.Combine(editor.ActiveVersion.fullPath, BannerImagePath)); } else { @@ -349,7 +349,7 @@ private void LoadTileImage() { if (!TileImagePath.ToLower().Contains("http") && editor != null) { - TileImage = new Bitmap(editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + TileImagePath); + TileImage = new Bitmap(Path.Combine(editor.ActiveVersion.fullPath, TileImagePath)); } else { @@ -418,14 +418,14 @@ internal async void NewScreenShot() var extension = Path.GetExtension(filepath); - using (FileStream? dest = new FileStream(editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + filename + extension, FileMode.Create, FileAccess.ReadWrite)) + using (FileStream? dest = new FileStream(Path.Combine(editor.ActiveVersion.fullPath, "kn_images", filename + extension), FileMode.Create, FileAccess.ReadWrite)) { file.Position = 0; await file.CopyToAsync(dest); dest.Close(); } file.Close(); - Screenshots.Add(new DevModScreenshot(editor.ActiveVersion.fullPath,"kn_images" + Path.DirectorySeparatorChar + filename + extension,this)); + Screenshots.Add(new DevModScreenshot(editor.ActiveVersion.fullPath, Path.Combine("kn_images", filename + extension), this)); } } } diff --git a/Knossos.NET/ViewModels/Templates/DevModEditorViewModel.cs b/Knossos.NET/ViewModels/Templates/DevModEditorViewModel.cs index 46e7884c..afcae653 100644 --- a/Knossos.NET/ViewModels/Templates/DevModEditorViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevModEditorViewModel.cs @@ -200,10 +200,10 @@ private void LoadActiveVersion() var mod = ActiveVersion; Name = mod.title; Version = mod.version; - if (!string.IsNullOrEmpty(mod.tile) && File.Exists(mod.fullPath + Path.DirectorySeparatorChar + mod.tile)) + if (!string.IsNullOrEmpty(mod.tile) && File.Exists(Path.Combine(mod.fullPath, mod.tile))) { ModImage?.Dispose(); - ModImage = new Bitmap(mod.fullPath + Path.DirectorySeparatorChar + mod.tile); + ModImage = new Bitmap(Path.Combine(mod.fullPath, mod.tile)); } //Templated Elements if (IsEngineBuild) diff --git a/Knossos.NET/ViewModels/Templates/DevModPkgMgrViewModel.cs b/Knossos.NET/ViewModels/Templates/DevModPkgMgrViewModel.cs index 23b820a2..de5d0509 100644 --- a/Knossos.NET/ViewModels/Templates/DevModPkgMgrViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevModPkgMgrViewModel.cs @@ -429,9 +429,9 @@ private void UpdateFolderSize() { if (PkgMgr.editor != null) { - if (Directory.Exists(PkgMgr.editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + Package.folder)) + if (Directory.Exists(Path.Combine(PkgMgr.editor.ActiveVersion.fullPath, Package.folder ?? ""))) { - long sizeInBytes = Directory.EnumerateFiles(PkgMgr.editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + Package.folder, "*", SearchOption.AllDirectories).Sum(fileInfo => new FileInfo(fileInfo).Length); + long sizeInBytes = Directory.EnumerateFiles(Path.Combine(PkgMgr.editor.ActiveVersion.fullPath, Package.folder ?? ""), "*", SearchOption.AllDirectories).Sum(fileInfo => new FileInfo(fileInfo).Length); DiskSpace = KnUtils.FormatBytes(sizeInBytes); } } @@ -544,7 +544,7 @@ internal void OpenModPackageFolder() try { if(PkgMgr.editor != null) - KnUtils.OpenFolder(PkgMgr.editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + Package.folder); + KnUtils.OpenFolder(Path.Combine(PkgMgr.editor.ActiveVersion.fullPath, Package.folder ?? "")); } catch (Exception ex) { @@ -723,7 +723,7 @@ internal void CreatePackage() MessageBox.Show(MainWindow.instance, NewPackageName + " is a reserved package folder name and cant be used", "Error creating new package", MessageBox.MessageBoxButtons.OK); return; } - Directory.CreateDirectory(editor!.ActiveVersion.fullPath + Path.DirectorySeparatorChar + NewPackageFolder + Path.DirectorySeparatorChar + "data"); + Directory.CreateDirectory(Path.Combine(editor!.ActiveVersion.fullPath, NewPackageFolder, "data")); var newPkg = new ModPackage(); newPkg.folder = NewPackageFolder; newPkg.name = NewPackageName; @@ -742,9 +742,9 @@ internal async void DeletePkg(EditorModPackageItem editorPackageItem) { try { - if (editor != null) + if (editor != null && editorPackageItem.Package.folder != null) { - var folderPath = editor.ActiveVersion.fullPath + Path.DirectorySeparatorChar + editorPackageItem.Package.folder; + var folderPath = Path.Combine(editor.ActiveVersion.fullPath, editorPackageItem.Package.folder); var resp = await MessageBox.Show(MainWindow.instance!, "This will delete the package: " + editorPackageItem.Package.name + " and ALL FILES on this folder: " + folderPath + " of the mod and version " + editor.ActiveVersion + "\n Do you really want to do this? This action cannot be undone.","Confirm package deletion",MessageBox.MessageBoxButtons.YesNo); if(resp == MessageBox.MessageBoxResult.Yes) { diff --git a/Knossos.NET/ViewModels/Templates/DevModVersionsViewModel.cs b/Knossos.NET/ViewModels/Templates/DevModVersionsViewModel.cs index 4b95cf28..85a013d6 100644 --- a/Knossos.NET/ViewModels/Templates/DevModVersionsViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/DevModVersionsViewModel.cs @@ -195,7 +195,7 @@ internal async void CreateNewVersion(object control) Log.Add(Log.LogSeverity.Error, "DevModVersionsViewModel.CreateNewVersion()", editor.ActiveVersion.fullPath+" get parent folder was null"); return; } - var newDir = parentDir.FullName + Path.DirectorySeparatorChar + editor.ActiveVersion.id + "-" + NewVersion; + var newDir = Path.Combine(parentDir.FullName, editor.ActiveVersion.id) + "-" + NewVersion; if (Directory.Exists(newDir)) { await MessageBox.Show(MainWindow.instance!, "The directory '"+ newDir + "' already exists.", "Validation error", MessageBox.MessageBoxButtons.OK); @@ -660,7 +660,7 @@ internal async void CreateDevEnv() Log.Add(Log.LogSeverity.Error, "DevModVersionsViewModel.CreateNewVersion()", editor.ActiveVersion.fullPath + " get parent folder was null"); return; } - var newDir = parentDir.FullName + Path.DirectorySeparatorChar + editor.ActiveVersion.id + "-" + devVersion; + var newDir = Path.Combine(parentDir.FullName, editor.ActiveVersion.id) + "-" + devVersion; if (Directory.Exists(newDir)) { await MessageBox.Show(MainWindow.instance!, "The directory '" + newDir + "' already exists.", "Validation error", MessageBox.MessageBoxButtons.OK); diff --git a/Knossos.NET/ViewModels/Templates/ModCardViewModel.cs b/Knossos.NET/ViewModels/Templates/ModCardViewModel.cs index b2ffefc3..cf7df048 100644 --- a/Knossos.NET/ViewModels/Templates/ModCardViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/ModCardViewModel.cs @@ -309,9 +309,9 @@ internal void ButtonCommandRelay(object command) private void OpenFS2Log() { - if (File.Exists(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log")) + if (File.Exists(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log"))) { - KnUtils.OpenFileInOS(KnUtils.GetFSODataFolderPath() + Path.DirectorySeparatorChar + "data" + Path.DirectorySeparatorChar + "fs2_open.log"); + KnUtils.OpenFileInOS(Path.Combine(KnUtils.GetFSODataFolderPath(), "data", "fs2_open.log")); } else { @@ -396,7 +396,7 @@ private void LoadImage() { if (!tile.ToLower().Contains("http")) { - tileModBitmap = new Bitmap(modVersions[activeVersionIndex].fullPath + Path.DirectorySeparatorChar + tile); + tileModBitmap = new Bitmap(Path.Combine(modVersions[activeVersionIndex].fullPath, tile)); } else { diff --git a/Knossos.NET/ViewModels/Templates/NebulaModCardViewModel.cs b/Knossos.NET/ViewModels/Templates/NebulaModCardViewModel.cs index 2b8f9703..c0f42976 100644 --- a/Knossos.NET/ViewModels/Templates/NebulaModCardViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/NebulaModCardViewModel.cs @@ -177,7 +177,7 @@ private async Task LoadImage(string modFullPath, string? tileString) { if (!tileString.ToLower().Contains("http")) { - tileModBitmap = new Bitmap(modFullPath + Path.DirectorySeparatorChar + tileString); + tileModBitmap = new Bitmap(Path.Combine(modFullPath, tileString)); } else { diff --git a/Knossos.NET/ViewModels/Templates/Tasks/CompressMod.cs b/Knossos.NET/ViewModels/Templates/Tasks/CompressMod.cs index 8da427ac..2dcfef01 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/CompressMod.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/CompressMod.cs @@ -64,9 +64,9 @@ await Dispatcher.UIThread.InvokeAsync(() => { ProgressBarMax = vpFiles.Count() + 1; //Loose Files Compression - if (Directory.Exists(mod.fullPath + Path.DirectorySeparatorChar + "data") || mod.devMode) + if (Directory.Exists(Path.Combine(mod.fullPath, "data")) || mod.devMode) { - var searchDir = mod.devMode ? mod.fullPath : mod.fullPath + Path.DirectorySeparatorChar + "data"; + var searchDir = mod.devMode ? mod.fullPath : Path.Combine(mod.fullPath, "data"); var allFilesInDataFolder = Directory.GetFiles(searchDir, "*.*", SearchOption.AllDirectories).ToList(); int skipped = 0; //Filter diff --git a/Knossos.NET/ViewModels/Templates/Tasks/CreateModVersion.cs b/Knossos.NET/ViewModels/Templates/Tasks/CreateModVersion.cs index ff4655c3..92c63568 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/CreateModVersion.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/CreateModVersion.cs @@ -25,7 +25,7 @@ public async Task CreateModVersion(Mod oldMod, string newVersion, Cancella Name = "Creating Mod Version: " + oldMod.title + " " + newVersion; var currentDir = new DirectoryInfo(oldMod.fullPath); var parentDir = currentDir.Parent; - newDir = parentDir!.FullName + Path.DirectorySeparatorChar + oldMod.id + "-" + newVersion; + newDir = Path.Combine(parentDir!.FullName, oldMod.id + "-" + newVersion); if (cancelSource != null) { @@ -55,7 +55,7 @@ public async Task CreateModVersion(Mod oldMod, string newVersion, Cancella Directory.CreateDirectory(newDir); - using (StreamWriter writer = new StreamWriter(newDir + Path.DirectorySeparatorChar + "knossos_net_download.token")) + using (StreamWriter writer = new StreamWriter(Path.Combine(newDir, "knossos_net_download.token"))) { writer.WriteLine("Warning: This token indicates an incomplete folder copy. If this token is present on the next KnossosNET startup this folder WILL BE DELETED."); } @@ -68,7 +68,7 @@ await KnUtils.CopyDirectoryAsync( copyCallback, Knossos.globalSettings.skipExtensionsModFilecopy != null && Knossos.globalSettings.skipExtensionsModFilecopy.Any() ? Knossos.globalSettings.skipExtensionsModFilecopy.ToArray() : null); - File.Delete(newDir + Path.DirectorySeparatorChar + "knossos_net_download.token"); + File.Delete(Path.Combine(newDir, "knossos_net_download.token")); var newMod = new Mod(newDir, oldMod.id + "-" + newVersion); newMod.version = newVersion; diff --git a/Knossos.NET/ViewModels/Templates/Tasks/DecompressMod.cs b/Knossos.NET/ViewModels/Templates/Tasks/DecompressMod.cs index 08996e6a..23eff261 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/DecompressMod.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/DecompressMod.cs @@ -50,9 +50,9 @@ public async Task DecompressMod(Mod mod, CancellationTokenSource? cancelSo ProgressBarMax = vpcFiles.Count() + 1; //Loose Files Compression - if (Directory.Exists(mod.fullPath + Path.DirectorySeparatorChar + "data") || mod.devMode) + if (Directory.Exists(Path.Combine(mod.fullPath, "data")) || mod.devMode) { - var searchDir = mod.devMode ? mod.fullPath : mod.fullPath + Path.DirectorySeparatorChar + "data"; + var searchDir = mod.devMode ? mod.fullPath : Path.Combine(mod.fullPath, "data"); var allFilesInDataFolder = Directory.GetFiles(searchDir, "*.*", SearchOption.AllDirectories).ToList(); int skipped = 0; //Filter diff --git a/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs b/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs index 8452b377..f19c6e7d 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/InstallBuild.cs @@ -102,6 +102,9 @@ private async Task InstallVCRedist(bool is86 = false) { await Dispatcher.UIThread.InvokeAsync(() => TaskRoot.Add(this)); Info = "In Queue"; + if (Knossos.GetKnossosLibraryPath() == null) + throw new TaskCanceledException("Knossos library path is not set!"); + //Wait in Queue while (TaskViewModel.Instance!.taskQueue.Count > 0 && TaskViewModel.Instance!.taskQueue.Peek() != this) { @@ -160,7 +163,7 @@ private async Task InstallVCRedist(bool is86 = false) { List files = new List(); string modFolder = modJson.id + "-" + modJson.version; - modPath = Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + modFolder; + modPath = Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", "bin", modFolder); if (modifyPkgs != null) { //Modify Build @@ -181,9 +184,9 @@ private async Task InstallVCRedist(bool is86 = false) { { foreach (var f in pkg.filelist) { - if (File.Exists(modPath + Path.DirectorySeparatorChar + f.filename)) + if (!string.IsNullOrEmpty(f.filename) && File.Exists(Path.Combine(modPath, f.filename))) { - File.Delete(modPath + Path.DirectorySeparatorChar + f.filename); + File.Delete(Path.Combine(modPath, f.filename)); } } deleteTask.IsCompleted = true; @@ -257,7 +260,7 @@ private async Task InstallVCRedist(bool is86 = false) { CancelTaskCommand(); return null; } - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + file.dest); + Directory.CreateDirectory(Path.Combine(modPath, file.dest)); } } @@ -270,7 +273,7 @@ private async Task InstallVCRedist(bool is86 = false) { try { - File.Create(modPath + Path.DirectorySeparatorChar + "knossos_net_download.token").Close(); + File.Create(Path.Combine(modPath, "knossos_net_download.token")).Close(); } catch { } @@ -308,7 +311,7 @@ private async Task InstallVCRedist(bool is86 = false) { CancelTaskCommand(); throw new TaskCanceledException(); } - var fileFullPath = modPath + Path.DirectorySeparatorChar + file.filename; + var fileFullPath = Path.Combine(modPath, file.filename); var result = await fileTask.DownloadFile(file.urls!, fileFullPath, "Downloading " + file.filename, false, null, cancellationTokenSource); if (cancellationTokenSource.IsCancellationRequested) @@ -375,7 +378,7 @@ private async Task InstallVCRedist(bool is86 = false) { //Decompress var decompressTask = new TaskItemViewModel(); await Dispatcher.UIThread.InvokeAsync(() => TaskList.Insert(0, decompressTask)); - var decompResult = await decompressTask.DecompressNebulaFile(fileFullPath, file.filename, modPath + Path.DirectorySeparatorChar + file.dest, cancellationTokenSource); + var decompResult = await decompressTask.DecompressNebulaFile(fileFullPath, file.filename, Path.Combine(modPath, file.dest), cancellationTokenSource); if (!decompResult) { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.InstallBuild()", "Error while decompressing the file " + fileFullPath); @@ -406,7 +409,7 @@ private async Task InstallVCRedist(bool is86 = false) { //Download Tile Image if (!string.IsNullOrEmpty(modJson.tile) && modifyPkgs == null) { - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); var uri = new Uri(modJson.tile); using (var fs = await KnUtils.GetRemoteResourceStream(modJson.tile)) { @@ -415,7 +418,7 @@ private async Task InstallVCRedist(bool is86 = false) { tileTask.ShowMsg("Getting tile image", null); if (fs != null) { - using (var destImg = new FileStream(modPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath), FileMode.Create, FileAccess.Write)) + using (var destImg = new FileStream(Path.Combine(modPath, "kn_images", Path.GetFileName(uri.LocalPath)), FileMode.Create, FileAccess.Write)) { await fs.CopyToAsync(destImg); fs.Close(); @@ -423,7 +426,7 @@ private async Task InstallVCRedist(bool is86 = false) { } } } - modJson.tile = "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath); + modJson.tile = Path.Combine("kn_images", Path.GetFileName(uri.LocalPath)); } @@ -436,7 +439,7 @@ private async Task InstallVCRedist(bool is86 = false) { //Download Banner Image if (!string.IsNullOrEmpty(modJson.banner) && modifyPkgs == null) { - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); var uri = new Uri(modJson.banner); using (var fs = await KnUtils.GetRemoteResourceStream(modJson.banner)) { @@ -445,7 +448,7 @@ private async Task InstallVCRedist(bool is86 = false) { bannerTask.ShowMsg("Getting banner image", null); if (fs != null) { - using (var destImg = new FileStream(modPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath), FileMode.Create, FileAccess.Write)) + using (var destImg = new FileStream(Path.Combine(modPath, "kn_images", Path.GetFileName(uri.LocalPath)), FileMode.Create, FileAccess.Write)) { await fs.CopyToAsync(destImg); fs.Close(); @@ -453,7 +456,7 @@ private async Task InstallVCRedist(bool is86 = false) { } } } - modJson.banner = "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath); + modJson.banner = Path.Combine("kn_images", Path.GetFileName(uri.LocalPath)); } if (cancellationTokenSource.IsCancellationRequested) @@ -464,7 +467,7 @@ private async Task InstallVCRedist(bool is86 = false) { //Download Screenshots if (modJson.screenshots != null && modJson.screenshots.Any() && modifyPkgs == null) { - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); var scList = new List(); foreach (var sc in modJson.screenshots) { @@ -480,7 +483,7 @@ private async Task InstallVCRedist(bool is86 = false) { scTask.ShowMsg("Getting screenshot #" + scList.Count() + " image", null); if (fs != null) { - using (var destImg = new FileStream(modPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath), FileMode.Create, FileAccess.Write)) + using (var destImg = new FileStream(Path.Combine(modPath, "kn_images", Path.GetFileName(uri.LocalPath)), FileMode.Create, FileAccess.Write)) { await fs.CopyToAsync(destImg); fs.Close(); @@ -488,7 +491,7 @@ private async Task InstallVCRedist(bool is86 = false) { } } } - scList.Add("kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath)); + scList.Add(Path.Combine("kn_images", Path.GetFileName(uri.LocalPath))); } modJson.screenshots = scList.ToArray(); } @@ -509,7 +512,7 @@ private async Task InstallVCRedist(bool is86 = false) { modJson.SaveJson(); try { - File.Delete(modJson.fullPath + Path.DirectorySeparatorChar + "knossos_net_download.token"); + File.Delete(Path.Combine(modJson.fullPath, "knossos_net_download.token")); } catch (Exception ex) { diff --git a/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs b/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs index 428c274e..43caa0c0 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/InstallMod.cs @@ -44,6 +44,9 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource Info = "In Queue"; bool compressMod = false; + if (Knossos.GetKnossosLibraryPath() == null) + throw new TaskCanceledException("Knossos library path is not set!"); + //Set Mod card as "installing" MainViewModel.Instance?.SetInstalling(mod.id, cancellationTokenSource); @@ -148,7 +151,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource } } - modPath = Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + rootPack + Path.DirectorySeparatorChar + modFolder; + modPath = Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", rootPack, modFolder); /* Metadata update */ bool metaUpdate = false; @@ -199,9 +202,9 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource { try { - if (File.Exists(installed.fullPath + Path.DirectorySeparatorChar + file.filename)) + if (!string.IsNullOrEmpty(file.filename) && File.Exists(Path.Combine(installed.fullPath, file.filename))) { - File.Delete(installed.fullPath + Path.DirectorySeparatorChar + file.filename); + File.Delete(Path.Combine(installed.fullPath, file.filename)); delCount++; } } @@ -250,7 +253,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource { foreach (var file in mod.packages[i].files!) { - file.dest = mod.packages[i].folder + Path.DirectorySeparatorChar + file.dest; + file.dest = Path.Combine(mod.packages[i].folder ?? "", file.dest ?? ""); if (mod.packages[i].isVp) vPExtractionNeeded++; } @@ -290,7 +293,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource CancelTaskCommand(); return false; } - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + file.dest); + Directory.CreateDirectory(Path.Combine(modPath, file.dest)); } } @@ -309,7 +312,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource { try { - File.Create(modPath + Path.DirectorySeparatorChar + "knossos_net_download.token").Close(); + File.Create(Path.Combine(modPath, "knossos_net_download.token")).Close(); } catch { } } @@ -378,7 +381,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource CancelTaskCommand(); throw new TaskCanceledException(); } - var fileFullPath = modPath + Path.DirectorySeparatorChar + file.filename; + var fileFullPath = Path.Combine(modPath, file.filename); var result = await fileTask.DownloadFile(file.urls!, fileFullPath, "Downloading " + file.filename, false, null, cancellationTokenSource); if (cancellationTokenSource.IsCancellationRequested) @@ -431,7 +434,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource //Decompress var decompressTask = new TaskItemViewModel(); await Dispatcher.UIThread.InvokeAsync(() => TaskList.Insert(0, decompressTask)); - var decompResult = await decompressTask.DecompressNebulaFile(fileFullPath, file.filename, modPath + Path.DirectorySeparatorChar + file.dest, cancellationTokenSource); + var decompResult = await decompressTask.DecompressNebulaFile(fileFullPath, file.filename, Path.Combine(modPath, file.dest), cancellationTokenSource); if (!decompResult) { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.InstallMod()", "Error while decompressing the file " + fileFullPath); @@ -476,7 +479,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource //Download Tile image if (!string.IsNullOrEmpty(mod.tile) && (installed == null || metaUpdate)) { - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); var uri = new Uri(mod.tile); using (var fs = await KnUtils.GetRemoteResourceStream(mod.tile)) { @@ -485,7 +488,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource tileTask.ShowMsg("Getting tile image", null); if (fs != null) { - using (var destImg = new FileStream(modPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath), FileMode.Create, FileAccess.Write)) + using (var destImg = new FileStream(Path.Combine(modPath, "kn_images", Path.GetFileName(uri.LocalPath)), FileMode.Create, FileAccess.Write)) { await fs.CopyToAsync(destImg); fs.Close(); @@ -493,7 +496,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource } } } - mod.tile = "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath); + mod.tile = Path.Combine("kn_images", Path.GetFileName(uri.LocalPath)); } if (cancellationTokenSource.IsCancellationRequested) @@ -504,8 +507,8 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource //Download Banner if (!string.IsNullOrEmpty(mod.banner) && (installed == null || metaUpdate)) { - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); var uri = new Uri(mod.banner); using (var fs = await KnUtils.GetRemoteResourceStream(mod.banner)) { @@ -514,7 +517,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource bannerTask.ShowMsg("Getting banner image", null); if (fs != null) { - using (var destImg = new FileStream(modPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath), FileMode.Create, FileAccess.Write)) + using (var destImg = new FileStream(Path.Combine(modPath, "kn_images", Path.GetFileName(uri.LocalPath)), FileMode.Create, FileAccess.Write)) { await fs.CopyToAsync(destImg); fs.Close(); @@ -522,7 +525,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource } } } - mod.banner = "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath); + mod.banner = Path.Combine("kn_images", Path.GetFileName(uri.LocalPath)); } if (cancellationTokenSource.IsCancellationRequested) @@ -533,7 +536,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource //Download Screenshots if (mod.screenshots != null && mod.screenshots.Any() && installed == null) { - Directory.CreateDirectory(modPath + Path.DirectorySeparatorChar + "kn_images"); + Directory.CreateDirectory(Path.Combine(modPath, "kn_images")); var scList = new List(); foreach (var sc in mod.screenshots) { @@ -549,7 +552,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource scTask.ShowMsg("Getting screenshot #" + scList.Count() + " image", null); if (fs != null) { - using (var destImg = new FileStream(modPath + Path.DirectorySeparatorChar + "kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath), FileMode.Create, FileAccess.Write)) + using (var destImg = new FileStream(Path.Combine(modPath, "kn_images", Path.GetFileName(uri.LocalPath)), FileMode.Create, FileAccess.Write)) { await fs.CopyToAsync(destImg); fs.Close(); @@ -557,7 +560,7 @@ public async Task InstallMod(Mod mod, CancellationTokenSource cancelSource } } } - scList.Add("kn_images" + Path.DirectorySeparatorChar + Path.GetFileName(uri.LocalPath)); + scList.Add(Path.Combine("kn_images", Path.GetFileName(uri.LocalPath))); } mod.screenshots = scList.ToArray(); } @@ -628,7 +631,7 @@ await Dispatcher.UIThread.InvokeAsync(() => try { - File.Delete(mod.fullPath + Path.DirectorySeparatorChar + "knossos_net_download.token"); + File.Delete(Path.Combine(mod.fullPath, "knossos_net_download.token")); } catch { } diff --git a/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs b/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs index 434999a8..ddeb328c 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/InstallTool.cs @@ -67,7 +67,7 @@ public async Task InstallTool(Tool tool, Tool? updateFrom, Action fi try { - File.Create(toolPath + Path.DirectorySeparatorChar + "knossos_net_download.token").Close(); + File.Create(Path.Combine(toolPath, "knossos_net_download.token")).Close(); } catch { } @@ -90,7 +90,7 @@ public async Task InstallTool(Tool tool, Tool? updateFrom, Action fi throw new TaskCanceledException("Tool download URL was null."); var fileName = Path.GetFileName(url); - var fileFullPath = toolPath + Path.DirectorySeparatorChar + fileName; + var fileFullPath = Path.Combine(toolPath, fileName); var result = await fileTask.DownloadFile(url, fileFullPath, "Downloading " + fileName, false, null, cancellationTokenSource); if (cancellationTokenSource.IsCancellationRequested) @@ -124,7 +124,7 @@ public async Task InstallTool(Tool tool, Tool? updateFrom, Action fi try { - File.Delete(toolPath + Path.DirectorySeparatorChar + "knossos_net_download.token"); + File.Delete(Path.Combine(toolPath, "knossos_net_download.token")); } catch { } diff --git a/Knossos.NET/ViewModels/Templates/Tasks/PrepareModPkg.cs b/Knossos.NET/ViewModels/Templates/Tasks/PrepareModPkg.cs index ba370760..88cf08ad 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/PrepareModPkg.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/PrepareModPkg.cs @@ -43,32 +43,32 @@ private async Task PrepareModPkg(ModPackage pkg, string modFullPath, Cance //Fill file.filename, file.checksum, file.dest, file.filesize //Note: MacOSX builds must be compressed as tar.gz keeping symblinks as links - if (!Directory.Exists(modFullPath + Path.DirectorySeparatorChar + pkg.folder)) + if (!Directory.Exists(Path.Combine(modFullPath, pkg.folder ?? ""))) { Info = "Fail - No Dir"; IsCompleted = true; CancelButtonVisible = false; ProgressCurrent = ProgressBarMax; - Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Package folder: " + modFullPath + Path.DirectorySeparatorChar + pkg.folder + " does not exist."); + Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Package folder: " + Path.Combine(modFullPath, pkg.folder ?? "") + " does not exist."); throw new TaskCanceledException(); } - var allfiles = Directory.GetFiles(modFullPath + Path.DirectorySeparatorChar + pkg.folder, "*.*", SearchOption.AllDirectories); + var allfiles = Directory.GetFiles(Path.Combine(modFullPath, pkg.folder ?? ""), "*.*", SearchOption.AllDirectories); if (!allfiles.Any()) { Info = "Fail - No Files"; IsCompleted = true; CancelButtonVisible = false; ProgressCurrent = ProgressBarMax; - Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Package folder: " + modFullPath + Path.DirectorySeparatorChar + pkg.folder + " is empty."); + Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Package folder: " + Path.Combine(modFullPath, pkg.folder ?? "") + " is empty."); throw new TaskCanceledException(); } - var zipPath = modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + pkg.folder + ".7z"; + var zipPath = Path.Combine(modFullPath, "kn_upload", pkg.folder + ".7z"); if (pkg.environment != null && pkg.environment.ToLower().Contains("macos")) { - zipPath = modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + pkg.folder; + zipPath = Path.Combine(modFullPath, "kn_upload", pkg.folder ?? ""); } if (File.Exists(zipPath)) { @@ -84,14 +84,14 @@ private async Task PrepareModPkg(ModPackage pkg, string modFullPath, Cance Info = "Creating VP"; ProgressBarMax = 100; ProgressCurrent = 0; - var vpPath = modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + "vps" + Path.DirectorySeparatorChar + pkg.name + ".vp"; - Directory.CreateDirectory(modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + "vps"); + var vpPath = Path.Combine(modFullPath, "kn_upload", "vps", pkg.name + ".vp"); + Directory.CreateDirectory(Path.Combine(modFullPath, "kn_upload", "vps")); if (File.Exists(vpPath)) { File.Delete(vpPath); } var vp = new VPContainer(); - vp.AddFolderToRoot(modFullPath + Path.DirectorySeparatorChar + pkg.folder); + vp.AddFolderToRoot(Path.Combine(modFullPath, pkg.folder ?? "")); vp.DisableCompression(); await vp.SaveAsAsync(vpPath, compressionCallback, cancellationTokenSource); Info = "Get VP Checksum"; @@ -107,7 +107,7 @@ private async Task PrepareModPkg(ModPackage pkg, string modFullPath, Cance var crcResult = false; do { - if (!await compressor.CompressFile(vpPath, modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + "vps", zipPath, true)) + if (!await compressor.CompressFile(vpPath, Path.Combine(modFullPath, "kn_upload", "vps"), zipPath, true)) { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Error while compressing the package"); //Disable failing and instead delete the file if it exists @@ -161,7 +161,7 @@ private async Task PrepareModPkg(ModPackage pkg, string modFullPath, Cance var fi = new FileInfo(file); if (fi.LinkTarget == null) { - var relativePath = Path.GetRelativePath(modFullPath + Path.DirectorySeparatorChar + pkg.folder, file).Replace(@"\", @"/"); + var relativePath = Path.GetRelativePath(Path.Combine(modFullPath, pkg.folder ?? ""), file).Replace(@"\", @"/"); var checksum = await KnUtils.GetFileHash(file); if (checksum != null) { @@ -189,7 +189,7 @@ private async Task PrepareModPkg(ModPackage pkg, string modFullPath, Cance var crcResult = false; do { - if (!await compressor.CompressFolderTarGz(modFullPath + Path.DirectorySeparatorChar + pkg.folder, zipPath)) + if (!await compressor.CompressFolderTarGz(Path.Combine(modFullPath, pkg.folder ?? ""), zipPath)) { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Error while compressing the package"); //Disable failing and instead delete the file if it exists @@ -228,7 +228,7 @@ private async Task PrepareModPkg(ModPackage pkg, string modFullPath, Cance var crcResult = false; do { - if (!await compressor.CompressFolder(modFullPath + Path.DirectorySeparatorChar + pkg.folder, zipPath)) + if (!await compressor.CompressFolder(Path.Combine(modFullPath, pkg.folder ?? ""), zipPath)) { Log.Add(Log.LogSeverity.Error, "TaskItemViewModel.PrepareModPkg()", "Error while compressing the package"); //Disable failing and instead delete the file if it exists diff --git a/Knossos.NET/ViewModels/Templates/Tasks/UploadModImages.cs b/Knossos.NET/ViewModels/Templates/Tasks/UploadModImages.cs index 4d34bfc5..8e9883e9 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/UploadModImages.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/UploadModImages.cs @@ -45,7 +45,7 @@ private async Task UploadModImages(Mod mod, CancellationTokenSource? cance { Info = $"Screenshot Image {i} / {mod.screenshots.Length}"; ProgressCurrent++; - var checksum = await Nebula.UploadImage(mod.fullPath + Path.DirectorySeparatorChar + sc); + var checksum = await Nebula.UploadImage(Path.Combine(mod.fullPath, sc)); if (checksum != null) { @@ -67,7 +67,7 @@ private async Task UploadModImages(Mod mod, CancellationTokenSource? cance if (!string.IsNullOrEmpty(mod.tile)) { Info = "Tile Image"; - var checksum = await Nebula.UploadImage(mod.fullPath + Path.DirectorySeparatorChar + mod.tile); + var checksum = await Nebula.UploadImage(Path.Combine(mod.fullPath, mod.tile)); if (checksum != null) { @@ -84,7 +84,7 @@ private async Task UploadModImages(Mod mod, CancellationTokenSource? cance if (!string.IsNullOrEmpty(mod.banner)) { Info = "Banner Image"; - var checksum = await Nebula.UploadImage(mod.fullPath + Path.DirectorySeparatorChar + mod.banner); + var checksum = await Nebula.UploadImage(Path.Combine(mod.fullPath, mod.banner)); if (checksum != null) { diff --git a/Knossos.NET/ViewModels/Templates/Tasks/UploadModPkg.cs b/Knossos.NET/ViewModels/Templates/Tasks/UploadModPkg.cs index 43c7774d..aa465453 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/UploadModPkg.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/UploadModPkg.cs @@ -31,10 +31,10 @@ private async Task UploadModPkg(ModPackage pkg, string modFullPath, Cancel if (cancellationTokenSource.IsCancellationRequested) throw new TaskCanceledException(); - var zipPath = modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + pkg.folder + ".7z"; + var zipPath = Path.Combine(modFullPath, "kn_upload", pkg.folder + ".7z"); if (pkg.environment != null && pkg.environment.ToLower().Contains("macos")) { - zipPath = modFullPath + Path.DirectorySeparatorChar + "kn_upload" + Path.DirectorySeparatorChar + pkg.folder + ".tar.gz"; + zipPath = Path.Combine(modFullPath, "kn_upload", pkg.folder + ".tar.gz"); } if (!File.Exists(zipPath)) { diff --git a/Knossos.NET/ViewModels/Templates/Tasks/UploadModVersion.cs b/Knossos.NET/ViewModels/Templates/Tasks/UploadModVersion.cs index d195940c..5f162bce 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/UploadModVersion.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/UploadModVersion.cs @@ -94,7 +94,7 @@ public async Task UploadModVersion(Mod mod, bool isNewMod, bool metaOnly, { //We are good. Im leaving image upload for meta stage Info = "Prepare Packages"; - Directory.CreateDirectory(mod.fullPath + Path.DirectorySeparatorChar + "kn_upload"); + Directory.CreateDirectory(Path.Combine(mod.fullPath, "kn_upload")); //Prepare packages, update data on mod await Parallel.ForEachAsync(mod.packages, new ParallelOptions { MaxDegreeOfParallelism = parallelCompression }, async (pkg, token) => { @@ -233,11 +233,11 @@ public async Task UploadModVersion(Mod mod, bool isNewMod, bool metaOnly, ProgressCurrent = ProgressBarMax; //Delete kn_upload folder? - if (Knossos.globalSettings.deleteUploadedFiles && Directory.Exists(mod.fullPath + Path.DirectorySeparatorChar + "kn_upload")) + if (Knossos.globalSettings.deleteUploadedFiles && Directory.Exists(Path.Combine(mod.fullPath, "kn_upload"))) { try { - Directory.Delete(mod.fullPath + Path.DirectorySeparatorChar + "kn_upload", true); + Directory.Delete(Path.Combine(mod.fullPath, "kn_upload"), true); } catch (Exception ex) { diff --git a/Knossos.NET/ViewModels/Templates/Tasks/VerifyMod.cs b/Knossos.NET/ViewModels/Templates/Tasks/VerifyMod.cs index ae6b7dcd..218b7d84 100644 --- a/Knossos.NET/ViewModels/Templates/Tasks/VerifyMod.cs +++ b/Knossos.NET/ViewModels/Templates/Tasks/VerifyMod.cs @@ -91,7 +91,7 @@ public async Task VerifyMod(Mod mod, CancellationTokenSource cancelSource) { try { - using (FileStream? filehash = new FileStream(mod.fullPath + Path.DirectorySeparatorChar + file.filename, FileMode.Open, FileAccess.Read)) + using (FileStream? filehash = new FileStream(Path.Combine(mod.fullPath, file.filename ?? ""), FileMode.Open, FileAccess.Read)) { using (SHA256 checksum = SHA256.Create()) { diff --git a/Knossos.NET/ViewModels/Windows/AddUserBuildViewModel.cs b/Knossos.NET/ViewModels/Windows/AddUserBuildViewModel.cs index 2bad58da..fc83a617 100644 --- a/Knossos.NET/ViewModels/Windows/AddUserBuildViewModel.cs +++ b/Knossos.NET/ViewModels/Windows/AddUserBuildViewModel.cs @@ -181,7 +181,7 @@ internal async void OpenFolderCommand() } Stage2 = true; buildId = @"user_build_" + KnUtils.GetTimestamp(DateTime.Now); - BuildNewPath = Knossos.GetKnossosLibraryPath()+ Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + buildId; + BuildNewPath = Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", "bin", buildId); } }catch(Exception ex) { diff --git a/Knossos.NET/ViewModels/Windows/DevModCreateNewViewModel.cs b/Knossos.NET/ViewModels/Windows/DevModCreateNewViewModel.cs index f0c9b8d0..bfff35fd 100644 --- a/Knossos.NET/ViewModels/Windows/DevModCreateNewViewModel.cs +++ b/Knossos.NET/ViewModels/Windows/DevModCreateNewViewModel.cs @@ -173,9 +173,9 @@ private async Task Verify() // Retail FS2 mods are stored on that same folder if (parent!.id.ToLower() == "fs2") { - if(Directory.Exists(parent.fullPath+Path.DirectorySeparatorChar+ModId+"-"+ModVersion) || File.Exists(parent.fullPath + Path.DirectorySeparatorChar + ModId + "-" + ModVersion)) + if(Directory.Exists(Path.Combine(parent.fullPath, ModId)+"-"+ModVersion) || File.Exists(Path.Combine(parent.fullPath, ModId) + "-" + ModVersion)) { - await MessageBox.Show(MainWindow.instance, "Folder or File already exists: "+ parent.fullPath + Path.DirectorySeparatorChar + ModId + "-" + ModVersion, "Validation error", MessageBox.MessageBoxButtons.OK); + await MessageBox.Show(MainWindow.instance, "Folder or File already exists: "+ Path.Combine(parent.fullPath, ModId) + "-" + ModVersion, "Validation error", MessageBox.MessageBoxButtons.OK); return false; } } @@ -184,9 +184,9 @@ private async Task Verify() var parentParentFolder = new DirectoryInfo(parent.fullPath).Parent; if (parentParentFolder != null) { - if (Directory.Exists(parentParentFolder.FullName + Path.DirectorySeparatorChar + ModId + "-" + ModVersion) || File.Exists(parentParentFolder.FullName + Path.DirectorySeparatorChar + ModId + "-" + ModVersion)) + if (Directory.Exists(Path.Combine(parentParentFolder.FullName, ModId) + "-" + ModVersion) || File.Exists(Path.Combine(parentParentFolder.FullName, ModId) + "-" + ModVersion)) { - await MessageBox.Show(MainWindow.instance, "Folder or File already exists: " + parentParentFolder.FullName + Path.DirectorySeparatorChar + ModId + "-" + ModVersion, "Validation error", MessageBox.MessageBoxButtons.OK); + await MessageBox.Show(MainWindow.instance, "Folder or File already exists: " + Path.Combine(parentParentFolder.FullName, ModId) + "-" + ModVersion, "Validation error", MessageBox.MessageBoxButtons.OK); return false; } } @@ -200,18 +200,18 @@ private async Task Verify() { if (TypeSelectedIndex == 1) //Total Conversion { - if(Directory.Exists(Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + ModId ) || File.Exists(Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + ModId)) + if(Directory.Exists(Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", ModId)) || File.Exists(Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", ModId))) { - await MessageBox.Show(MainWindow.instance, "Folder or File already exists: " + Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + ModId, "Validation error", MessageBox.MessageBoxButtons.OK); + await MessageBox.Show(MainWindow.instance, "Folder or File already exists: " + Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", ModId), "Validation error", MessageBox.MessageBoxButtons.OK); return false; } } else { //FSO Build - if (Directory.Exists(Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + ModId + "-" + ModVersion) || File.Exists(Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + ModId + "-" + ModVersion)) + if (Directory.Exists(Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", "bin", ModId + "-" + ModVersion)) || File.Exists(Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", "bin", ModId + "-" + ModVersion))) { - await MessageBox.Show(MainWindow.instance, "Folder or File already exists: " + Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + ModId + "-" + ModVersion, "Validation error", MessageBox.MessageBoxButtons.OK); + await MessageBox.Show(MainWindow.instance, "Folder or File already exists: " + Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", "bin", ModId + "-" + ModVersion), "Validation error", MessageBox.MessageBoxButtons.OK); return false; } } @@ -241,14 +241,14 @@ internal async void CreateMod() // Retail FS2 mods are stored on that same folder if (parent!.id.ToLower() == "fs2") { - folderPath = parent.fullPath + Path.DirectorySeparatorChar + ModId + "-" + ModVersion; + folderPath = Path.Combine(parent.fullPath, ModId) + "-" + ModVersion; } else { var parentParentFolder = new DirectoryInfo(parent.fullPath).Parent; if (parentParentFolder != null) { - folderPath = parentParentFolder.FullName + Path.DirectorySeparatorChar + ModId + "-" + ModVersion; + folderPath = Path.Combine(parentParentFolder.FullName, ModId) + "-" + ModVersion; } } } @@ -256,12 +256,12 @@ internal async void CreateMod() { if (TypeSelectedIndex == 1) //Total Conversion { - folderPath = Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + ModId + Path.DirectorySeparatorChar + ModId + "-" + ModVersion; + folderPath = Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", ModId, ModId + "-" + ModVersion); } else { //FSO Build - folderPath = Knossos.GetKnossosLibraryPath() + Path.DirectorySeparatorChar + "bin" + Path.DirectorySeparatorChar + ModId + "-" + ModVersion; + folderPath = Path.Combine(Knossos.GetKnossosLibraryPath() ?? "", "bin", ModId + "-" + ModVersion); } } Directory.CreateDirectory(folderPath); diff --git a/Knossos.NET/ViewModels/Windows/ModDetailsViewModel.cs b/Knossos.NET/ViewModels/Windows/ModDetailsViewModel.cs index d10e16de..23fbe86b 100644 --- a/Knossos.NET/ViewModels/Windows/ModDetailsViewModel.cs +++ b/Knossos.NET/ViewModels/Windows/ModDetailsViewModel.cs @@ -283,7 +283,7 @@ private void LoadBanner(int selectedIndex) if (!string.IsNullOrEmpty(modVersions[selectedIndex].banner)) { HasBanner = true; - var bannerLocalPath = modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + modVersions[selectedIndex].banner; + var bannerLocalPath = Path.Combine(modVersions[selectedIndex].fullPath, modVersions[selectedIndex].banner ?? ""); if (System.IO.File.Exists(bannerLocalPath)) { var isApng = false; @@ -386,10 +386,10 @@ private void LoadScreenshots(int selectedIndex) { try { - if (System.IO.File.Exists(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + scn)) + if (System.IO.File.Exists(Path.Combine(modVersions[selectedIndex].fullPath, scn))) { Dispatcher.UIThread.Invoke(() => { - var item = new ScreenshotItem(modVersions[selectedIndex].fullPath + Path.DirectorySeparatorChar + scn); + var item = new ScreenshotItem(Path.Combine(modVersions[selectedIndex].fullPath, scn)); Screenshots.Add(item); }); }