Example #1
0
        public Mod(LocalManifest mf, string downloadDir)
        {
            this.name     = mf.name;
            this.fullName = new DirectoryInfo(downloadDir).Name;
            this.author   = fullName.Substring(0, fullName.LastIndexOf('-'));

            this.description = mf.description;
            this.version     = mf.version_number;

            if (mf.website_url.Length > 0)
            {
                this.modLink = new Uri(mf.website_url);
            }

            this.authorLink = new Uri("https://thunderstore.io/package/" + this.author);

            BitmapImage icon = new BitmapImage();

            icon.BeginInit();
            icon.CacheOption = BitmapCacheOption.OnLoad;
            icon.UriSource   = new Uri(Path.Combine(downloadDir, "icon.png"));
            icon.EndInit();

            this.image = icon;

            this.dependencies = mf.dependencies;

            this.isInstalled = CheckIfInstalled();
        }
Example #2
0
        public override void RefreshCollection()
        {
            collection.Clear();

            foreach (string dir in Directory.GetDirectories(ManagerInfo.Get().GetFullDownloadDirectory()))
            {
                string mfPath = Path.Combine(dir, "manifest.json");

                if (File.Exists(mfPath))
                {
                    try
                    {
                        string json = File.ReadAllText(mfPath);

                        LocalManifest manifest = JsonConvert.DeserializeObject <LocalManifest>(json);

                        collection.Add(new Mod(manifest, dir));
                    }
                    catch (IOException ex)
                    {
                        var result = MessageBox.Show($"Exception reading manifest for \"{new DirectoryInfo(dir).Name}\":\n{ex.Message}\nDo you want to re-download this mod?");

                        if (result == MessageBoxResult.Yes)
                        {
                            try
                            {
                                Directory.Delete(dir, true);

                                Mod mod = ModManager.onlineModList.Find(new DirectoryInfo(dir).Name);

                                mod.isInstalled = false;
                                ModManager.EnQueueModDownload(mod, mod.version);
                            }
                            catch (IOException ex2)
                            {
                                MessageBox.Show("Oh no! An exception was thrown when trying to delete the mod, too!\n" + ex2.Message);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public static void ActivateMod(Mod mod, string version = null)
        {
            string downloadDir = mod.GetDownloadDirectory();

            if (!mod.IsDownloaded())
            {
                EnQueueModDownload(mod, version ?? mod.version);
                return;
            }


            if (version != null)
            {
                string manifestPath = Path.Combine(downloadDir, "manifest.json");

                if (File.Exists(manifestPath))
                {
                    LocalManifest manifest = JsonConvert.DeserializeObject <LocalManifest>(File.ReadAllText(manifestPath));

                    if (version != manifest.version_number)
                    {
                        Directory.Delete(downloadDir, true);
                        mod.installOnDownloaded = true;
                        EnQueueModDownload(mod, version);
                    }
                    else
                    {
                        InstallMod(mod, version);
                    }

                    return;
                }
                else
                {
                    MessageBox.Show($"\"{mod.fullName}\" is downloaded, but doesn't have a manifest!\nThis should never happen, good job.", "Oh No!", MessageBoxButton.OK);
                }
            }

            InstallMod(mod, mod.version);
        }