[chore:] code cleanup
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -7,10 +8,7 @@ namespace Logof_Client.Wiki;
|
|||||||
|
|
||||||
public class WikiService
|
public class WikiService
|
||||||
{
|
{
|
||||||
public string WikiRoot { get; }
|
public WikiService(string wikiRoot = null)
|
||||||
public string WikiRootFullPath { get; }
|
|
||||||
|
|
||||||
public WikiService(string wikiRoot = "wiki")
|
|
||||||
{
|
{
|
||||||
// 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))
|
||||||
@@ -23,11 +21,18 @@ public class WikiService
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (wikiRoot == null)
|
||||||
|
wikiRoot = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"logofclient",
|
||||||
|
"wiki");
|
||||||
WikiRoot = wikiRoot;
|
WikiRoot = wikiRoot;
|
||||||
WikiRootFullPath = Path.Combine(Directory.GetCurrentDirectory(), wikiRoot);
|
WikiRootFullPath = Path.Combine(Directory.GetCurrentDirectory(), wikiRoot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string WikiRoot { get; }
|
||||||
|
public string WikiRootFullPath { get; }
|
||||||
|
|
||||||
public List<WikiItem> GetRootItems()
|
public List<WikiItem> GetRootItems()
|
||||||
{
|
{
|
||||||
var list = new List<WikiItem>();
|
var list = new List<WikiItem>();
|
||||||
@@ -37,16 +42,11 @@ public class WikiService
|
|||||||
var dirInfo = new DirectoryInfo(WikiRootFullPath);
|
var dirInfo = new DirectoryInfo(WikiRootFullPath);
|
||||||
|
|
||||||
// Add folders
|
// Add folders
|
||||||
foreach (var dir in dirInfo.GetDirectories())
|
foreach (var dir in dirInfo.GetDirectories()) list.Add(BuildFolderItem(dir));
|
||||||
{
|
|
||||||
list.Add(BuildFolderItem(dir));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add files in root
|
// Add files in root
|
||||||
foreach (var file in dirInfo.GetFiles("*.md"))
|
foreach (var file in dirInfo.GetFiles("*.md"))
|
||||||
{
|
|
||||||
list.Add(new WikiItem { Name = file.Name, Path = file.FullName, IsFolder = false });
|
list.Add(new WikiItem { Name = file.Name, Path = file.FullName, IsFolder = false });
|
||||||
}
|
|
||||||
|
|
||||||
return list.OrderBy(i => i.IsFolder ? 0 : 1).ToList();
|
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 };
|
var node = new WikiItem { Name = dir.Name, Path = dir.FullName, IsFolder = true };
|
||||||
|
|
||||||
foreach (var subdir in dir.GetDirectories())
|
foreach (var subdir in dir.GetDirectories()) node.Children.Add(BuildFolderItem(subdir));
|
||||||
{
|
|
||||||
node.Children.Add(BuildFolderItem(subdir));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var file in dir.GetFiles("*.md"))
|
foreach (var file in dir.GetFiles("*.md"))
|
||||||
{
|
|
||||||
node.Children.Add(new WikiItem { Name = file.Name, Path = file.FullName, IsFolder = false });
|
node.Children.Add(new WikiItem { Name = file.Name, Path = file.FullName, IsFolder = false });
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -73,4 +68,4 @@ public class WikiService
|
|||||||
if (!File.Exists(path)) return Task.FromResult<string?>(null);
|
if (!File.Exists(path)) return Task.FromResult<string?>(null);
|
||||||
return File.ReadAllTextAsync(path);
|
return File.ReadAllTextAsync(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user