Merge pull request '[fix?:] windows paths (ai-based since windows is boring)' (#57) from windows-paths into main
Reviewed-on: #57 since this still works on any linux machines and theoretical on windows machines, we're merging it to prevent wrong commits cause i configured something wrong
This commit was merged in pull request #57.
This commit is contained in:
+13
-6
@@ -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<Global>(contents);
|
||||
_instance = JsonConvert.DeserializeObject<Global>(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
|
||||
|
||||
+33
-19
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -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<string?>(null);
|
||||
return File.ReadAllTextAsync(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user