Beispiel #1
0
        public Inflator(string cacheDir, bool overwriteCache, string githubToken, bool prerelease)
        {
            log.Debug("Initializing inflator");
            cache = FindCache(
                new KSPManager(new ConsoleUser(false)),
                ServiceLocator.Container.Resolve <IConfiguration>(),
                cacheDir
                );

            IModuleService moduleService = new ModuleService();
            IFileService   fileService   = new FileService();

            http          = new CachingHttpService(cache, overwriteCache);
            ckanValidator = new CkanValidator(http, moduleService);
            transformer   = new NetkanTransformer(http, fileService, moduleService, githubToken, prerelease);
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            try
            {
                ProcessArgs(args);

                // If we see the --version flag, then display our build info
                // and exit.
                if (Options.Version)
                {
                    Console.WriteLine(Meta.GetVersion(VersionFormat.Full));
                    return(ExitOk);
                }

                if (Options.File != null)
                {
                    Log.InfoFormat("Transforming {0}", Options.File);

                    var moduleService = new ModuleService();
                    var fileService   = new FileService();
                    var http          = new CachingHttpService(FindCache(new KSPManager(new ConsoleUser(false))));

                    var netkan = ReadNetkan();
                    Log.Info("Finished reading input");

                    new NetkanValidator().Validate(netkan);
                    Log.Info("Input successfully passed pre-validation");

                    var transformer = new NetkanTransformer(
                        http,
                        fileService,
                        moduleService,
                        Options.GitHubToken,
                        Options.PreRelease
                        );

                    var ckan = transformer.Transform(netkan);
                    Log.Info("Finished transformation");

                    new CkanValidator(netkan, http, moduleService).Validate(ckan);
                    Log.Info("Output successfully passed post-validation");

                    WriteCkan(ckan);
                }
                else
                {
                    Log.Fatal(
                        "Usage: netkan [--verbose|--debug] [--debugger] [--prerelease] [--outputdir=...] <filename>"
                        );

                    return(ExitBadOpt);
                }
            }
            catch (Exception e)
            {
                Log.Fatal(e.Message);

                if (Options == null || Options.Debug)
                {
                    Log.Fatal(e.StackTrace);
                }

                return(ExitError);
            }

            return(ExitOk);
        }
Beispiel #3
0
        public static int Main(string[] args)
        {
            // Keep these for purging downloads in the exception handler
            NetFileCache cache = null;
            IHttpService http  = null;

            try
            {
                ProcessArgs(args);

                // Force-allow TLS 1.2 for HTTPS URLs, because GitHub requires it.
                // This is on by default in .NET 4.6, but not in 4.5.
                ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

                // If we see the --version flag, then display our build info
                // and exit.
                if (Options.Version)
                {
                    Console.WriteLine(Meta.GetVersion(VersionFormat.Full));
                    return(ExitOk);
                }

                if (Options.File != null)
                {
                    Log.InfoFormat("Transforming {0}", Options.File);

                    var moduleService = new ModuleService();
                    var fileService   = new FileService();
                    cache = FindCache(
                        new KSPManager(new ConsoleUser(false)),
                        new Win32Registry()
                        );
                    http = new CachingHttpService(cache, Options.OverwriteCache);

                    var netkan = ReadNetkan();
                    Log.Info("Finished reading input");

                    new NetkanValidator().Validate(netkan);
                    Log.Info("Input successfully passed pre-validation");

                    var transformer = new NetkanTransformer(
                        http,
                        fileService,
                        moduleService,
                        Options.GitHubToken,
                        Options.PreRelease,
                        ParseReleases(Options.Releases)
                        );

                    IEnumerable <Metadata> ckans = transformer.Transform(netkan);
                    Log.Info("Finished transformation");
                    foreach (Metadata ckan in ckans)
                    {
                        new CkanValidator(netkan, http, moduleService).Validate(ckan);
                        Log.Info("Output successfully passed post-validation");

                        WriteCkan(ckan);
                    }
                }
                else
                {
                    Log.Fatal(
                        "Usage: netkan [--verbose|--debug] [--debugger] [--prerelease] [--outputdir=...] <filename>"
                        );

                    return(ExitBadOpt);
                }
            }
            catch (Exception e)
            {
                e = e.GetBaseException() ?? e;

                // Purge anything we download for a failed indexing attempt from the cache to allow re-downloads
                PurgeDownloads(http, cache);

                Log.Fatal(e.Message);

                if (Options == null || Options.Debug)
                {
                    Log.Fatal(e.StackTrace);
                }

                return(ExitError);
            }

            return(ExitOk);
        }