Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
 public GameBananaItem GetItem()
 {
     return(GameBananaItem.Load(ItemType, ItemId));
 }