コード例 #1
0
        public MainWindow(RunMode mode, string source)
        {
            var    args = Environment.GetCommandLineArgs();
            var    DebugMode = false;
            string MO2Folder = null, InstallFolder = null, MO2Profile = null;

            InitializeComponent();

            var context = new AppState(Dispatcher, "Building");

            context.LogMsg($"Wabbajack Build - {ThisAssembly.Git.Sha}");
            SetupHandlers(context);
            DataContext = context;
            WorkQueue.Init((id, msg, progress) => context.SetProgress(id, msg, progress),
                           (max, current) => context.SetQueueSize(max, current));

            Utils.SetLoggerFn(s => context.LogMsg(s));
            Utils.SetStatusFn((msg, progress) => WorkQueue.Report(msg, progress));
            UIUtils.Dispatcher = Dispatcher;

            _state._nexusSiteURL = "https://github.com/halgari/wabbajack";

            new Thread(() =>
            {
                if (mode == RunMode.Compile)
                {
                    Utils.Log("Compiler ready to execute");
                    context.Location = Path.GetDirectoryName(source);
                }
                else if (mode == RunMode.Install)
                {
                    context.UIReady = false;
                    var modlist     = Installer.LoadModlist(source);
                    if (modlist == null)
                    {
                        MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        Dispatcher.Invoke(() =>
                        {
                            context.Running      = false;
                            ExitWhenClosing      = false;
                            var window           = new ModeSelectionWindow();
                            window.ShowActivated = true;
                            window.Show();
                            Close();
                        });
                    }
                    else
                    {
                        context.ConfigureForInstall(modlist);
                    }
                }

                context.UIReady = true;
            }).Start();
        }
コード例 #2
0
        public MainWindow(RunMode mode, string source)
        {
            var args = Environment.GetCommandLineArgs();

            InitializeComponent();

            var context = new AppState(TaskMode.BUILDING);

            context.LogMsg($"Wabbajack Build - {ThisAssembly.Git.Sha}");
            SetupHandlers(context);
            DataContext = context;

            Utils.SetLoggerFn(s => context.LogMsg(s));
            Utils.SetStatusFn((msg, progress) => WorkQueue.Report(msg, progress));

            _state._nexusSiteURL = "https://github.com/wabbajack-tools/wabbajack";

            if (mode == RunMode.Compile)
            {
                PropertyCompilerGrid.Visibility  = Visibility.Visible;
                PropertyInstallerGrid.Visibility = Visibility.Hidden;
            }
            else
            {
                PropertyCompilerGrid.Visibility  = Visibility.Hidden;
                PropertyInstallerGrid.Visibility = Visibility.Visible;
            }

            new Thread(() =>
            {
                if (mode == RunMode.Compile)
                {
                    Utils.Log("Compiler ready to execute");
                    context.Location      = Path.GetDirectoryName(source);
                    context.LocationLabel = "MO2 Profile:";
                }
                else if (mode == RunMode.Install)
                {
                    context.UIReady       = false;
                    context.LocationLabel = "Installation Location:";
                    var modlist           = Installer.LoadFromFile(source);
                    if (modlist == null)
                    {
                        MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
                                        MessageBoxImage.Error);
                        Dispatcher.Invoke(() =>
                        {
                            ExitWhenClosing = false;
                            var window      = new ModeSelectionWindow
                            {
                                ShowActivated = true
                            };
                            window.Show();
                            Close();
                        });
                    }
                    else
                    {
                        context.ConfigureForInstall(source, modlist);
                    }
                }

                context.UIReady = true;
            }).Start();
        }
コード例 #3
0
        public InstallerVM(MainWindowVM mainWindowVM)
        {
            if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower())
            {
                MessageBox.Show(
                    "Wabbajack is running inside your Downloads folder. This folder is often highly monitored by antivirus software and these can often " +
                    "conflict with the operations Wabbajack needs to perform. Please move this executable outside of your Downloads folder and then restart the app.",
                    "Cannot run inside Downloads",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                Environment.Exit(1);
            }

            this.MWVM = mainWindowVM;

            this._ModList = this.WhenAny(x => x.ModListPath)
                            .ObserveOn(RxApp.TaskpoolScheduler)
                            .Select(source =>
            {
                if (source == null)
                {
                    return(default(ModListVM));
                }
                var modList = Installer.LoadFromFile(source);
                if (modList == null)
                {
                    MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        this.MWVM.MainWindow.ExitWhenClosing = false;
                        var window = new ModeSelectionWindow
                        {
                            ShowActivated = true
                        };
                        window.Show();
                        this.MWVM.MainWindow.Close();
                    });
                    return(default(ModListVM));
                }
                return(new ModListVM(modList, source));
            })
                            .ObserveOnGuiThread()
                            .StartWith(default(ModListVM))
                            .ToProperty(this, nameof(this.ModList));
            this._HTMLReport = this.WhenAny(x => x.ModList)
                               .Select(modList => modList?.ReportHTML)
                               .ToProperty(this, nameof(this.HTMLReport));
            this._ProgressPercent = Observable.CombineLatest(
                this.WhenAny(x => x.Installing),
                this.WhenAny(x => x.InstallingMode),
                resultSelector: (installing, mode) => !installing && mode)
                                    .Select(show => show ? 1f : 0f)
                                    // Disable for now, until more reliable
                                    //this.WhenAny(x => x.MWVM.QueueProgress)
                                    //    .Select(i => i / 100f)
                                    .ToProperty(this, nameof(this.ProgressPercent));

            this.Slideshow = new SlideShow(this);

            // Set display items to modlist if configuring or complete,
            // or to the current slideshow data if installing
            this._Image = Observable.CombineLatest(
                this.WhenAny(x => x.ModList)
                .SelectMany(x => x?.ImageObservable ?? Observable.Empty <BitmapImage>())
                .NotNull()
                .StartWith(WabbajackLogo),
                this.WhenAny(x => x.Slideshow.Image)
                .StartWith(default(BitmapImage)),
                this.WhenAny(x => x.Installing),
                resultSelector: (modList, slideshow, installing) => installing ? slideshow : modList)
                          .ToProperty(this, nameof(this.Image));
            this._TitleText = Observable.CombineLatest(
                this.WhenAny(x => x.ModList.Name),
                this.WhenAny(x => x.Slideshow.TargetMod.ModName)
                .StartWith(default(string)),
                this.WhenAny(x => x.Installing),
                resultSelector: (modList, mod, installing) => installing ? mod : modList)
                              .ToProperty(this, nameof(this.TitleText));
            this._AuthorText = Observable.CombineLatest(
                this.WhenAny(x => x.ModList.Author),
                this.WhenAny(x => x.Slideshow.TargetMod.ModAuthor)
                .StartWith(default(string)),
                this.WhenAny(x => x.Installing),
                resultSelector: (modList, mod, installing) => installing ? mod : modList)
                               .ToProperty(this, nameof(this.AuthorText));
            this._Description = Observable.CombineLatest(
                this.WhenAny(x => x.ModList.Description),
                this.WhenAny(x => x.Slideshow.TargetMod.ModDescription)
                .StartWith(default(string)),
                this.WhenAny(x => x.Installing),
                resultSelector: (modList, mod, installing) => installing ? mod : modList)
                                .ToProperty(this, nameof(this.Description));

            this._LocationError = this.WhenAny(x => x.Location)
                                  .Select(x => Utils.IsDirectoryPathValid(x))
                                  .ToProperty(this, nameof(this.LocationError));

            this._DownloadLocationError = this.WhenAny(x => x.DownloadLocation)
                                          .Select(x => Utils.IsDirectoryPathValid(x))
                                          .ToProperty(this, nameof(this.DownloadLocationError));

            // Define commands
            this.ShowReportCommand = ReactiveCommand.Create(ShowReport);
            this.OpenReadmeCommand = ReactiveCommand.Create(
                execute: this.OpenReadmeWindow,
                canExecute: this.WhenAny(x => x.ModList)
                .Select(modList => !string.IsNullOrEmpty(modList?.Readme))
                .ObserveOnGuiThread());
            this.BeginCommand = ReactiveCommand.Create(
                execute: this.ExecuteBegin,
                canExecute: Observable.CombineLatest(
                    this.WhenAny(x => x.Installing),
                    this.WhenAny(x => x.LocationError),
                    this.WhenAny(x => x.DownloadLocationError),
                    resultSelector: (installing, loc, download) =>
            {
                if (installing)
                {
                    return(false);
                }
                return((loc?.Succeeded ?? false) &&
                       (download?.Succeeded ?? false));
            })
                .ObserveOnGuiThread());
            this.VisitWebsiteCommand = ReactiveCommand.Create(
                execute: () => Process.Start(this.ModList.Website),
                canExecute: this.WhenAny(x => x.ModList.Website)
                .Select(x => x?.StartsWith("https://") ?? false)
                .ObserveOnGuiThread());

            // Have Installation location updates modify the downloads location if empty
            this.WhenAny(x => x.Location)
            .Skip(1)     // Don't do it initially
            .Subscribe(installPath =>
            {
                if (string.IsNullOrWhiteSpace(this.DownloadLocation))
                {
                    this.DownloadLocation = Path.Combine(installPath, "downloads");
                }
            })
            .DisposeWith(this.CompositeDisposable);
        }