mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
* [Analyzers][AdvancedPaste] Apply fix for SA1516 * [Analyzers][EnvironmentVariables] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Peek] Apply fix for SA1516 * [Analyzers][PreviewPane] Apply fix for SA1516 * [Analyzers][FancyZones] Apply fix for SA1516 * [Analyzers][PT Run][Plugins] Apply fix for SA1516 * [Analyzers][PT Run] Apply fix for SA1516 * [Analyzers][PT Run][Wox] Apply fix for SA1516 * [Analyzers][Common] Apply fix for SA1516 * [Analyzers][ImageResizer] Apply fix for SA1516 * [Analyzers][ColorPicker] Apply fix for SA1516 * [Analyzers][MouseUtils] Apply fix for SA1516 * [Analyzers][DSC Schema Generator] Apply fix for SA1516 * [Analyzers][FileLocksmith] Apply fix for SA1516 * [Analyzers][Hosts] Apply fix for SA1516 * [Analyzers][MeasureTool] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1516 * [Analyzers][TextExtractor] Apply fix for SA1516 * [Analyzers][Workspaces] Apply fix for SA1516 * [Analyzers][Awake] Apply fix for SA1516 * [Analyzers][PowerAccent] Apply fix for SA1516 * [Analyzers][RegistryPreview] Apply fix for SA1516 * [Analyzers][Settings] Apply fix for SA1516 * [Analyzers][MouseWithoutBorders] Apply fix for SA1616
97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
using Windows.Storage;
|
|
using WinUIEx;
|
|
|
|
namespace RegistryPreview
|
|
{
|
|
public sealed partial class MainWindow : WindowEx
|
|
{
|
|
private void OpenWindowPlacementFile(string path, string filename)
|
|
{
|
|
string fileContents = string.Empty;
|
|
string storageFile = Path.Combine(path, filename);
|
|
if (File.Exists(storageFile))
|
|
{
|
|
try
|
|
{
|
|
StreamReader reader = new StreamReader(storageFile);
|
|
fileContents = reader.ReadToEnd();
|
|
reader.Close();
|
|
}
|
|
catch
|
|
{
|
|
// set up default JSON blob
|
|
fileContents = "{ }";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Task.Run(() => SaveWindowPlacementFile(path, filename)).GetAwaiter().GetResult();
|
|
}
|
|
|
|
try
|
|
{
|
|
jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents);
|
|
}
|
|
catch
|
|
{
|
|
// set up default JSON blob
|
|
fileContents = "{ }";
|
|
jsonWindowPlacement = Windows.Data.Json.JsonObject.Parse(fileContents);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save the window placement JSON blob out to a local file
|
|
/// </summary>
|
|
private async void SaveWindowPlacementFile(string path, string filename)
|
|
{
|
|
StorageFolder storageFolder = null;
|
|
StorageFile storageFile = null;
|
|
string fileContents = string.Empty;
|
|
|
|
try
|
|
{
|
|
storageFolder = await StorageFolder.GetFolderFromPathAsync(path);
|
|
}
|
|
catch (FileNotFoundException ex)
|
|
{
|
|
Debug.WriteLine(ex.Message);
|
|
Directory.CreateDirectory(path);
|
|
storageFolder = await StorageFolder.GetFolderFromPathAsync(path);
|
|
}
|
|
|
|
try
|
|
{
|
|
storageFile = await storageFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);
|
|
}
|
|
catch (FileNotFoundException ex)
|
|
{
|
|
Debug.WriteLine(ex.Message);
|
|
storageFile = await storageFolder.CreateFileAsync(filename);
|
|
}
|
|
|
|
try
|
|
{
|
|
if (jsonWindowPlacement != null)
|
|
{
|
|
fileContents = jsonWindowPlacement.Stringify();
|
|
await Windows.Storage.FileIO.WriteTextAsync(storageFile, fileContents);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|