Ejemplo n.º 1
0
        static public ORConfig DeserializeJSON(string fileName)
        {
            ORConfig p = null;

            try
            {
                JsonSerializer serializer = new JsonSerializer();
                using (StreamReader sr = new StreamReader(fileName))
                {
                    ORConfig orConfig = JsonConvert.DeserializeObject <ORConfig>((string)sr.ReadToEnd(), new JsonSerializerSettings
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        TypeNameHandling           = TypeNameHandling.Auto
                    });
                    p               = orConfig;
                    p.FileName      = fileName;
                    p.CanSaveConfig = false;
                }
            }
            catch
            {
                p               = new ORConfig();
                p.FileName      = fileName;
                p.CanSaveConfig = false;
            }
            return(p);
        }
Ejemplo n.º 2
0
        static public ORConfig LoadConfig(string dataFolder, ORConfig mainConfig = null)
        {
            string currentProgFolder = dataFolder;

            currentProgFolder = Path.GetDirectoryName(currentProgFolder);
            string completeFileName = Path.Combine(currentProgFolder, "Open Rails");

            if (!Directory.Exists(completeFileName))
            {
                Directory.CreateDirectory(completeFileName);
            }
            completeFileName = Path.Combine(completeFileName, "ORConfig.json");
            ORConfig loaded = DeserializeJSON(completeFileName);

            return(loaded);
        }