mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 10:19:20 +08:00
Standardize Image Resizer naming (#14694)
* Standardize Image Resizer naming * Use no-throw methods * Do not move if new dir already exist * Update test files paths
This commit is contained in:
parent
22f8390ef9
commit
87f6278bf9
@ -7,5 +7,6 @@ namespace ImageResizerConstants
|
|||||||
inline const std::wstring ModuleKey = L"Image Resizer";
|
inline const std::wstring ModuleKey = L"Image Resizer";
|
||||||
|
|
||||||
// Name of the ImageResizer save folder.
|
// Name of the ImageResizer save folder.
|
||||||
inline const std::wstring ModuleSaveFolderKey = L"ImageResizer";
|
inline const std::wstring ModuleOldSaveFolderKey = L"ImageResizer";
|
||||||
|
inline const std::wstring ModuleSaveFolderKey = L"Image Resizer";
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ BEGIN
|
|||||||
BLOCK "040904b0"
|
BLOCK "040904b0"
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", COMPANY_NAME
|
VALUE "CompanyName", COMPANY_NAME
|
||||||
VALUE "FileDescription", "ImageResizer PowerToy"
|
VALUE "FileDescription", "Image Resizer PowerToy"
|
||||||
VALUE "FileVersion", FILE_VERSION_STRING
|
VALUE "FileVersion", FILE_VERSION_STRING
|
||||||
VALUE "InternalName", "ImageResizerExt.dll"
|
VALUE "InternalName", "ImageResizerExt.dll"
|
||||||
VALUE "LegalCopyright", COPYRIGHT_NOTE
|
VALUE "LegalCopyright", COPYRIGHT_NOTE
|
||||||
|
@ -45,8 +45,16 @@ namespace
|
|||||||
|
|
||||||
CSettings::CSettings()
|
CSettings::CSettings()
|
||||||
{
|
{
|
||||||
std::wstring result = PTSettingsHelper::get_module_save_folder_location(ImageResizerConstants::ModuleSaveFolderKey);
|
std::wstring oldSavePath = PTSettingsHelper::get_module_save_folder_location(ImageResizerConstants::ModuleOldSaveFolderKey);
|
||||||
jsonFilePath = result + std::wstring(c_imageResizerDataFilePath);
|
std::wstring savePath = PTSettingsHelper::get_module_save_folder_location(ImageResizerConstants::ModuleSaveFolderKey);
|
||||||
|
std::error_code ec;
|
||||||
|
if (std::filesystem::exists(oldSavePath, ec))
|
||||||
|
{
|
||||||
|
std::filesystem::copy(oldSavePath, savePath, std::filesystem::copy_options::recursive, ec);
|
||||||
|
std::filesystem::remove_all(oldSavePath, ec);
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonFilePath = savePath + std::wstring(c_imageResizerDataFilePath);
|
||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ namespace ImageResizer.Properties
|
|||||||
{
|
{
|
||||||
// Generated Settings file in 0.72
|
// Generated Settings file in 0.72
|
||||||
var defaultInput =
|
var defaultInput =
|
||||||
"{\r\n \"properties\": {\r\n \"imageresizer_selectedSizeIndex\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_shrinkOnly\": {\r\n \"value\": true\r\n },\r\n \"imageresizer_replace\": {\r\n \"value\": true\r\n },\r\n \"imageresizer_ignoreOrientation\": {\r\n \"value\": false\r\n },\r\n \"imageresizer_jpegQualityLevel\": {\r\n \"value\": 91\r\n },\r\n \"imageresizer_pngInterlaceOption\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_tiffCompressOption\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_fileName\": {\r\n \"value\": \"%1 %1 (%2)\"\r\n },\r\n \"imageresizer_sizes\": {\r\n \"value\": [\r\n {\r\n \"Id\": 0,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"Small-NotDefault\",\r\n \"fit\": 1,\r\n \"width\": 854,\r\n \"height\": 480,\r\n \"unit\": 3\r\n },\r\n {\r\n \"Id\": 3,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"Phone\",\r\n \"fit\": 1,\r\n \"width\": 320,\r\n \"height\": 568,\r\n \"unit\": 3\r\n }\r\n ]\r\n },\r\n \"imageresizer_keepDateModified\": {\r\n \"value\": false\r\n },\r\n \"imageresizer_fallbackEncoder\": {\r\n \"value\": \"19e4a5aa-5662-4fc5-a0c0-1758028e1057\"\r\n },\r\n \"imageresizer_customSize\": {\r\n \"value\": {\r\n \"Id\": 4,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"custom\",\r\n \"fit\": 1,\r\n \"width\": 1024,\r\n \"height\": 640,\r\n \"unit\": 3\r\n }\r\n }\r\n },\r\n \"name\": \"ImageResizer\",\r\n \"version\": \"1\"\r\n}";
|
"{\r\n \"properties\": {\r\n \"imageresizer_selectedSizeIndex\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_shrinkOnly\": {\r\n \"value\": true\r\n },\r\n \"imageresizer_replace\": {\r\n \"value\": true\r\n },\r\n \"imageresizer_ignoreOrientation\": {\r\n \"value\": false\r\n },\r\n \"imageresizer_jpegQualityLevel\": {\r\n \"value\": 91\r\n },\r\n \"imageresizer_pngInterlaceOption\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_tiffCompressOption\": {\r\n \"value\": 1\r\n },\r\n \"imageresizer_fileName\": {\r\n \"value\": \"%1 %1 (%2)\"\r\n },\r\n \"imageresizer_sizes\": {\r\n \"value\": [\r\n {\r\n \"Id\": 0,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"Small-NotDefault\",\r\n \"fit\": 1,\r\n \"width\": 854,\r\n \"height\": 480,\r\n \"unit\": 3\r\n },\r\n {\r\n \"Id\": 3,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"Phone\",\r\n \"fit\": 1,\r\n \"width\": 320,\r\n \"height\": 568,\r\n \"unit\": 3\r\n }\r\n ]\r\n },\r\n \"imageresizer_keepDateModified\": {\r\n \"value\": false\r\n },\r\n \"imageresizer_fallbackEncoder\": {\r\n \"value\": \"19e4a5aa-5662-4fc5-a0c0-1758028e1057\"\r\n },\r\n \"imageresizer_customSize\": {\r\n \"value\": {\r\n \"Id\": 4,\r\n \"ExtraBoxOpacity\": 100,\r\n \"EnableEtraBoxes\": true,\r\n \"name\": \"custom\",\r\n \"fit\": 1,\r\n \"width\": 1024,\r\n \"height\": 640,\r\n \"unit\": 3\r\n }\r\n }\r\n },\r\n \"name\": \"Image Resizer\",\r\n \"version\": \"1\"\r\n}";
|
||||||
|
|
||||||
// Execute readFile/writefile twice and see if serialized string is still correct
|
// Execute readFile/writefile twice and see if serialized string is still correct
|
||||||
var resultWrapper = JsonSerializer.Deserialize<SettingsWrapper>(defaultInput);
|
var resultWrapper = JsonSerializer.Deserialize<SettingsWrapper>(defaultInput);
|
||||||
@ -362,7 +362,7 @@ namespace ImageResizer.Properties
|
|||||||
var serializedInput2 = JsonSerializer.Serialize(resultWrapper2, new JsonSerializerOptions() { WriteIndented = true });
|
var serializedInput2 = JsonSerializer.Serialize(resultWrapper2, new JsonSerializerOptions() { WriteIndented = true });
|
||||||
|
|
||||||
Assert.AreEqual(serializedInput, serializedInput2);
|
Assert.AreEqual(serializedInput, serializedInput2);
|
||||||
Assert.AreEqual("ImageResizer", resultWrapper2.Name);
|
Assert.AreEqual("Image Resizer", resultWrapper2.Name);
|
||||||
Assert.AreEqual("1", resultWrapper2.Version);
|
Assert.AreEqual("1", resultWrapper2.Version);
|
||||||
Assert.IsNotNull(resultWrapper2.Properties);
|
Assert.IsNotNull(resultWrapper2.Properties);
|
||||||
Assert.IsTrue(resultWrapper2.Properties.ShrinkOnly);
|
Assert.IsTrue(resultWrapper2.Properties.ShrinkOnly);
|
||||||
|
@ -24,7 +24,7 @@ namespace ImageResizer.Properties
|
|||||||
|
|
||||||
// Used to synchronize access to the settings.json file
|
// Used to synchronize access to the settings.json file
|
||||||
private static Mutex _jsonMutex = new Mutex();
|
private static Mutex _jsonMutex = new Mutex();
|
||||||
private static string _settingsPath = _fileSystem.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Microsoft", "PowerToys", "ImageResizer", "settings.json");
|
private static string _settingsPath = _fileSystem.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Microsoft", "PowerToys", "Image Resizer", "settings.json");
|
||||||
private string _fileNameFormat;
|
private string _fileNameFormat;
|
||||||
private bool _shrinkOnly;
|
private bool _shrinkOnly;
|
||||||
private int _selectedSizeIndex;
|
private int _selectedSizeIndex;
|
||||||
@ -422,6 +422,14 @@ namespace ImageResizer.Properties
|
|||||||
|
|
||||||
public void Reload()
|
public void Reload()
|
||||||
{
|
{
|
||||||
|
string oldSettingsDir = _fileSystem.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Microsoft", "PowerToys", "ImageResizer");
|
||||||
|
string settingsDir = _fileSystem.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "Microsoft", "PowerToys", "Image Resizer");
|
||||||
|
|
||||||
|
if (_fileSystem.Directory.Exists(oldSettingsDir) && !_fileSystem.Directory.Exists(settingsDir))
|
||||||
|
{
|
||||||
|
_fileSystem.Directory.Move(oldSettingsDir, settingsDir);
|
||||||
|
}
|
||||||
|
|
||||||
_jsonMutex.WaitOne();
|
_jsonMutex.WaitOne();
|
||||||
if (!_fileSystem.File.Exists(SettingsPath))
|
if (!_fileSystem.File.Exists(SettingsPath))
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ namespace ImageResizer.Properties
|
|||||||
public class SettingsWrapper
|
public class SettingsWrapper
|
||||||
{
|
{
|
||||||
[JsonPropertyName("name")]
|
[JsonPropertyName("name")]
|
||||||
public string Name { get; set; } = "ImageResizer";
|
public string Name { get; set; } = "Image Resizer";
|
||||||
|
|
||||||
[JsonPropertyName("version")]
|
[JsonPropertyName("version")]
|
||||||
public string Version { get; set; } = "1";
|
public string Version { get; set; } = "1";
|
||||||
|
@ -11,7 +11,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
|||||||
{
|
{
|
||||||
public class ImageResizerSettings : BasePTModuleSettings, ISettingsConfig
|
public class ImageResizerSettings : BasePTModuleSettings, ISettingsConfig
|
||||||
{
|
{
|
||||||
public const string ModuleName = "ImageResizer";
|
public const string ModuleName = "Image Resizer";
|
||||||
|
|
||||||
[JsonPropertyName("properties")]
|
[JsonPropertyName("properties")]
|
||||||
public ImageResizerProperties Properties { get; set; }
|
public ImageResizerProperties Properties { get; set; }
|
||||||
|
Loading…
Reference in New Issue
Block a user