[chore:] code cleanup
This commit is contained in:
@@ -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<WikiItem> GetRootItems()
|
||||
{
|
||||
var list = new List<WikiItem>();
|
||||
@@ -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<string?>(null);
|
||||
return File.ReadAllTextAsync(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user