Esempio n. 1
0
        internal static void ImportFromExisting(string settingsFilePath)
        {
            if (string.IsNullOrEmpty(settingsFilePath) || !File.Exists(settingsFilePath))
            {
                return;
            }

            var printerIdentifier = new PrinterInfo
            {
                Name = Path.GetFileNameWithoutExtension(settingsFilePath),
                Id   = Guid.NewGuid().ToString()
            };

            string importType = Path.GetExtension(settingsFilePath).ToLower();

            switch (importType)
            {
            case ".printer":
                var profile = LoadProfileFromDisk(settingsFilePath);
                profile.ID = Guid.NewGuid().ToString();
                break;

            case ".ini":
                var settingsToImport = SettingsLayer.LoadFromIni(settingsFilePath);

                var           oemProfile = new OemProfile(settingsToImport);
                SettingsLayer baseConfig = SliceSettingsOrganizer.Instance.GetDefaultSettings();

                var layeredProfile = new LayeredProfile(oemProfile, baseConfig)
                {
                    ID           = printerIdentifier.Id,
                    DocumentPath = Path.Combine(profilesPath, printerIdentifier.Id + ".json")
                };

                // TODO: Resolve name conflicts
                layeredProfile.UserLayer["MatterControl.PrinterName"] = printerIdentifier.Name;
                layeredProfile.Save();

                break;
            }

            ProfileData.Profiles.Add(printerIdentifier);

            UserSettings.Instance.set("ActiveProfileID", printerIdentifier.Id);

            Instance = LoadProfile(printerIdentifier.Id);
        }
        private static SettingsLayer LoadMatterHackersBaseLayer()
        {
            string baseConfigPath = Path.Combine(profilesPath, "config.json");

            if (!File.Exists(baseConfigPath))
            {
                string configIniPath = Path.Combine("PrinterSettings", "config.ini");

                SettingsLayer baseLayer;

                using (var sourceStream = StaticData.Instance.OpenSteam(configIniPath))
                    using (var reader = new StreamReader(sourceStream))
                    {
                        baseLayer = SettingsLayer.LoadFromIni(reader);
                    }
                File.WriteAllText(baseConfigPath, JsonConvert.SerializeObject(baseLayer));

                return(baseLayer);
            }

            return(JsonConvert.DeserializeObject <SettingsLayer>(File.ReadAllText(baseConfigPath)));
        }