mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-24 07:29:35 +01:00
FancyZones and Shortcut Guide initial commit
Co-authored-by: Alexis Campailla <alexis@janeasystems.com> Co-authored-by: Bret Anderson <bretan@microsoft.com> Co-authored-by: Enrico Giordani <enrico.giordani@gmail.com> Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Jeff Bogdan <jeffbog@microsoft.com> Co-authored-by: March Rogers <marchr@microsoft.com> Co-authored-by: Mike Harsh <mharsh@microsoft.com> Co-authored-by: Nachum Bundak <Nachum.Bundak@microsoft.com> Co-authored-by: Oliver Jones <ojones@microsoft.com> Co-authored-by: Patrick Little <plittle@microsoft.com>
This commit is contained in:
committed by
Bartosz Sosnowski
parent
10c5396099
commit
8431b80e48
75
src/common/settings_helpers.cpp
Normal file
75
src/common/settings_helpers.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "pch.h"
|
||||
#include "settings_helpers.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
namespace PTSettingsHelper {
|
||||
std::wstring get_root_save_folder_location() {
|
||||
PWSTR local_app_path;
|
||||
std::wstring result(L"");
|
||||
|
||||
winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &local_app_path));
|
||||
result = std::wstring(local_app_path);
|
||||
CoTaskMemFree(local_app_path);
|
||||
|
||||
result += L"\\Microsoft\\PowerToys";
|
||||
std::filesystem::path save_path(result);
|
||||
if (!std::filesystem::exists(save_path)) {
|
||||
std::filesystem::create_directories(save_path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring get_module_save_folder_location(const std::wstring& powertoy_name) {
|
||||
std::wstring result = get_root_save_folder_location();
|
||||
result += L"\\";
|
||||
result += powertoy_name;
|
||||
std::filesystem::path save_path(result);
|
||||
if (!std::filesystem::exists(save_path)) {
|
||||
std::filesystem::create_directories(save_path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring get_module_save_file_location(const std::wstring& powertoy_name) {
|
||||
std::wstring result = get_module_save_folder_location(powertoy_name);
|
||||
result += L"\\settings.json";
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring get_powertoys_general_save_file_location() {
|
||||
std::wstring result = get_root_save_folder_location();
|
||||
result += L"\\settings.json";
|
||||
return result;
|
||||
}
|
||||
|
||||
void save_module_settings(const std::wstring& powertoy_name, web::json::value& settings) {
|
||||
std::wstring save_file_location = get_module_save_file_location(powertoy_name);
|
||||
std::ofstream save_file(save_file_location, std::ios::binary);
|
||||
settings.serialize(save_file);
|
||||
save_file.close();
|
||||
}
|
||||
|
||||
web::json::value load_module_settings(const std::wstring& powertoy_name) {
|
||||
std::wstring save_file_location = get_module_save_file_location(powertoy_name);
|
||||
std::ifstream save_file(save_file_location, std::ios::binary);
|
||||
web::json::value result = web::json::value::parse(save_file);
|
||||
save_file.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
void save_general_settings(web::json::value& settings) {
|
||||
std::wstring save_file_location = get_powertoys_general_save_file_location();
|
||||
std::ofstream save_file(save_file_location, std::ios::binary);
|
||||
settings.serialize(save_file);
|
||||
save_file.close();
|
||||
}
|
||||
|
||||
web::json::value load_general_settings() {
|
||||
std::wstring save_file_location = get_powertoys_general_save_file_location();
|
||||
std::ifstream save_file(save_file_location, std::ios::binary);
|
||||
web::json::value result = web::json::value::parse(save_file);
|
||||
save_file.close();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user