Skip to content

Commit

Permalink
update structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeOgre committed Aug 31, 2024
1 parent b74692c commit 2c74125
Show file tree
Hide file tree
Showing 70 changed files with 8,850 additions and 0 deletions.
18 changes: 18 additions & 0 deletions App/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DevModManager.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<DevModManager.Properties.Settings>
<setting name="ProbingPaths" serializeAs="String">
<value>lib;locale</value>
</setting>
<setting name="version" serializeAs="String">
<value>0.0.8</value>
</setting>
</DevModManager.Properties.Settings>
</applicationSettings>
</configuration>
7 changes: 7 additions & 0 deletions App/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application x:Class="DevModManager.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<!-- Application resource dictionary -->
</Application.Resources>
</Application>
91 changes: 91 additions & 0 deletions App/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.Loader;
using System.Windows;

namespace DevModManager
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public App()
{
AssemblyLoadContext.Default.Resolving += OnAssemblyResolve;
}

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Debug.WriteLine("Application_Startup called");

try
{
// Set the probing paths before any other DLLs are loaded
string probingPaths = DevModManager.Properties.Settings.Default.ProbingPaths;
AppDomain.CurrentDomain.SetData("PROBING_DIRECTORIES", probingPaths);

// Initialize the database
Debug.WriteLine("Initializing database...");
DbManager.Instance.Initialize();
Debug.WriteLine("Database initialized.");

// Initialize the configuration
Debug.WriteLine("Initializing configuration...");
Config.Initialize();
Debug.WriteLine("Configuration initialized.");

// Check if the database is correctly initialized
if (DbManager.Instance.IsDatabaseInitialized())
{
// Open MainWindow if the database is initialized
Debug.WriteLine("Database initialized. Opening MainWindow.");
var mainWindow = new MainWindow();
mainWindow.Show();
}
else
{
// The DbManager should handle showing the SettingsWindow if needed
Debug.WriteLine("Database not initialized. DbManager will handle SettingsWindow.");
}
}
catch (Exception ex)
{
Debug.WriteLine($"Exception during startup: {ex.Message}");
_ = MessageBox.Show($"An error occurred during startup: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown();
}
}

private void RestartApplication()
{
var exePath = Process.GetCurrentProcess().MainModule?.FileName;
if (exePath != null)
{
_ = Process.Start(exePath);
Shutdown();
}
}

private static Assembly? OnAssemblyResolve(AssemblyLoadContext context, AssemblyName assemblyName)
{
string probingPaths = DevModManager.Properties.Settings.Default.ProbingPaths;
string[] paths = probingPaths.Split(';');

foreach (string path in paths)
{
string assemblyPath = Path.Combine(AppContext.BaseDirectory, path, $"{assemblyName.Name}.dll");

if (File.Exists(assemblyPath))
{
return context.LoadFromAssemblyPath(assemblyPath);
}
}

return null;
}
}
}
10 changes: 10 additions & 0 deletions App/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Loading

0 comments on commit 2c74125

Please sign in to comment.