mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-26 18:58:29 +08:00
ee904ae1b1
* Merge and conflict resolution * Messages good, backup/restore algo better. * Start of "GetExportVerion" * fixed spelling * New backup/restore mode working. * Rename a project * Removed test project * Switch to text.json * Renamed BackupAndSync to BackupAndRestore * Added IgnoredPTRunSettings and full merge * Restored "fixed" settings that change for no reason * Various UI updates. * speling * Some cleanup and zip support. * Merge and clean * code clean up * code clean up * code clean up * Smarter settings compare and merge. * config based file include/exclude * Removed some "words" * Code clean up * cleanup * cleanup * cleanup * cleanup * fixed spelling. * Fixed clean up 1 * more clean up * Trying to add ptb as an OK word * Some UI updates. * UI tweaks and PR review items. * UI tweaks * Merge conflicts resolved. * Added CurrentSettingMatchText * PR review updates. * Removed weird file. * Review updates and fixes * More UI tweaks. * UI tweaks * Set default backup location to "%USERPROFILE%\\Documents\\PowerToys\\Backup" * settings ui tweaks * Added ExpanderContentSettingStyle * fix missing config file * fix missing config file, part 2 * update ui, cleanup cope * update ui, cleanup code - Part2 * update method comments * code cleanup and adjust Backup message time * fix changing backup location on empty Regsitry * fix select location - part 2 * location input box min-width * remove lastRestoreDate from ViewModel * Code or backup timing, and error handling. * Should fix file/folder name crash. * Progress to instance class for backup/restore * Persist backup status state, added refresh button. * Better auto check for settings status * Some UI/text updates. * Clean up * Added prefix for "General_Settings" to resources * Code review updates. * Code review changes. * Changed to FolderPicker per review * Fixed issue with early delete of cleanup. * Testing issues with FolderPicker * Removed WinForm req and fixed win10 issue. * Review update. * Review changes. Co-authored-by: htcfreek <61519853+htcfreek@users.noreply.github.com>
126 lines
3.7 KiB
C#
126 lines
3.7 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.Globalization;
|
|
using System.IO;
|
|
using System.IO.Abstractions;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
{
|
|
public class UpdatingSettings
|
|
{
|
|
public enum UpdatingState
|
|
{
|
|
UpToDate = 0,
|
|
ErrorDownloading,
|
|
ReadyToDownload,
|
|
ReadyToInstall,
|
|
}
|
|
|
|
// Gets or sets a value of the updating state
|
|
[JsonPropertyName("state")]
|
|
public UpdatingState State { get; set; }
|
|
|
|
// Gets or sets a value of the release page url
|
|
[JsonPropertyName("releasePageUrl")]
|
|
public string ReleasePageLink { get; set; }
|
|
|
|
// Gets or sets a value of the github last checked date
|
|
[JsonPropertyName("githubUpdateLastCheckedDate")]
|
|
public string LastCheckedDate { get; set; }
|
|
|
|
// Gets or sets a value of the updating state
|
|
[JsonPropertyName("downloadedInstallerFilename")]
|
|
public string DownloadedInstallerFilename { get; set; }
|
|
|
|
// Non-localizable strings: Files
|
|
public const string SettingsFilePath = "\\Microsoft\\PowerToys\\";
|
|
public const string SettingsFile = "UpdateState.json";
|
|
|
|
public string NewVersion
|
|
{
|
|
get
|
|
{
|
|
if (ReleasePageLink == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
try
|
|
{
|
|
string version = ReleasePageLink.Substring(ReleasePageLink.LastIndexOf('/') + 1);
|
|
return version.Trim();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
public string LastCheckedDateLocalized
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
if (LastCheckedDate == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
long seconds = long.Parse(LastCheckedDate, CultureInfo.CurrentCulture);
|
|
var date = DateTimeOffset.FromUnixTimeSeconds(seconds).UtcDateTime;
|
|
return date.ToLocalTime().ToString(CultureInfo.CurrentCulture);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
}
|
|
|
|
public UpdatingSettings()
|
|
{
|
|
State = UpdatingState.UpToDate;
|
|
}
|
|
|
|
public static UpdatingSettings LoadSettings()
|
|
{
|
|
FileSystem fileSystem = new FileSystem();
|
|
var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
var file = localAppDataDir + SettingsFilePath + SettingsFile;
|
|
|
|
if (fileSystem.File.Exists(file))
|
|
{
|
|
try
|
|
{
|
|
Stream inputStream = fileSystem.File.Open(file, FileMode.Open);
|
|
StreamReader reader = new StreamReader(inputStream);
|
|
string data = reader.ReadToEnd();
|
|
inputStream.Close();
|
|
reader.Dispose();
|
|
|
|
return JsonSerializer.Deserialize<UpdatingSettings>(data);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public string ToJsonString()
|
|
{
|
|
return JsonSerializer.Serialize(this);
|
|
}
|
|
}
|
|
}
|