示例#1
0
        private void UpdateChecker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (modUpdater.ForceUpdate)
            {
                updateChecker?.Dispose();
                updateChecker          = null;
                modUpdater.ForceUpdate = false;
                modUpdater.Clear();
            }

            if (e.Cancelled)
            {
                return;
            }

            if (!(e.Result is Tuple <List <ModDownload>, List <string> > data))
            {
                return;
            }

            List <string> errors = data.Item2;

            if (errors.Count != 0)
            {
                MessageBox.Show(this, "The following errors occurred while checking for updates:\n\n" + string.Join("\n", errors),
                                "Update Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            bool manual = manualModUpdate;

            manualModUpdate = false;

            List <ModDownload> updates = data.Item1;

            if (updates.Count == 0)
            {
                if (manual)
                {
                    MessageBox.Show(this, "Mods are up to date.",
                                    "No Updates", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                return;
            }

            using (var dialog = new ModUpdatesDialog(updates))
            {
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                updates = dialog.SelectedMods;
            }

            if (updates.Count == 0)
            {
                return;
            }

            DialogResult result;

            do
            {
                try
                {
                    result = DialogResult.Cancel;
                    if (!Directory.Exists(updatePath))
                    {
                        Directory.CreateDirectory(updatePath);
                    }
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show(this, "Failed to create temporary update directory:\n" + ex.Message
                                             + "\n\nWould you like to retry?", "Directory Creation Failed", MessageBoxButtons.RetryCancel);
                }
            } while (result == DialogResult.Retry);

            using (var progress = new ModDownloadDialog(updates, updatePath))
            {
                progress.ShowDialog(this);
            }

            do
            {
                try
                {
                    result = DialogResult.Cancel;
                    Directory.Delete(updatePath, true);
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show(this, "Failed to remove temporary update directory:\n" + ex.Message
                                             + "\n\nWould you like to retry? You can remove the directory manually later.",
                                             "Directory Deletion Failed", MessageBoxButtons.RetryCancel);
                }
            } while (result == DialogResult.Retry);

            LoadModList();
        }
示例#2
0
        private void HandleUri(string uri)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                WindowState = FormWindowState.Normal;
            }

            Activate();

            var fields = uri.Substring("skcmm:".Length).Split(',');

            // TODO: lib-ify
            string itemType = fields.FirstOrDefault(x => x.StartsWith("gb_itemtype", StringComparison.InvariantCultureIgnoreCase));

            itemType = itemType.Substring(itemType.IndexOf(":") + 1);

            string itemId = fields.FirstOrDefault(x => x.StartsWith("gb_itemid", StringComparison.InvariantCultureIgnoreCase));

            itemId = itemId.Substring(itemId.IndexOf(":") + 1);

            var dummyInfo = new ModInfo();

            GameBananaItem gbi = GameBananaItem.Load(itemType, long.Parse(itemId));

            dummyInfo.Name = gbi.Name;

            dummyInfo.Author = gbi.OwnerName;

            DialogResult result = MessageBox.Show(this, $"Do you want to install mod \"{dummyInfo.Name}\" by {dummyInfo.Author} from {new Uri(fields[0]).DnsSafeHost}?", "Mod Download", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result != DialogResult.Yes)
            {
                return;
            }

            #region create update folder
            do
            {
                try
                {
                    result = DialogResult.Cancel;
                    if (!Directory.Exists(updatePath))
                    {
                        Directory.CreateDirectory(updatePath);
                    }
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show(this, "Failed to create temporary update directory:\n" + ex.Message
                                             + "\n\nWould you like to retry?", "Directory Creation Failed", MessageBoxButtons.RetryCancel);
                }
            } while (result == DialogResult.Retry);
            #endregion

            string dummyPath = dummyInfo.Name;

            foreach (char c in Path.GetInvalidFileNameChars())
            {
                dummyPath = dummyPath.Replace(c, '_');
            }

            dummyPath = Path.Combine("mods", dummyPath);

            var updates = new List <ModDownload>
            {
                new ModDownload(dummyInfo, dummyPath, fields[0], null, 0)
            };

            using (var progress = new ModDownloadDialog(updates, updatePath))
            {
                progress.ShowDialog(this);
            }

            do
            {
                try
                {
                    result = DialogResult.Cancel;
                    Directory.Delete(updatePath, true);
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show(this, "Failed to remove temporary update directory:\n" + ex.Message
                                             + "\n\nWould you like to retry? You can remove the directory manually later.",
                                             "Directory Deletion Failed", MessageBoxButtons.RetryCancel);
                }
            } while (result == DialogResult.Retry);

            LoadModList();
        }