mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
Merge branch 'master' into spelling
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public interface ISettingsPath
|
||||
{
|
||||
bool SettingsFolderExists(string powertoy);
|
||||
|
||||
void CreateSettingsFolder(string powertoy);
|
||||
|
||||
void DeleteSettings(string powertoy = "");
|
||||
|
||||
string GetSettingsPath(string powertoy, string fileName);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.IO.Abstractions" Version="12.2.5" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.7.2" />
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
|
||||
<Version>3.3.0</Version>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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;
|
||||
|
||||
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)
|
||||
{
|
||||
return _directory.Exists(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public void CreateSettingsFolder(string powertoy)
|
||||
{
|
||||
_directory.CreateDirectory(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public void DeleteSettings(string powertoy = "")
|
||||
{
|
||||
_directory.Delete(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
|
||||
/// <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(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{fileName}");
|
||||
}
|
||||
|
||||
return _path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{powertoy}\\{fileName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
@@ -15,49 +16,34 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
private const string DefaultFileName = "settings.json";
|
||||
private const string DefaultModuleName = "";
|
||||
private IIOProvider _ioProvider;
|
||||
private readonly IFile _file;
|
||||
private readonly ISettingsPath _settingsPath;
|
||||
|
||||
public SettingsUtils(IIOProvider ioProvider)
|
||||
public SettingsUtils()
|
||||
: this(new FileSystem())
|
||||
{
|
||||
_ioProvider = ioProvider ?? throw new ArgumentNullException(nameof(ioProvider));
|
||||
}
|
||||
|
||||
private bool SettingsFolderExists(string powertoy)
|
||||
public SettingsUtils(IFileSystem fileSystem)
|
||||
: this(fileSystem?.File, new SettingPath(fileSystem?.Directory, fileSystem?.Path))
|
||||
{
|
||||
return _ioProvider.DirectoryExists(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
private void CreateSettingsFolder(string powertoy)
|
||||
public SettingsUtils(IFile file, ISettingsPath settingPath)
|
||||
{
|
||||
_ioProvider.CreateDirectory(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
public void DeleteSettings(string powertoy = "")
|
||||
{
|
||||
_ioProvider.DeleteDirectory(System.IO.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{powertoy}"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get path to the json settings file.
|
||||
/// </summary>
|
||||
/// <returns>string path.</returns>
|
||||
public static string GetSettingsPath(string powertoy, string fileName = DefaultFileName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(powertoy))
|
||||
{
|
||||
return System.IO.Path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{fileName}");
|
||||
}
|
||||
|
||||
return System.IO.Path.Combine(
|
||||
LocalApplicationDataFolder(),
|
||||
$"Microsoft\\PowerToys\\{powertoy}\\{fileName}");
|
||||
_file = file ?? throw new ArgumentNullException(nameof(file));
|
||||
_settingsPath = settingPath;
|
||||
}
|
||||
|
||||
public bool SettingsExists(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
return _ioProvider.FileExists(GetSettingsPath(powertoy, fileName));
|
||||
var settingsPath = _settingsPath.GetSettingsPath(powertoy, fileName);
|
||||
return _file.Exists(settingsPath);
|
||||
}
|
||||
|
||||
public void DeleteSettings(string powertoy = "")
|
||||
{
|
||||
_settingsPath.DeleteSettings(powertoy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,7 +92,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
// Look at issue https://github.com/microsoft/PowerToys/issues/6413 you'll see the file has a large sum of \0 to fill up a 4096 byte buffer for writing to disk
|
||||
// This, while not totally ideal, does work around the problem by trimming the end.
|
||||
// The file itself did write the content correctly but something is off with the actual end of the file, hence the 0x00 bug
|
||||
var jsonSettingsString = _ioProvider.ReadAllText(GetSettingsPath(powertoyFolderName, fileName)).Trim('\0');
|
||||
var jsonSettingsString = _file.ReadAllText(_settingsPath.GetSettingsPath(powertoyFolderName, fileName)).Trim('\0');
|
||||
return JsonSerializer.Deserialize<T>(jsonSettingsString);
|
||||
}
|
||||
|
||||
@@ -118,12 +104,12 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
if (jsonSettings != null)
|
||||
{
|
||||
if (!SettingsFolderExists(powertoy))
|
||||
if (!_settingsPath.SettingsFolderExists(powertoy))
|
||||
{
|
||||
CreateSettingsFolder(powertoy);
|
||||
_settingsPath.CreateSettingsFolder(powertoy);
|
||||
}
|
||||
|
||||
_ioProvider.WriteAllText(GetSettingsPath(powertoy, fileName), jsonSettings);
|
||||
_file.WriteAllText(_settingsPath.GetSettingsPath(powertoy, fileName), jsonSettings);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -137,10 +123,5 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private static string LocalApplicationDataFolder()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.CustomAction;
|
||||
@@ -13,6 +14,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
public static readonly IFileSystem FileSystem = new FileSystem();
|
||||
|
||||
public static bool AllowRunnerToForeground()
|
||||
{
|
||||
var result = false;
|
||||
@@ -47,22 +50,20 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
return sendCustomAction.ToJsonString();
|
||||
}
|
||||
|
||||
public static FileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
|
||||
public static IFileSystemWatcher GetFileWatcher(string moduleName, string fileName, Action onChangedCallback)
|
||||
{
|
||||
var path = Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
|
||||
var path = FileSystem.Path.Combine(LocalApplicationDataFolder(), $"Microsoft\\PowerToys\\{moduleName}");
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
if (!FileSystem.Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
FileSystem.Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
var watcher = new FileSystemWatcher
|
||||
{
|
||||
Path = path,
|
||||
Filter = fileName,
|
||||
NotifyFilter = NotifyFilters.LastWrite,
|
||||
EnableRaisingEvents = true,
|
||||
};
|
||||
var watcher = FileSystem.FileSystemWatcher.CreateNew();
|
||||
watcher.Path = path;
|
||||
watcher.Filter = fileName;
|
||||
watcher.NotifyFilter = NotifyFilters.LastWrite;
|
||||
watcher.EnableRaisingEvents = true;
|
||||
|
||||
watcher.Changed += (o, e) => onChangedCallback();
|
||||
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
private static readonly IPath Path = FileSystem.Path;
|
||||
private static readonly IDirectory Directory = FileSystem.Directory;
|
||||
|
||||
private static readonly string ApplicationLogPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft\\PowerToys\\Settings Logs");
|
||||
|
||||
static Logger()
|
||||
@@ -20,6 +24,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
Directory.CreateDirectory(ApplicationLogPath);
|
||||
}
|
||||
|
||||
// Using InvariantCulture since this is used for a log file name
|
||||
var logFilePath = Path.Combine(ApplicationLogPath, "Log_" + DateTime.Now.ToString(@"yyyy-MM-dd", CultureInfo.InvariantCulture) + ".txt");
|
||||
|
||||
Trace.Listeners.Add(new TextWriterTraceListener(logFilePath));
|
||||
|
||||
@@ -2,41 +2,61 @@
|
||||
// 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.IO;
|
||||
using System;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
|
||||
{
|
||||
public class SystemIOProvider : IIOProvider
|
||||
{
|
||||
private readonly IDirectory _directory;
|
||||
private readonly IFile _file;
|
||||
|
||||
public SystemIOProvider()
|
||||
: this(new FileSystem())
|
||||
{
|
||||
}
|
||||
|
||||
public SystemIOProvider(IFileSystem fileSystem)
|
||||
: this(fileSystem?.Directory, fileSystem?.File)
|
||||
{
|
||||
}
|
||||
|
||||
private SystemIOProvider(IDirectory directory, IFile file)
|
||||
{
|
||||
_directory = directory ?? throw new ArgumentNullException(nameof(directory));
|
||||
_file = file ?? throw new ArgumentNullException(nameof(file));
|
||||
}
|
||||
|
||||
public bool CreateDirectory(string path)
|
||||
{
|
||||
var directoryInfo = Directory.CreateDirectory(path);
|
||||
var directoryInfo = _directory.CreateDirectory(path);
|
||||
return directoryInfo != null;
|
||||
}
|
||||
|
||||
public void DeleteDirectory(string path)
|
||||
{
|
||||
Directory.Delete(path, recursive: true);
|
||||
_directory.Delete(path, recursive: true);
|
||||
}
|
||||
|
||||
public bool DirectoryExists(string path)
|
||||
{
|
||||
return Directory.Exists(path);
|
||||
return _directory.Exists(path);
|
||||
}
|
||||
|
||||
public bool FileExists(string path)
|
||||
{
|
||||
return File.Exists(path);
|
||||
return _file.Exists(path);
|
||||
}
|
||||
|
||||
public string ReadAllText(string path)
|
||||
{
|
||||
return File.ReadAllText(path);
|
||||
return _file.ReadAllText(path);
|
||||
}
|
||||
|
||||
public void WriteAllText(string path, string content)
|
||||
{
|
||||
File.WriteAllText(path, content);
|
||||
_file.WriteAllText(path, content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
|
||||
{
|
||||
@@ -15,6 +13,9 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
|
||||
{
|
||||
public const string RootPathStubFiles = "..\\..\\..\\..\\src\\core\\Microsoft.PowerToys.Settings.UI.UnitTests\\BackwardsCompatibility\\TestFiles\\{0}\\Microsoft\\PowerToys\\{1}\\{2}";
|
||||
|
||||
// Using Ordinal since this is used internally for a path
|
||||
private static readonly Expression<Func<string, bool>> SettingsFilterExpression = s => s == null || s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
|
||||
|
||||
internal class MockSettingsRepository<T> : ISettingsRepository<T> where T : ISettingsConfig, new()
|
||||
{
|
||||
T _settingsConfig;
|
||||
@@ -43,44 +44,56 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility
|
||||
}
|
||||
|
||||
|
||||
public static Mock<IIOProvider>GetModuleIOProvider(string version, string module, string fileName)
|
||||
public static Mock<IFile>GetModuleIOProvider(string version, string module, string fileName)
|
||||
{
|
||||
|
||||
var stubSettingsPath = string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, module, fileName);
|
||||
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains(module, StringComparison.Ordinal);
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression);
|
||||
return mockIOProvider;
|
||||
var stubSettingsPath = StubSettingsPath(version, module, fileName);
|
||||
Expression<Func<string, bool>> filterExpression = ModuleFilterExpression(module);
|
||||
return IIOProviderMocks.GetMockIOReadWithStubFile(stubSettingsPath, filterExpression);
|
||||
}
|
||||
|
||||
public static void VerifyModuleIOProviderWasRead(Mock<IIOProvider> provider, string module, int expectedCallCount)
|
||||
public static string StubGeneralSettingsPath(string version)
|
||||
{
|
||||
return StubSettingsPath(version, string.Empty, "settings.json");
|
||||
}
|
||||
|
||||
public static string StubSettingsPath(string version, string module, string fileName)
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, module, fileName);
|
||||
}
|
||||
|
||||
public static void VerifyModuleIOProviderWasRead(Mock<IFile> provider, string module, int expectedCallCount)
|
||||
{
|
||||
if(provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
|
||||
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains(module, StringComparison.Ordinal);
|
||||
Expression<Func<string, bool>> filterExpression = ModuleFilterExpression(module);
|
||||
|
||||
IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount);
|
||||
}
|
||||
|
||||
public static Mock<IIOProvider> GetGeneralSettingsIOProvider(string version)
|
||||
private static Expression<Func<string, bool>> ModuleFilterExpression(string module)
|
||||
{
|
||||
var stubGeneralSettingsPath = string.Format(CultureInfo.InvariantCulture, BackCompatTestProperties.RootPathStubFiles, version, string.Empty, "settings.json");
|
||||
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
|
||||
var mockGeneralIOProvider = IIOProviderMocks.GetMockIOReadWithStubFile(stubGeneralSettingsPath, filterExpression);
|
||||
return mockGeneralIOProvider;
|
||||
// Using Ordinal since this is used internally for a path
|
||||
return s => s == null || s.Contains(module, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static void VerifyGeneralSettingsIOProviderWasRead(Mock<IIOProvider> provider, int expectedCallCount)
|
||||
public static Mock<IFile> GetGeneralSettingsIOProvider(string version)
|
||||
{
|
||||
var stubGeneralSettingsPath = StubGeneralSettingsPath(version);
|
||||
return IIOProviderMocks.GetMockIOReadWithStubFile(stubGeneralSettingsPath, SettingsFilterExpression);
|
||||
}
|
||||
|
||||
public static void VerifyGeneralSettingsIOProviderWasRead(Mock<IFile> provider, int expectedCallCount)
|
||||
{
|
||||
if (provider == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
}
|
||||
|
||||
Expression<Func<string, bool>> filterExpression = (string s) => s.Contains("Microsoft\\PowerToys\\settings.json", StringComparison.Ordinal);
|
||||
IIOProviderMocks.VerifyIOReadWithStubFile(provider, filterExpression, expectedCallCount);
|
||||
IIOProviderMocks.VerifyIOReadWithStubFile(provider, SettingsFilterExpression, expectedCallCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -29,6 +29,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="12.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
|
||||
{
|
||||
@@ -26,11 +25,13 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
|
||||
savePath = path;
|
||||
saveContent = content;
|
||||
});
|
||||
// Using Ordinal since this is used internally for a path
|
||||
mockIOProvider.Setup(x => x.ReadAllText(It.Is<string>(x => x.Equals(savePath, StringComparison.Ordinal))))
|
||||
.Returns(() => saveContent);
|
||||
|
||||
// Using Ordinal since this is used internally for a path
|
||||
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(x => x.Equals(savePath, StringComparison.Ordinal))))
|
||||
.Returns(true);
|
||||
// Using Ordinal since this is used internally for a path
|
||||
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(x => !x.Equals(savePath, StringComparison.Ordinal))))
|
||||
.Returns(false);
|
||||
|
||||
@@ -39,6 +40,8 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
|
||||
|
||||
|
||||
|
||||
private static readonly IFileSystem FileSystem = new FileSystem();
|
||||
private static readonly IFile File = FileSystem.File;
|
||||
/// <summary>
|
||||
/// This method mocks an IO provider so that it will always return data at the savePath location.
|
||||
/// This mock is specific to a given module, and is verifiable that the stub file was read.
|
||||
@@ -46,25 +49,25 @@ namespace Microsoft.PowerToys.Settings.UI.UnitTests.Mocks
|
||||
/// <param name="savePath">The path to the stub settings file</param>
|
||||
/// <param name="expectedPathSubstring">The substring in the path that identifies the module eg. Microsoft\\PowerToys\\ColorPicker</param>
|
||||
/// <returns></returns>
|
||||
internal static Mock<IIOProvider> GetMockIOReadWithStubFile(string savePath, Expression<Func<string, bool>> filterExpression)
|
||||
internal static Mock<IFile> GetMockIOReadWithStubFile(string savePath, Expression<Func<string, bool>> filterExpression)
|
||||
{
|
||||
string saveContent = File.ReadAllText(savePath);
|
||||
var mockIOProvider = new Mock<IIOProvider>();
|
||||
var fileMock = new Mock<IFile>();
|
||||
|
||||
|
||||
mockIOProvider.Setup(x => x.ReadAllText(It.Is<string>(filterExpression)))
|
||||
fileMock.Setup(x => x.ReadAllText(It.Is<string>(filterExpression)))
|
||||
.Returns(() => saveContent).Verifiable();
|
||||
|
||||
|
||||
mockIOProvider.Setup(x => x.FileExists(It.Is<string>(filterExpression)))
|
||||
fileMock.Setup(x => x.Exists(It.Is<string>(filterExpression)))
|
||||
.Returns(true);
|
||||
|
||||
return mockIOProvider;
|
||||
return fileMock;
|
||||
}
|
||||
|
||||
internal static void VerifyIOReadWithStubFile(Mock<IIOProvider> mockIOProvider, Expression<Func<string, bool>> filterExpression, int expectedCallCount)
|
||||
internal static void VerifyIOReadWithStubFile(Mock<IFile> fileMock, Expression<Func<string, bool>> filterExpression, int expectedCallCount)
|
||||
{
|
||||
mockIOProvider.Verify(x => x.ReadAllText(It.Is<string>(filterExpression)), Times.Exactly(expectedCallCount));
|
||||
fileMock.Verify(x => x.ReadAllText(It.Is<string>(filterExpression)), Times.Exactly(expectedCallCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ using System;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using Microsoft.PowerToys.Settings.UnitTest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Schema;
|
||||
|
||||
@@ -25,11 +25,8 @@ namespace CommonLibTest
|
||||
public void ToJsonStringShouldReturnValidJSONOfModelWhenSuccessful()
|
||||
{
|
||||
//Mock Disk access
|
||||
string saveContent = string.Empty;
|
||||
string savePath = string.Empty;
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
|
||||
var settingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var mockFileSystem = new MockFileSystem();
|
||||
var settingsUtils = new SettingsUtils(mockFileSystem);
|
||||
|
||||
// Arrange
|
||||
string file_name = "test\\BasePTModuleSettingsTest";
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
// 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.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Microsoft.PowerToys.Settings.UnitTest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
@@ -19,14 +22,13 @@ namespace CommonLibTest
|
||||
public class SettingsUtilsTests
|
||||
{
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void SaveSettingsSaveSettingsToFileWhenFilePathExists()
|
||||
{
|
||||
// Arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var settingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
|
||||
var mockFileSystem = new MockFileSystem();
|
||||
var settingsUtils = new SettingsUtils(mockFileSystem);
|
||||
|
||||
string file_name = "\\test";
|
||||
string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";
|
||||
|
||||
@@ -44,8 +46,8 @@ namespace CommonLibTest
|
||||
public void SaveSettingsShouldCreateFileWhenFilePathIsNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var settingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var mockFileSystem = new MockFileSystem();
|
||||
var settingsUtils = new SettingsUtils(mockFileSystem);
|
||||
string file_name = "test\\Test Folder";
|
||||
string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";
|
||||
|
||||
@@ -62,8 +64,8 @@ namespace CommonLibTest
|
||||
public void SettingsFolderExistsShouldReturnFalseWhenFilePathIsNotFound()
|
||||
{
|
||||
// Arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var settingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var mockFileSystem = new MockFileSystem();
|
||||
var settingsUtils = new SettingsUtils(mockFileSystem);
|
||||
string file_name_random = "test\\" + RandomString();
|
||||
string file_name_exists = "test\\exists";
|
||||
string file_contents_correct_json_content = "{\"name\":\"powertoy module name\",\"version\":\"powertoy version\"}";
|
||||
@@ -79,6 +81,21 @@ namespace CommonLibTest
|
||||
Assert.IsTrue(pathFound);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SettingsUtilsMustReturnDefaultItemWhenFileIsCorrupt()
|
||||
{
|
||||
// Arrange
|
||||
var mockFileSystem = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(mockFileSystem);
|
||||
|
||||
// Act
|
||||
TestClass settings = mockSettingsUtils.GetSettings<TestClass>(string.Empty);
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual(settings.TestInt, 100);
|
||||
Assert.AreEqual(settings.TestString, "test");
|
||||
}
|
||||
|
||||
public static string RandomString()
|
||||
{
|
||||
Random random = new Random();
|
||||
@@ -88,5 +105,26 @@ namespace CommonLibTest
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[random.Next(s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
partial class TestClass : ISettingsConfig
|
||||
{
|
||||
public int TestInt { get; set; } = 100;
|
||||
public string TestString { get; set; } = "test";
|
||||
|
||||
public string GetModuleName()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string ToJsonString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
public bool UpgradeSettingsConfiguration()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
// 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.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
|
||||
namespace ViewModelTests
|
||||
{
|
||||
@@ -27,11 +26,14 @@ namespace ViewModelTests
|
||||
{
|
||||
//Arrange
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, ColorPickerSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
ColorPickerSettings originalSettings = mockSettingsUtils.GetSettings<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using CommonLibTest;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
@@ -33,13 +30,16 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0", "settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, FancyZonesSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
|
||||
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, FancyZonesSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
FancyZonesSettings originalSettings = mockSettingsUtils.GetSettings<FancyZonesSettings>(FancyZonesSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
var fancyZonesRepository = new BackCompatTestProperties.MockSettingsRepository<FancyZonesSettings>(mockSettingsUtils);
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace ViewModelTests
|
||||
|
||||
//Verify that the stub file was used
|
||||
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, FancyZonesSettings.ModuleName, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, FancyZonesSettings.ModuleName, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
@@ -12,7 +11,7 @@ using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using NuGet.Frameworks;
|
||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||
|
||||
namespace ViewModelTests
|
||||
{
|
||||
@@ -40,16 +39,20 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0")]
|
||||
public void OriginalFilesModificationTest(string version)
|
||||
{
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
var fileMock = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
// Arrange
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => 0;
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => 0;
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => 0;
|
||||
var viewModel = new GeneralViewModel(
|
||||
settingsRepository: generalSettingsRepository,
|
||||
runAsAdminText: "GeneralSettings_RunningAsAdminText",
|
||||
@@ -71,7 +74,7 @@ namespace ViewModelTests
|
||||
|
||||
//Verify that the stub file was used
|
||||
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(fileMock, expectedCallCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -82,7 +85,7 @@ namespace ViewModelTests
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
|
||||
GeneralViewModel viewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
"GeneralSettings_RunningAsAdminText",
|
||||
"GeneralSettings_RunningAsUserText",
|
||||
false,
|
||||
@@ -119,7 +122,7 @@ namespace ViewModelTests
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
|
||||
GeneralViewModel viewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
"GeneralSettings_RunningAsAdminText",
|
||||
"GeneralSettings_RunningAsUserText",
|
||||
false,
|
||||
@@ -151,7 +154,7 @@ namespace ViewModelTests
|
||||
|
||||
// Arrange
|
||||
GeneralViewModel viewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
"GeneralSettings_RunningAsAdminText",
|
||||
"GeneralSettings_RunningAsUserText",
|
||||
false,
|
||||
@@ -184,7 +187,7 @@ namespace ViewModelTests
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
|
||||
viewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
"GeneralSettings_RunningAsAdminText",
|
||||
"GeneralSettings_RunningAsUserText",
|
||||
false,
|
||||
@@ -215,7 +218,7 @@ namespace ViewModelTests
|
||||
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
|
||||
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
|
||||
GeneralViewModel viewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
settingsRepository: SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
|
||||
"GeneralSettings_RunningAsAdminText",
|
||||
"GeneralSettings_RunningAsUserText",
|
||||
false,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// 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.IO.Abstractions.TestingHelpers;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
@@ -20,16 +20,15 @@ namespace ViewModelTests
|
||||
[TestClass]
|
||||
public class ImageResizer
|
||||
{
|
||||
private Mock<ISettingsUtils> _mockGeneralSettingsUtils;
|
||||
|
||||
private Mock<ISettingsUtils> mockGeneralSettingsUtils;
|
||||
|
||||
private Mock<ISettingsUtils> mockImgResizerSettingsUtils;
|
||||
private Mock<ISettingsUtils> _mockImgResizerSettingsUtils;
|
||||
|
||||
[TestInitialize]
|
||||
public void SetUpStubSettingUtils()
|
||||
{
|
||||
mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>();
|
||||
mockImgResizerSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
_mockGeneralSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>();
|
||||
_mockImgResizerSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +43,17 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0", "settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, ImageResizerSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
|
||||
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, ImageResizerSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
|
||||
ImageResizerSettings originalSettings = mockSettingsUtils.GetSettings<ImageResizerSettings>(ImageResizerSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
var mockGeneralFileMock = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralFileMock.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
@@ -69,8 +72,8 @@ namespace ViewModelTests
|
||||
|
||||
//Verify that the stub file was used
|
||||
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, ImageResizerSettings.ModuleName, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, ImageResizerSettings.ModuleName, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralFileMock, expectedCallCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -85,7 +88,7 @@ namespace ViewModelTests
|
||||
};
|
||||
|
||||
// arrange
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockImgResizerSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(_mockImgResizerSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.IsEnabled = true;
|
||||
@@ -95,16 +98,16 @@ namespace ViewModelTests
|
||||
public void JPEGQualityLevelShouldSetValueToTenWhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.JPEGQualityLevel = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(10, viewModel.JPEGQualityLevel);
|
||||
}
|
||||
|
||||
@@ -112,16 +115,16 @@ namespace ViewModelTests
|
||||
public void PngInterlaceOptionShouldSetValueToTenWhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.PngInterlaceOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(10, viewModel.PngInterlaceOption);
|
||||
}
|
||||
|
||||
@@ -129,16 +132,16 @@ namespace ViewModelTests
|
||||
public void TiffCompressOptionShouldSetValueToTenWhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.TiffCompressOption = 10;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(10, viewModel.TiffCompressOption);
|
||||
}
|
||||
|
||||
@@ -146,17 +149,17 @@ namespace ViewModelTests
|
||||
public void FileNameShouldUpdateValueWhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
string expectedValue = "%1 (%3)";
|
||||
|
||||
// act
|
||||
viewModel.FileName = expectedValue;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
Assert.AreEqual(expectedValue, viewModel.FileName);
|
||||
}
|
||||
|
||||
@@ -167,6 +170,7 @@ namespace ViewModelTests
|
||||
var settingUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
|
||||
var expectedSettingsString = new ImageResizerSettings() { Properties = new ImageResizerProperties() { ImageresizerKeepDateModified = new BoolProperty() { Value = true } } }.ToJsonString();
|
||||
// Using Ordinal since this is used internally
|
||||
settingUtils.Setup(x => x.SaveSettings(
|
||||
It.Is<string>(content => content.Equals(expectedSettingsString, StringComparison.Ordinal)),
|
||||
It.Is<string>(module => module.Equals(ImageResizerSettings.ModuleName, StringComparison.Ordinal)),
|
||||
@@ -174,7 +178,7 @@ namespace ViewModelTests
|
||||
.Verifiable();
|
||||
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(settingUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.KeepDateModified = true;
|
||||
@@ -187,16 +191,16 @@ namespace ViewModelTests
|
||||
public void EncoderShouldUpdateValueWhenSuccessful()
|
||||
{
|
||||
// arrange
|
||||
var mockIOProvider = IIOProviderMocks.GetMockIOProviderForSaveLoadExists();
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var fileSystemMock = new MockFileSystem();
|
||||
var mockSettingsUtils = new SettingsUtils(fileSystemMock);
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
|
||||
// act
|
||||
viewModel.Encoder = 3;
|
||||
|
||||
// Assert
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
viewModel = new ImageResizerViewModel(mockSettingsUtils, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
Assert.AreEqual("163bcc30-e2e9-4f0b-961d-a3e9fdb788a3", viewModel.EncoderGuid);
|
||||
Assert.AreEqual(3, viewModel.Encoder);
|
||||
}
|
||||
@@ -207,7 +211,7 @@ namespace ViewModelTests
|
||||
// arrange
|
||||
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
|
||||
// act
|
||||
@@ -223,7 +227,7 @@ namespace ViewModelTests
|
||||
// arrange
|
||||
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ImageResizerSettings>();
|
||||
Func<string, int> SendMockIPCConfigMSG = msg => { return 0; };
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
ImageResizerViewModel viewModel = new ImageResizerViewModel(mockSettingsUtils.Object, SettingsRepository<GeneralSettings>.GetInstance(_mockGeneralSettingsUtils.Object), SendMockIPCConfigMSG);
|
||||
int sizeOfOriginalArray = viewModel.Sizes.Count;
|
||||
ImageSize deleteCandidate = viewModel.Sizes.Where<ImageSize>(x => x.Id == 0).First();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using Moq;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.Mocks;
|
||||
using Microsoft.PowerToys.Settings.UI.UnitTests.BackwardsCompatibility;
|
||||
using System.Globalization;
|
||||
using System.IO.Abstractions;
|
||||
|
||||
namespace ViewModelTests
|
||||
{
|
||||
@@ -52,13 +53,16 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0", "settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerLauncherSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
PowerLauncherSettings originalSettings = mockSettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
// Initialise View Model with test Config files
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
@@ -40,13 +40,15 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0", "settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerPreviewSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
var fileMock = BackCompatTestProperties.GetModuleIOProvider(version, PowerPreviewSettings.ModuleName, fileName);
|
||||
|
||||
var mockSettingsUtils = new SettingsUtils(fileMock.Object, settingPathMock.Object);
|
||||
PowerPreviewSettings originalSettings = mockSettingsUtils.GetSettings<PowerPreviewSettings>(PowerPreviewSettings.ModuleName);
|
||||
var repository = new BackCompatTestProperties.MockSettingsRepository<PowerPreviewSettings>(mockSettingsUtils);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
@@ -62,7 +64,7 @@ namespace ViewModelTests
|
||||
|
||||
//Verify that the stub file was used
|
||||
var expectedCallCount = 2; //once via the view model, and once by the test (GetSettings<T>)
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(mockIOProvider, PowerPreviewSettings.ModuleName, expectedCallCount);
|
||||
BackCompatTestProperties.VerifyModuleIOProviderWasRead(fileMock, PowerPreviewSettings.ModuleName, expectedCallCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
@@ -40,12 +40,16 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0", "power-rename-settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, PowerRenameSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
PowerRenameLocalProperties originalSettings = mockSettingsUtils.GetSettings<PowerRenameLocalProperties>(PowerRenameSettings.ModuleName);
|
||||
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
@@ -30,12 +29,13 @@ namespace ViewModelTests
|
||||
[DataRow("v0.22.0", "settings.json")]
|
||||
public void OriginalFilesModificationTest(string version, string fileName)
|
||||
{
|
||||
var settingPathMock = new Mock<ISettingsPath>();
|
||||
var mockIOProvider = BackCompatTestProperties.GetModuleIOProvider(version, ShortcutGuideSettings.ModuleName, fileName);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object);
|
||||
var mockSettingsUtils = new SettingsUtils(mockIOProvider.Object, settingPathMock.Object);
|
||||
ShortcutGuideSettings originalSettings = mockSettingsUtils.GetSettings<ShortcutGuideSettings>(ShortcutGuideSettings.ModuleName);
|
||||
|
||||
var mockGeneralIOProvider = BackCompatTestProperties.GetGeneralSettingsIOProvider(version);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object);
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettings<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
var shortcutSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<ShortcutGuideSettings>(mockSettingsUtils);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Media;
|
||||
@@ -14,7 +13,7 @@ namespace Microsoft.PowerToys.Settings.UI.Converters
|
||||
{
|
||||
public sealed class ModuleEnabledToForegroundConverter : IValueConverter
|
||||
{
|
||||
private readonly ISettingsUtils settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
private readonly ISettingsUtils settingsUtils = new SettingsUtils();
|
||||
|
||||
private string selectedTheme = string.Empty;
|
||||
|
||||
|
||||
@@ -163,7 +163,10 @@
|
||||
</data>
|
||||
<data name="KeyboardManager_EnableToggle.Header" xml:space="preserve">
|
||||
<value>Enable Keyboard Manager</value>
|
||||
<comment>Keyboard Manager enable toggle header</comment>
|
||||
<comment>
|
||||
Keyboard Manager enable toggle header
|
||||
do not loc the Product name. Do you want this feature on / off
|
||||
</comment>
|
||||
</data>
|
||||
<data name="KeyboardManager_ProfileDescription.Text" xml:space="preserve">
|
||||
<value>Select the profile to display the active key remap and shortcuts</value>
|
||||
@@ -214,6 +217,7 @@
|
||||
</data>
|
||||
<data name="ColorPicker_EnableColorPicker.Header" xml:space="preserve">
|
||||
<value>Enable Color Picker</value>
|
||||
<comment>do not loc the Product name. Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="ColorPicker_ChangeCursor.Content" xml:space="preserve">
|
||||
<value>Change cursor when picking a color</value>
|
||||
@@ -229,6 +233,7 @@
|
||||
</data>
|
||||
<data name="PowerLauncher_EnablePowerLauncher.Header" xml:space="preserve">
|
||||
<value>Enable PowerToys Run</value>
|
||||
<comment>do not loc the Product name. Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="PowerLauncher_SearchResults.Text" xml:space="preserve">
|
||||
<value>Search & results</value>
|
||||
@@ -311,6 +316,7 @@
|
||||
</data>
|
||||
<data name="FancyZones_EnableToggleControl_HeaderText.Header" xml:space="preserve">
|
||||
<value>Enable FancyZones</value>
|
||||
<comment>do not loc the Product name. Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FancyZones_ExcludeApps.Text" xml:space="preserve">
|
||||
<value>Excluded apps</value>
|
||||
@@ -373,10 +379,12 @@
|
||||
<value>Give feedback</value>
|
||||
</data>
|
||||
<data name="Module_overview.Text" xml:space="preserve">
|
||||
<value>Module overview</value>
|
||||
<value>Learn more</value>
|
||||
<comment>This label is there to point people to additional overview for how to use the product</comment>
|
||||
</data>
|
||||
<data name="AttributionTitle.Text" xml:space="preserve">
|
||||
<value>Attribution</value>
|
||||
<comment>giving credit to the projects this utility was based on</comment>
|
||||
</data>
|
||||
<data name="GeneralPage_AboutPowerToysHeader.Text" xml:space="preserve">
|
||||
<value>About PowerToys</value>
|
||||
@@ -392,12 +400,15 @@
|
||||
</data>
|
||||
<data name="GeneralPage_ReportAbug.Text" xml:space="preserve">
|
||||
<value>Report a bug</value>
|
||||
<comment>Report an issue inside powertoys</comment>
|
||||
</data>
|
||||
<data name="GeneralPage_RequestAFeature_URL.Text" xml:space="preserve">
|
||||
<value>Request a feature</value>
|
||||
<comment>Tell our team what we should build</comment>
|
||||
</data>
|
||||
<data name="GeneralPage_RestartAsAdmin_Button.Content" xml:space="preserve">
|
||||
<value>Restart as administrator</value>
|
||||
<comment>running PowerToys as a higher level user, account is typically referred to as an admin / administrator</comment>
|
||||
</data>
|
||||
<data name="GeneralPage_ToggleSwitch_RunAtStartUp.Header" xml:space="preserve">
|
||||
<value>Run at startup</value>
|
||||
@@ -407,9 +418,11 @@
|
||||
</data>
|
||||
<data name="PowerRename_ShellIntegration.Text" xml:space="preserve">
|
||||
<value>Shell integration</value>
|
||||
<comment>This refers to directly integrating in with Windows</comment>
|
||||
</data>
|
||||
<data name="PowerRename_Toggle_Enable.Header" xml:space="preserve">
|
||||
<value>Enable PowerRename</value>
|
||||
<comment>do not loc the Product name. Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="RadioButtons_Name_Theme.Text" xml:space="preserve">
|
||||
<value>Settings theme</value>
|
||||
@@ -428,12 +441,15 @@
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_MD.Header" xml:space="preserve">
|
||||
<value>Enable Markdown (.md) preview</value>
|
||||
<comment>Do not loc "Markdown". Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_Preview_SVG.Header" xml:space="preserve">
|
||||
<value>Enable SVG (.svg) preview</value>
|
||||
<comment>Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_ToggleSwitch_SVG_Thumbnail.Header" xml:space="preserve">
|
||||
<value>Enable SVG (.svg) thumbnails</value>
|
||||
<comment>Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="FileExplorerPreview_Description.Text" xml:space="preserve">
|
||||
<value>These settings allow you to manage your Windows File Explorer custom preview handlers.</value>
|
||||
@@ -464,6 +480,7 @@
|
||||
</data>
|
||||
<data name="ShortcutGuide_Enable.Header" xml:space="preserve">
|
||||
<value>Enable Shortcut Guide</value>
|
||||
<comment>do not loc the Product name. Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="ShortcutGuide_OverlayOpacity.Header" xml:space="preserve">
|
||||
<value>Opacity of background</value>
|
||||
@@ -476,6 +493,7 @@
|
||||
</data>
|
||||
<data name="ImageResizer_EnableToggle.Header" xml:space="preserve">
|
||||
<value>Enable Image Resizer</value>
|
||||
<comment>do not loc the Product name. Do you want this feature on / off</comment>
|
||||
</data>
|
||||
<data name="ImagesSizesListView.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Image Size</value>
|
||||
@@ -768,4 +786,4 @@
|
||||
<value>Windows color settings</value>
|
||||
<comment>Windows refers to the Operating system</comment>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// 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.IO.Abstractions;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
@@ -15,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
|
||||
public ColorPickerPage()
|
||||
{
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new ColorPickerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
InitializeComponent();
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public FancyZonesPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new FancyZonesViewModel(SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), SettingsRepository<FancyZonesSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
|
||||
// Load string resources
|
||||
ResourceLoader loader = ResourceLoader.GetForViewIndependentUse();
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
|
||||
ViewModel = new GeneralViewModel(
|
||||
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public ImageResizerPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new ImageResizerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
@@ -24,7 +24,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
private const string PowerToyName = "Keyboard Manager";
|
||||
|
||||
private readonly CoreDispatcher dispatcher;
|
||||
private readonly FileSystemWatcher watcher;
|
||||
private readonly IFileSystemWatcher watcher;
|
||||
|
||||
public KeyboardManagerViewModel ViewModel { get; }
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
dispatcher = Window.Current.Dispatcher;
|
||||
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new KeyboardManagerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, FilterRemapKeysList);
|
||||
|
||||
watcher = Helper.GetFileWatcher(
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public PowerLauncherPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new PowerLauncherViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, (int)Windows.System.VirtualKey.Space);
|
||||
DataContext = ViewModel;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public PowerPreviewPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new PowerPreviewViewModel(SettingsRepository<PowerPreviewSettings>.GetInstance(settingsUtils), SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public PowerRenamePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new PowerRenameViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
|
||||
DataContext = ViewModel;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
var settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new ShortcutGuideViewModel(SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), SettingsRepository<ShortcutGuideSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
}
|
||||
|
||||
@@ -148,6 +148,9 @@
|
||||
<Item ItemId=";ColorModeHeader.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Choose a mode]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[モードの選択]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
@@ -1483,33 +1486,6 @@
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Dark.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Dark]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[ダーク]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Default.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[System default]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[システムの既定値]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Light.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Light]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[ライト]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_SearchResultPreference.Header" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Search result preference]]></Val>
|
||||
@@ -1600,15 +1576,6 @@
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Theme.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Choose color]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[色の選択]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerRename_AutoCompleteHeader.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Autocomplete]]></Val>
|
||||
@@ -1783,7 +1750,7 @@
|
||||
<Item ItemId=";SettingsPage_SetShortcut.AutomationProperties.Name" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Shortcut setting]]></Val>
|
||||
<Tgt Cat="Text" Stat="Update" Orig="New">
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[ショートカットの設定]]></Val>
|
||||
</Tgt>
|
||||
<Prev Cat="Text">
|
||||
|
||||
@@ -148,6 +148,9 @@
|
||||
<Item ItemId=";ColorModeHeader.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Choose a mode]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Välj ett läge]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
@@ -1483,33 +1486,6 @@
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Dark.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Dark]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Mörk]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Default.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[System default]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Systemstandard]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Light.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Light]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Ljus]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_SearchResultPreference.Header" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Search result preference]]></Val>
|
||||
@@ -1600,12 +1576,6 @@
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Theme.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Choose color]]></Val>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerRename_AutoCompleteHeader.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Autocomplete]]></Val>
|
||||
@@ -1736,7 +1706,7 @@
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Windows default]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Windows-standard]]></Val>
|
||||
<Val><![CDATA[Windows-standardinställning]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
@@ -1780,8 +1750,8 @@
|
||||
<Item ItemId=";SettingsPage_SetShortcut.AutomationProperties.Name" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Shortcut setting]]></Val>
|
||||
<Tgt Cat="Text" Stat="Update" Orig="New">
|
||||
<Val><![CDATA[Ange genväg]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Genvägsinställning]]></Val>
|
||||
</Tgt>
|
||||
<Prev Cat="Text">
|
||||
<Val><![CDATA[Set Shortcut]]></Val>
|
||||
|
||||
@@ -148,6 +148,9 @@
|
||||
<Item ItemId=";ColorModeHeader.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Choose a mode]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Mod seçin]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
@@ -1483,33 +1486,6 @@
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Dark.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Dark]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Koyu]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Default.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[System default]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Sistem varsayılanı]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Radio_Theme_Light.Content" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Light]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Açık]]></Val>
|
||||
</Tgt>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_SearchResultPreference.Header" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Search result preference]]></Val>
|
||||
@@ -1600,12 +1576,6 @@
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerLauncher_Theme.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Choose color]]></Val>
|
||||
</Str>
|
||||
<Disp Icon="Str" />
|
||||
</Item>
|
||||
<Item ItemId=";PowerRename_AutoCompleteHeader.Text" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Autocomplete]]></Val>
|
||||
@@ -1780,8 +1750,8 @@
|
||||
<Item ItemId=";SettingsPage_SetShortcut.AutomationProperties.Name" ItemType="0;.resx" PsrId="211" Leaf="true">
|
||||
<Str Cat="Text">
|
||||
<Val><![CDATA[Shortcut setting]]></Val>
|
||||
<Tgt Cat="Text" Stat="Update" Orig="New">
|
||||
<Val><![CDATA[Kısayolu Ayarla]]></Val>
|
||||
<Tgt Cat="Text" Stat="Loc" Orig="New">
|
||||
<Val><![CDATA[Kısayol ayarı]]></Val>
|
||||
</Tgt>
|
||||
<Prev Cat="Text">
|
||||
<Val><![CDATA[Set Shortcut]]></Val>
|
||||
|
||||
Reference in New Issue
Block a user