[FancyZones] Remove Editor tmp files paths cmd args and make Editor 'debugable' easier (#4279)

* Remove Editor cmd args - tmp files
Add 'Debug mode' startup for Editor

* Remove fixed device info string

* Move if file exist check

* Add enum to improve readability

* Introduce ParseDeviceMode enum

* Organize strings

* Move title to localizable strings
This commit is contained in:
stefansjfw
2020-07-06 17:40:25 +02:00
committed by GitHub
parent 3d623506a8
commit 70405045d7
8 changed files with 136 additions and 105 deletions

View File

@@ -552,7 +552,6 @@ void FancyZones::ToggleEditor() noexcept
std::to_wstring(height);
const auto& fancyZonesData = JSONHelpers::FancyZonesDataInstance();
fancyZonesData.CustomZoneSetsToJsonFile(ZoneWindowUtils::GetCustomZoneSetsTmpPath());
const auto deviceInfo = fancyZonesData.FindDeviceInfo(zoneWindow->UniqueId());
if (!deviceInfo.has_value())
@@ -565,10 +564,7 @@ void FancyZones::ToggleEditor() noexcept
const std::wstring params =
/*1*/ editorLocation + L" " +
/*2*/ L"\"" + ZoneWindowUtils::GetActiveZoneSetTmpPath() + L"\" " +
/*3*/ L"\"" + ZoneWindowUtils::GetAppliedZoneSetTmpPath() + L"\" " +
/*4*/ L"\"" + ZoneWindowUtils::GetCustomZoneSetsTmpPath() + L"\" " +
/*5*/ L"\"" + std::to_wstring(GetCurrentProcessId()) + L"\"";
/*2*/ L"\"" + std::to_wstring(GetCurrentProcessId()) + L"\"";
SHELLEXECUTEINFO sei{ sizeof(sei) };
sei.fMask = { SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI };
@@ -990,7 +986,7 @@ void FancyZones::OnEditorExitEvent() noexcept
{
// Collect information about changes in zone layout after editor exited.
JSONHelpers::FancyZonesDataInstance().ParseDeviceInfoFromTmpFile(ZoneWindowUtils::GetActiveZoneSetTmpPath());
JSONHelpers::FancyZonesDataInstance().ParseDeletedCustomZoneSetsFromTmpFile(ZoneWindowUtils::GetCustomZoneSetsTmpPath());
JSONHelpers::FancyZonesDataInstance().ParseDeletedCustomZoneSetsFromTmpFile(ZoneWindowUtils::GetDeletedCustomZoneSetsTmpPath());
JSONHelpers::FancyZonesDataInstance().ParseCustomZoneSetFromTmpFile(ZoneWindowUtils::GetAppliedZoneSetTmpPath());
JSONHelpers::FancyZonesDataInstance().SaveFancyZonesData();

View File

@@ -763,15 +763,6 @@ namespace JSONHelpers
return customZoneSetsJSON;
}
void FancyZonesData::CustomZoneSetsToJsonFile(std::wstring_view filePath) const
{
std::scoped_lock lock{ dataLock };
const auto& customZoneSetsJson = SerializeCustomZoneSets();
json::JsonObject root{};
root.SetNamedValue(L"custom-zone-sets", customZoneSetsJson);
json::to_file(filePath, root);
}
void FancyZonesData::LoadFancyZonesData()
{
std::scoped_lock lock{ dataLock };

View File

@@ -258,7 +258,6 @@ namespace JSONHelpers
json::JsonArray SerializeDeviceInfos() const;
bool ParseCustomZoneSets(const json::JsonObject& fancyZonesDataJSON);
json::JsonArray SerializeCustomZoneSets() const;
void CustomZoneSetsToJsonFile(std::wstring_view filePath) const;
void LoadFancyZonesData();
void SaveFancyZonesData() const;

View File

@@ -8,60 +8,52 @@
#include <ShellScalingApi.h>
#include <mutex>
#include <fileapi.h>
#include <gdiplus.h>
namespace ZoneWindowUtils
{
const std::wstring& GetActiveZoneSetTmpPath()
const wchar_t ActiveZoneSetsTmpFileName[] = L"FancyZonesActiveZoneSets.json";
const wchar_t AppliedZoneSetsTmpFileName[] = L"FancyZonesAppliedZoneSets.json";
const wchar_t DeletedCustomZoneSetsTmpFileName[] = L"FancyZonesDeletedCustomZoneSets.json";
const std::wstring& GetTempDirPath()
{
static std::wstring activeZoneSetTmpFileName;
static std::wstring tmpDirPath;
static std::once_flag flag;
std::call_once(flag, []() {
wchar_t fileName[L_tmpnam_s];
wchar_t buffer[MAX_PATH];
if (_wtmpnam_s(fileName, L_tmpnam_s) != 0)
abort();
auto charsWritten = GetTempPath(MAX_PATH, buffer);
if (charsWritten > MAX_PATH || (charsWritten == 0))
{
abort();
}
activeZoneSetTmpFileName = std::wstring{ fileName };
tmpDirPath = std::wstring{ buffer };
});
return tmpDirPath;
}
const std::wstring& GetActiveZoneSetTmpPath()
{
static std::wstring activeZoneSetTmpFileName = GetTempDirPath() + ActiveZoneSetsTmpFileName;
return activeZoneSetTmpFileName;
}
const std::wstring& GetAppliedZoneSetTmpPath()
{
static std::wstring appliedZoneSetTmpFileName;
static std::once_flag flag;
std::call_once(flag, []() {
wchar_t fileName[L_tmpnam_s];
if (_wtmpnam_s(fileName, L_tmpnam_s) != 0)
abort();
appliedZoneSetTmpFileName = std::wstring{ fileName };
});
static std::wstring appliedZoneSetTmpFileName = GetTempDirPath() + AppliedZoneSetsTmpFileName;
return appliedZoneSetTmpFileName;
}
const std::wstring& GetCustomZoneSetsTmpPath()
const std::wstring& GetDeletedCustomZoneSetsTmpPath()
{
static std::wstring customZoneSetsTmpFileName;
static std::once_flag flag;
std::call_once(flag, []() {
wchar_t fileName[L_tmpnam_s];
if (_wtmpnam_s(fileName, L_tmpnam_s) != 0)
abort();
customZoneSetsTmpFileName = std::wstring{ fileName };
});
return customZoneSetsTmpFileName;
static std::wstring deletedCustomZoneSetsTmpFileName = GetTempDirPath() + DeletedCustomZoneSetsTmpFileName;
return deletedCustomZoneSetsTmpFileName;
}
std::wstring GenerateUniqueId(HMONITOR monitor, PCWSTR deviceId, PCWSTR virtualDesktopId)

View File

@@ -6,7 +6,7 @@ namespace ZoneWindowUtils
{
const std::wstring& GetActiveZoneSetTmpPath();
const std::wstring& GetAppliedZoneSetTmpPath();
const std::wstring& GetCustomZoneSetsTmpPath();
const std::wstring& GetDeletedCustomZoneSetsTmpPath();
std::wstring GenerateUniqueId(HMONITOR monitor, PCWSTR deviceId, PCWSTR virtualDesktopId);
}