update data folders

This commit is contained in:
seraphima
2024-06-12 17:52:04 +02:00
parent 7e93d1f767
commit 6fba21d9ad
5 changed files with 45 additions and 27 deletions

View File

@@ -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";
}
}

View File

@@ -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

View 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";
}
}
}

View File

@@ -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();
}

View File

@@ -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