コード例 #1
0
        public async Task AddZippedVersion(string path)
        {
            var archiveFile = new FileInfo(path);

            if (FactorioFile.TryLoad(archiveFile, out var file))
            {
                if (file.Is64Bit == Environment.Is64BitOperatingSystem)
                {
                    var folder = await ExtractToFolder(file);

                    var factorioVersion = new FactorioVersion(folder);
                    FactorioVersions.Add(factorioVersion);
                    factorioVersion.BeginEdit();
                }
                else
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("IncompatiblePlatform", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("IncompatiblePlatform", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("InvalidFactorioArchive", MessageType.Error),
                                App.Instance.GetLocalizedMessageTitle("InvalidFactorioArchive", MessageType.Error),
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
        private async Task SelectSteamVersion()
        {
            var  dialog = new VistaFolderBrowserDialog();
            bool?result = dialog.ShowDialog(Window);

            if (result.HasValue && result.Value)
            {
                var     selectedDirectory = new DirectoryInfo(dialog.SelectedPath);
                Version version;

                bool is64Bit;
                if (!FactorioVersion.LocalInstallationValid(selectedDirectory, out version, out is64Bit))
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("InvalidFactorioFolder", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("InvalidFactorioFolder", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (is64Bit != Environment.Is64BitOperatingSystem)
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("IncompatiblePlatform", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("IncompatiblePlatform", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                if (MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("MoveSteamFactorio", MessageType.Warning),
                                    App.Instance.GetLocalizedMessageTitle("MoveSteamFactorio", MessageType.Warning),
                                    MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    App.Instance.Settings.SteamVersionPath = selectedDirectory.FullName;
                    App.Instance.Settings.Save();

                    var progressWindow = new ProgressWindow()
                    {
                        Owner = Window
                    };
                    var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                    progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("AddingSteamVersionAction");
                    progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("MovingFilesDescription");
                    progressViewModel.IsIndeterminate     = true;

                    var  steamAppDataDirectory = new DirectoryInfo(FactorioSteamVersion.SteamAppDataPath);
                    Task moveTask = PreserveContentsAsync(steamAppDataDirectory, true);

                    Task closeWindowTask = moveTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                    progressWindow.ShowDialog();
                    await moveTask;
                    await closeWindowTask;

                    FactorioVersions.Add(new FactorioSteamVersion(selectedDirectory, version));
                }
            }
        }
コード例 #3
0
        private async Task SelectSteamVersion()
        {
            if (!FactorioSteamVersion.IsPresent())
            {
                MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("NoSteam", MessageType.Information),
                                App.Instance.GetLocalizedMessageTitle("NoSteam", MessageType.Information),
                                MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            var progressWindow = new ProgressWindow()
            {
                Owner = Window
            };
            var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;

            progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("AddingSteamVersionAction");
            progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("CopyingFilesDescription");
            progressViewModel.IsIndeterminate     = true;

            Task closeWindowTask = null;

            try
            {
                Task moveTask = MoveSteamVersionContents();

                closeWindowTask = moveTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                progressWindow.ShowDialog();

                await moveTask;
            }
            finally
            {
                if (closeWindowTask != null)
                {
                    await closeWindowTask;
                }
            }

            App.Instance.Settings.LoadSteamVersion = true;
            App.Instance.Settings.Save();

            FactorioSteamVersion.TryLoad(out var steamVersion);
            FactorioVersions.Add(steamVersion);
        }
コード例 #4
0
        private async Task AddFactorioInstallation(FactorioFolder folder)
        {
            await PreserveContentsAsync(folder.Directory);

            var factorioDir = App.Instance.Settings.GetFactorioDirectory();

            if (!factorioDir.Exists)
            {
                factorioDir.Create();
            }

            var newFolder = await folder.CopyToAsync(factorioDir);

            newFolder.RenameToUnique();

            var factorioVersion = new FactorioVersion(newFolder);

            FactorioVersions.Add(factorioVersion);
            factorioVersion.BeginEdit();
        }
コード例 #5
0
        private async Task AddLocalVersion()
        {
            var  dialog = new VistaFolderBrowserDialog();
            bool?result = dialog.ShowDialog(Window);

            if (result.HasValue && result.Value)
            {
                var     installationDirectory = new DirectoryInfo(dialog.SelectedPath);
                Version version;

                bool is64Bit;
                if (!FactorioVersion.LocalInstallationValid(installationDirectory, out version, out is64Bit))
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("InvalidFactorioFolder", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("InvalidFactorioFolder", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (is64Bit != Environment.Is64BitOperatingSystem)
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("IncompatiblePlatform", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("IncompatiblePlatform", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (FactorioVersions.Any(factorioVersion => factorioVersion.Version == version))
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("FactorioVersionInstalled", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("FactorioVersionInstalled", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }


                var copyOrMoveWindow = new CopyOrMoveMessageWindow()
                {
                    Owner = Window
                };
                ((CopyOrMoveViewModel)copyOrMoveWindow.ViewModel).CopyOrMoveType = CopyOrMoveType.Factorio;
                result = copyOrMoveWindow.ShowDialog();
                if (result.HasValue && result.Value)
                {
                    bool move = copyOrMoveWindow.Move;

                    DirectoryInfo factorioDirectory = App.Instance.Settings.GetFactorioDirectory();
                    if (!factorioDirectory.Exists)
                    {
                        factorioDirectory.Create();
                    }
                    DirectoryInfo destinationDirectory = new DirectoryInfo(Path.Combine(factorioDirectory.FullName, version.ToString(3)));

                    var progressWindow = new ProgressWindow()
                    {
                        Owner = Window
                    };
                    var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                    progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("AddingLocalInstallationAction");
                    progressViewModel.ProgressDescription = move ? App.Instance.GetLocalizedResourceString("MovingFilesDescription") : App.Instance.GetLocalizedResourceString("CopyingFilesDescription");
                    progressViewModel.IsIndeterminate     = true;

                    Task addTask = move
                        ? MoveFactorioInstallationAsync(installationDirectory, destinationDirectory)
                        : CopyFactorioInstallationAsync(installationDirectory, destinationDirectory);

                    Task closeWindowTask = addTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                    progressWindow.ShowDialog();

                    await addTask;
                    await closeWindowTask;

                    FactorioVersions.Add(new FactorioVersion(destinationDirectory, version));
                }
            }
        }
コード例 #6
0
        private async Task AddZippedVersion()
        {
            var dialog = new VistaOpenFileDialog();

            dialog.Filter = App.Instance.GetLocalizedResourceString("ZipDescription") + @" (*.zip)|*.zip";
            bool?result = dialog.ShowDialog(Window);

            if (result.HasValue && result.Value)
            {
                var           archiveFile      = new FileInfo(dialog.FileName);
                Version       version          = null;
                DirectoryInfo versionDirectory = null;

                var progressWindow = new ProgressWindow()
                {
                    Owner = Window
                };
                var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("AddingFromZipAction");
                progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("CheckingValidityDescription");
                progressViewModel.IsIndeterminate     = true;

                bool            invalidArchiveFile = false;
                bool            invalidPlatform    = false;
                bool            versionInstalled   = false;
                IProgress <int> progress           = new Progress <int>(stage =>
                {
                    switch (stage)
                    {
                    case 1:
                        progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("ExtractingDescription");
                        break;

                    case -1:
                        invalidArchiveFile = true;
                        break;

                    case -2:
                        invalidPlatform = true;
                        break;

                    case -3:
                        versionInstalled = true;
                        break;
                    }
                });

                Task extractTask = Task.Run(() =>
                {
                    bool is64Bit;
                    if (FactorioVersion.ArchiveFileValid(archiveFile, out version, out is64Bit))
                    {
                        if (is64Bit == Environment.Is64BitOperatingSystem)
                        {
                            if (FactorioVersions.All(factorioVersion => factorioVersion.Version != version))
                            {
                                progress.Report(1);

                                DirectoryInfo factorioDirectory = App.Instance.Settings.GetFactorioDirectory();
                                ZipFile.ExtractToDirectory(archiveFile.FullName, factorioDirectory.FullName);

                                string versionString = version.ToString(3);
                                versionDirectory     = factorioDirectory.EnumerateDirectories($"Factorio_{versionString}*").First();
                                versionDirectory.MoveTo(Path.Combine(factorioDirectory.FullName, versionString));
                            }
                            else
                            {
                                progress.Report(-3);
                            }
                        }
                        else
                        {
                            progress.Report(-2);
                        }
                    }
                    else
                    {
                        progress.Report(-1);
                    }
                });

                Task closeWindowTask =
                    extractTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                progressWindow.ShowDialog();

                await extractTask;
                await closeWindowTask;

                if (invalidArchiveFile)
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("InvalidFactorioArchive", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("InvalidFactorioArchive", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if (invalidPlatform)
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("IncompatiblePlatform", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("IncompatiblePlatform", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else if (versionInstalled)
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("FactorioVersionInstalled", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("FactorioVersionInstalled", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    FactorioVersions.Add(new FactorioVersion(versionDirectory, version));

                    if (MessageBox.Show(Window,
                                        App.Instance.GetLocalizedMessage("DeleteFactorioArchive", MessageType.Question),
                                        App.Instance.GetLocalizedMessageTitle("DeleteFactorioArchive", MessageType.Question),
                                        MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        archiveFile.Delete();
                    }
                }
            }
        }
コード例 #7
0
        private async Task DownloadOnlineVersion()
        {
            CookieContainer container;

            if (GlobalCredentials.Instance.LogIn(Window, out container))
            {
                FactorioOnlineVersion selectedVersion;
                if (ShowVersionList(container, out selectedVersion))
                {
                    var cancellationSource = new CancellationTokenSource();
                    var progressWindow     = new ProgressWindow {
                        Owner = Window
                    };
                    var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                    progressViewModel.ActionName          = App.Instance.GetLocalizedResourceString("DownloadingAction");
                    progressViewModel.ProgressDescription = string.Format(App.Instance.GetLocalizedResourceString("DownloadingDescription"), selectedVersion.DownloadUrl);
                    progressViewModel.CanCancel           = true;
                    progressViewModel.CancelRequested    += (sender, e) => cancellationSource.Cancel();

                    FactorioVersion newVersion;
                    try
                    {
                        Task closeWindowTask = null;
                        try
                        {
                            DirectoryInfo          directory    = App.Instance.Settings.GetFactorioDirectory();
                            Task <FactorioVersion> downloadTask = FactorioWebsite.DownloadFactorioPackageAsync(selectedVersion, directory, container, new Progress <double>(p =>
                            {
                                if (p > 1)
                                {
                                    progressViewModel.ProgressDescription = App.Instance.GetLocalizedResourceString("ExtractingDescription");
                                    progressViewModel.IsIndeterminate     = true;
                                    progressViewModel.CanCancel           = false;
                                }
                                else
                                {
                                    progressViewModel.Progress = p;
                                }
                            }), cancellationSource.Token);

                            closeWindowTask = downloadTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                            progressWindow.ShowDialog();

                            newVersion = await downloadTask;
                        }
                        finally
                        {
                            if (closeWindowTask != null)
                            {
                                await closeWindowTask;
                            }
                        }
                    }
                    catch (HttpRequestException)
                    {
                        MessageBox.Show(Window,
                                        App.Instance.GetLocalizedMessage("InternetConnection", MessageType.Error),
                                        App.Instance.GetLocalizedMessageTitle("InternetConnection", MessageType.Error),
                                        MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    if (newVersion != null)
                    {
                        FactorioVersions.Add(newVersion);
                    }
                }
            }
        }