Files
PowerToys/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.WindowsSettings/Helper/WindowsSettingsPathHelper.cs

68 lines
3.2 KiB
C#
Raw Normal View History

// 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.Collections.Generic;
using System.Linq;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
{
/// <summary>
/// Helper class to help with the path of a <see cref="WindowsSetting"/>. The settings path shows where to find a setting within Windows' user interface.
/// </summary>
internal static class WindowsSettingsPathHelper
{
/// <summary>
/// The symbol which is used as delimiter between the parts of the path.
/// </summary>
private const string _pathDelimiterSequence = "\u0020\u0020\u02C3\u0020\u0020"; // = "<space><space><arrow><space><space>"
/// <summary>
/// Generates the values for <see cref="WindowsSetting.JoinedAreaPath"/> and <see cref="WindowsSetting.JoinedFullSettingsPath"/> on all settings of the given list with <see cref="WindowsSetting"/>.
/// </summary>
/// <param name="settingsList">The list that contains <see cref="WindowsSetting"/> to translate.</param>
internal static void GenerateSettingsPathValues(in IEnumerable<WindowsSetting>? settingsList)
{
if (settingsList is null)
{
return;
}
foreach (var settings in settingsList)
{
// Check if type value is filled. If not, then write log warning.
if (string.IsNullOrEmpty(settings.Type))
{
Log.Warn($"The type property is not set for setting [{settings.Name}] in json. Skipping generating of settings path.", typeof(WindowsSettingsPathHelper));
continue;
}
// Check if "JoinedAreaPath" and "JoinedFullSettingsPath" are filled. Then log debug message.
if (!string.IsNullOrEmpty(settings.JoinedAreaPath))
{
Log.Debug($"The property [JoinedAreaPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten.", typeof(WindowsSettingsPathHelper));
}
if (!string.IsNullOrEmpty(settings.JoinedFullSettingsPath))
{
Log.Debug($"The property [JoinedFullSettingsPath] of setting [{settings.Name}] was filled from the json. This value is not used and will be overwritten.", typeof(WindowsSettingsPathHelper));
}
// Generating path values.
if (!(settings.Areas is null) && settings.Areas.Any())
{
var areaValue = string.Join(WindowsSettingsPathHelper._pathDelimiterSequence, settings.Areas);
settings.JoinedAreaPath = areaValue;
settings.JoinedFullSettingsPath = $"{settings.Type}{WindowsSettingsPathHelper._pathDelimiterSequence}{areaValue}";
}
else
{
settings.JoinedAreaPath = string.Empty;
settings.JoinedFullSettingsPath = settings.Type;
}
}
}
}
}