Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MicroWin/AppState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion MicroWin/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WizardPage.Page> VerifyInPages = [
Expand Down
20 changes: 10 additions & 10 deletions MicroWin/functions/Helpers/DynaLog/DynaLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
Loading