コード例 #1
0
ファイル: Cache.cs プロジェクト: cranehawk/CKAN
 public void MakeCache()
 {
     cache_dir = TestData.NewTempDir();
     Directory.CreateDirectory(cache_dir);
     cache        = new NetFileCache(cache_dir);
     module_cache = new NetModuleCache(cache_dir);
 }
コード例 #2
0
ファイル: Cache.cs プロジェクト: zxasqwsss/CKAN
 public void RemoveCache()
 {
     cache.Dispose();
     cache = null;
     module_cache.Dispose();
     module_cache = null;
     Directory.Delete(cache_dir, true);
 }
コード例 #3
0
        public void Setup()
        {
            manager = new KSPManager(new NullUser());
            // Give us a registry to play with.
            ksp = new DisposableKSP();
            registry_manager = CKAN.RegistryManager.Instance(ksp.KSP);
            registry         = registry_manager.registry;
            registry.ClearDlls();
            registry.Installed().Clear();
            // Make sure we have a registry we can use.
            CKAN.Repo.Update(registry_manager, ksp.KSP, new NullUser(), TestData.TestKANZip());

            // Ready our downloader.
            async = new CKAN.NetAsyncModulesDownloader(new NullUser(), manager.Cache);

            // General shortcuts
            cache = manager.Cache;
        }
コード例 #4
0
ファイル: DownloadImportDialog.cs プロジェクト: zilti/CKAN
        /// <summary>
        /// Let the user choose some zip files, then import them to the mod cache.
        /// </summary>
        /// <param name="gameInst">Game instance to import into</param>
        /// <param name="cache">Cache object to import into</param>
        /// <param name="cp">Change plan object for marking things to be installed</param>
        public static void ImportDownloads(KSP gameInst, NetModuleCache cache, ChangePlan cp)
        {
            ConsoleFileMultiSelectDialog cfmsd = new ConsoleFileMultiSelectDialog(
                "Import Downloads",
                FindDownloadsPath(gameInst),
                "*.zip",
                "Import"
                );
            HashSet <FileInfo> files = cfmsd.Run();

            if (files.Count > 0)
            {
                ProgressScreen  ps   = new ProgressScreen("Importing Downloads", "Calculating...");
                ModuleInstaller inst = ModuleInstaller.GetInstance(gameInst, cache, ps);
                ps.Run(() => inst.ImportFiles(files, ps,
                                              (CkanModule mod) => cp.Install.Add(mod)));
                // Don't let the installer re-use old screen references
                inst.User = null;
            }
        }
コード例 #5
0
 private static int Clean(NetModuleCache cache)
 {
     cache.RemoveAll();
     return(Exit.OK);
 }
コード例 #6
0
ファイル: FileService.cs プロジェクト: prestja/CKAN
 public string GetFileHashSha256(string filePath)
 {
     // Use shared implementation from Core.
     // Also needs to be an instance method so it can be Moq'd for testing.
     return(NetModuleCache.GetFileHashSha256(filePath));
 }
コード例 #7
0
        /// <summary>
        /// Import a list of files into the download cache, with progress bar and
        /// interactive prompts for installation and deletion.
        /// </summary>
        /// <param name="gameInst">Game instance to install into</param>
        /// <param name="files">Set of files to import</param>
        /// <param name="user">Object for user interaction</param>
        /// <param name="inst">Module installer object</param>
        /// <param name="installMod">Function to call to mark a mod for installation</param>
        public static void ImportFiles(KSP gameInst, HashSet <FileInfo> files,
                                       IUser user, ModuleInstaller inst, Action <string> installMod)
        {
            Registry         registry    = RegistryManager.Instance(gameInst).registry;
            HashSet <string> installable = new HashSet <string>();
            List <FileInfo>  deletable   = new List <FileInfo>();
            // Get the mapping of known hashes to modules
            Dictionary <string, List <CkanModule> > index = registry.GetSha1Index();
            int i = 0;

            foreach (FileInfo f in files)
            {
                int percent = i * 100 / files.Count;
                user.RaiseProgress($"Importing {f.Name}... ({percent}%)", percent);
                // Calc SHA-1 sum
                string sha1 = NetModuleCache.GetFileHashSha1(f.FullName);
                // Find SHA-1 sum in registry (potentially multiple)
                if (index.ContainsKey(sha1))
                {
                    deletable.Add(f);
                    List <CkanModule> matches = index[sha1];
                    foreach (CkanModule mod in matches)
                    {
                        if (mod.IsCompatibleKSP(gameInst.VersionCriteria()))
                        {
                            installable.Add(mod.identifier);
                        }
                        if (inst.Cache.IsMaybeCachedZip(mod))
                        {
                            user.RaiseMessage("Already cached: {0}", f.Name);
                        }
                        else
                        {
                            user.RaiseMessage($"Importing {mod.identifier} {Formatting.StripEpoch(mod.version)}...");
                            inst.Cache.Store(mod, f.FullName);
                        }
                    }
                }
                else
                {
                    user.RaiseMessage("Not found in index: {0}", f.Name);
                }
                ++i;
            }
            if (installable.Count > 0 && user.RaiseYesNoDialog($"Install {installable.Count} compatible imported mods?"))
            {
                // Install the imported mods
                foreach (string identifier in installable)
                {
                    installMod(identifier);
                }
            }
            if (user.RaiseYesNoDialog($"Import complete. Delete {deletable.Count} old files?"))
            {
                // Delete old files
                foreach (FileInfo f in deletable)
                {
                    f.Delete();
                }
            }
        }