Ejemplo n.º 1
0
        public void AddAvailable()
        {
            // We shouldn't have kOS in our registry.
            Assert.IsFalse(registry.available_modules.ContainsKey(module.identifier));

            // Register
            registry.AddAvailable(module);

            // Make sure it's now there.
            Assert.IsTrue(registry.available_modules.ContainsKey(module.identifier));
        }
Ejemplo n.º 2
0
        public void SetUp()
        {
            _testModule = TestData.DogeCoinFlag_101_module();

            _nullUser = new NullUser();

            _manager         = new KSPManager(_nullUser);
            _instance        = new DisposableKSP();
            _registryManager = CKAN.RegistryManager.Instance(_instance.KSP);
            _registry        = _registryManager.registry;
            _installer       = CKAN.ModuleInstaller.GetInstance(_instance.KSP, _manager.Cache, _nullUser);

            _gameDataDir = _instance.KSP.GameData();
            _registry.AddAvailable(_testModule);
            var testModFile = TestData.DogeCoinFlagZip();

            _manager.Cache.Store(_testModule, testModFile);
            _installer.InstallList(
                new List <string>()
            {
                _testModule.identifier
            },
                new RelationshipResolverOptions(),
                _registryManager
                );
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            _testModule = TestData.DogeCoinFlag_101_module();

            _instance        = new DisposableKSP();
            _nullUser        = new NullUser();
            _config          = new FakeConfiguration(_instance.KSP, _instance.KSP.Name);
            _manager         = new GameInstanceManager(_nullUser, _config);
            _registryManager = CKAN.RegistryManager.Instance(_instance.KSP);
            _registry        = _registryManager.registry;
            _installer       = CKAN.ModuleInstaller.GetInstance(_instance.KSP, _manager.Cache, _nullUser);

            _gameDir     = _instance.KSP.GameDir();
            _gameDataDir = _instance.KSP.game.PrimaryModDirectory(_instance.KSP);
            _registry.AddAvailable(_testModule);
            var testModFile = TestData.DogeCoinFlagZip();

            _manager.Cache.Store(_testModule, testModFile);
            HashSet <string> possibleConfigOnlyDirs = null;

            _installer.InstallList(
                new List <string>()
            {
                _testModule.identifier
            },
                new RelationshipResolverOptions(),
                _registryManager,
                ref possibleConfigOnlyDirs
                );
        }
Ejemplo n.º 4
0
        internal static void ProcessRegistryMetadataFromJSON(string metadata, Registry registry, string filename)
        {
            log.DebugFormat("Converting metadata from JSON.");

            try
            {
                CkanModule module = CkanModule.FromJson(metadata);
                log.InfoFormat("Found {0} version {1}", module.identifier, module.version);
                registry.AddAvailable(module);
            }
            catch (Exception exception)
            {
                // Alas, we can get exceptions which *wrap* our exceptions,
                // because json.net seems to enjoy wrapping rather than propagating.
                // See KSP-CKAN/CKAN-meta#182 as to why we need to walk the whole
                // exception stack.

                bool handled = false;

                while (exception != null)
                {
                    if (exception is UnsupportedKraken || exception is BadMetadataKraken)
                    {
                        // Either of these can be caused by data meant for future
                        // clients, so they're not really warnings, they're just
                        // informational.

                        log.InfoFormat("Skipping {0} : {1}", filename, exception.Message);

                        // I'd *love a way to "return" from the catch block.
                        handled = true;
                        break;
                    }

                    // Look further down the stack.
                    exception = exception.InnerException;
                }

                // If we haven't handled our exception, then it really was exceptional.
                if (handled == false)
                {
                    if (exception == null)
                    {
                        // Had exception, walked exception tree, reached leaf, got stuck.
                        log.ErrorFormat("Error processing {0} (exception tree leaf)", filename);
                    }
                    else
                    {
                        // In case whatever's calling us is lazy in error reporting, we'll
                        // report that we've got an issue here.
                        log.ErrorFormat("Error processing {0} : {1}", filename, exception.Message);
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 5
0
        internal static void ProcessRegistryMetadataFromJSON(string metadata, Registry registry, string filename)
        {
            log.DebugFormat("Converting metadata from JSON.");

            try
            {
                CkanModule module = CkanModule.FromJson(metadata);
                log.InfoFormat("Found {0} version {1}", module.identifier, module.version);
                registry.AddAvailable(module);
            }
            catch (Exception exception)
            {
                // Alas, we can get exceptions which *wrap* our exceptions,
                // because json.net seems to enjoy wrapping rather than propagating.
                // See KSP-CKAN/CKAN-meta#182 as to why we need to walk the whole
                // exception stack.

                bool handled = false;

                while (exception != null)
                {
                    if (exception is UnsupportedKraken || exception is BadMetadataKraken)
                    {
                        // Either of these can be caused by data meant for future
                        // clients, so they're not really warnings, they're just
                        // informational.

                        log.InfoFormat("Skipping {0} : {1}", filename, exception.Message);

                        // I'd *love a way to "return" from the catch block.
                        handled = true;
                        break;
                    }

                    // Look further down the stack.
                    exception = exception.InnerException;
                }

                // If we haven't handled our exception, then it really was exceptional.
                if (handled == false)
                {
                    if (exception == null)
                    {
                        // Had exception, walked exception tree, reached leaf, got stuck.
                        log.ErrorFormat("Error processing {0} (exception tree leaf)", filename);
                    }
                    else
                    {
                        // In case whatever's calling us is lazy in error reporting, we'll
                        // report that we've got an issue here.
                        log.ErrorFormat("Error processing {0} : {1}", filename, exception.Message);
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 6
0
        public void Constructor_WithMissingDependants_Throws()
        {
            var list      = new List <string>();
            var dependant = generator.GeneratorRandomModule();
            var depender  = generator.GeneratorRandomModule(depends: new List <RelationshipDescriptor>
            {
                new RelationshipDescriptor {
                    name = dependant.identifier
                }
            });

            list.Add(depender.identifier);
            registry.AddAvailable(depender);

            Assert.Throws <DependencyNotSatisfiedKraken>(() => new RelationshipResolver(
                                                             list,
                                                             options,
                                                             registry,
                                                             null));
        }
Ejemplo n.º 7
0
        public void Constructor_WithMissingDependants_Throws()
        {
            var list      = new List <string>();
            var dependant = generator.GeneratorRandomModule();
            var depender  = generator.GeneratorRandomModule(depends: new List <ModDependency>
            {
                new ModDependency($"{dependant.identifier}")
            });

            list.Add(depender.identifier);
            registry.AddAvailable(depender);

            var modList = list.Select(p => new CfanModuleIdAndVersion(p, new ModVersion("1.0")));

            Assert.Throws <ModuleNotFoundKraken>(() => new RelationshipResolver(
                                                     modList,
                                                     options,
                                                     registry,
                                                     null));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Updates the supplied registry from the URL given.
        /// This will *clear* the registry of available modules first.
        /// This does not *save* the registry. For that, you probably want Repo.Update
        /// </summary>
        internal static void UpdateRegistry(Uri repo, Registry registry)
        {
            log.InfoFormat("Downloading {0}", repo);

            string repo_file = Net.Download(repo);

            using (var zipfile = new ZipFile(repo_file))
            {
                // Clear our list of known modules.
                registry.ClearAvailable();

                // Walk the archive, looking for .ckan files.
                string filter = @"\.ckan$";

                foreach (ZipEntry entry in zipfile)
                {
                    string filename = entry.Name;

                    // Skip things we don't want.
                    if (!Regex.IsMatch(filename, filter))
                    {
                        log.DebugFormat("Skipping archive entry {0}", filename);
                        continue;
                    }

                    log.DebugFormat("Reading CKAN data from {0}", filename);

                    // Read each file into a string.
                    string metadata_json;
                    using (var stream = new StreamReader(zipfile.GetInputStream(entry)))
                    {
                        metadata_json = stream.ReadToEnd();
                        stream.Close();
                    }

                    log.Debug("Converting from JSON...");

                    try
                    {
                        CkanModule module = CkanModule.FromJson(metadata_json);
                        log.InfoFormat("Found {0} version {1}", module.identifier, module.version);
                        registry.AddAvailable(module);
                    }
                    catch (Kraken kraken)
                    {
                        if (kraken is UnsupportedKraken || kraken is BadMetadataKraken)
                        {
                            // Either of these can be caused by data meant for future
                            // clients, so they're not really warnings, they're just
                            // informational.

                            log.InfoFormat("Skipping {0} : {1}", filename, kraken.Message);
                        }

                        // This is not the kraken we're looking for.
                        throw;
                    }
                }

                zipfile.Close();
            }

            // Remove our downloaded meta-data now we've processed it.
            // Seems weird to do this as part of a transaction, but Net.Download uses them, so let's be consistent.
            file_transaction.Delete(repo_file);
        }
Ejemplo n.º 9
0
        public void Up()
        {
            _instance = new DisposableKSP();
            _registry = Registry.Empty();
            _manager = new KSPManager(new NullUser(), new FakeWin32Registry(_instance.KSP));

            // this module contains a ksp_version of "any" which repros our issue
            _anyVersionModule = TestData.DogeCoinFlag_101_module();

            // install it and set it as pre-installed
            _instance.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, TestData.DogeCoinFlagZip());
            _registry.RegisterModule(_anyVersionModule, new string[] { }, _instance.KSP);
            _registry.AddAvailable(_anyVersionModule);

            ModuleInstaller.GetInstance(_instance.KSP, _manager.User).InstallList(
                new List<CkanModule> { { _anyVersionModule } },
                new RelationshipResolverOptions(),
                new NetAsyncModulesDownloader(_manager.User)
            );

            // this module is not for "any" version, to provide another to sort against
            _registry.AddAvailable(TestData.kOS_014_module());

            // test object
            _modList = new MainModList(null, null, _manager.User);
            _listGui = new MainModListGUI();

            // todo: refactor the column header code to allow mocking of the GUI without creating columns
            _listGui.Columns.Add(new DataGridViewCheckBoxColumn());
            _listGui.Columns.Add(new DataGridViewCheckBoxColumn());
            for (int i = 0; i < 10; i++)
            {
                _listGui.Columns.Add(i.ToString(), "Column" + i);
            }
        }