예제 #1
0
 /// <summary>
 /// Get all xml files in de directory and subdirectory
 /// </summary>
 /// <param name="source">Where to search for XML</param>
 /// <returns></returns>
 private static Tuple <string, SCType>[] GetFiles(string source, SCType filter)
 {
     try
     {
         return(Directory.GetFiles(source, "*.json", SearchOption.AllDirectories)
                .Where(f => (filter & CryJSON.DetectType(f)) != SCType.None)
                .ToList()
                .ConvertAll(f => new Tuple <string, SCType>(f, CryJSON.DetectType(f)))
                .OrderBy(f => f.Item2)
                .ToArray());
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
     }
     return(new Tuple <string, SCType> [0]);
 }
예제 #2
0
        public static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            bool hasException            = false;

            if (args.Contains("-v") || args.Contains("--version"))
            {
                PrintVersion();
                return;
            }
            else
            if (args.Length < 4 || args.Contains("-h") || args.Contains("--help"))
            {
                PrintHelp();
                return;
            }

            string working_dir = Environment.CurrentDirectory;

            args[0] = args[0].Trim(new char[] { '\'', '\"' });
            args[1] = args[1].Trim(new char[] { '\'', '\"' });
            args[2] = args[2].Trim(new char[] { '\'', '\"' });
            args[3] = args[3].Trim(new char[] { '\'', '\"' });

            string source        = new DirectoryInfo(args[0]).FullName;
            string destination   = args[1];
            string database_name = args[2];
            string version       = args[3];

            SCType filters = FindParameters(args.Skip(destination == "./" ? 3 : 4).ToArray());             // skip source and destination from args

            Logger.LogEmpty("Process has started.");
            Logger.LogDebug("DEBUG MODE ENABLED");
            Logger.LogDebug("Arguments: " + String.Join(' ', args));
            Logger.LogEmpty();
            Logger.LogEmpty("Parameters:");
            Logger.LogEmpty($"\tSource:\t\t{source}");
            Logger.LogEmpty($"\tDestination:\t{destination}");
            Logger.LogEmpty($"\tDatabase:\t{database_name}");
            Logger.LogEmpty($"\tVersion:\t{version}");
            Logger.LogEmpty($"\tMinify:\t\t{(minify ? "Yes" : "No")}");

            if (debug)
            {
                Logger.LogEmpty($"Filter:");
                Logger.LogEmpty("\tShips: " + ((filters & SCType.Ship) == SCType.None ? "No" : "Yes"));
                Logger.LogEmpty("\tShops: " + ((filters & SCType.Shop) == SCType.None ? "No" : "Yes"));
                Logger.LogEmpty("\tWeapons: " + ((filters & SCType.Weapon) == SCType.None ? "No" : "Yes"));
                Logger.LogEmpty("\tStations: " + ((filters & SCType.None) == SCType.None ? "No" : "Yes"));
                Logger.LogEmpty("\tCommodities: " + ((filters & SCType.Commodity) == SCType.None ? "No" : "Yes"));
                Logger.LogEmpty("\tManufacturers: " + ((filters & SCType.Manufacturer) == SCType.None ? "No" : "Yes"));
            }
            Logger.LogEmpty();

            if (filters == SCType.None)
            {
                Logger.LogInfo("No filter(s) entered, try to add a least one filter.");
                Logger.LogInfo("Type '--help' for help.");
                return;
            }

            Logger.Log("Loading directory.. ", end: "");
            Tuple <string, SCType>[] files = null;

#if DEBUG
            files = (Tuple <string, SCType>[])Progress.Process(() => GetFiles(source, filters), "Done");
#else
            try
            {
                files = (Tuple <string, SCType>[])Progress.Process(() => GetFiles(source, filters), "Done");
            }
            catch (Exception ex)
            {
                Logger.LogError("Loading directory.. FAILED", ex, start: "\r");
                Exit(true);
            }
#endif
            Logger.LogInfo("Starting..");
            CryJSON cryJson = new CryJSON(destination, database_name, version);

            var category = SCType.None;
            foreach (Tuple <string, SCType> file in new ProgressBar(files, "Converting", true))
            {
                FileInfo f = new FileInfo(file.Item1);

                if (category != file.Item2)
                {
                    category = file.Item2;
                    Logger.LogEmpty();
                    Logger.LogInfo($"Category [{category.ToString()}]", clear_line: true);
                }

                Logger.Log($"Converting {f.Name}..  ", end: "");

#if DEBUG
                Progress.Process(() => cryJson.ConvertJSON(f, file.Item2), "Done");
#else
                try
                {
                    Progress.Process(() => cryJson.ConvertJSON(f, file.Item2), "Done");
                }
                catch (Exception ex)
                {
                    Logger.LogError($"Converting {f.Name}.. FAILED 🔥", start: "\r", exception: ex);
                    hasException = true;
                }
#endif
            }

            Exit(hasException);
        }