Beispiel #1
0
        static int Main(string[] args)
        {
            CmdArgs = ParseArgs(args);
            LogHelper.SetLogger(CmdArgs);
            PrintProgramInfo();
            if (!CmdArgs.IsValid())
            {
                PrintUsage();
                PrintArgsError();
                return(-1);
            }
            PrintPluginInfo();
            var crage = Crage.Process(CmdArgs);

            crage.PrintContent();
            try
            {
                crage.SaveContent(CmdArgs);
            }
            catch (Exception ex)
            {
                LogHelper.VerboseLine(ex.ToString());
                return(-2);
            }
            return(0);
        }
Beispiel #2
0
        public static Crage SaveContent(this Crage crage, CrageCmdArgs cmdArgs)
        {
            if (crage == null)
            {
                return(crage);
            }
            crage.OutputDirBase.EnsureDirectoryIsCreated();

            foreach (var contentList in crage.PackageContents)
            {
                using (contentList.Package)
                {
                    LogHelper.InfoLine($"Package:{contentList.Package.Name},Content Count:{contentList.Count}");

                    for (var i = 0; i < contentList.Count; i++)
                    {
                        using (var content = contentList[i])
                        {
                            LogHelper.Info($"Saving: {i + 1}/{contentList.Count}");

                            var packageNameWithoutExt = Path.GetFileNameWithoutExtension(content.Package.Path);
                            var targetDir             = Path.Combine(crage.OutputDirBase, packageNameWithoutExt);
                            targetDir.EnsureDirectoryIsCreated();
                            var targetPath = Path.Combine(targetDir, content.Name);
                            File.WriteAllBytes(targetPath, content.Data);

                            LogHelper.Verbose($" : {content.Package.Name}->{content.Name} > {targetPath}");
                            LogHelper.InfoLine();
                        }
                    }
                }
            }
            return(crage);
        }
Beispiel #3
0
        private static CrageCmdArgs ParseArgs(string[] args)
        {
            var cmdArg = new CrageCmdArgs();

            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    switch (args[i])
                    {
                    case "-d":
                        cmdArg.PackageDir = args[++i];
                        break;

                    case "-I":
                        cmdArg.PluginName = args[++i];
                        break;

                    case "-l":
                        cmdArg.PackageIndex = args[++i];
                        break;

                    case "-o":
                        cmdArg.OutputDir = args[++i];
                        break;

                    case "-p":
                        cmdArg.PackagePath = args[++i];
                        break;

                    case "-q":
                    case "--quiet":
                        cmdArg.Quiet = true;
                        break;

                    case "-v":
                        cmdArg.Verbose = true;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (IndexOutOfRangeException)
            {
                cmdArg = null;
            }
            return(cmdArg);
        }
Beispiel #4
0
 public static bool IsValid(this CrageCmdArgs cmdArgs)
 {
     if (cmdArgs == null)
     {
         return(false);
     }
     if (string.IsNullOrWhiteSpace(cmdArgs.PackageDir) && string.IsNullOrWhiteSpace(cmdArgs.PackagePath))
     {
         return(false);
     }
     if ((!string.IsNullOrWhiteSpace(cmdArgs.PackageDir)) && (!string.IsNullOrWhiteSpace(cmdArgs.PackagePath)))
     {
         return(false);
     }
     return(true);
 }
Beispiel #5
0
        public override IEnumerable <IPackage> BuildPackageFromCmdArgs(CrageCmdArgs cmdArgs)
        {
            var      list  = Enumerable.Empty <IPackage>();
            IPackage index = default(IPackage);

            if (!string.IsNullOrWhiteSpace(cmdArgs.PackageIndex))
            {
                index = new Package(cmdArgs.PackageIndex);
            }
            if (!string.IsNullOrWhiteSpace(cmdArgs.PackagePath))
            {
                var package = new Package(cmdArgs.PackagePath, index);
                list = Enumerable.Repeat(package, 1);
            }
            else if (!string.IsNullOrWhiteSpace(cmdArgs.PackageDir))
            {
                list = Directory.EnumerateFiles(cmdArgs.PackageDir, "*.*",
                                                SearchOption.AllDirectories)
                       .Select(path => new Package(path, index));
            }
            return(list);
        }
Beispiel #6
0
 public abstract IEnumerable <IPackage> BuildPackageFromCmdArgs(CrageCmdArgs cmdArgs);