Example #1
0
        private void SavePreset()
        {
            var json = PresetSerializer.SerializePreset(preset);

            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "Impulse Workshop file (*.irw)|*.irw";
            saveFileDialog.RestoreDirectory = true;
            if (loadedFile != null)
            {
                saveFileDialog.InitialDirectory = Path.GetDirectoryName(loadedFile);
                saveFileDialog.FileName         = Path.GetFileName(loadedFile);
            }
            else
            {
                saveFileDialog.InitialDirectory = savePresetDirectory;
                saveFileDialog.FileName         = (preset.ImpulseConfig != null && preset.ImpulseConfig.Length > 0) ? preset.ImpulseConfig[0].Name : "New Impulse";
            }

            if (saveFileDialog.ShowDialog() == true)
            {
                savePresetDirectory = Path.GetDirectoryName(saveFileDialog.FileName);
                File.WriteAllText(saveFileDialog.FileName, json);
                loadedFile = saveFileDialog.FileName;
            }
        }
Example #2
0
        private void NewPreset()
        {
            var dir           = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var defaultPreset = Path.Combine(dir, "Default.irw");
            var json          = File.ReadAllText(defaultPreset);
            var newPreset     = PresetSerializer.DeserializePreset(json);

            loadedFile = null;
            ApplyPreset(newPreset);
        }
Example #3
0
        public GradiantPresetLoader(string folder)
        {
            _presets = new Dictionary <string, List <GradientPresets.GradientKeyData> > ();
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
                return;
            }

            string[] presetFiles = Directory.GetFiles(folder, "*.json");
            for (int i = 0; i < presetFiles.Length; i++)
            {
                PresetSerializer preset = FileManager.LoadObject <PresetSerializer>(presetFiles[i], false);
                _presets.Add(preset.name, preset.preset);
            }
        }
Example #4
0
        private void OpenPreset()
        {
            var openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Impulse Workshop file (*.irw)|*.irw";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.InitialDirectory = savePresetDirectory;

            if (openFileDialog.ShowDialog() == true)
            {
                savePresetDirectory = Path.GetDirectoryName(openFileDialog.FileName);
                var json      = File.ReadAllText(openFileDialog.FileName);
                var newPreset = PresetSerializer.DeserializePreset(json);
                loadedFile = openFileDialog.FileName;
                ApplyPreset(newPreset);
            }
        }
Example #5
0
        private void CloneImpulse()
        {
            var idx = selectedImpulseConfigIndex;

            if (idx < 0 || idx >= preset.ImpulseConfig.Length)
            {
                return;
            }

            var json = PresetSerializer.SerializeImpulse(preset.ImpulseConfig[selectedImpulseConfigIndex]);
            var ic   = PresetSerializer.DeserializeImpulse(json);

            preset.ImpulseConfig = preset.ImpulseConfig.Concat(new[] { ic }).ToArray();
            var vm = AddImpulseConfigVm(ic);

            Task.Delay(100).ContinueWith(_ => vm.Update());
            SelectedImpulseConfigIndex = ImpulseConfig.Count - 1;
        }
Example #6
0
        public void LoadPreset(string file)
        {
            if (!File.Exists(file))
            {
                return;
            }

            try
            {
                savePresetDirectory = Path.GetDirectoryName(file);
                var json      = File.ReadAllText(file);
                var newPreset = PresetSerializer.DeserializePreset(json);
                loadedFile = file;
                ApplyPreset(newPreset);
            }
            catch (Exception ex)
            {
                Logging.ShowMessage($"Cannot load preset from file {file}.\r\n" + ex.Message, LogType.Error, true);
            }
        }