Repository: microsoft/PowerToys
File: src/modules/fancyzones/FancyZonesLib/FancyZonesData/AppZoneHistory.cpp (C++)

Code before:
            {
                data.workAreaId.virtualDesktopId = GUID_NULL;
                dirtyFlag = true;
            }
        }

        updatedHistory.insert(std::make_pair(path, updatedVector));
    }

    if (dirtyFlag)
    {
        json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(updatedHistory));
    }
    else
    {
        json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(m_history));
    }
}

void AppZoneHistory::AdjustWorkAreaIds(const std::vector<FancyZonesDataTypes::MonitorId>& ids)
{
    bool dirtyFlag = false;

    for (auto& iter : m_history)
    {
        auto& [app, data] = iter;
        for (auto& dataIter : data)
        {
            auto& dataMonitorId = dataIter.workAreaId.monitorId;
            bool serialNumberNotSet = dataMonitorId.serialNumber.empty() && !dataMonitorId.deviceId.isDefault();
            bool monitorNumberNotSet = dataMonitorId.deviceId.number == 0;
            if (serialNumberNotSet || monitorNumberNotSet)
            {
                for (const auto& monitorId : ids)
                {
                    if (dataMonitorId.deviceId.id == monitorId.deviceId.id && dataMonitorId.deviceId.instanceId == monitorId.deviceId.instanceId)
                    {
                        dataMonitorId.serialNumber = monitorId.serialNumber;
                        dataMonitorId.deviceId.number = monitorId.deviceId.number;
                        dirtyFlag = true;
                        break;
                    }
                }
            }
        }
    }

    if (dirtyFlag)
    {
        SaveData();
    }

Review comment (suggestion):
```suggestion
        for (auto& dataIter : data)
```

Code after:
            {
                data.workAreaId.virtualDesktopId = GUID_NULL;
                dirtyFlag = true;
            }
        }

        updatedHistory.insert(std::make_pair(path, updatedVector));
    }

    if (dirtyFlag)
    {
        json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(updatedHistory));
    }
    else
    {
        json::to_file(AppZoneHistoryFileName(), JsonUtils::SerializeJson(m_history));
    }
}

void AppZoneHistory::AdjustWorkAreaIds(const std::vector<FancyZonesDataTypes::MonitorId>& ids)
{
    bool dirtyFlag = false;

    for (auto& [app, data] : m_history)
    {
        for (auto& dataIter : data)
        {
            auto& dataMonitorId = dataIter.workAreaId.monitorId;
            bool serialNumberNotSet = dataMonitorId.serialNumber.empty() && !dataMonitorId.deviceId.isDefault();
            bool monitorNumberNotSet = dataMonitorId.deviceId.number == 0;
            if (serialNumberNotSet || monitorNumberNotSet)
            {
                for (const auto& monitorId : ids)
                {
                    if (dataMonitorId.deviceId.id == monitorId.deviceId.id && dataMonitorId.deviceId.instanceId == monitorId.deviceId.instanceId)
                    {
                        dataMonitorId.serialNumber = monitorId.serialNumber;
                        dataMonitorId.deviceId.number = monitorId.deviceId.number;
                        dirtyFlag = true;
                        break;
                    }
                }
            }
        }
    }

    if (dirtyFlag)
    {
        SaveData();
    }
}