mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge pull request #774 from Noggog/init-standardization
Standardized Init/Warmup into one place
This commit is contained in:
commit
a92d4c141d
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wabbajack.Common.StoreHandlers
|
||||
{
|
||||
@ -13,7 +14,7 @@ namespace Wabbajack.Common.StoreHandlers
|
||||
|
||||
public class StoreHandler
|
||||
{
|
||||
private static readonly Lazy<StoreHandler> _instance = new Lazy<StoreHandler>(() => new StoreHandler(), true);
|
||||
private static readonly Lazy<StoreHandler> _instance = new Lazy<StoreHandler>(() => new StoreHandler(), isThreadSafe: true);
|
||||
public static StoreHandler Instance => _instance.Value;
|
||||
|
||||
private static readonly Lazy<SteamHandler> _steamHandler = new Lazy<SteamHandler>(() => new SteamHandler());
|
||||
@ -72,6 +73,11 @@ namespace Wabbajack.Common.StoreHandlers
|
||||
{
|
||||
return StoreGames.FirstOrDefault(g => g.Game == game)?.Path;
|
||||
}
|
||||
|
||||
public static void Warmup()
|
||||
{
|
||||
Task.Run(() => _instance.Value).FireAndForget();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AStoreGame
|
||||
|
@ -18,7 +18,10 @@ namespace Wabbajack.Common
|
||||
_cleanTask = Task.Run(() => "tmp_files".RelativeTo(AbsolutePath.EntryPoint).DeleteDirectory());
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
/// <summary>
|
||||
/// Starts the initialization in a background task
|
||||
/// </summary>
|
||||
public static void Warmup()
|
||||
{
|
||||
// Nothing to do, as work is done in static ctor
|
||||
}
|
||||
|
@ -1,15 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.StoreHandlers;
|
||||
using Wabbajack.Util;
|
||||
|
||||
namespace Wabbajack
|
||||
{
|
||||
@ -23,7 +14,6 @@ namespace Wabbajack
|
||||
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
|
||||
if (CLIArguments.Help)
|
||||
CLIOld.DisplayHelpText();
|
||||
var storeHandler = new StoreHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Windows;
|
||||
using MahApps.Metro.Controls;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Common.StoreHandlers;
|
||||
using Wabbajack.Lib.LibCefHelpers;
|
||||
using Wabbajack.Util;
|
||||
using Application = System.Windows.Application;
|
||||
@ -23,8 +24,6 @@ namespace Wabbajack
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
TempFolder.Init();
|
||||
Helpers.Init();
|
||||
// Wire any unhandled crashing exceptions to log before exiting
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
|
||||
{
|
||||
@ -44,22 +43,7 @@ namespace Wabbajack
|
||||
Utils.Log(
|
||||
$"System settings - ({p.SystemMemorySize.ToFileSizeString()} RAM), Display: {p.ScreenWidth} x {p.ScreenHeight} ({p.VideoMemorySize.ToFileSizeString()} VRAM - VideoMemorySizeMb={p.EnbLEVRAMSize})");
|
||||
|
||||
// Run logic to associate wabbajack lists with this app in the background
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
try
|
||||
{
|
||||
if (!ModListAssociationManager.IsAssociated() || ModListAssociationManager.NeedsUpdating(appPath))
|
||||
{
|
||||
ModListAssociationManager.Associate(appPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utils.Log($"ExtensionManager had an exception:\n{e}");
|
||||
}
|
||||
}).FireAndForget();
|
||||
Warmup();
|
||||
|
||||
// Load settings
|
||||
if (CLIArguments.NoSettings || !MainSettings.TryLoadTypicalSettings(out var settings))
|
||||
@ -100,6 +84,40 @@ namespace Wabbajack
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts some background initialization tasks spinning so they're already prepped when actually needed
|
||||
/// </summary>
|
||||
private void Warmup()
|
||||
{
|
||||
TempFolder.Warmup();
|
||||
// ToDo
|
||||
// Currently this is a blocking call. Perhaps upgrade to be run in a background task.
|
||||
// Would first need to ensure users of CEF properly await the background initialization before use
|
||||
Helpers.Init();
|
||||
StoreHandler.Warmup();
|
||||
|
||||
Task.Run(AssociateListsWithWabbajack).FireAndForget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Run logic to associate wabbajack lists with this app in the background
|
||||
/// </summary>
|
||||
private void AssociateListsWithWabbajack()
|
||||
{
|
||||
var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
try
|
||||
{
|
||||
if (!ModListAssociationManager.IsAssociated() || ModListAssociationManager.NeedsUpdating(appPath))
|
||||
{
|
||||
ModListAssociationManager.Associate(appPath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Utils.Log($"ExtensionManager had an exception:\n{e}");
|
||||
}
|
||||
}
|
||||
|
||||
private void RunWhenLoaded(Action a)
|
||||
{
|
||||
if (IsLoaded)
|
||||
|
Loading…
Reference in New Issue
Block a user