Пример #1
0
 /// <summary>
 /// Checks the path against a list of reserved game directories
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 private bool IsReservedDirectory(string path)
 {
     return(path == ksp.Tutorial() || path == ksp.ShipsVab() ||
            path == ksp.ShipsSph() || path == ksp.Ships() ||
            path == ksp.Scenarios() || path == ksp.GameData() ||
            path == ksp.GameDir() || path == ksp.CkanDir() ||
            path == ksp.ShipsThumbs() || path == ksp.ShipsThumbsVAB() ||
            path == ksp.ShipsThumbsSPH());
 }
Пример #2
0
        /// <summary>
        /// Returns an instance of the registry manager for the KSP install.
        /// The file `registry.json` is assumed.
        /// </summary>
        public static RegistryManager Instance(KSP ksp)
        {
            string directory = ksp.CkanDir();
            if (!singleton.ContainsKey(directory))
            {
                log.DebugFormat("Preparing to load registry at {0}", directory);
                singleton[directory] = new RegistryManager(directory, ksp);
            }

            return singleton[directory];
        }
Пример #3
0
        protected void Dispose(bool safeToAlsoFreeManagedObjects)
        {
            // Right now we just release our lock, and leave everything else
            // to the GC, but if we were implementing the full pattern we'd also
            // free managed (.NET core) objects when called with a true value here.

            ReleaseLock();
            var directory = ksp.CkanDir();

            if (!registryCache.ContainsKey(directory))
            {
                return;
            }

            log.DebugFormat("Dispose of registry at {0}", directory);
            if (!registryCache.Remove(directory))
            {
                throw new RegistryInUseKraken(directory);
            }
        }
Пример #4
0
        /// <summary>
        /// Returns an instance of the registry manager for the KSP install.
        /// The file `registry.json` is assumed.
        /// </summary>
        public static RegistryManager Instance(KSP ksp)
        {
            string directory = ksp.CkanDir();
            if (!registryCache.ContainsKey(directory))
            {
                log.DebugFormat("Preparing to load registry at {0}", directory);
                registryCache[directory] = new RegistryManager(directory, ksp);
            }

            return registryCache[directory];
        }
Пример #5
0
        /// <summary>
        /// Uninstall the module provided. For internal use only.
        /// Use UninstallList for user queries, it also does dependency handling.
        /// This does *NOT* save the registry.
        /// </summary>

        private void Uninstall(string modName)
        {
            using (var transaction = CkanTransaction.CreateTransactionScope())
            {
                InstalledModule mod = registry_manager.registry.InstalledModule(modName);

                if (mod == null)
                {
                    log.ErrorFormat("Trying to uninstall {0} but it's not installed", modName);
                    throw new ModNotInstalledKraken(modName);
                }

                // Walk our registry to find all files for this mod.
                IEnumerable <string> files = mod.Files;

                var directoriesToDelete = new HashSet <string>();

                foreach (string file in files)
                {
                    string path = ksp.ToAbsoluteGameDataDir(file);

                    try
                    {
                        FileAttributes attr = File.GetAttributes(path);

                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            directoriesToDelete.Add(path);
                        }
                        else
                        {
                            log.InfoFormat("Removing {0}", file);
                            file_transaction.Delete(path);
                        }
                    }
                    catch (Exception ex)
                    {
                        // XXX: This is terrible, we're catching all exceptions.
                        log.ErrorFormat("Failure in locating file {0} : {1}", path, ex.Message);
                    }
                }

                // Remove from registry.

                registry_manager.registry.DeregisterModule(ksp, modName);

                // Sort our directories from longest to shortest, to make sure we remove child directories
                // before parents. GH #78.
                foreach (string directory in directoriesToDelete.OrderBy(dir => dir.Length).Reverse())
                {
                    if (!Directory.EnumerateFileSystemEntries(directory).Any())
                    {
                        // It is bad if any of this directories get's removed
                        // So we protect them
                        if (directory == ksp.Scenarios() || directory == ksp.GameData() ||
                            directory == ksp.GameDir() || directory == ksp.CkanDir() ||
                            directory == ksp.Mods())
                        {
                            continue;
                        }

                        // We *don't* use our file_transaction to delete files here, because
                        // it fails if the system's temp directory is on a different device
                        // to KSP. However we *can* safely delete it now we know it's empty,
                        // because the TxFileMgr *will* put it back if there's a file inside that
                        // needs it.
                        //
                        // This works around GH #251.
                        // The filesystem boundry bug is described in https://transactionalfilemgr.codeplex.com/workitem/20

                        log.InfoFormat("Removing {0}", directory);
                        Directory.Delete(directory);
                    }
                    else
                    {
                        log.InfoFormat("Not removing directory {0}, it's not empty", directory);
                    }
                }
                transaction.Complete();
            }
        }
Пример #6
0
 // Default registry location
 private static string DefaultRegistry()
 {
     return(Path.Combine(KSP.CkanDir(), "registry.json"));
 }