コード例 #1
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);
        }
コード例 #2
0
        public ImageResizerViewModel(ISettingsUtils settingsUtils, ISettingsRepository <GeneralSettings> settingsRepository, Func <string, int> ipcMSGCallBackFunc, Func <string, string> resourceLoader)
        {
            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            // To obtain the general settings configurations of PowerToys.
            if (settingsRepository == null)
            {
                throw new ArgumentNullException(nameof(settingsRepository));
            }

            GeneralSettingsConfig = settingsRepository.SettingsConfig;

            try
            {
                Settings = _settingsUtils.GetSettings <ImageResizerSettings>(ModuleName);
            }
            catch (Exception e)
            {
                Logger.LogError($"Exception encountered while reading {ModuleName} settings.", e);
#if DEBUG
                if (e is ArgumentException || e is ArgumentNullException || e is PathTooLongException)
                {
                    throw;
                }
#endif
                Settings = new ImageResizerSettings(resourceLoader);
                _settingsUtils.SaveSettings(Settings.ToJsonString(), ModuleName);
            }

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

            _isEnabled          = GeneralSettingsConfig.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 += SizePropertyChanged;
            }
        }
コード例 #3
0
        public ImageResizerViewModel(ISettingsUtils settingsUtils, Func <string, int> ipcMSGCallBackFunc)
        {
            _settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));

            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;
            }
        }
        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;
            }
        }