diff --git a/MicroWin/AppState.cs b/MicroWin/AppState.cs index ffeb810..a22baf9 100755 --- a/MicroWin/AppState.cs +++ b/MicroWin/AppState.cs @@ -9,6 +9,7 @@ public static class AppState { public static string? IsoPath { get; set; } public static string TempRoot => Path.Combine(Path.GetTempPath(), "microwin"); + public static string TempRootlogs => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Temp", "microwin"); public static string MountPath => $"{Path.Combine(TempRoot, "mount")}"; public static string ScratchPath => $"{Path.Combine(TempRoot, "scratch")}"; public static int? SelectedImageIndex { get; set; } = 0; diff --git a/MicroWin/MainForm.cs b/MicroWin/MainForm.cs index ffc6c04..d7865f0 100755 --- a/MicroWin/MainForm.cs +++ b/MicroWin/MainForm.cs @@ -34,7 +34,7 @@ namespace MicroWin public partial class MainForm : Form { private const string swStatus = "stable"; - private const string appVer = "2.0.1"; + private const string appVer = "2.0.2"; private WizardPage CurrentWizardPage = new(); private List VerifyInPages = [ diff --git a/MicroWin/functions/Helpers/DynaLog/DynaLog.cs b/MicroWin/functions/Helpers/DynaLog/DynaLog.cs index 835d56f..304ffc8 100644 --- a/MicroWin/functions/Helpers/DynaLog/DynaLog.cs +++ b/MicroWin/functions/Helpers/DynaLog/DynaLog.cs @@ -42,7 +42,7 @@ private static void RemoveLogArchives() logMessage($"Removing archived logs older than {DYNALOG_LOG_ARCHIVE_RETENTION_MAXIMUM_THRESHOLD_DAYS_ABS} days...", false); try { - string[] LogArchives = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"), "MW_DynaLog_*.old", SearchOption.TopDirectoryOnly); + string[] LogArchives = Directory.GetFiles(Path.Combine(AppState.TempRootlogs, "logs"), "MW_DynaLog_*.old", SearchOption.TopDirectoryOnly); logMessage($"Archives found: {LogArchives.Length}"); if (LogArchives.Any()) { @@ -79,21 +79,21 @@ private static void RemoveLogArchives() public static void CheckLogAge() { logMessage("Checking existing logs...", false); - if (File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\logs\\MW_DynaLog.log")) + if (File.Exists($"{AppState.TempRootlogs}\\logs\\MW_DynaLog.log")) { logMessage("Log File Found. Checking log file creation DateTime...", false); try { - DateTime CreationDate = File.GetCreationTimeUtc($"{AppDomain.CurrentDomain.BaseDirectory}\\logs\\MW_DynaLog.log"); + DateTime CreationDate = File.GetCreationTimeUtc($"{AppState.TempRootlogs}\\logs\\MW_DynaLog.log"); if (CreationDate < DateTime.UtcNow.AddDays(DYNALOG_LOG_ARCHIVE_MINIMUM_THRESHOLD_DAYS)) { logMessage("Current log file is more than 2 weeks old. Archiving...", false); string ArchivedFileName = $"MW_DynaLog_{DateTime.UtcNow.ToString("yyMMdd-HHmm")}.old"; try { - File.Move("{AppDomain.CurrentDomain.BaseDirectory}\\logs\\MW_DynaLog.log", $"{AppDomain.CurrentDomain.BaseDirectory}\\logs\\{ArchivedFileName}"); + File.Move("{AppState.TempRootlogs}\\logs\\MW_DynaLog.log", $"{AppState.TempRootlogs}\\logs\\{ArchivedFileName}"); logMessage("The old log file has been archived. New messages will be shown in a new log file", false); // A blank sheet of... logs? - File.SetCreationTimeUtc($"{AppDomain.CurrentDomain.BaseDirectory}\\logs\\MW_DynaLog.log", DateTime.UtcNow); + File.SetCreationTimeUtc($"{AppState.TempRootlogs}\\logs\\MW_DynaLog.log", DateTime.UtcNow); } catch (Exception ex) { @@ -144,19 +144,19 @@ public static void logMessage(string message, bool getParentCaller = false) Debug.WriteLine(message); try { - if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"))) + if (!Directory.Exists(Path.Combine(AppState.TempRootlogs, "logs"))) { Debug.WriteLine("Creating log directory..."); - Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs")); + Directory.CreateDirectory(Path.Combine(AppState.TempRootlogs, "logs")); } long fileLength = 0L; - if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "MW_DynaLog.log"))) + if (File.Exists(Path.Combine(AppState.TempRootlogs, "logs", "MW_DynaLog.log"))) { - fileLength = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "MW_DynaLog.log")).Length; + fileLength = new FileInfo(Path.Combine(AppState.TempRootlogs, "logs", "MW_DynaLog.log")).Length; } string messagePrefix = $"[{DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture)}] [PID {Process.GetCurrentProcess().Id}] [{new StackFrame(1)?.GetMethod()?.Name}{(getParentCaller ? $" ({new StackFrame(2)?.GetMethod()?.Name})" : "")}] "; string messageLine = $"{messagePrefix}{message.Replace("\n", $"\n{messagePrefix}").Trim()}"; - File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs", "MW_DynaLog.log"), $"{(fileLength > 0 ? "\n" : "")}{messageLine}"); + File.AppendAllText(Path.Combine(AppState.TempRootlogs, "logs", "MW_DynaLog.log"), $"{(fileLength > 0 ? "\n" : "")}{messageLine}"); } catch (Exception ex) {