From 569c18c9f15ffda01bf82b27f67e794b34806bc7 Mon Sep 17 00:00:00 2001 From: stefansjfw <57057282+stefansjfw@users.noreply.github.com> Date: Wed, 8 Apr 2020 15:43:19 +0200 Subject: [PATCH] Remove uneeded TmpMigrateAppliedZoneSets() (#1850) This was needed while we were migratin device-info so active layout could be migrated as well. At some point we dropped migration of device-info. Therefore, this has no puprose anymore. --- src/modules/fancyzones/lib/JsonHelpers.cpp | 87 +++------------------- src/modules/fancyzones/lib/JsonHelpers.h | 3 - 2 files changed, 12 insertions(+), 78 deletions(-) diff --git a/src/modules/fancyzones/lib/JsonHelpers.cpp b/src/modules/fancyzones/lib/JsonHelpers.cpp index eba75334f0..5ff3abc28a 100644 --- a/src/modules/fancyzones/lib/JsonHelpers.cpp +++ b/src/modules/fancyzones/lib/JsonHelpers.cpp @@ -604,9 +604,6 @@ namespace JSONHelpers if (!std::filesystem::exists(jsonFilePath)) { - TmpMigrateAppliedZoneSetsFromRegistry(); - - // Custom zone sets have to be migrated after applied zone sets! MigrateCustomZoneSetsFromRegistry(); SaveFancyZonesData(); @@ -639,56 +636,6 @@ namespace JSONHelpers json::to_file(jsonFilePath, root); } - void FancyZonesData::TmpMigrateAppliedZoneSetsFromRegistry() - { - std::wregex ex(L"^[0-9]{3,4}_[0-9]{3,4}$"); - - std::scoped_lock lock{ dataLock }; - wchar_t key[256]; - StringCchPrintf(key, ARRAYSIZE(key), L"%s", RegistryHelpers::REG_SETTINGS); - HKEY hkey; - if (RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS) - { - wchar_t resolutionKey[256]{}; - DWORD resolutionKeyLength = ARRAYSIZE(resolutionKey); - DWORD i = 0; - while (RegEnumKeyW(hkey, i++, resolutionKey, resolutionKeyLength) == ERROR_SUCCESS) - { - std::wstring resolution{ resolutionKey }; - wchar_t appliedZoneSetskey[256]; - StringCchPrintf(appliedZoneSetskey, ARRAYSIZE(appliedZoneSetskey), L"%s\\%s", RegistryHelpers::REG_SETTINGS, resolutionKey); - HKEY appliedZoneSetsHkey; - if (std::regex_match(resolution, ex) && RegOpenKeyExW(HKEY_CURRENT_USER, appliedZoneSetskey, 0, KEY_ALL_ACCESS, &appliedZoneSetsHkey) == ERROR_SUCCESS) - { - ZoneSetPersistedDataOLD data; - DWORD dataSize = sizeof(data); - wchar_t value[256]{}; - DWORD valueLength = ARRAYSIZE(value); - DWORD i = 0; - - while (RegEnumValueW(appliedZoneSetsHkey, i++, value, &valueLength, nullptr, nullptr, reinterpret_cast(&data), &dataSize) == ERROR_SUCCESS) - { - ZoneSetData appliedZoneSetData; - appliedZoneSetData.type = TypeFromLayoutId(data.LayoutId); - if (appliedZoneSetData.type != ZoneSetLayoutType::Custom) - { - appliedZoneSetData.uuid = std::wstring{ value }; - } - else - { - // uuid is changed later to actual uuid when migrating custom zone sets - appliedZoneSetData.uuid = std::to_wstring(data.LayoutId); - } - appliedZoneSetsMap[value] = appliedZoneSetData; - dataSize = sizeof(data); - valueLength = ARRAYSIZE(value); - } - } - resolutionKeyLength = ARRAYSIZE(resolutionKey); - } - } - } - void FancyZonesData::MigrateCustomZoneSetsFromRegistry() { std::scoped_lock lock{ dataLock }; @@ -709,29 +656,19 @@ namespace JSONHelpers zoneSetData.type = static_cast(data[2]); // int version = data[0] * 256 + data[1]; - Not used anymore - std::wstring uuid = std::to_wstring(data[3] * 256 + data[4]); - auto it = std::find_if(appliedZoneSetsMap.cbegin(), appliedZoneSetsMap.cend(), [&uuid](std::pair zoneSetMap) { - return zoneSetMap.second.uuid.compare(uuid) == 0; - }); + GUID guid; + auto result = CoCreateGuid(&guid); + if (result != S_OK) + { + continue; + } + wil::unique_cotaskmem_string guidString; + if (!SUCCEEDED_LOG(StringFromCLSID(guid, &guidString))) + { + continue; + } - if (it != appliedZoneSetsMap.cend()) - { - uuid = it->first; - } - else - { - GUID guid; - auto result = CoCreateGuid(&guid); - if (result != S_OK) - { - return; - } - wil::unique_cotaskmem_string guidString; - if (SUCCEEDED_LOG(StringFromCLSID(guid, &guidString))) - { - uuid = guidString.get(); - } - } + std::wstring uuid = guidString.get(); switch (zoneSetData.type) { diff --git a/src/modules/fancyzones/lib/JsonHelpers.h b/src/modules/fancyzones/lib/JsonHelpers.h index 04069110be..9917209bb1 100644 --- a/src/modules/fancyzones/lib/JsonHelpers.h +++ b/src/modules/fancyzones/lib/JsonHelpers.h @@ -207,7 +207,6 @@ namespace JSONHelpers #if defined(UNIT_TESTS) inline void clear_data() { - appliedZoneSetsMap.clear(); appZoneHistoryMap.clear(); deviceInfoMap.clear(); customZoneSetsMap.clear(); @@ -254,10 +253,8 @@ namespace JSONHelpers void SaveFancyZonesData() const; private: - void TmpMigrateAppliedZoneSetsFromRegistry(); void MigrateCustomZoneSetsFromRegistry(); - std::unordered_map appliedZoneSetsMap{}; std::unordered_map appZoneHistoryMap{}; std::unordered_map deviceInfoMap{}; std::unordered_map customZoneSetsMap{};