From 02ddb58686a56146aa3545307067350a45eb2de5 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Tue, 21 Feb 2023 15:16:54 +0800 Subject: [PATCH] Fix cwd issues --- extra/exe-builder/FS.cs | 65 +++++++++++++++++++++++++++++ extra/exe-builder/UptimeKuma.csproj | 1 + 2 files changed, 66 insertions(+) create mode 100644 extra/exe-builder/FS.cs diff --git a/extra/exe-builder/FS.cs b/extra/exe-builder/FS.cs new file mode 100644 index 00000000..99a63694 --- /dev/null +++ b/extra/exe-builder/FS.cs @@ -0,0 +1,65 @@ +using System.IO; +using System.Reflection; + +namespace UptimeKuma { + + /** + * Current Directory using App location + */ + public class Directory { + private static string baseDir; + + public static string FullPath(string path) { + return Path.Combine(GetBaseDir(), path); + } + + public static string GetBaseDir() { + if (baseDir == null) { + baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + } + return baseDir; + } + + public static bool Exists(string path) { + return System.IO.Directory.Exists(FullPath(path)); + } + + public static void Delete(string path, bool recursive) { + System.IO.Directory.Delete(FullPath(path), recursive); + } + + public static void Move(string src, string dest) { + System.IO.Directory.Move(FullPath(src), FullPath(dest)); + } + + public static string[] GetDirectories(string path) { + return System.IO.Directory.GetDirectories(FullPath(path)); + } + } + + public class File { + + private static string FullPath(string path) { + return Directory.FullPath(path); + } + public static bool Exists(string path) { + return System.IO.File.Exists(FullPath(path)); + } + + public static FileStream Create(string path) { + return System.IO.File.Create(FullPath(path)); + } + + public static string ReadAllText(string path) { + return System.IO.File.ReadAllText(FullPath(path)); + } + + public static void Delete(string path) { + System.IO.File.Delete(FullPath(path)); + } + + public static void WriteAllText(string path, string content) { + System.IO.File.WriteAllText(FullPath(path), content); + } + } +} diff --git a/extra/exe-builder/UptimeKuma.csproj b/extra/exe-builder/UptimeKuma.csproj index 6b7534af..1b484d7a 100644 --- a/extra/exe-builder/UptimeKuma.csproj +++ b/extra/exe-builder/UptimeKuma.csproj @@ -148,6 +148,7 @@ DownloadForm.cs +