/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/ShortcutGuide/ShortcutGuide.IndexYmlGenerator/IndexYmlGenerator.cs
68 строк
2 KB
Noraa Junker
Shortcut Guide V2 (#40834)
21 май 2026, 18:27
Не верифицирован
21 май 2026, 18:27
9699d8a
Код
Авторство
О чём код?
// 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.IO; using System.Linq; using ShortcutGuide.Helpers; using ShortcutGuide.Models; using YamlDotNet.Serialization; // This class should be moved to WinGet in the future namespace ShortcutGuide.IndexYmlGenerator { public class IndexYmlGenerator { public static void Main() { CreateIndexYmlFile(); } // Todo: Exception handling public static void CreateIndexYmlFile() { string path = ManifestInterpreter.PathOfManifestFiles; if (File.Exists(Path.Combine(path, "index.yml"))) { File.Delete(Path.Combine(path, "index.yml")); } IndexFile indexFile = new() { }; Dictionary<(string WindowFilter, bool BackgroundProcess), List<string>> processes = []; foreach (string file in Directory.EnumerateFiles(path, "*.yml")) { string content = File.ReadAllText(file); Deserializer deserializer = new(); ShortcutFile shortcutFile = deserializer.Deserialize<ShortcutFile>(content); if (processes.TryGetValue((shortcutFile.WindowFilter, shortcutFile.BackgroundProcess), out List<string>? apps)) { if (apps.Contains(shortcutFile.PackageName)) { continue; } apps.Add(shortcutFile.PackageName); continue; } processes[(shortcutFile.WindowFilter, shortcutFile.BackgroundProcess)] = [shortcutFile.PackageName]; } indexFile.Index = processes.Select(item => new IndexFile.IndexItem { WindowFilter = item.Key.WindowFilter, BackgroundProcess = item.Key.BackgroundProcess, Apps = [.. item.Value], }).ToArray(); // Todo: Take the default shell name from the settings or environment variable, default to "+WindowsNT.Shell" indexFile.DefaultShellName = "+WindowsNT.Shell"; Serializer serializer = new(); string yamlContent = serializer.Serialize(indexFile); File.WriteAllText(Path.Combine(path, "index.yml"), yamlContent); } } }