// 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 { /// /// Helper class to help with the path of a . The settings path shows where to find a setting within Windows' user interface. /// internal static class WindowsSettingsPathHelper { /// /// The symbol which is used as delimiter between the parts of the path. /// private const string _pathDelimiterSequence = "\u0020\u0020\u02C3\u0020\u0020"; // = "" /// /// Generates the values for and on all settings of the list in the given class. /// /// A class that contain all possible windows settings. internal static void GenerateSettingsPathValues(in WindowsSettings windowsSettings) { if (windowsSettings?.Settings is null) { return; } foreach (var settings in windowsSettings.Settings) { // 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(_pathDelimiterSequence, settings.Areas); settings.JoinedAreaPath = areaValue; settings.JoinedFullSettingsPath = $"{settings.Type}{_pathDelimiterSequence}{areaValue}"; } else { settings.JoinedAreaPath = string.Empty; settings.JoinedFullSettingsPath = settings.Type; } } } } }