Ejemplo n.º 1
0
        public string CreateNewSettingsFolder(MachineDatabase db, Manufacturer mfg, MachineModel machine, string rootPath)
        {
            string mfgPath = Path.Combine(rootPath, mfg.Name);

            if (!Directory.Exists(mfgPath))
            {
                Directory.CreateDirectory(mfgPath);
                if (!Directory.Exists(mfgPath))
                {
                    throw new Exception("SettingsSerializer: cannot create directory for manufacturer " + mfg.Name);
                }
            }

            string machinePath = Path.Combine(mfgPath, machine.Name);

            if (!Directory.Exists(machinePath))
            {
                Directory.CreateDirectory(machinePath);
                if (!Directory.Exists(machinePath))
                {
                    throw new Exception("SettingsSerializer: cannot create directory for machine " + mfg.Name + "::" + machine.Name);
                }
            }

            return(machinePath);
        }
Ejemplo n.º 2
0
        public void UpdateSettingsFromJson(MachineDatabase db, MachinePreset preset, string newJson, bool bCreate)
        {
            JsonSerializerSettings jsonSettings = makeWriteSerializer();

            if (bCreate == false && File.Exists(preset.SourcePath) == false)
            {
                throw new Exception("SettingsSerializer.StoreSettings: path " + preset.SourcePath + " does not exist!");
            }

            var save_culture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            System.IO.File.WriteAllText(preset.SourcePath, newJson);
            Thread.CurrentThread.CurrentCulture = save_culture;

            RefreshSettingsFromDisk(db, preset);
        }
Ejemplo n.º 3
0
        public void StoreSettings(MachineDatabase db, MachinePreset preset, bool bCreate = false)
        {
            JsonSerializerSettings jsonSettings = makeWriteSerializer();

            if (bCreate == false && File.Exists(preset.SourcePath) == false)
            {
                throw new Exception("SettingsSerializer.StoreSettings: path " + preset.SourcePath + " does not exist!");
            }

            var save_culture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            string json = JsonConvert.SerializeObject(preset.Settings, jsonSettings);

            System.IO.File.WriteAllText(preset.SourcePath, json);

            Thread.CurrentThread.CurrentCulture = save_culture;
        }
Ejemplo n.º 4
0
        public void GenerateSettingsFolder(MachineDatabase db, string rootPath)
        {
            JsonSerializerSettings jsonSettings = makeWriteSerializer();

            foreach (Manufacturer mfg in db.Manufacturers)
            {
                string mfgPath = Path.Combine(rootPath, mfg.Name);
                if (!Directory.Exists(mfgPath))
                {
                    Directory.CreateDirectory(mfgPath);
                    if (!Directory.Exists(mfgPath))
                    {
                        throw new Exception("SettingsSerializer: cannot create directory for manufacturer " + mfg.Name);
                    }
                }

                IReadOnlyList <MachineModel> machines = db.ModelsForManufacturer(mfg);
                foreach (MachineModel machine in machines)
                {
                    string machinePath = Path.Combine(mfgPath, machine.Name);
                    if (!Directory.Exists(machinePath))
                    {
                        Directory.CreateDirectory(machinePath);
                        if (!Directory.Exists(machinePath))
                        {
                            throw new Exception("SettingsSerializer: cannot create directory for machine " + mfg.Name + "::" + machine.Name);
                        }
                    }


                    PlanarAdditiveSettings settings = machine.DefaultPreset.Settings;
                    string settingsPath             = Path.Combine(machinePath, settings.Identifier + ".txt");

                    var save_culture = Thread.CurrentThread.CurrentCulture;
                    Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
                    string json = JsonConvert.SerializeObject(settings, jsonSettings);
                    System.IO.File.WriteAllText(settingsPath, json);
                    Thread.CurrentThread.CurrentCulture = save_culture;
                }
            }
        }
Ejemplo n.º 5
0
        public void RefreshSettingsFromDisk(MachineDatabase db, MachinePreset preset)
        {
            if (File.Exists(preset.SourcePath) == false)
            {
                throw new Exception("SettingsSerializer.RefreshSettingsFromDisk: path " + preset.SourcePath + " does not exist!");
            }

            var save_culture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            string data = File.ReadAllText(preset.SourcePath);

            Thread.CurrentThread.CurrentCulture = save_culture;

            SingleMaterialFFFSettings settings = JsonToSettings(data);

            if (settings == null)
            {
                throw new Exception("SettingsSerializer.RefreshSettingsFromDisk: json data could not be parsed!");
            }

            preset.Settings = settings;
        }