mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
update data folders
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T>
|
||||
{
|
||||
// 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
|
||||
|
||||
28
src/modules/Projects/ProjectsEditor/Utils/FolderUtils.cs
Normal file
28
src/modules/Projects/ProjectsEditor/Utils/FolderUtils.cs
Normal file
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -72,13 +72,17 @@ struct ProjectsList
|
||||
std::vector<Project> 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
|
||||
|
||||
Reference in New Issue
Block a user