Beispiel #1
0
        private void ButtonDownload_Click(object sender, RoutedEventArgs e)
        {
            Button     button     = (Button)sender;
            AddonGroup addonGroup = (AddonGroup)button.DataContext;

            if (downloadManager == null)
            {
                // start new download

                // disable all buttons that should not be pressed while download is running
                foreach (AddonGroup addonGrp in FileIndexer.Instance.AddonGroups)
                {
                    if (addonGroup != addonGrp)
                    {
                        addonGrp.ButtonIsEnabled = false;
                    }
                }
                ButtonUpdate.IsEnabled = false;
                ListViewAddonGroups.Items.Refresh();
                MainWindow.Instance.PlayUpdateButton.IsEnabled = false;

                // in case of missing addons decide where to download them to, if all addons already exist locally skip this step
                FilePath downloadDirectoryForMissingAddons = null;

                // decide where to download missing addons to
                switch (Settings.Instance.GetAddonSearchDirectories().Count)
                {
                case 0:
                    // there is no addon search directory set, tell user to choose at least one
                    MessageBox.Show(Properties.Resources.MissingAddonSearchDirectoryInfoMessage, "kellerkompanie-sync");
                    return;

                case 1:
                    // there is exactly one folder set as search directory, so this one will be download destination for all
                    downloadDirectoryForMissingAddons = Settings.Instance.GetAddonSearchDirectories()[0];
                    break;

                default:
                    // there is more than one addon search directory, make user choose to which one he wants to download missing files
                    ChooseDirectoryWindow inputDialog = new();
                    if (inputDialog.ShowDialog() == true)
                    {
                        downloadDirectoryForMissingAddons = inputDialog.ChosenDirectory;
                    }
                    else
                    {
                        MainWindow.Instance.EnablePlayButton();
                        foreach (AddonGroup addonGrp in FileIndexer.Instance.AddonGroups)
                        {
                            addonGrp.ButtonIsEnabled = true;
                        }
                        ButtonUpdate.IsEnabled = true;
                        ListViewAddonGroups.Items.Refresh();
                        return;
                    }
                    break;
                }

                if (downloadDirectoryForMissingAddons == null)
                {
                    throw new InvalidOperationException("the download folder for missing addons is null");
                }

                Dictionary <RemoteAddon, FilePath> webAddonToDownloadDirectoryDict = new();
                foreach (RemoteAddon webAddon in addonGroup.RemoteAddons)
                {
                    if (addonGroup.WebAddonToLocalAddonDict.ContainsKey(webAddon))
                    {
                        // some addons might already exist, for these download to existing folder
                        LocalAddon existingLocalAddon = addonGroup.WebAddonToLocalAddonDict[webAddon];
                        string     parentFolder       = Directory.GetParent(existingLocalAddon.AbsoluteFilepath.OriginalValue).FullName;
                        FilePath   addonParentFolder  = new(parentFolder);
                        webAddonToDownloadDirectoryDict.Add(webAddon, addonParentFolder);
                    }
                    else
                    {
                        // for all others choose the previously selected folder
                        Debug.Assert(addonGroup.State != AddonGroupState.CompleteButNotSubscribed);
                        webAddonToDownloadDirectoryDict.Add(webAddon, downloadDirectoryForMissingAddons);
                    }
                }

                addonGroup.StatusText       = Properties.Resources.ProgressDownloading;
                addonGroup.StatusVisibility = Visibility.Visible;
                addonGroup.ButtonText       = Properties.Resources.Pause;
                ListViewAddonGroups.Items.Refresh();

                BackgroundWorker worker = new();
                worker.WorkerReportsProgress = true;
                worker.DoWork += DownloadWorker_DoWork;
                DownloadArguments args = new()
                {
                    AddonGroup            = addonGroup,
                    DownloadDirectoryDict = webAddonToDownloadDirectoryDict
                };
                worker.RunWorkerAsync(args);
            }
            else if (downloadManager?.State == DownloadState.Paused)
            {
                // previous download is about to be resumed
                downloadManager.StartDownloads();
            }
            else if (downloadManager?.State == DownloadState.Downloading)
            {
                // download is currently running, pause it
                downloadManager.PauseDownloads();
            }
        }
Beispiel #2
0
        private void PlayUpdateButton_Click(object sender, RoutedEventArgs e)
        {
            if (!IsSteamRunning())
            {
                Log.Information("PlayUpdateButton_Click: steam is not running");
                MessageBox.Show(Properties.Resources.SteamNotRunningInfoMessage, "kellerkompanie-sync");
                return;
            }

            StringBuilder sb = new StringBuilder();

            if (Settings.Instance.ParamDefaultWorldEmpty)
            {
                sb.Append(" -world=empty");
            }

            if (Settings.Instance.ParamNoLogs)
            {
                sb.Append(" -nologs");
            }

            if (Settings.Instance.ParamNoPause)
            {
                sb.Append(" -noPause");
            }

            if (Settings.Instance.ParamNoSplashScreen)
            {
                sb.Append(" -nosplash");
            }

            if (Settings.Instance.ParamShowScriptErrors)
            {
                sb.Append(" -showScriptErrors");
            }

            if (Settings.Instance.ParamWindowMode)
            {
                sb.Append(" -window");
            }

            foreach (AddonGroup addonGroup in FileIndexer.Instance.AddonGroups)
            {
                if (!addonGroup.CheckBoxIsChecked)
                {
                    continue;
                }

                foreach (RemoteAddon webAddon in addonGroup.RemoteAddons)
                {
                    Uuid       uuid       = webAddon.Uuid;
                    LocalAddon localAddon = FileIndexer.Instance.addonUuidToLocalAddonMap[uuid][0];
                    sb.Append(" \"-mod=");
                    sb.Append(localAddon.AbsoluteFilepath);
                    sb.Append(";\"");
                }
            }

            if (!string.IsNullOrEmpty(Settings.Instance.ParamAdditional))
            {
                sb.Append(' ');
                sb.Append(Settings.Instance.ParamAdditional);
            }

            string args = sb.ToString();

            Log.Information(string.Format("PlayUpdateButton_Click: starting arma from executable: {0}\nwith args:\n{1}", Settings.Instance.ExecutableLocation, args));
            PlayUpdateButton.IsEnabled = false;
            Process.Start(new ProcessStartInfo(Settings.Instance.ExecutableLocation, args)
            {
                CreateNoWindow = true
            });
            timer.Elapsed += Timer_Elapsed;
            timer.Start();
        }