示例#1
0
        private bool ProcessArgs(bool ignoreCommandFile = false)
        {
            if (!string.IsNullOrEmpty(PocoyoDataFilePath))
            {
                if (!File.Exists(PocoyoDataFilePath))
                {
                    LogError($"Missing file: {PocoyoDataFilePath}");
                    return(false);
                }

                PocoyoData.LoadFromData(PocoyoDataFilePath);
            }

            if (!ignoreCommandFile)
            {
                if (!string.IsNullOrEmpty(CommandFile))
                {
                    if (!File.Exists(CommandFile))
                    {
                        LogError($"Missing --commands file: {CommandFile}");
                        return(false);
                    }

                    return(false);
                }
            }

            if (Files.Count == 0)
            {
                LogError($"Missing input files / folders");
                return(false);
            }

            foreach (var filePath in Files)
            {
                var inputFile = Path.GetFullPath(filePath);
                if (Directory.Exists(inputFile))
                {
                    foreach (var csharpFilePath in Directory.EnumerateFiles(inputFile, "*.cs", SearchOption.AllDirectories))
                    {
                        var found = InputFiles.FirstOrDefault(item => string.Equals(item, csharpFilePath));
                        if (found == null)
                        {
                            InputFiles.Add(csharpFilePath);
                        }
                    }
                }
                else if (File.Exists(inputFile))
                {
                    var found = InputFiles.FirstOrDefault(item => string.Equals(item, inputFile));
                    if (found == null)
                    {
                        InputFiles.Add(inputFile);
                    }
                }
                else
                {
                    LogError($"Invalid file: {inputFile}");
                    return(false);
                }
            }

            if (string.IsNullOrEmpty(OutputFile))
            {
                LogError($"Missing --outputFile");
                return(false);
            }

            var outputFilePath = Path.GetFullPath(OutputFile);
            var outputFolder   = Path.GetDirectoryName(outputFilePath);

            Directory.CreateDirectory(outputFolder);

            if (Directory.Exists(outputFilePath))
            {
                OutputFolder = outputFilePath;
            }
            else
            {
                if (File.Exists(outputFilePath))
                {
                    File.Delete(outputFilePath);
                }
                OutputFile = outputFilePath;
            }

            if (InputFiles.Count == 0)
            {
                LogError($"Missing input files / folders");
                return(false);
            }

            if (string.IsNullOrEmpty(CommandFile) || !CommandFile.ToLower().EndsWith(".json"))
            {
                SerializeToJson();
            }

            return(true);
        }