-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
81 lines (71 loc) · 2.55 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using BauphysikToolWPF.Models;
using BauphysikToolWPF.Repository;
using BauphysikToolWPF.Services;
using BauphysikToolWPF.SessionData;
using BT.Logging;
using System;
using System.IO;
using System.Windows;
namespace BauphysikToolWPF
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
#region Logging Setup
try
{
Logger.SetLogFilePath();
Logger.ClearLog();
}
catch (Exception exception)
{
Console.WriteLine($"Error during Logging Setup: {exception}");
}
#endregion
if (e.Args.Length > 0)
{
Logger.LogInfo($"Opening Application with Arguments: {e.Args}");
string filePath = e.Args[0];
if (File.Exists(filePath))
{
try
{
// Load the project from the specified file
Project loadedProject = ApplicationServices.LoadProjectFromFile(filePath);
UserSaved.SelectedProject = loadedProject;
UserSaved.ProjectFilePath = filePath;
Logger.LogInfo($"Loaded Project: '{UserSaved.SelectedProject}' from Arguments!");
}
catch (Exception ex)
{
Logger.LogError($"Error reading Project from Arguments: {ex.Message}");
}
}
else
{
Logger.LogWarning($"File does not exist: {filePath}");
}
}
else
{
Logger.LogInfo("Opened Application without Arguments");
UserSaved.SelectedProject = DatabaseAccess.QueryProjectById(1);
Logger.LogInfo($"Loaded Project: '{UserSaved.SelectedProject}' from Database!");
}
}
protected override void OnExit(ExitEventArgs e)
{
Logger.LogInfo($"Checking for Updates...");
Updater.CheckForUpdates();
Logger.LogInfo($"Closing Application with ExitCode: {e.ApplicationExitCode}");
}
// cmd test:
//
// "C:\Users\arnes\source\repos\BauphysikToolWPF\bin\Debug\net8.0-windows10.0.22621.0\BauphysikToolWPF.exe" "C:\Users\arnes\Desktop\project.btk"
}
}