示例#1
0
        public void UninstallMod(KspPackage pkg)
        {
            var mod = db.Table <InstalledMods>().First(m => m.ModArchive == pkg.Filename);

            db.RunInTransaction(() =>
            {
                db.Delete(mod);
                foreach (var modfile in db.Table <ModFiles>().Where(mf => mf.ModArchive == pkg.Filename))
                {
                    db.Delete(modfile);
                    if (db.Table <ModFiles>().Count(mf => mf.Filename == modfile.Filename) == 0)
                    {
                        Console.WriteLine("Deleting file: {0}", modfile.Filename);
                        db.Delete <InstalledFiles>(modfile.Filename);
                        var full_filename = Path.Combine(InstallationDirectory, modfile.Filename);
                        File.Delete(full_filename);
                        RemoveEmptyFolders(Path.GetDirectoryName(full_filename), InstallationDirectory);
                    }
                    else
                    {
                        Console.WriteLine("NOT Deleting file: {0}", modfile.Filename);
                    }
                }
            });
            pkg.MoveTo(ModPath);
        }
示例#2
0
        public bool InstallMod(KspPackage pkg)
        {
            var installation_date      = DateTime.Now;
            IEnumerable <string> files = null;

            if (Properties.Settings.Default.CompatibilityMode == "0.20")
            {
                var name_without_ext = pkg.Filename;
                name_without_ext = name_without_ext.Substring(0, name_without_ext.LastIndexOf('.'));
                var new_style_path = Path.Combine("GameData", name_without_ext);
                files = pkg.Install(InstallationDirectory, new_style_path);
            }
            else
            {
                files = pkg.Install(InstallationDirectory);
            }

            if (files == null)
            {
                return(false);
            }

            db.RunInTransaction(() =>
            {
                db.Insert(new InstalledMods()
                {
                    ModArchive       = pkg.Filename,
                    InstallationDate = installation_date
                });
                foreach (var filename in files)
                {
                    Console.WriteLine(filename);
                    if (db.Table <InstalledFiles>().Count(t => t.Filename == filename) == 0)
                    {
                        db.Insert(new InstalledFiles()
                        {
                            Filename         = filename,
                            InstallationDate = installation_date
                        });
                    }
                    db.Insert(new ModFiles()
                    {
                        ModArchive = pkg.Filename,
                        Filename   = filename,
                    });
                }

                pkg.MoveTo(InstalledModCache);
            });
            return(true);
        }
示例#3
0
        public KspPackage[] GetInstalledMods()
        {
            var mods = new List <KspPackage>();

            foreach (var file in Directory.GetFiles(InstalledModCache, "*.zip", SearchOption.TopDirectoryOnly))
            {
                try
                {
                    var pkg = new KspPackage(file);
                    mods.Add(pkg);
                }
                catch (Exception) { continue; }
            }

            return(mods.ToArray());
        }