From b3ab21ae38bcffdd62ed3a94267168faac1289e6 Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Mon, 18 May 2026 11:42:32 +0200 Subject: [PATCH] [fix?:] windows paths (ai-based since windows is boring) --- DataStore/Settings.cs | 19 +++++++++----- MainWindow.axaml.cs | 52 ++++++++++++++++++++++++-------------- Wiki/EditorWindow.axaml.cs | 11 ++++---- Wiki/WikiService.cs | 9 ++++--- 4 files changed, 58 insertions(+), 33 deletions(-) diff --git a/DataStore/Settings.cs b/DataStore/Settings.cs index cee3058..e769fd8 100644 --- a/DataStore/Settings.cs +++ b/DataStore/Settings.cs @@ -24,8 +24,7 @@ public class Settings public static void Save() { if (!Directory.Exists(Global._instance.config_path)) - Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - "logofclient")); + Directory.CreateDirectory(Global._instance.config_path); // if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path; var json = JsonConvert.SerializeObject(_instance); @@ -79,14 +78,14 @@ public class Global _instance = this; } - public string config_path { get; } = Path.Combine( + public string config_path { get; set; } = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient"); public void SetConfigPath(string path) { - Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); + if (!string.IsNullOrWhiteSpace(path)) + config_path = PathUtilities.NormalizeFileSystemPath(path); } public string wiki_storage_path { get; set; } = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @@ -121,7 +120,8 @@ public class Global var contents = File.ReadAllText(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient", "global.config")); - _instance = JsonConvert.DeserializeObject(contents); + _instance = JsonConvert.DeserializeObject(contents) ?? new Global(); + _instance.NormalizePaths(); } catch (Exception ex) { @@ -130,6 +130,13 @@ public class Global Save(); } } + + private void NormalizePaths() + { + config_path = PathUtilities.NormalizeFileSystemPath(config_path); + wiki_storage_path = PathUtilities.NormalizeFileSystemPath(wiki_storage_path); + font_path = PathUtilities.NormalizeFileSystemPath(font_path); + } } public class Customers diff --git a/MainWindow.axaml.cs b/MainWindow.axaml.cs index f3581f3..c1c5b56 100644 --- a/MainWindow.axaml.cs +++ b/MainWindow.axaml.cs @@ -57,7 +57,7 @@ public partial class MainWindow : Window try { if (!string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path)) - TbWikiPath.Text = Global._instance.wiki_storage_path; + TbWikiPath.Text = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path); } catch (Exception ex) { @@ -275,7 +275,7 @@ public partial class MainWindow : Window { try { - var wikiRoot = Global._instance.wiki_storage_path; + var wikiRoot = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path); if (NavTree.SelectedItem is TreeViewItem treeItem && treeItem.Tag is WikiItem selectedItem) { if (selectedItem.IsFolder) return selectedItem.Path; @@ -294,6 +294,9 @@ public partial class MainWindow : Window private static bool PathsEqual(string left, string right) { + left = PathUtilities.NormalizeFileSystemPath(left); + right = PathUtilities.NormalizeFileSystemPath(right); + var normalizedLeft = Path.GetFullPath(left) .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); var normalizedRight = Path.GetFullPath(right) @@ -337,7 +340,7 @@ public partial class MainWindow : Window private void OpenFolderButton_Click(object? sender, RoutedEventArgs e) { - var path = Global._instance.wiki_storage_path; + var path = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path); if (!Directory.Exists(path)) return; try @@ -364,9 +367,9 @@ public partial class MainWindow : Window }); if (folder == null || folder.Count == 0) return; - var chosen = folder[0].Path; - TbWikiPath.Text = chosen.ToString(); - Global._instance.wiki_storage_path = chosen.ToString(); + var chosen = PathUtilities.NormalizeFileSystemPath(folder[0].Path); + TbWikiPath.Text = chosen; + Global._instance.wiki_storage_path = chosen; Global.Save(); // reinit wiki service and reload tree @@ -384,9 +387,9 @@ public partial class MainWindow : Window }); if (folder == null || folder.Count == 0) return; - var chosen = folder[0].Path; - TbFontPath.Text = chosen.ToString(); - Global._instance.font_path = chosen.ToString(); + var chosen = PathUtilities.NormalizeFileSystemPath(folder[0].Path); + TbFontPath.Text = chosen; + Global._instance.font_path = chosen; Global.Save(); } @@ -400,8 +403,8 @@ public partial class MainWindow : Window }); if (folder == null || folder.Count == 0) return; - var chosen = folder[0].Path; - Global._instance.SetConfigPath(chosen.ToString()); + var chosen = PathUtilities.NormalizeFileSystemPath(folder[0].Path); + Global._instance.SetConfigPath(chosen); TbConfigPath.Text = Global._instance.config_path; Global.Save(); @@ -829,10 +832,7 @@ public partial class MainWindow : Window if (!string.IsNullOrWhiteSpace(filePath)) { - if (filePath.StartsWith("file://")) - { - filePath = new Uri(filePath).LocalPath; - } + filePath = PathUtilities.NormalizeFileSystemPath(filePath); Console.WriteLine($"PATH: {filePath}"); @@ -1106,11 +1106,18 @@ public partial class MainWindow : Window result = result.Trim(); if (!result.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) result += ".md"; - if (!Directory.Exists(Global._instance.wiki_storage_path)) - Directory.CreateDirectory(Global._instance.wiki_storage_path); + var wikiRoot = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path); + if (!Directory.Exists(wikiRoot)) + Directory.CreateDirectory(wikiRoot); try { + if (PathUtilities.HasInvalidFileNameChars(result)) + { + MessageBox.Show(this, "Der Dateiname enthält ungültige Zeichen.", "Fehler"); + return; + } + var targetDirectory = GetSelectedWikiTargetDirectory(); Directory.CreateDirectory(targetDirectory); var newFilePath = Path.Combine(targetDirectory, result); @@ -1131,11 +1138,18 @@ public partial class MainWindow : Window result = result.Trim(); - if (!Directory.Exists(Global._instance.wiki_storage_path)) - Directory.CreateDirectory(Global._instance.wiki_storage_path); + var wikiRoot = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path); + if (!Directory.Exists(wikiRoot)) + Directory.CreateDirectory(wikiRoot); try { + if (PathUtilities.HasInvalidFileNameChars(result)) + { + MessageBox.Show(this, "Der Ordnername enthält ungültige Zeichen.", "Fehler"); + return; + } + var targetDirectory = GetSelectedWikiTargetDirectory(); var newFolderPath = Path.Combine(targetDirectory, result); Directory.CreateDirectory(newFolderPath); diff --git a/Wiki/EditorWindow.axaml.cs b/Wiki/EditorWindow.axaml.cs index 4ff8fc4..e0fe836 100644 --- a/Wiki/EditorWindow.axaml.cs +++ b/Wiki/EditorWindow.axaml.cs @@ -14,14 +14,14 @@ public partial class EditorWindow : Window try { InitializeComponent(); - this.filename = filename; - if (!string.IsNullOrWhiteSpace(filename) && File.Exists(filename)) + this.filename = PathUtilities.NormalizeFileSystemPath(filename); + if (!string.IsNullOrWhiteSpace(this.filename) && File.Exists(this.filename)) { var content = TbContent; if (content != null) content.Text = File.ReadAllText(this.filename); Title = "Wiki Editor - " + filename; } - else if (!string.IsNullOrWhiteSpace(filename)) + else if (!string.IsNullOrWhiteSpace(this.filename)) { MessageBox.Show(null, "Die Datei existiert nicht", "Fehler"); Close(); @@ -49,7 +49,8 @@ public partial class EditorWindow : Window private void BtnSaveAs_OnClick(object? sender, RoutedEventArgs e) { MessageBox.Show(null, - "Feature noch nicht implemetiert.\nErstelle neue Dateien unter " + Global._instance.wiki_storage_path, + "Feature noch nicht implemetiert.\nErstelle neue Dateien unter " + + PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path), "Fehler"); } @@ -65,4 +66,4 @@ public partial class EditorWindow : Window MainWindow._instance.PopulateNavTree(); Close(); } -} \ No newline at end of file +} diff --git a/Wiki/WikiService.cs b/Wiki/WikiService.cs index 4a14833..afe3b23 100644 --- a/Wiki/WikiService.cs +++ b/Wiki/WikiService.cs @@ -13,7 +13,7 @@ public class WikiService // prefer global wiki storage path if configured if (Global._instance != null && !string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path)) { - var cfg = Global._instance.wiki_storage_path; + var cfg = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path); WikiRootFullPath = Path.IsPathRooted(cfg) ? cfg : Path.Combine(Directory.GetCurrentDirectory(), cfg); @@ -25,8 +25,11 @@ public class WikiService wikiRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient", "wiki"); + wikiRoot = PathUtilities.NormalizeFileSystemPath(wikiRoot); WikiRoot = wikiRoot; - WikiRootFullPath = Path.Combine(Directory.GetCurrentDirectory(), wikiRoot); + WikiRootFullPath = Path.IsPathRooted(wikiRoot) + ? wikiRoot + : Path.Combine(Directory.GetCurrentDirectory(), wikiRoot); } } @@ -68,4 +71,4 @@ public class WikiService if (!File.Exists(path)) return Task.FromResult(null); return File.ReadAllTextAsync(path); } -} \ No newline at end of file +}