From fee8fd932093aa466050fc49ea8fcdcf1912726b Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 27 Feb 2023 18:45:54 +0800 Subject: [PATCH] [exe] Use `Environment.CurrentDirectory` instead of overriding fs --- extra/exe-builder/FS.cs | 65 ----------------------------- extra/exe-builder/Program.cs | 6 +++ extra/exe-builder/UptimeKuma.csproj | 1 - 3 files changed, 6 insertions(+), 66 deletions(-) delete mode 100644 extra/exe-builder/FS.cs diff --git a/extra/exe-builder/FS.cs b/extra/exe-builder/FS.cs deleted file mode 100644 index 99a63694..00000000 --- a/extra/exe-builder/FS.cs +++ /dev/null @@ -1,65 +0,0 @@ -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/Program.cs b/extra/exe-builder/Program.cs index c120d6df..69cb1a73 100644 --- a/extra/exe-builder/Program.cs +++ b/extra/exe-builder/Program.cs @@ -21,6 +21,12 @@ namespace UptimeKuma { /// [STAThread] static void Main(string[] args) { + var cwd = Path.GetDirectoryName(Application.ExecutablePath); + + if (cwd != null) { + Environment.CurrentDirectory = cwd; + } + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new UptimeKumaApplicationContext()); diff --git a/extra/exe-builder/UptimeKuma.csproj b/extra/exe-builder/UptimeKuma.csproj index bd4e0dea..ecd6a46b 100644 --- a/extra/exe-builder/UptimeKuma.csproj +++ b/extra/exe-builder/UptimeKuma.csproj @@ -160,7 +160,6 @@ DownloadForm.cs -