Example #1
0
 /// <summary>
 /// Create the JSON files directory if it doesn't exist
 /// </summary>
 public static void CreateJsonDirectory()
 {
     if (!System.IO.Directory.Exists(DirectoryJson))
     {
         FilesUtils.TryCreateDirectory(DirectoryJson);
     }
 }
Example #2
0
        /// <summary>
        /// Read the associated JSON file and create it if it's doesn't exist.
        /// </summary>
        /// <param name="jsonEnum">Enumeration associating the file to load</param>
        /// <returns>The JSON string</returns>
        public static string ReadJson(JsonFileEnum jsonEnum)
        {
            string jsonFile   = null;
            string jsonBackup = null;

            switch (jsonEnum)
            {
            case JsonFileEnum.Shader:
                jsonFile   = ShaderJson;
                jsonBackup = ShaderBackup;
                break;

            case JsonFileEnum.SurfaceProp:
                jsonFile   = SurfacePropJson;
                jsonBackup = SurfacePropBackup;
                break;

            case JsonFileEnum.Parameters:
                jsonFile   = ParametersJson;
                jsonBackup = ParametersBackup;
                break;
            }

            string jsonText = null;

            if (System.IO.File.Exists(jsonFile))
            {
                // If the json file exists, we read it
                jsonText = FilesUtils.TryReadAllText(jsonFile);
            }
            else
            {
                // Otherwise we read the embedded file and then create the json
                jsonText = FilesUtils.ReadResourceFile(jsonBackup);
                FilesUtils.TryWriteAllText(jsonFile, jsonText);
            }
            return(jsonText);
        }