Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("NoPipeline v" + Version);

            // Print help information if parameter was not provided.
            if (args.Length != 1)
            {
                PrintHelp();
                return;
            }

            // Read config file name from the input parameter.

            string MGCBConfigPath, NPLConfigPath;

            var configPath = args[0].Replace("\\", "/");

            if (configPath.EndsWith(".mgcb"))
            {
                MGCBConfigPath = configPath;
                NPLConfigPath  = Path.GetDirectoryName(configPath)
                                 + "/"
                                 + Path.GetFileNameWithoutExtension(configPath)
                                 + ".npl";
            }
            else
            {
                NPLConfigPath  = configPath;
                MGCBConfigPath = Path.GetDirectoryName(configPath)
                                 + "/"
                                 + Path.GetFileNameWithoutExtension(configPath)
                                 + ".mgcb";
            }

            // Check if configuration file exists.
            if (!File.Exists(NPLConfigPath) || !File.Exists(NPLConfigPath))
            {
                Console.WriteLine(NPLConfigPath + " not found!");
                PrintHelp();
                return;
            }


            JObject conf = ReadConfigFile(NPLConfigPath);

            var rootPath = Path.GetDirectoryName(configPath).Replace("\\", "/") + "/";

            // Create MGCB object to read mgcb file.
            var content = new MGCB(conf, MGCBConfigPath);

            // Create ContentProcessor object to read config file and update content
            // content will be overwrited from config file.
            var cp = new ContentProcessor(conf, content, rootPath);

            // Check all rules in content object and update timestamp of files if required.
            content.ContentCheck();

            // Save MGCB file.
            content.Save();
        }
Пример #2
0
        public ContentProcessor(JObject conf, MGCB content, string rootPath)
        {
            JObject contentJson = conf["content"] as JObject;

            Console.WriteLine("Reading NPL config.");

            foreach (var itm in contentJson)
            {
                // Read section
                string  sectionName = itm.Key;
                JObject section     = itm.Value as JObject;

                // read item
                string path;
                try
                {
                    path = section["path"].ToString();
                }
                catch
                {
                    Console.WriteLine($"Key 'path' doesn't exist in  {sectionName}!");
                    throw new Exception($"Key 'path' doesn't exist in  {sectionName}!");
                }

                Console.WriteLine("Rule: " + path);

                var fileName = Path.GetFileName(path);
                var filePath = Path.GetDirectoryName(path);
                var files    = new string[] { };

                try
                {
                    var searchOpt = SearchOption.TopDirectoryOnly;
                    if (section.ContainsKey("recursive"))
                    {
                        searchOpt = (section["recursive"].ToString().ToLower() == "true") ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
                    }
                    files = Directory.GetFiles($"{rootPath}{filePath}", fileName, searchOpt);
                }
                catch
                {
                    Console.WriteLine($"Error reading files from {rootPath}{filePath}");
                }

                foreach (var file in files)
                {
                    var name = file.Remove(0, rootPath.Length).Replace('\\', '/');
                    var it   = new Item()
                    {
                        Path = name
                    };
                    it.FixPath();
                    Console.WriteLine("    Reading " + name);

                    foreach (var sect in section)
                    {
                        if (sect.Key == "path")
                        {                         // path - already get - ignore
                            continue;
                        }
                        if (sect.Key == "processorParam")
                        {                         // read processor's parameters
                            JObject processorParam = section["processorParam"] as JObject;
                            foreach (var pp in processorParam)
                            {
                                it.Add("processorParam", $"{pp.Key}={pp.Value}");
                            }
                        }
                        else
                        {
                            it.Add(sect.Key, sect.Value);
                        }
                    }

                    if (content.Items.ContainsKey(it.Path))
                    {
                        content.Items[it.Path] = it;
                    }
                    else
                    {
                        content.Items.Add(it.Path, it);
                    }
                }
            }

            Console.WriteLine("Finished reading NPL config!");
            Console.WriteLine();
        }