Exemple #1
0
        /// <summary>
        /// Writes the the GameMaster object into a .json file.
        /// </summary>
        /// <param name="filePathJson"></param>
        internal static void WriteGameMasterJson(GameMaster gameMaster, string filePathJson)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented,
            };

            using (StreamWriter writer = new StreamWriter(filePathJson))
                writer.Write(JsonConvert.SerializeObject(gameMaster, settings));

            GameMasterTimestampUtils.FixGameMasterFileTime(filePathJson);
        }
Exemple #2
0
        /// <summary>
        /// Static method to load a GAME_MASTER file.
        /// </summary>
        /// <param name="filePathGameMaster">Path to the GAME_MASTER file.</param>
        /// <returns></returns>
        /// <remarks>
        /// If a .json exists, it will be loaded.
        /// If not, the GAME_MASTER file will be loaded and the .json will be created.
        /// </remarks>
        public static GameMaster GetGameMaster(string filePathGameMaster)
        {
            string filePathJson = filePathGameMaster + ".json";

            if (File.Exists(filePathJson))
            {
                return(ReadGameMasterJson(filePathJson));
            }
            else
            {
                GameMaster gameMaster = ReadGameMaster(filePathGameMaster);
                if (gameMaster != null)
                {
                    GameMasterTimestampUtils.FixGameMasterFileTime(filePathGameMaster);
                    WriteGameMasterJson(gameMaster, filePathJson);
                }

                return(gameMaster);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Count() < 1 || args[0].Contains("?"))
                {
                    WriteHelp();
                    return;
                }

                int decoded = 0;
                for (int arg = 0; arg < args.Length; arg++)
                {
                    bool createOnly = string.Equals(args[arg], "-c") || string.Equals(args[arg], "-create");
                    if (createOnly)
                    {
                        arg++;
                        if (arg >= args.Length)
                        {
                            break;
                        }
                    }

                    string folder;
                    string filePattern;
                    int    pos = args[arg].LastIndexOf('\\');
                    if (pos == -1)
                    {
                        folder      = ".";
                        filePattern = args[arg];
                    }
                    else
                    {
                        folder      = args[arg].Substring(0, pos);
                        filePattern = args[arg].Substring(pos + 1);
                    }

                    if (!Directory.Exists(folder))
                    {
                        ConsoleOutput.OutputError("ERROR: Folder does not exist: \"{0}\"", folder);
                        continue;
                    }

                    GameMasterTimestampUtils.Init(folder);

                    foreach (var filePath in Directory.EnumerateFiles(folder, filePattern))
#if true
                    { if (Path.GetExtension(filePath).Length == 0 && (!createOnly || !File.Exists(filePath + ".json")))
                      {
                          Console.Out.WriteLine("Decoding \"" + filePath + "\"");
                          GameMasterDecoder.WriteGameMasterJson(filePath);
                          decoded++;
                      }
                    }
#else
                    {   // This code is to reset the timestamps of the files
                        try
                        {
                            GameMasterTimestampUtils.FixGameMasterFileTime(filePath);
                        }
                        catch (Exception) { }
                    }
#endif
                }

                ConsoleOutput.OutputSuccess($"Finished. {decoded} files decoded.");
            }
            catch (Exception ex)
            {
                ConsoleOutput.OutputException(ex, "********** ERROR!!! **********");
            }
        }