From f05470249a8533b2f6578df9f0e998bbb3796186 Mon Sep 17 00:00:00 2001 From: Elias Fierke Date: Tue, 13 Jan 2026 20:46:22 +0100 Subject: [PATCH] [chore:] code cleanup --- Wiki/WikiService.cs | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Wiki/WikiService.cs b/Wiki/WikiService.cs index a7f40c0..4a14833 100644 --- a/Wiki/WikiService.cs +++ b/Wiki/WikiService.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -7,10 +8,7 @@ namespace Logof_Client.Wiki; public class WikiService { - public string WikiRoot { get; } - public string WikiRootFullPath { get; } - - public WikiService(string wikiRoot = "wiki") + public WikiService(string wikiRoot = null) { // prefer global wiki storage path if configured if (Global._instance != null && !string.IsNullOrWhiteSpace(Global._instance.wiki_storage_path)) @@ -23,11 +21,18 @@ public class WikiService } else { + if (wikiRoot == null) + wikiRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + "logofclient", + "wiki"); WikiRoot = wikiRoot; WikiRootFullPath = Path.Combine(Directory.GetCurrentDirectory(), wikiRoot); } } + public string WikiRoot { get; } + public string WikiRootFullPath { get; } + public List GetRootItems() { var list = new List(); @@ -37,16 +42,11 @@ public class WikiService var dirInfo = new DirectoryInfo(WikiRootFullPath); // Add folders - foreach (var dir in dirInfo.GetDirectories()) - { - list.Add(BuildFolderItem(dir)); - } + foreach (var dir in dirInfo.GetDirectories()) list.Add(BuildFolderItem(dir)); // Add files in root foreach (var file in dirInfo.GetFiles("*.md")) - { list.Add(new WikiItem { Name = file.Name, Path = file.FullName, IsFolder = false }); - } return list.OrderBy(i => i.IsFolder ? 0 : 1).ToList(); } @@ -55,15 +55,10 @@ public class WikiService { var node = new WikiItem { Name = dir.Name, Path = dir.FullName, IsFolder = true }; - foreach (var subdir in dir.GetDirectories()) - { - node.Children.Add(BuildFolderItem(subdir)); - } + foreach (var subdir in dir.GetDirectories()) node.Children.Add(BuildFolderItem(subdir)); foreach (var file in dir.GetFiles("*.md")) - { node.Children.Add(new WikiItem { Name = file.Name, Path = file.FullName, IsFolder = false }); - } return node; } @@ -73,4 +68,4 @@ public class WikiService if (!File.Exists(path)) return Task.FromResult(null); return File.ReadAllTextAsync(path); } -} +} \ No newline at end of file