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()
|
public static void Save()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(Global._instance.config_path))
|
if (!Directory.Exists(Global._instance.config_path))
|
||||||
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
Directory.CreateDirectory(Global._instance.config_path);
|
||||||
"logofclient"));
|
|
||||||
// if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path;
|
// if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path;
|
||||||
|
|
||||||
var json = JsonConvert.SerializeObject(_instance);
|
var json = JsonConvert.SerializeObject(_instance);
|
||||||
@@ -79,14 +78,14 @@ public class Global
|
|||||||
_instance = this;
|
_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string config_path { get; } = Path.Combine(
|
public string config_path { get; set; } = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
"logofclient");
|
"logofclient");
|
||||||
|
|
||||||
public void SetConfigPath(string path)
|
public void SetConfigPath(string path)
|
||||||
{
|
{
|
||||||
Path.Combine(
|
if (!string.IsNullOrWhiteSpace(path))
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
|
config_path = PathUtilities.NormalizeFileSystemPath(path);
|
||||||
}
|
}
|
||||||
public string wiki_storage_path { get; set; } = Path.Combine(
|
public string wiki_storage_path { get; set; } = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
@@ -121,7 +120,8 @@ public class Global
|
|||||||
var contents = File.ReadAllText(Path.Combine(
|
var contents = File.ReadAllText(Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
||||||
"global.config"));
|
"global.config"));
|
||||||
_instance = JsonConvert.DeserializeObject<Global>(contents);
|
_instance = JsonConvert.DeserializeObject<Global>(contents) ?? new Global();
|
||||||
|
_instance.NormalizePaths();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -130,6 +130,13 @@ public class Global
|
|||||||
Save();
|
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
|
public class Customers
|
||||||
|
|||||||
+33
-19
@@ -57,7 +57,7 @@ public partial class MainWindow : Window
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path))
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -275,7 +275,7 @@ public partial class MainWindow : Window
|
|||||||
{
|
{
|
||||||
try
|
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 (NavTree.SelectedItem is TreeViewItem treeItem && treeItem.Tag is WikiItem selectedItem)
|
||||||
{
|
{
|
||||||
if (selectedItem.IsFolder) return selectedItem.Path;
|
if (selectedItem.IsFolder) return selectedItem.Path;
|
||||||
@@ -294,6 +294,9 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
private static bool PathsEqual(string left, string right)
|
private static bool PathsEqual(string left, string right)
|
||||||
{
|
{
|
||||||
|
left = PathUtilities.NormalizeFileSystemPath(left);
|
||||||
|
right = PathUtilities.NormalizeFileSystemPath(right);
|
||||||
|
|
||||||
var normalizedLeft = Path.GetFullPath(left)
|
var normalizedLeft = Path.GetFullPath(left)
|
||||||
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
||||||
var normalizedRight = Path.GetFullPath(right)
|
var normalizedRight = Path.GetFullPath(right)
|
||||||
@@ -337,7 +340,7 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
private void OpenFolderButton_Click(object? sender, RoutedEventArgs e)
|
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;
|
if (!Directory.Exists(path)) return;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -364,9 +367,9 @@ public partial class MainWindow : Window
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (folder == null || folder.Count == 0) return;
|
if (folder == null || folder.Count == 0) return;
|
||||||
var chosen = folder[0].Path;
|
var chosen = PathUtilities.NormalizeFileSystemPath(folder[0].Path);
|
||||||
TbWikiPath.Text = chosen.ToString();
|
TbWikiPath.Text = chosen;
|
||||||
Global._instance.wiki_storage_path = chosen.ToString();
|
Global._instance.wiki_storage_path = chosen;
|
||||||
Global.Save();
|
Global.Save();
|
||||||
|
|
||||||
// reinit wiki service and reload tree
|
// reinit wiki service and reload tree
|
||||||
@@ -384,9 +387,9 @@ public partial class MainWindow : Window
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (folder == null || folder.Count == 0) return;
|
if (folder == null || folder.Count == 0) return;
|
||||||
var chosen = folder[0].Path;
|
var chosen = PathUtilities.NormalizeFileSystemPath(folder[0].Path);
|
||||||
TbFontPath.Text = chosen.ToString();
|
TbFontPath.Text = chosen;
|
||||||
Global._instance.font_path = chosen.ToString();
|
Global._instance.font_path = chosen;
|
||||||
Global.Save();
|
Global.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,8 +403,8 @@ public partial class MainWindow : Window
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (folder == null || folder.Count == 0) return;
|
if (folder == null || folder.Count == 0) return;
|
||||||
var chosen = folder[0].Path;
|
var chosen = PathUtilities.NormalizeFileSystemPath(folder[0].Path);
|
||||||
Global._instance.SetConfigPath(chosen.ToString());
|
Global._instance.SetConfigPath(chosen);
|
||||||
TbConfigPath.Text = Global._instance.config_path;
|
TbConfigPath.Text = Global._instance.config_path;
|
||||||
Global.Save();
|
Global.Save();
|
||||||
|
|
||||||
@@ -829,10 +832,7 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(filePath))
|
if (!string.IsNullOrWhiteSpace(filePath))
|
||||||
{
|
{
|
||||||
if (filePath.StartsWith("file://"))
|
filePath = PathUtilities.NormalizeFileSystemPath(filePath);
|
||||||
{
|
|
||||||
filePath = new Uri(filePath).LocalPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine($"PATH: {filePath}");
|
Console.WriteLine($"PATH: {filePath}");
|
||||||
|
|
||||||
@@ -1106,11 +1106,18 @@ public partial class MainWindow : Window
|
|||||||
result = result.Trim();
|
result = result.Trim();
|
||||||
if (!result.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) result += ".md";
|
if (!result.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) result += ".md";
|
||||||
|
|
||||||
if (!Directory.Exists(Global._instance.wiki_storage_path))
|
var wikiRoot = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path);
|
||||||
Directory.CreateDirectory(Global._instance.wiki_storage_path);
|
if (!Directory.Exists(wikiRoot))
|
||||||
|
Directory.CreateDirectory(wikiRoot);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (PathUtilities.HasInvalidFileNameChars(result))
|
||||||
|
{
|
||||||
|
MessageBox.Show(this, "Der Dateiname enthält ungültige Zeichen.", "Fehler");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var targetDirectory = GetSelectedWikiTargetDirectory();
|
var targetDirectory = GetSelectedWikiTargetDirectory();
|
||||||
Directory.CreateDirectory(targetDirectory);
|
Directory.CreateDirectory(targetDirectory);
|
||||||
var newFilePath = Path.Combine(targetDirectory, result);
|
var newFilePath = Path.Combine(targetDirectory, result);
|
||||||
@@ -1131,11 +1138,18 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
result = result.Trim();
|
result = result.Trim();
|
||||||
|
|
||||||
if (!Directory.Exists(Global._instance.wiki_storage_path))
|
var wikiRoot = PathUtilities.NormalizeFileSystemPath(Global._instance.wiki_storage_path);
|
||||||
Directory.CreateDirectory(Global._instance.wiki_storage_path);
|
if (!Directory.Exists(wikiRoot))
|
||||||
|
Directory.CreateDirectory(wikiRoot);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (PathUtilities.HasInvalidFileNameChars(result))
|
||||||
|
{
|
||||||
|
MessageBox.Show(this, "Der Ordnername enthält ungültige Zeichen.", "Fehler");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var targetDirectory = GetSelectedWikiTargetDirectory();
|
var targetDirectory = GetSelectedWikiTargetDirectory();
|
||||||
var newFolderPath = Path.Combine(targetDirectory, result);
|
var newFolderPath = Path.Combine(targetDirectory, result);
|
||||||
Directory.CreateDirectory(newFolderPath);
|
Directory.CreateDirectory(newFolderPath);
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ public partial class EditorWindow : Window
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.filename = filename;
|
this.filename = PathUtilities.NormalizeFileSystemPath(filename);
|
||||||
if (!string.IsNullOrWhiteSpace(filename) && File.Exists(filename))
|
if (!string.IsNullOrWhiteSpace(this.filename) && File.Exists(this.filename))
|
||||||
{
|
{
|
||||||
var content = TbContent;
|
var content = TbContent;
|
||||||
if (content != null) content.Text = File.ReadAllText(this.filename);
|
if (content != null) content.Text = File.ReadAllText(this.filename);
|
||||||
Title = "Wiki Editor - " + filename;
|
Title = "Wiki Editor - " + filename;
|
||||||
}
|
}
|
||||||
else if (!string.IsNullOrWhiteSpace(filename))
|
else if (!string.IsNullOrWhiteSpace(this.filename))
|
||||||
{
|
{
|
||||||
MessageBox.Show(null, "Die Datei existiert nicht", "Fehler");
|
MessageBox.Show(null, "Die Datei existiert nicht", "Fehler");
|
||||||
Close();
|
Close();
|
||||||
@@ -49,7 +49,8 @@ public partial class EditorWindow : Window
|
|||||||
private void BtnSaveAs_OnClick(object? sender, RoutedEventArgs e)
|
private void BtnSaveAs_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
MessageBox.Show(null,
|
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");
|
"Fehler");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -13,7 +13,7 @@ public class WikiService
|
|||||||
// prefer global wiki storage path if configured
|
// prefer global wiki storage path if configured
|
||||||
if (Global._instance != null && !string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path))
|
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)
|
WikiRootFullPath = Path.IsPathRooted(cfg)
|
||||||
? cfg
|
? cfg
|
||||||
: Path.Combine(Directory.GetCurrentDirectory(), cfg);
|
: Path.Combine(Directory.GetCurrentDirectory(), cfg);
|
||||||
@@ -25,8 +25,11 @@ public class WikiService
|
|||||||
wikiRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
wikiRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
"logofclient",
|
"logofclient",
|
||||||
"wiki");
|
"wiki");
|
||||||
|
wikiRoot = PathUtilities.NormalizeFileSystemPath(wikiRoot);
|
||||||
WikiRoot = wikiRoot;
|
WikiRoot = wikiRoot;
|
||||||
WikiRootFullPath = Path.Combine(Directory.GetCurrentDirectory(), wikiRoot);
|
WikiRootFullPath = Path.IsPathRooted(wikiRoot)
|
||||||
|
? wikiRoot
|
||||||
|
: Path.Combine(Directory.GetCurrentDirectory(), wikiRoot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user