Added functionality for General Settings Page (#1664)

* archive

* formmated code

* reverted changes to test class file.

* reverted changes to test file: reverted name

* added class models and updated link

* removed test console project
This commit is contained in:
Lavius Motileng
2020-03-24 19:55:02 -07:00
parent 2a0e92e4e2
commit 4243feaf37
32 changed files with 442 additions and 307 deletions

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
public class GeneralSettings
{
public bool packaged { get; set; }
public bool startup { get; set; }
public bool is_elevated { get; set; }
public bool run_elevated { get; set; }
public bool is_admin { get; set; }
public string theme { get; set; }
public string system_theme { get; set; }
public string powertoys_version { get; set; }
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
public class OutGoingGeneralSettings
{
public GeneralSettings general { get; set; }
public OutGoingGeneralSettings()
{
this.general = null;
}
public OutGoingGeneralSettings(GeneralSettings generalSettings)
{
this.general = generalSettings;
}
public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
}

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.7.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
namespace Microsoft.PowerToys.Settings.UI.Lib
{
public static class SettingsUtils
{
/// <summary>
/// Get path to the json settings file.
/// </summary>
/// <returns>string path.</returns>
public static string GetSettingsPath(string powertoy)
{
if(string.IsNullOrWhiteSpace(powertoy))
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
$"Microsoft\\PowerToys\\settings.json");
}
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
$"Microsoft\\PowerToys\\{powertoy}\\settings.json");
}
/// <summary>
/// Get a Deserialized object of the json settings string.
/// </summary>
/// <returns>Deserialized json settings object.</returns>
public static T GetSettings<T>(string powertoy)
{
var jsonSettingsString = System.IO.File.ReadAllText(SettingsUtils.GetSettingsPath(powertoy));
return JsonSerializer.Deserialize<T>(jsonSettingsString);
}
/// <summary>
/// Save settings to a json file.
/// </summary>
/// <param name="settings">dynamic json settings object.</param>
public static void SaveSettings<T>(T settings, string powertoy)
{
if(settings != null)
{
System.IO.File.WriteAllText(
SettingsUtils.GetSettingsPath(powertoy),
settings.ToString());
}
}
}
}