Exemplo n.º 1
0
        public static bool TryLoadTypicalSettings(out MainSettings settings)
        {
            if (!Consts.SettingsFile.Exists)
            {
                settings = default;
                return(false);
            }

            // Version check
            try
            {
                settings = Consts.SettingsFile.FromJson <MainSettings>();
                if (settings.Version == Consts.SettingsVersion)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Utils.Error(ex, "Error loading settings");
            }

            var backup = Consts.SettingsFile.AppendToName("-backup");

            backup.Delete();

            Consts.SettingsFile.CopyTo(backup);
            Consts.SettingsFile.Delete();

            settings = default;
            return(false);
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            // Wire any unhandled crashing exceptions to log before exiting
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                // Don't do any special logging side effects
                Wabbajack.Common.Utils.Error(((Exception)e.ExceptionObject), "Uncaught error");
            };

            Wabbajack.Common.Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");

            // Run some init tasks in background
            Task.Run(async() =>
            {
                await Helpers.Initialize();
                var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                try
                {
                    if (!ExtensionManager.IsAssociated() || ExtensionManager.NeedsUpdating(appPath))
                    {
                        ExtensionManager.Associate(appPath);
                    }
                }
                catch (Exception e)
                {
                    Utils.Log($"ExtensionManager had an exception:\n{e}");
                }
            }).FireAndForget();

            // Load settings
            string[] args = Environment.GetCommandLineArgs();
            if ((args.Length > 1 && args[1] == "nosettings") ||
                !MainSettings.TryLoadTypicalSettings(out var settings))
            {
                _settings = new MainSettings();
                RunWhenLoaded(DefaultSettings);
            }
            else
            {
                _settings = settings;
                RunWhenLoaded(LoadSettings);
            }

            // Set datacontext
            _mwvm       = new MainWindowVM(this, _settings);
            DataContext = _mwvm;

            // Bring window to the front if it isn't already
            this.Initialized += (s, e) =>
            {
                this.Activate();
                this.Topmost = true;
                this.Focus();
            };
            this.ContentRendered += (s, e) =>
            {
                this.Topmost = false;
            };
        }
Exemplo n.º 3
0
        public MainWindowVM(MainWindow mainWindow, MainSettings settings)
        {
            MainWindow               = mainWindow;
            ViewDispatcher           = MainWindow.Dispatcher;
            Settings                 = settings;
            Installer                = new Lazy <InstallerVM>(() => new InstallerVM(this));
            Compiler                 = new Lazy <CompilerVM>(() => new CompilerVM(this));
            Gallery                  = new Lazy <ModListGalleryVM>(() => new ModListGalleryVM(this));
            ModeSelectionVM          = new ModeSelectionVM(this);
            UserInterventionHandlers = new UserInterventionHandlers(this);

            // Set up logging
            Utils.LogMessages
            .ObserveOn(RxApp.TaskpoolScheduler)
            .ToObservableChangeSet()
            .Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
            .Where(l => l.Count > 0)
            .ObserveOn(RxApp.MainThreadScheduler)
            .FlattenBufferResult()
            .Bind(Log)
            .Subscribe()
            .DisposeWith(CompositeDisposable);

            Utils.LogMessages
            .OfType <IUserIntervention>()
            .ObserveOnGuiThread()
            .SelectTask(msg => UserInterventionHandlers.Handle(msg))
            .Subscribe()
            .DisposeWith(CompositeDisposable);

            if (IsStartingFromModlist(out var path))
            {
                Installer.Value.ModListLocation.TargetPath = path;
                ActivePane = Installer.Value;
            }
            else
            {
                // Start on mode selection
                ActivePane = ModeSelectionVM;
            }

            try
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
                FileVersionInfo            fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                VersionDisplay = $"v{fvi.FileVersion}";
            }
            catch (Exception ex)
            {
                Utils.Error(ex);
                VersionDisplay = "ERROR";
            }
            CopyVersionCommand = ReactiveCommand.Create(() =>
            {
                Clipboard.SetText($"Wabbajack {VersionDisplay}\n{ThisAssembly.Git.Sha}");
            });
        }
Exemplo n.º 4
0
        public MainWindow()
        {
            // Wire any unhandled crashing exceptions to log before exiting
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                // Don't do any special logging side effects
                Utils.Error(((Exception)e.ExceptionObject), "Uncaught error");
            };

            Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
            var p = SystemParametersConstructor.Create();

            Utils.Log($"Detected Windows Version: {p.WindowsVersion}");

            if (!(p.WindowsVersion.Major >= 6 && p.WindowsVersion.Minor >= 2))
            {
                Utils.Log(
                    $"You are not running a recent version of Windows (version 10 or greater), Wabbajack is not supported on OS versions older than Windows 10.");
            }

            Utils.Log(
                $"System settings - ({p.SystemMemorySize.ToFileSizeString()} RAM), Display: {p.ScreenWidth} x {p.ScreenHeight} ({p.VideoMemorySize.ToFileSizeString()} VRAM - VideoMemorySizeMb={p.EnbLEVRAMSize})");

            Warmup();

            var(settings, loadedSettings) = MainSettings.TryLoadTypicalSettings().AsTask().Result;
            // Load settings
            if (CLIArguments.NoSettings || !loadedSettings)
            {
                _settings = new MainSettings
                {
                    Version = Consts.SettingsVersion
                };
                RunWhenLoaded(DefaultSettings);
            }
            else
            {
                _settings = settings;
                RunWhenLoaded(LoadSettings);
            }

            // Set datacontext
            _mwvm       = new MainWindowVM(this, _settings);
            DataContext = _mwvm;

            // Bring window to the front if it isn't already
            this.Initialized += (s, e) =>
            {
                this.Activate();
                this.Topmost = true;
                this.Focus();
            };
            this.ContentRendered += (s, e) =>
            {
                this.Topmost = false;
            };
        }
Exemplo n.º 5
0
        public MainWindow()
        {
            Helpers.Init();
            // Wire any unhandled crashing exceptions to log before exiting
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                // Don't do any special logging side effects
                Utils.Error(((Exception)e.ExceptionObject), "Uncaught error");
            };

            Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");

            // 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();

            // Load settings
            if (CLIArguments.NoSettings || !MainSettings.TryLoadTypicalSettings(out var settings))
            {
                _settings = new MainSettings();
                RunWhenLoaded(DefaultSettings);
            }
            else
            {
                _settings = settings;
                RunWhenLoaded(LoadSettings);
            }

            // Set datacontext
            _mwvm       = new MainWindowVM(this, _settings);
            DataContext = _mwvm;

            // Bring window to the front if it isn't already
            this.Initialized += (s, e) =>
            {
                this.Activate();
                this.Topmost = true;
                this.Focus();
            };
            this.ContentRendered += (s, e) =>
            {
                this.Topmost = false;
            };
        }
Exemplo n.º 6
0
 public void ShutdownApplication()
 {
     Dispose();
     Settings.PosX   = MainWindow.Left;
     Settings.PosY   = MainWindow.Top;
     Settings.Width  = MainWindow.Width;
     Settings.Height = MainWindow.Height;
     MainSettings.SaveSettings(Settings);
     Application.Current.Shutdown();
 }
Exemplo n.º 7
0
 public static bool TryLoadTypicalSettings(out MainSettings settings)
 {
     if (!File.Exists(_filename))
     {
         settings = default;
         return(false);
     }
     settings = JsonConvert.DeserializeObject <MainSettings>(File.ReadAllText(_filename));
     return(true);
 }
Exemplo n.º 8
0
        public static void SaveSettings(MainSettings settings)
        {
            settings._saveSignal.OnNext(Unit.Default);

            // Might add this if people are putting save work on other threads or other
            // things that delay the operation.
            //settings._saveSignal.OnCompleted();
            //await settings._saveSignal;

            File.WriteAllText(_filename, JsonConvert.SerializeObject(settings, Formatting.Indented));
        }
Exemplo n.º 9
0
        public static void SaveSettings(MainSettings settings)
        {
            settings._saveSignal.OnNext(Unit.Default);

            // Might add this if people are putting save work on other threads or other
            // things that delay the operation.
            //settings._saveSignal.OnCompleted();
            //await settings._saveSignal;

            settings.ToJson(Consts.SettingsFile);
        }
Exemplo n.º 10
0
        public MainWindowVM(MainWindow mainWindow, MainSettings settings)
        {
            ConverterRegistration.Register();
            MainWindow               = mainWindow;
            Settings                 = settings;
            Installer                = new Lazy <InstallerVM>(() => new InstallerVM(this));
            Compiler                 = new Lazy <CompilerVM>(() => new CompilerVM(this));
            SettingsPane             = new Lazy <SettingsVM>(() => new SettingsVM(this));
            Gallery                  = new Lazy <ModListGalleryVM>(() => new ModListGalleryVM(this));
            ModeSelectionVM          = new ModeSelectionVM(this);
            UserInterventionHandlers = new UserInterventionHandlers(this);

            // Set up logging
            Utils.LogMessages
            .ObserveOn(RxApp.TaskpoolScheduler)
            .ToObservableChangeSet()
            .Buffer(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler)
            .Where(l => l.Count > 0)
            .FlattenBufferResult()
            .ObserveOnGuiThread()
            .Bind(Log)
            .Subscribe()
            .DisposeWith(CompositeDisposable);

            var singleton_lock = new AsyncLock();

            Utils.LogMessages
            .OfType <IUserIntervention>()
            .ObserveOnGuiThread()
            .SelectTask(async msg =>
            {
                using var _ = await singleton_lock.Wait();
                try
                {
                    await UserInterventionHandlers.Handle(msg);
                }
                catch (Exception ex)
                    when(ex.GetType() != typeof(TaskCanceledException))
                    {
                        Utils.Error(ex, $"Error while handling user intervention of type {msg?.GetType()}");
                        try
                        {
                            if (!msg.Handled)
                            {
                                msg.Cancel();
                            }
                        }
                        catch (Exception cancelEx)
                        {
                            Utils.Error(cancelEx, $"Error while cancelling user intervention of type {msg?.GetType()}");
                        }
                    }
            })
            .Subscribe()
            .DisposeWith(CompositeDisposable);

            if (IsStartingFromModlist(out var path))
            {
                Installer.Value.ModListLocation.TargetPath = path;
                NavigateTo(Installer.Value);
            }
            else
            {
                // Start on mode selection
                NavigateTo(ModeSelectionVM);
            }

            try
            {
                var assembly = Assembly.GetExecutingAssembly();
                var fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);
                VersionDisplay = $"v{fvi.FileVersion}";
                Utils.Log($"Wabbajack Version: {fvi.FileVersion}");
            }
            catch (Exception ex)
            {
                Utils.Error(ex);
                VersionDisplay = "ERROR";
            }
            CopyVersionCommand = ReactiveCommand.Create(() =>
            {
                Clipboard.SetText($"Wabbajack {VersionDisplay}\n{ThisAssembly.Git.Sha}");
            });
            OpenSettingsCommand = ReactiveCommand.Create(
                canExecute: this.WhenAny(x => x.ActivePane)
                .Select(active => !SettingsPane.IsValueCreated || !object.ReferenceEquals(active, SettingsPane.Value)),
                execute: () => NavigateTo(SettingsPane.Value));

            OpenTerminalCommand = ReactiveCommand.Create(() => OpenTerminal());
        }
Exemplo n.º 11
0
 public void Init(MainWindowVM vm, MainSettings settings)
 {
     DataContext = vm;
     _mwvm       = vm;
     _settings   = settings;
 }
Exemplo n.º 12
0
        public MainWindow()
        {
            Helpers.Init();
            // Wire any unhandled crashing exceptions to log before exiting
            AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
            {
                // Don't do any special logging side effects
                Utils.Error(((Exception)e.ExceptionObject), "Uncaught error");
            };

            Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
            var p = SystemParametersConstructor.Create();

            Utils.Log($"Detected Windows Version: {p.WindowsVersion}");

            if (!(p.WindowsVersion.Major >= 6 && p.WindowsVersion.Minor >= 2))
            {
                Utils.Log(
                    $"You are not running a recent version of Windows (version 10 or greater), Wabbajack is not supported on OS versions older than Windows 10.");
            }

            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();

            // Load settings
            if (CLIArguments.NoSettings || !MainSettings.TryLoadTypicalSettings(out var settings))
            {
                _settings = new MainSettings
                {
                    Version = Consts.SettingsVersion
                };
                RunWhenLoaded(DefaultSettings);
            }
            else
            {
                _settings = settings;
                RunWhenLoaded(LoadSettings);
            }

            // Set datacontext
            _mwvm       = new MainWindowVM(this, _settings);
            DataContext = _mwvm;

            // Bring window to the front if it isn't already
            this.Initialized += (s, e) =>
            {
                this.Activate();
                this.Topmost = true;
                this.Focus();
            };
            this.ContentRendered += (s, e) =>
            {
                this.Topmost = false;
            };
        }
Exemplo n.º 13
0
        public MainWindow()
        {
            try
            {
                // Wire any unhandled crashing exceptions to log before exiting
                AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
                {
                    // Don't do any special logging side effects
                    Utils.LogStraightToFile("Error.");
                    Utils.LogStraightToFile(((Exception)e.ExceptionObject).ToString());
                    Environment.Exit(-1);
                };

                Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
                Utils.Log($"Running in {AbsolutePath.EntryPoint}");

                var p = SystemParametersConstructor.Create();

                Utils.Log($"Detected Windows Version: {p.WindowsVersion}");

                if (!(p.WindowsVersion.Major >= 10 && p.WindowsVersion.Minor >= 0))
                {
                    Utils.Log(
                        $"You are not running a recent version of Windows (version 10 or greater), Wabbajack is not supported on OS versions older than Windows 10.");
                }

                Utils.Log(
                    $"System settings - ({p.SystemMemorySize.ToFileSizeString()} RAM) ({p.SystemPageSize.ToFileSizeString()} Page), Display: {p.ScreenWidth} x {p.ScreenHeight} ({p.VideoMemorySize.ToFileSizeString()} VRAM - VideoMemorySizeMb={p.EnbLEVRAMSize})");

                if (p.SystemPageSize == 0)
                {
                    Utils.Log("Pagefile is disabled! Consider increasing to 20000MB. A disabled pagefile can cause crashes and poor in-game performance.");
                }
                else if (p.SystemPageSize < 2e+10)
                {
                    Utils.Log("Pagefile below recommended! Consider increasing to 20000MB. A suboptimal pagefile can cause crashes and poor in-game performance.");
                }

                Warmup();

                var _ = LauncherUpdater.Run();

                var(settings, loadedSettings) = MainSettings.TryLoadTypicalSettings().AsTask().Result;
                // Load settings
                if (CLIArguments.NoSettings || !loadedSettings)
                {
                    _settings = new MainSettings {
                        Version = Consts.SettingsVersion
                    };
                    RunWhenLoaded(DefaultSettings);
                }
                else
                {
                    _settings = settings;
                    RunWhenLoaded(LoadSettings);
                }

                // Set datacontext
                _mwvm       = new MainWindowVM(this, _settings);
                DataContext = _mwvm;

                // Bring window to the front if it isn't already
                this.Initialized += (s, e) =>
                {
                    this.Activate();
                    this.Topmost = true;
                    this.Focus();
                };
                this.ContentRendered += (s, e) =>
                {
                    this.Topmost = false;
                };
            }
            catch (Exception ex)
            {
                Utils.LogStraightToFile("Error");
                Utils.LogStraightToFile(ex.ToString());
                Environment.Exit(-1);
            }
        }