Program.cs refactor

This commit is contained in:
2022-05-30 10:47:57 +02:00
parent 3f0c17b6cc
commit e9ed2c01e6

View File

@@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection;
using Avalonia; using Avalonia;
using Avalonia.ReactiveUI; using Avalonia.ReactiveUI;
@@ -7,16 +9,26 @@ namespace FileTime.GuiApp.App;
public static class Program public static class Program
{ {
public static string AppDataRoot { get; } public static string AppDataRoot { get; private set; }
public static string EnvironmentName { get; } public static string EnvironmentName { get; private set; }
static Program() static Program()
{ {
#if DEBUG #if DEBUG
EnvironmentName = "Development"; InitDevelopment();
AppDataRoot = Path.Combine(Environment.CurrentDirectory, "appdata");
#else #else
InitRelease();
#endif
void InitDevelopment()
{
EnvironmentName = "Development";
AppDataRoot = Path.Combine(Environment.CurrentDirectory, "appdata");
}
void InitRelease()
{
EnvironmentName = "Release"; EnvironmentName = "Release";
var possibleDataRootsPaths = new List<string>() var possibleDataRootsPaths = new List<string>()
@@ -37,12 +49,13 @@ public static class Program
appDataRoot = possibleAppDataRoot; appDataRoot = possibleAppDataRoot;
break; break;
} }
catch { } catch
{
}
} }
if (appDataRoot == null) throw new UnauthorizedAccessException(); AppDataRoot = appDataRoot ?? throw new UnauthorizedAccessException();
AppDataRoot = appDataRoot; }
#endif
} }
// Initialization code. Don't use any Avalonia, third-party APIs or any // Initialization code. Don't use any Avalonia, third-party APIs or any