diff --git a/src/modules/registrypreview/RegistryPreviewExt/RegistryPreviewExt.rc b/src/modules/registrypreview/RegistryPreviewExt/RegistryPreviewExt.rc index e13a322c4f..8b42af4243 100644 --- a/src/modules/registrypreview/RegistryPreviewExt/RegistryPreviewExt.rc +++ b/src/modules/registrypreview/RegistryPreviewExt/RegistryPreviewExt.rc @@ -88,7 +88,7 @@ END STRINGTABLE BEGIN - IDS_REGISTRYPREVIEW_NAME "Registry Preview" + IDS_REGISTRYPREVIEW_NAME "RegistryPreview" END #endif // English (United States) resources diff --git a/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Events.cs b/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Events.cs index 9fbfbd1931..62845d5bae 100644 --- a/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Events.cs +++ b/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Events.cs @@ -29,10 +29,10 @@ namespace RegistryPreview /// private void AppWindow_Closing(Microsoft.UI.Windowing.AppWindow sender, Microsoft.UI.Windowing.AppWindowClosingEventArgs args) { - jsonSettings.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(appWindow.Position.X)); - jsonSettings.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(appWindow.Position.Y)); - jsonSettings.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(appWindow.Size.Width)); - jsonSettings.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(appWindow.Size.Height)); + jsonWindowPlacement.SetNamedValue("appWindow.Position.X", JsonValue.CreateNumberValue(appWindow.Position.X)); + jsonWindowPlacement.SetNamedValue("appWindow.Position.Y", JsonValue.CreateNumberValue(appWindow.Position.Y)); + jsonWindowPlacement.SetNamedValue("appWindow.Size.Width", JsonValue.CreateNumberValue(appWindow.Size.Width)); + jsonWindowPlacement.SetNamedValue("appWindow.Size.Height", JsonValue.CreateNumberValue(appWindow.Size.Height)); } /// @@ -55,8 +55,8 @@ namespace RegistryPreview resourceLoader.GetString("YesNoCancelDialogCloseButtonText")); } - // Save app settings - SaveSettingsFile(settingsFolder, settingsFile); + // Save window placement + SaveWindowPlacementFile(settingsFolder, windowPlacementFile); } /// diff --git a/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs b/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs index 8206826473..16916ae882 100644 --- a/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs +++ b/src/modules/registrypreview/RegistryPreviewUI/MainWindow.Utilities.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; +using System.Threading.Tasks; using Microsoft.UI.Input; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; @@ -842,7 +843,7 @@ namespace RegistryPreview ChangeCursor(gridPreview, false); } - private void OpenSettingsFile(string path, string filename) + private void OpenWindowPlacementFile(string path, string filename) { string fileContents = string.Empty; string storageFile = Path.Combine(path, filename); @@ -860,23 +861,27 @@ namespace RegistryPreview fileContents = "{ }"; } } + else + { + Task.Run(() => SaveWindowPlacementFile(path, filename)).GetAwaiter().GetResult(); + } try { - jsonSettings = Windows.Data.Json.JsonObject.Parse(fileContents); + jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents); } catch { // set up default JSON blob fileContents = "{ }"; - jsonSettings = Windows.Data.Json.JsonObject.Parse(fileContents); + jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents); } } /// - /// Save the settings JSON blob out to a local file + /// Save the window placement JSON blob out to a local file /// - private async void SaveSettingsFile(string path, string filename) + private async void SaveWindowPlacementFile(string path, string filename) { StorageFolder storageFolder = null; StorageFile storageFile = null; @@ -905,7 +910,7 @@ namespace RegistryPreview try { - fileContents = jsonSettings.Stringify(); + fileContents = jsonWindowPlacement.Stringify(); await Windows.Storage.FileIO.WriteTextAsync(storageFile, fileContents); } catch (Exception ex) diff --git a/src/modules/registrypreview/RegistryPreviewUI/MainWindow.xaml.cs b/src/modules/registrypreview/RegistryPreviewUI/MainWindow.xaml.cs index 615d0c97e6..b20903b81d 100644 --- a/src/modules/registrypreview/RegistryPreviewUI/MainWindow.xaml.cs +++ b/src/modules/registrypreview/RegistryPreviewUI/MainWindow.xaml.cs @@ -19,7 +19,7 @@ namespace RegistryPreview // Const values private const string REGISTRYHEADER4 = "regedit4"; private const string REGISTRYHEADER5 = "windows registry editor version 5.00"; - private const string APPNAME = "Registry Preview"; + private const string APPNAME = "RegistryPreview"; private const string KEYIMAGE = "ms-appx:///Assets/folder32.png"; private const string DELETEDKEYIMAGE = "ms-appx:///Assets/deleted-folder32.png"; private const string ERRORIMAGE = "ms-appx:///Assets/error32.png"; @@ -30,9 +30,9 @@ namespace RegistryPreview private bool visualTreeReady; private Dictionary mapRegistryKeys; private List listRegistryValues; - private JsonObject jsonSettings; + private JsonObject jsonWindowPlacement; private string settingsFolder = string.Empty; - private string settingsFile = string.Empty; + private string windowPlacementFile = "app-placement.json"; internal MainWindow() { @@ -43,8 +43,7 @@ namespace RegistryPreview // Open settings file; this moved to after the window tweak because it gives the window time to start up settingsFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Microsoft\PowerToys\" + APPNAME; - settingsFile = APPNAME + "_settings.json"; - OpenSettingsFile(settingsFolder, settingsFile); + OpenWindowPlacementFile(settingsFolder, windowPlacementFile); // Update the Win32 looking window with the correct icon (and grab the appWindow handle for later) IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(this); @@ -58,14 +57,14 @@ namespace RegistryPreview SetTitleBar(titleBar); // if have settings, update the location of the window - if (jsonSettings != null) + if (jsonWindowPlacement != null) { // resize the window - if (jsonSettings.ContainsKey("appWindow.Size.Width") && jsonSettings.ContainsKey("appWindow.Size.Height")) + if (jsonWindowPlacement.ContainsKey("appWindow.Size.Width") && jsonWindowPlacement.ContainsKey("appWindow.Size.Height")) { SizeInt32 size; - size.Width = (int)jsonSettings.GetNamedNumber("appWindow.Size.Width"); - size.Height = (int)jsonSettings.GetNamedNumber("appWindow.Size.Height"); + size.Width = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Size.Width"); + size.Height = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Size.Height"); // check to make sure the size values are reasonable before attempting to restore the last saved size if (size.Width >= 320 && size.Height >= 240) @@ -75,11 +74,11 @@ namespace RegistryPreview } // reposition the window - if (jsonSettings.ContainsKey("appWindow.Position.X") && jsonSettings.ContainsKey("appWindow.Position.Y")) + if (jsonWindowPlacement.ContainsKey("appWindow.Position.X") && jsonWindowPlacement.ContainsKey("appWindow.Position.Y")) { PointInt32 point; - point.X = (int)jsonSettings.GetNamedNumber("appWindow.Position.X"); - point.Y = (int)jsonSettings.GetNamedNumber("appWindow.Position.Y"); + point.X = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Position.X"); + point.Y = (int)jsonWindowPlacement.GetNamedNumber("appWindow.Position.Y"); // check to make sure the move values are reasonable before attempting to restore the last saved location if (point.X >= 0 && point.Y >= 0)