public void ToJsonString_ShouldReturnValidJSONOfModel_WhenSuccessful()
        {
            // Arrange
            string file_name          = "test\\BasePTModuleSettingsTest";
            string expectedSchemaText = @"
                {
                    '$schema': 'http://json-schema.org/draft-04/schema#',
                    'type': 'object',
                    'properties': {
                    'name': {
                        'type': 'string'
                    },
                    'version': {
                        'type': 'string'
                    }
                    },
                'additionalProperties': false
                }";

            string testSettingsConfigs = new BasePTSettingsTest().ToJsonString();

            SettingsUtils.SaveSettings(testSettingsConfigs, file_name);
            JsonSchema expectedSchema = JsonSchema.Parse(expectedSchemaText);

            // Act
            JObject actualSchema = JObject.Parse(SettingsUtils.GetSettings <BasePTSettingsTest>(file_name).ToJsonString());
            bool    valid        = actualSchema.IsValid(expectedSchema);

            // Assert
            Assert.IsTrue(valid);
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            // initialize creation of test settings file.
            GeneralSettings generalSettings = new GeneralSettings();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
        }
Ejemplo n.º 3
0
        public KeyboardManagerViewModel(Func <string, int> ipcMSGCallBackFunc, Func <List <KeysDataModel>, int> filterRemapKeysList)
        {
            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG       = ipcMSGCallBackFunc;
            FilterRemapKeysList = filterRemapKeysList;

            if (SettingsUtils.SettingsExists(PowerToyName))
            {
                // Todo: Be more resilient while reading and saving settings.
                settings = SettingsUtils.GetSettings <KeyboardManagerSettings>(PowerToyName);

                // Load profile.
                if (!LoadProfile())
                {
                    profile = new KeyboardManagerProfile();
                }
            }
            else
            {
                settings = new KeyboardManagerSettings(PowerToyName);
                SettingsUtils.SaveSettings(settings.ToJsonString(), PowerToyName);
            }

            if (SettingsUtils.SettingsExists())
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            else
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }
        }
Ejemplo n.º 4
0
        public PowerRenameViewModel()
        {
            try
            {
                PowerRenameLocalProperties localSettings = SettingsUtils.GetSettings <PowerRenameLocalProperties>(ModuleName, "power-rename-settings.json");
                Settings = new PowerRenameSettings(localSettings);
            }
            catch
            {
                PowerRenameLocalProperties localSettings = new PowerRenameLocalProperties();
                Settings = new PowerRenameSettings(localSettings);
                SettingsUtils.SaveSettings(localSettings.ToJsonString(), ModuleName, "power-rename-settings.json");
            }

            _powerRenameEnabledOnContextMenu         = Settings.Properties.ShowIcon.Value;
            _powerRenameEnabledOnContextExtendedMenu = Settings.Properties.ExtendedContextMenuOnly.Value;
            _powerRenameRestoreFlagsOnLaunch         = Settings.Properties.PersistState.Value;
            _powerRenameMaxDispListNumValue          = Settings.Properties.MaxMRUSize.Value;
            _autoComplete = Settings.Properties.MRUEnabled.Value;

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            _powerRenameEnabled = generalSettings.Enabled.PowerRename;
        }
        public KeyboardManagerViewModel()
        {
            dispatcher = Window.Current.Dispatcher;
            if (SettingsUtils.SettingsExists(PowerToyName))
            {
                // Todo: Be more resillent while reading and saving settings.
                settings = SettingsUtils.GetSettings <KeyboardManagerSettings>(PowerToyName);

                // Load profile.
                if (!LoadProfile())
                {
                    profile = new KeyboardManagerProfile();
                }
            }
            else
            {
                settings = new KeyboardManagerSettings(PowerToyName);
                SettingsUtils.SaveSettings(settings.ToJsonString(), PowerToyName);
            }

            if (SettingsUtils.SettingsExists())
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            else
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            watcher = Helper.GetFileWatcher(
                PowerToyName,
                settings.Properties.ActiveConfiguration.Value + JsonFileType,
                OnConfigFileUpdate);
        }
Ejemplo n.º 6
0
        public void Setup()
        {
            var generalSettings     = new GeneralSettings();
            var colorPickerSettings = new ColorPickerSettings();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
            SettingsUtils.SaveSettings(colorPickerSettings.ToJsonString(), colorPickerSettings.Name, ModuleName + ".json");
        }
Ejemplo n.º 7
0
        public void Setup()
        {
            // initialize creation of test settings file.
            GeneralSettings      generalSettings = new GeneralSettings();
            PowerPreviewSettings powerpreview    = new PowerPreviewSettings();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
            SettingsUtils.SaveSettings(powerpreview.ToJsonString(), powerpreview.name);
        }
Ejemplo n.º 8
0
        public void Setup()
        {
            // initialize creation of test settings file.
            GeneralSettings    generalSettings    = new GeneralSettings();
            FZConfigProperties fZConfigProperties = new FZConfigProperties();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
            SettingsUtils.SaveSettings(fZConfigProperties.ToJsonString(), ModuleName);
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            // initialize creation of test settings file.
            GeneralSettings     generalSettings = new GeneralSettings();
            PowerRenameSettings powerRename     = new PowerRenameSettings();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
            SettingsUtils.SaveSettings(powerRename.ToJsonString(), generalSettings_file_name, "power-rename-settings.json");
        }
Ejemplo n.º 10
0
        public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
        {
            OnPropertyChanged(propertyName);

            SndShortcutGuideSettings outsettings = new SndShortcutGuideSettings(Settings);
            SndModuleSettings<SndShortcutGuideSettings> ipcMessage = new SndModuleSettings<SndShortcutGuideSettings>(outsettings);
            SendConfigMSG(ipcMessage.ToJsonString());
            SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
        }
Ejemplo n.º 11
0
        public FancyZonesViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <FancyZonesSettings>(ModuleName);
            }
            catch
            {
                Settings = new FancyZonesSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            this.LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

            this._shiftDrag                       = Settings.Properties.FancyzonesShiftDrag.Value;
            this._mouseSwitch                     = Settings.Properties.FancyzonesMouseSwitch.Value;
            this._overrideSnapHotkeys             = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
            this._moveWindowsAcrossMonitors       = Settings.Properties.FancyzonesMoveWindowsAcrossMonitors.Value;
            this._displayChangemoveWindows        = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
            this._zoneSetChangeMoveWindows        = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
            this._appLastZoneMoveWindows          = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
            this._openWindowOnActiveMonitor       = Settings.Properties.FancyzonesOpenWindowOnActiveMonitor.Value;
            this._restoreSize                     = Settings.Properties.FancyzonesRestoreSize.Value;
            this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
            this._showOnAllMonitors               = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
            this._makeDraggedWindowTransparent    = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value;
            this._highlightOpacity                = Settings.Properties.FancyzonesHighlightOpacity.Value;
            this._excludedApps                    = Settings.Properties.FancyzonesExcludedApps.Value;
            this.EditorHotkey                     = Settings.Properties.FancyzonesEditorHotkey.Value;

            string inactiveColor = Settings.Properties.FancyzonesInActiveColor.Value;

            this._zoneInActiveColor = inactiveColor != string.Empty ? inactiveColor.ToColor() : "#F5FCFF".ToColor();

            string borderColor = Settings.Properties.FancyzonesBorderColor.Value;

            this._zoneBorderColor = borderColor != string.Empty ? borderColor.ToColor() : "#FFFFFF".ToColor();

            string highlightColor = Settings.Properties.FancyzonesZoneHighlightColor.Value;

            this._zoneHighlightColor = highlightColor != string.Empty ? highlightColor.ToColor() : "#0078D7".ToColor();

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            this._isEnabled = generalSettings.Enabled.FancyZones;
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            // initialize creation of test settings file.
            // Test base path:
            // C:\Users\<user name>\AppData\Local\Packages\08e1807b-8b6d-4bfa-adc4-79c64aae8e78_9abkseg265h2m\LocalState\Microsoft\PowerToys\
            GeneralSettings       generalSettings = new GeneralSettings();
            ShortcutGuideSettings shortcutGuide   = new ShortcutGuideSettings();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
            SettingsUtils.SaveSettings(shortcutGuide.ToJsonString(), ShortCutGuideTestFolderName);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 'Don't show again' button action.
        /// </summary>
        /// <returns>True (always)</returns>
        internal static bool DontShowAgain()
        {
            // Save current version to settings file.
            ModSettings.whatsNewVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // Save current version header as beta.
            ModSettings.whatsNewBetaVersion = WhatsNewMessages[0].betaVersion;
            SettingsUtils.SaveSettings();

            return(true);
        }
Ejemplo n.º 14
0
        public void Setup()
        {
            // initialize creation of test settings file.
            // Test base path:
            // C:\Users\<user name>\AppData\Local\Packages\08e1807b-8b6d-4bfa-adc4-79c64aae8e78_9abkseg265h2m\LocalState\Microsoft\PowerToys\
            GeneralSettings      generalSettings = new GeneralSettings();
            ImageResizerSettings imageResizer    = new ImageResizerSettings();

            SettingsUtils.SaveSettings(generalSettings.ToJsonString());
            SettingsUtils.SaveSettings(imageResizer.ToJsonString(), imageResizer.Name);
        }
        /// <summary>
        /// Closes the panel by destroying the object (removing any ongoing UI overhead).
        /// </summary>
        private static void Close()
        {
            // Save settings first.
            SettingsUtils.SaveSettings();

            // We're no longer visible - destroy our game object.
            if (optionsGameObject != null)
            {
                GameObject.Destroy(optionsGameObject);
                optionsGameObject = null;
            }
        }
Ejemplo n.º 16
0
        public ShortcutGuideViewModel(Func <string, int> ipcMSGCallBackFunc, string configFileSubfolder = "")
        {
            // Update Settings file folder:
            _settingsConfigFileFolder = configFileSubfolder;

            try
            {
                Settings = SettingsUtils.GetSettings <ShortcutGuideSettings>(GetSettingsSubPath());
            }
            catch
            {
                Settings = new ShortcutGuideSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
            }

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;

            _isEnabled = generalSettings.Enabled.ShortcutGuide;
            _pressTime = Settings.Properties.PressTime.Value;
            _opacity   = Settings.Properties.OverlayOpacity.Value;

            string theme = Settings.Properties.Theme.Value;

            if (theme == "dark")
            {
                _themeIndex = 0;
            }

            if (theme == "light")
            {
                _themeIndex = 1;
            }

            if (theme == "system")
            {
                _themeIndex = 2;
            }
        }
        /// <summary>
        /// Adds header controls to the panel.
        /// </summary>
        /// <param name="yPos">Relative Y position for buttons</param>
        /// <returns>Relative Y coordinate below the finished setup</returns>
        protected override float PanelHeader(float yPos)
        {
            // Y position reference.
            float currentY = yPos + Margin;

            // Add 'Use legacy by default' header.

            // Label.
            UILabel legacyLabel = UIControls.AddLabel(panel, Margin, currentY, Translations.Translate(LegacyCheckLabel), panel.width - Margin, textScale: 0.9f);

            currentY += legacyLabel.height + 5f;

            // Use legacy by default for this save check.
            UICheckBox legacyThisSaveCheck = UIControls.LabelledCheckBox(panel, Margin * 2, currentY, Translations.Translate("RPR_DEF_LTS"));

            legacyThisSaveCheck.label.wordWrap     = true;
            legacyThisSaveCheck.label.autoSize     = false;
            legacyThisSaveCheck.label.width        = 710f;
            legacyThisSaveCheck.label.autoHeight   = true;
            legacyThisSaveCheck.isChecked          = ThisLegacyCategory;
            legacyThisSaveCheck.eventCheckChanged += (control, isChecked) =>
            {
                ThisLegacyCategory = isChecked;
                UpdateControls();
                SettingsUtils.SaveSettings();
            };

            // Use legacy by default for new saves check.
            currentY += 20f;
            UICheckBox legacyNewSaveCheck = UIControls.LabelledCheckBox(panel, Margin * 2, currentY, Translations.Translate("RPR_DEF_LAS"));

            legacyNewSaveCheck.label.wordWrap     = true;
            legacyNewSaveCheck.label.autoSize     = false;
            legacyNewSaveCheck.label.width        = 710f;
            legacyNewSaveCheck.label.autoHeight   = true;
            legacyNewSaveCheck.isChecked          = NewLegacyCategory;
            legacyNewSaveCheck.eventCheckChanged += (control, isChecked) =>
            {
                NewLegacyCategory = isChecked;
                UpdateControls();
                SettingsUtils.SaveSettings();
            };

            // Spacer bar.
            currentY += 25f;
            UIControls.OptionsSpacer(panel, Margin, currentY, panel.width - (Margin * 2f));

            return(currentY + 10f);
        }
Ejemplo n.º 18
0
        public PowerPreviewViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <PowerPreviewSettings>(ModuleName);
            }
            catch
            {
                Settings = new PowerPreviewSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            this._svgRenderIsEnabled = Settings.properties.EnableSvg;
            this._mdRenderIsEnabled  = Settings.properties.EnableMd;
        }
Ejemplo n.º 19
0
        public void SaveSettings_SaveSettingsToFile_WhenFilePathExists()
        {
            // Arrange
            string file_name = "\\test";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content);

            // Act
            SettingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
            BasePTSettingsTest actual_json = SettingsUtils.GetSettings <BasePTSettingsTest>(file_name);

            // Assert
            Assert.IsTrue(actual_json.Equals(actual_json));
        }
Ejemplo n.º 20
0
        public PowerPreviewViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <PowerPreviewSettings>(ModuleName);
            }
            catch
            {
                Settings = new PowerPreviewSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            _svgRenderIsEnabled    = Settings.Properties.EnableSvgPreview;
            _svgThumbnailIsEnabled = Settings.Properties.EnableSvgThumbnail;
            _mdRenderIsEnabled     = Settings.Properties.EnableMdPreview;
        }
Ejemplo n.º 21
0
        public void SaveSettingsShouldCreateFileWhenFilePathIsNotFound()
        {
            // Arrange
            var    mockFileSystem = new MockFileSystem();
            var    settingsUtils  = new SettingsUtils(mockFileSystem);
            string file_name      = "test\\Test Folder";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content);

            settingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
            BasePTSettingsTest actual_json = settingsUtils.GetSettings <BasePTSettingsTest>(file_name);

            // Assert
            Assert.AreEqual(expected_json.ToJsonString(), actual_json.ToJsonString());
        }
Ejemplo n.º 22
0
        public void SettingsFolderExists_ShouldReturnFalse_WhenFilePathIsNotFound()
        {
            // Arrange
            string file_name_random = "test\\" + RandomString();
            string file_name_exists = "test\\exists";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            // Act
            bool pathNotFound = SettingsUtils.SettingsFolderExists(file_name_random);

            SettingsUtils.SaveSettings(file_contents_correct_json_content, file_name_exists);
            bool pathFound = SettingsUtils.SettingsFolderExists(file_name_exists);

            // Assert
            Assert.IsFalse(pathNotFound);
            Assert.IsTrue(pathFound);
        }
Ejemplo n.º 23
0
        public ShortcutGuideViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <ShortcutGuideSettings>(ModuleName);
            }
            catch
            {
                Settings = new ShortcutGuideSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            _isEnabled = generalSettings.Enabled.ShortcutGuide;
            _pressTime = Settings.Properties.PressTime.Value;
            _opacity   = Settings.Properties.OverlayOpacity.Value;

            string theme = Settings.Properties.Theme.Value;

            if (theme == "dark")
            {
                _themeIndex = 0;
            }

            if (theme == "light")
            {
                _themeIndex = 1;
            }

            if (theme == "system")
            {
                _themeIndex = 2;
            }
        }
Ejemplo n.º 24
0
        public ImageResizerViewModel(Func <string, int> ipcMSGCallBackFunc)
        {
            try
            {
                Settings = SettingsUtils.GetSettings <ImageResizerSettings>(ModuleName);
            }
            catch
            {
                Settings = new ImageResizerSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            // set the callback functions value to hangle outgoing IPC message.
            SendConfigMSG = ipcMSGCallBackFunc;

            _isEnabled          = generalSettings.Enabled.ImageResizer;
            _advancedSizes      = Settings.Properties.ImageresizerSizes.Value;
            _jpegQualityLevel   = Settings.Properties.ImageresizerJpegQualityLevel.Value;
            _pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
            _tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
            _fileName           = Settings.Properties.ImageresizerFileName.Value;
            _keepDateModified   = Settings.Properties.ImageresizerKeepDateModified.Value;
            _encoderGuidId      = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);

            int i = 0;

            foreach (ImageSize size in _advancedSizes)
            {
                size.Id = i;
                i++;
                size.PropertyChanged += Size_PropertyChanged;
            }
        }
Ejemplo n.º 25
0
        public void SaveSettingsSaveSettingsToFileWhenFilePathExists()
        {
            // Arrange
            var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
            var settingsUtils  = new SettingsUtils(mockIOProvider.Object);

            string file_name = "\\test";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content);

            // Act
            settingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
            BasePTSettingsTest actual_json = settingsUtils.GetSettings <BasePTSettingsTest>(file_name);

            // Assert
            Assert.AreEqual(expected_json.ToJsonString(), actual_json.ToJsonString());
        }
Ejemplo n.º 26
0
        public FancyZonesViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <FancyZonesSettings>(ModuleName);
            }
            catch
            {
                Settings = new FancyZonesSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            this.LaunchEditorEventHandler = new ButtonClickCommand(LaunchEditor);

            this._shiftDrag                       = Settings.Properties.FancyzonesShiftDrag.Value;
            this._overrideSnapHotkeys             = Settings.Properties.FancyzonesOverrideSnapHotkeys.Value;
            this._flashZones                      = Settings.Properties.FancyzonesZoneSetChangeFlashZones.Value;
            this._displayChangemoveWindows        = Settings.Properties.FancyzonesDisplayChangeMoveWindows.Value;
            this._zoneSetChangeMoveWindows        = Settings.Properties.FancyzonesZoneSetChangeMoveWindows.Value;
            this._virtualDesktopChangeMoveWindows = Settings.Properties.FancyzonesVirtualDesktopChangeMoveWindows.Value;
            this._appLastZoneMoveWindows          = Settings.Properties.FancyzonesAppLastZoneMoveWindows.Value;
            this._useCursorPosEditorStartupScreen = Settings.Properties.UseCursorposEditorStartupscreen.Value;
            this._showOnAllMonitors               = Settings.Properties.FancyzonesShowOnAllMonitors.Value;
            this._zoneHighlightColor              = Settings.Properties.FancyzonesZoneHighlightColor.Value;
            this._highlightOpacity                = Settings.Properties.FancyzonesHighlightOpacity.Value;
            this._excludedApps                    = Settings.Properties.FancyzonesExcludedApps.Value;
            this._editorHotkey                    = Settings.Properties.FancyzonesEditorHotkey.Value;
            this._zoneBorderColor                 = Settings.Properties.FancyzonesBorderColor.Value;
            this._zoneInActiveColor               = Settings.Properties.FancyzonesInActiveColor.Value;

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            this._isEnabled = generalSettings.Enabled.FancyZones;
        }
Ejemplo n.º 27
0
        public void SettingsFolderExistsShouldReturnFalseWhenFilePathIsNotFound()
        {
            // Arrange
            var    mockIOProvider   = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
            var    settingsUtils    = new SettingsUtils(mockIOProvider.Object);
            string file_name_random = "test\\" + RandomString();
            string file_name_exists = "test\\exists";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            // Act
            bool pathNotFound = settingsUtils.SettingsExists(file_name_random);

            settingsUtils.SaveSettings(file_contents_correct_json_content, file_name_exists);
            bool pathFound = settingsUtils.SettingsExists(file_name_exists);

            // Assert
            Assert.IsFalse(pathNotFound);
            Assert.IsTrue(pathFound);
        }
        public ImageResizerViewModel()
        {
            try
            {
                Settings = SettingsUtils.GetSettings <ImageResizerSettings>(ModuleName);
            }
            catch
            {
                Settings = new ImageResizerSettings();
                SettingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

            GeneralSettings generalSettings;

            try
            {
                generalSettings = SettingsUtils.GetSettings <GeneralSettings>(string.Empty);
            }
            catch
            {
                generalSettings = new GeneralSettings();
                SettingsUtils.SaveSettings(generalSettings.ToJsonString(), string.Empty);
            }

            this._isEnabled          = generalSettings.Enabled.ImageResizer;
            this._advancedSizes      = Settings.Properties.ImageresizerSizes.Value;
            this._jpegQualityLevel   = Settings.Properties.ImageresizerJpegQualityLevel.Value;
            this._pngInterlaceOption = Settings.Properties.ImageresizerPngInterlaceOption.Value;
            this._tiffCompressOption = Settings.Properties.ImageresizerTiffCompressOption.Value;
            this._fileName           = Settings.Properties.ImageresizerFileName.Value;
            this._keepDateModified   = Settings.Properties.ImageresizerKeepDateModified.Value;
            this._encoderGuidId      = GetEncoderIndex(Settings.Properties.ImageresizerFallbackEncoder.Value);

            int i = 0;

            foreach (ImageSize size in _advancedSizes)
            {
                size.Id = i;
                i++;
                size.PropertyChanged += Size_PropertyChanged;
            }
        }
        /// <summary>
        /// Adds mod options tab to tabstrip.
        /// </summary>
        /// <param name="tabStrip">Tab strip to add to</param>
        /// <param name="tabIndex">Index number of tab</param>
        internal ModOptionsPanel(UITabstrip tabStrip, int tabIndex)
        {
            // Add tab and helper.
            UIPanel  panel  = PanelUtils.AddTab(tabStrip, Translations.Translate("RPR_OPT_MOD"), tabIndex);
            UIHelper helper = new UIHelper(panel);

            panel.autoLayout = true;

            // Language dropdown.
            UIDropDown languageDrop = PanelUtils.AddPlainDropDown(panel, Translations.Translate("TRN_CHOICE"), Translations.LanguageList, Translations.Index);

            languageDrop.eventSelectedIndexChanged += (control, index) =>
            {
                Translations.Index = index;
                SettingsUtils.SaveSettings();
            };

            // Hotkey control.
            panel.gameObject.AddComponent <OptionsKeymapping>();
        }
Ejemplo n.º 30
0
        public async Task SaveSettings_ShouldCreateFile_WhenFilePathIsNotFoundAsync()
        {
            // Arrange
            string file_name = "test\\Test Folder";
            string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";

            BasePTSettingsTest expected_json = JsonSerializer.Deserialize <BasePTSettingsTest>(file_contents_correct_json_content);

            // Act
            if (SettingsUtils.SettingsFolderExists(file_name))
            {
                DeleteFolder(file_name);
            }

            SettingsUtils.SaveSettings(file_contents_correct_json_content, file_name);
            BasePTSettingsTest actual_json = SettingsUtils.GetSettings <BasePTSettingsTest>(file_name);

            // Assert
            Assert.IsTrue(actual_json.Equals(actual_json));
        }