private void SetDefaults() { ControlStyle = SCStyle.Normal; ControlType = SCType.Active; ControlBorder = SCBorder.None; ControlState = SCState.Design; ControlText = ""; BaseIconFileName = "NoImage"; DisplayMode = true; }
/// <summary> /// Convert a file into a JSON representation /// </summary> /// <param name="file">FileInfo: the file to convert</param> /// <param name="filter">SCType: filter</param> public void ConvertJSON(FileInfo file, SCType type) { // Cast JObject to the right type JObject jObject = null; switch (type) { case SCType.Ship: jObject = new JShip(file, destination, source); break; case SCType.Shop: jObject = new JShop(file, destination, source); break; case SCType.Weapon: jObject = new JWeapon(file, destination, source); break; case SCType.Weapon_Magazine: jObject = new JWeaponMagazine(file, destination, source); break; case SCType.Commodity: jObject = new JCommodity(file, destination, source); break; //case SCType.Tag: // break; case SCType.Manufacturer: jObject = new JManufacturer(file, destination, source); break; //case SCType.Starmap: // break; case SCType.Every: break; case SCType.None: default: throw new Exception($"Unknow CSType: '{file.FullName}', cannot determine the SCType"); } // Start processing jObject?.Process(); // Validate generated file(s) jObject?.ValidateFiles(); }
/// <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]); }
/// <summary> /// Get all xml files in a directory and its subdirectories /// </summary> /// <param name="source">Where to search for XML</param> /// <returns></returns> private static Tuple <string, SCType>[] GetFiles(string source, SCType filter) { List <Tuple <string, SCType> > files = new List <Tuple <string, SCType> >(); foreach (var f in Directory.GetFiles(source, "*.xml", SearchOption.AllDirectories)) { SCType type = CryXML.DetectType(f); // Dont process game.xml and not supported files if (f.ToLower().Equals("game.xml") || (filter & type) == SCType.None) { continue; } files.Add(new Tuple <string, SCType>(f, type)); } return(files.OrderBy(f => f.Item2).ToArray()); }
public void ConvertJSON(FileInfo f, SCType type) { string sql_format = "INSERT IGNORE INTO `{0}`.`gamedata`(`category_id`, `version`, `name`, `data`) VALUES ({1}, '{2}', '{3}', '{4}');"; string content = File.ReadAllText(f.FullName); if (Program.minify) { content = Regex.Replace(content, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1"); content = Regex.Replace(content, "\\\\", "\\\\"); content = Regex.Replace(content, @"\\\\'", "\\\'"); content = Regex.Replace(content, "\t", "\\\\t"); } string name = f.Name.Replace(".json", "").Replace("_", " "); using (StreamWriter writer = new StreamWriter(destination, true)) { writer.WriteLine( String.Format(sql_format, database_name, getCategoryId(type), version, name, content)); } }
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); }
/// <summary> /// Parse all args from terminal /// </summary> /// <param name="args"></param> /// <returns></returns> private static SCType FindParameters(string[] args) { SCType parameters = SCType.None; foreach (string arg in args) { switch (arg) { case "--debug": debug = true; break; case "--minify": minify = true; break; case "--ships": case "-s": parameters |= SCType.Ship; break; case "--shops": case "-S": parameters |= SCType.Shop; break; case "--weapons": case "-w": parameters |= SCType.Weapon; break; case "--weapons-magazine": case "-wm": parameters |= SCType.Weapon_Magazine; break; case "--commodities": case "-c": parameters |= SCType.Commodity; break; case "--manufacturer": case "-m": parameters |= SCType.Manufacturer; break; case "--all": parameters = SCType.Every; break; default: Logger.LogWarning("Unknown parameter: " + arg); Logger.LogInfo("Type '--help' for help."); Logger.LogEmpty(); break; } } #if DEBUG debug = true; #endif Logger.debug = debug; return(parameters); }
public static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; System.Text.StringBuilder sb = new System.Text.StringBuilder(); bool hasException = false; // Check if version or required arguments are passed if (args.Contains("-v") || args.Contains("--version")) { PrintVersion(); return; } else if (args.Length < 2 || args.Contains("-h") || args.Contains("--help")) { PrintHelp(); return; } string working_dir = Environment.CurrentDirectory; args[0] = args[0].Trim(new char[] { '\'', '\"' }); // Trim ' in source args[1] = args[1].Trim(new char[] { '\'', '\"' }); // Trim " in destination string source = new DirectoryInfo(args[0]).FullName; var destination = new DirectoryInfo((Directory.Exists(args[1])) ? args[1] : "./").FullName; // Ignore destination if not specified in arguments args = args.Skip(destination == "./" ? 1 : 2).ToArray(); // Process arguments SCType filters = FindParameters(args); // 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}"); 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 no filter is provided, print message 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 (this can take some time).. ", end: ""); Tuple <string, SCType>[] files = null; // Load all files form the source directory #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, saveCache: false); } #endif Logger.Log("Preparing resources.. ", end: ""); CryXML cryXml = null; // Load some XML file in memory #if DEBUG cryXml = (CryXML)Progress.Process(() => new CryXML(source, destination), "Done"); #else try { cryXml = (CryXML)Progress.Process(() => new CryXML(source, destination), "Done"); } catch (Exception ex) { Logger.LogError("Preparing resources.. FAILED", ex, start: "\r"); Exit(true, saveCache: false); } #endif // Load cached data if (useCache) { try { Logger.Log("Loading cache.. ", end: ""); var exist = (bool)Progress.Process(() => CryXML.game.LoadCache(), "Done"); if (!exist) { Logger.Log("Cache is empty"); } } catch (System.Runtime.Serialization.SerializationException ex) { Logger.LogError("Loading cache.. Format error", ex, start: "\r"); Logger.LogWarning("Loading cache failed, the cache will rebuild."); CryXML.game.DeleteCache(); } catch (Exception ex) { Logger.LogError("Loading cache.. FAILED", ex, start: "\r"); Exit(true, saveCache: false); } } Logger.Log("Loading localization.. ", end: ""); Progress.Process(() => CryXML.localization.LoadLocalization(Language.ENGLISH), "Done"); Logger.LogInfo($"Files to be converted: {files.Length}"); Logger.LogEmpty(); Logger.LogInfo("Starting.."); var category = SCType.None; foreach (Tuple <string, SCType> file in new ProgressBar(files, "Converting", true)) { FileInfo f = new FileInfo(file.Item1); // Print category section if (category != file.Item2) { category = file.Item2; Logger.LogEmpty(); Logger.LogInfo($"Category [{category.ToString()}]", clear_line: true); } Logger.Log($"Converting {f.Name}.. ", end: ""); // Start XML conversion #if DEBUG Progress.Process(() => cryXml.ConvertJSON(f, file.Item2), "Done"); #else try { Progress.Process(() => cryXml.ConvertJSON(f, file.Item2), "Done"); } catch (Exception ex) { Logger.LogError($"Converting {f.Name}.. FAILED 🔥", start: "\r", exception: ex); hasException = true; } #endif } Exit(hasException); }
private int getCategoryId(SCType type) { return((int)Math.Log((int)type, 2)); }
public StringContext(SCType contextType) { this.ContextType = contextType; }