diff --git a/src/modules/Projects/ProjectsEditor/Data/ProjectsData.cs b/src/modules/Projects/ProjectsEditor/Data/ProjectsData.cs index d3fc650056..e5937ca45f 100644 --- a/src/modules/Projects/ProjectsEditor/Data/ProjectsData.cs +++ b/src/modules/Projects/ProjectsEditor/Data/ProjectsData.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Projects.Data; +using ProjectsEditor.Utils; using static ProjectsEditor.Data.ProjectsData; namespace ProjectsEditor.Data @@ -14,7 +15,7 @@ namespace ProjectsEditor.Data { get { - return GetDataFolder() + "\\projects.json"; + return FolderUtils.DataFolder() + "\\projects.json"; } } diff --git a/src/modules/Projects/ProjectsEditor/Data/ProjectsEditorData`1.cs b/src/modules/Projects/ProjectsEditor/Data/ProjectsEditorData`1.cs index 48b12fdbea..9cee0c0943 100644 --- a/src/modules/Projects/ProjectsEditor/Data/ProjectsEditorData`1.cs +++ b/src/modules/Projects/ProjectsEditor/Data/ProjectsEditorData`1.cs @@ -2,8 +2,6 @@ // 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; using System.Text.Json; using ProjectsEditor.Utils; @@ -11,18 +9,6 @@ namespace Projects.Data { public class ProjectsEditorData { - // Note: the same path should be used in SnapshotTool and Launcher - public string GetDataFolder() - { - // return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - return Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - } - - public string GetTempDataFolder() - { - return Path.GetTempPath(); - } - protected JsonSerializerOptions JsonOptions { get diff --git a/src/modules/Projects/ProjectsEditor/Utils/FolderUtils.cs b/src/modules/Projects/ProjectsEditor/Utils/FolderUtils.cs new file mode 100644 index 0000000000..38b6856338 --- /dev/null +++ b/src/modules/Projects/ProjectsEditor/Utils/FolderUtils.cs @@ -0,0 +1,28 @@ +// 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; + +namespace ProjectsEditor.Utils +{ + public class FolderUtils + { + public static string Desktop() + { + return Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + } + + public static string Temp() + { + return Path.GetTempPath(); + } + + // Note: the same path should be used in SnapshotTool and Launcher + public static string DataFolder() + { + return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Microsoft\\PowerToys\\Projects"; + } + } +} diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs index e6da20086e..c8b7295f54 100644 --- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs +++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs @@ -136,20 +136,19 @@ namespace ProjectsEditor.ViewModels private void CreateShortcut(Project project) { - object shDesktop = (object)"Desktop"; - IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); - string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + $"\\{project.Name}.lnk"; - IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress); - shortcut.Description = $"Project Launcher {project.Id}"; string basePath = AppDomain.CurrentDomain.BaseDirectory; - shortcut.TargetPath = Path.Combine(basePath, "PowerToys.ProjectsLauncher.exe"); - shortcut.Arguments = '"' + project.Id + '"'; - shortcut.WorkingDirectory = basePath; + string shortcutAddress = FolderUtils.Desktop() + $"\\{project.Name}.lnk"; + string shortcutIconFilename = FolderUtils.Temp() + $"\\{project.Name}.ico"; - string shortcutIconFilename = (string)shell.SpecialFolders.Item(ref shDesktop) + $"\\{project.Name}.ico"; Bitmap icon = ProjectIcon.DrawIcon(ProjectIcon.IconTextFromProjectName(project.Name)); ProjectIcon.SaveIcon(icon, shortcutIconFilename); + IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); + IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress); + shortcut.Description = $"Project Launcher {project.Id}"; + shortcut.TargetPath = Path.Combine(basePath, "PowerToys.ProjectsLauncher.exe"); + shortcut.Arguments = '"' + project.Id + '"'; + shortcut.WorkingDirectory = basePath; shortcut.IconLocation = shortcutIconFilename; shortcut.Save(); } diff --git a/src/modules/Projects/projects-common/Data.h b/src/modules/Projects/projects-common/Data.h index a24cc66767..b79c296320 100644 --- a/src/modules/Projects/projects-common/Data.h +++ b/src/modules/Projects/projects-common/Data.h @@ -72,13 +72,17 @@ struct ProjectsList std::vector projects; }; +namespace NonLocalizable +{ + const inline wchar_t ModuleKey[] = L"Projects"; +} + namespace JsonUtils { inline std::wstring ProjectsFile() { - wchar_t path[MAX_PATH + 1] = { 0 }; - SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, path); - return std::wstring(path) + L"\\projects.json"; + std::wstring settingsFolderPath = PTSettingsHelper::get_module_save_folder_location(NonLocalizable::ModuleKey); + return std::wstring(settingsFolderPath) + L"\\projects.json"; } namespace ProjectJSON