2020-11-03 01:33:43 +08:00
|
|
|
|
// 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.IO.Abstractions;
|
2023-05-16 06:32:26 +08:00
|
|
|
|
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
2020-11-03 01:33:43 +08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
|
|
|
|
{
|
|
|
|
|
public class SettingPath : ISettingsPath
|
|
|
|
|
{
|
|
|
|
|
private const string DefaultFileName = "settings.json";
|
|
|
|
|
|
|
|
|
|
private readonly IDirectory _directory;
|
|
|
|
|
|
|
|
|
|
private readonly IPath _path;
|
|
|
|
|
|
|
|
|
|
public SettingPath(IDirectory directory, IPath path)
|
|
|
|
|
{
|
|
|
|
|
_directory = directory ?? throw new ArgumentNullException(nameof(directory));
|
|
|
|
|
_path = path ?? throw new ArgumentNullException(nameof(path));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SettingsFolderExists(string powertoy)
|
|
|
|
|
{
|
2023-05-16 06:32:26 +08:00
|
|
|
|
return _directory.Exists(System.IO.Path.Combine(Helper.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
2020-11-03 01:33:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CreateSettingsFolder(string powertoy)
|
|
|
|
|
{
|
2023-05-16 06:32:26 +08:00
|
|
|
|
_directory.CreateDirectory(System.IO.Path.Combine(Helper.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
2020-11-03 01:33:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteSettings(string powertoy = "")
|
|
|
|
|
{
|
2023-05-16 06:32:26 +08:00
|
|
|
|
_directory.Delete(System.IO.Path.Combine(Helper.LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
2020-11-03 01:33:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get path to the json settings file.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>string path.</returns>
|
|
|
|
|
public string GetSettingsPath(string powertoy, string fileName = DefaultFileName)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(powertoy))
|
|
|
|
|
{
|
|
|
|
|
return _path.Combine(
|
2023-05-16 06:32:26 +08:00
|
|
|
|
Helper.LocalApplicationDataFolder(),
|
2020-11-03 01:33:43 +08:00
|
|
|
|
$"Microsoft\\PowerToys\\{fileName}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _path.Combine(
|
2023-05-16 06:32:26 +08:00
|
|
|
|
Helper.LocalApplicationDataFolder(),
|
2020-11-03 01:33:43 +08:00
|
|
|
|
$"Microsoft\\PowerToys\\{powertoy}\\{fileName}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|