2020-02-10 21:59:51 +08:00
|
|
|
#pragma once
|
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
#include "FancyZonesDataTypes.h"
|
|
|
|
|
2020-02-10 21:59:51 +08:00
|
|
|
#include <common/json.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2020-07-22 16:39:13 +08:00
|
|
|
#include <unordered_map>
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
namespace JSONHelpers
|
|
|
|
{
|
2020-07-22 16:39:13 +08:00
|
|
|
namespace CanvasLayoutInfoJSON
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-07-22 16:39:13 +08:00
|
|
|
json::JsonObject ToJson(const FancyZonesDataTypes::CanvasLayoutInfo& canvasInfo);
|
|
|
|
std::optional<FancyZonesDataTypes::CanvasLayoutInfo> FromJson(const json::JsonObject& infoJson);
|
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
namespace GridLayoutInfoJSON
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-07-22 16:39:13 +08:00
|
|
|
json::JsonObject ToJson(const FancyZonesDataTypes::GridLayoutInfo& gridInfo);
|
|
|
|
std::optional<FancyZonesDataTypes::GridLayoutInfo> FromJson(const json::JsonObject& infoJson);
|
|
|
|
}
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
struct CustomZoneSetJSON
|
|
|
|
{
|
|
|
|
std::wstring uuid;
|
2020-07-22 16:39:13 +08:00
|
|
|
FancyZonesDataTypes::CustomZoneSetData data;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
static json::JsonObject ToJson(const CustomZoneSetJSON& device);
|
|
|
|
static std::optional<CustomZoneSetJSON> FromJson(const json::JsonObject& customZoneSet);
|
|
|
|
};
|
|
|
|
|
2020-09-18 15:16:06 +08:00
|
|
|
namespace ZoneSetDataJSON
|
2020-02-10 21:59:51 +08:00
|
|
|
{
|
2020-07-22 16:39:13 +08:00
|
|
|
json::JsonObject ToJson(const FancyZonesDataTypes::ZoneSetData& zoneSet);
|
|
|
|
std::optional<FancyZonesDataTypes::ZoneSetData> FromJson(const json::JsonObject& zoneSet);
|
2020-02-10 21:59:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct AppZoneHistoryJSON
|
|
|
|
{
|
|
|
|
std::wstring appPath;
|
2020-07-22 16:39:13 +08:00
|
|
|
std::vector<FancyZonesDataTypes::AppZoneHistoryData> data;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
static json::JsonObject ToJson(const AppZoneHistoryJSON& appZoneHistory);
|
|
|
|
static std::optional<AppZoneHistoryJSON> FromJson(const json::JsonObject& zoneSet);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct DeviceInfoJSON
|
|
|
|
{
|
|
|
|
std::wstring deviceId;
|
2020-07-22 16:39:13 +08:00
|
|
|
FancyZonesDataTypes::DeviceInfoData data;
|
2020-02-10 21:59:51 +08:00
|
|
|
|
|
|
|
static json::JsonObject ToJson(const DeviceInfoJSON& device);
|
|
|
|
static std::optional<DeviceInfoJSON> FromJson(const json::JsonObject& device);
|
|
|
|
};
|
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
using TAppZoneHistoryMap = std::unordered_map<std::wstring, std::vector<FancyZonesDataTypes::AppZoneHistoryData>>;
|
|
|
|
using TDeviceInfoMap = std::unordered_map<std::wstring, FancyZonesDataTypes::DeviceInfoData>;
|
|
|
|
using TCustomZoneSetsMap = std::unordered_map<std::wstring, FancyZonesDataTypes::CustomZoneSetData>;
|
2020-02-17 23:28:49 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
json::JsonObject GetPersistFancyZonesJSON(const std::wstring& zonesSettingsFileName, const std::wstring& appZoneHistoryFileName);
|
|
|
|
void SaveFancyZonesData(const std::wstring& zonesSettingsFileName,
|
2020-09-18 15:16:06 +08:00
|
|
|
const std::wstring& appZoneHistoryFileName,
|
|
|
|
const TDeviceInfoMap& deviceInfoMap,
|
|
|
|
const TCustomZoneSetsMap& customZoneSetsMap,
|
|
|
|
const TAppZoneHistoryMap& appZoneHistoryMap);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
TAppZoneHistoryMap ParseAppZoneHistory(const json::JsonObject& fancyZonesDataJSON);
|
|
|
|
json::JsonArray SerializeAppZoneHistory(const TAppZoneHistoryMap& appZoneHistoryMap);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
TDeviceInfoMap ParseDeviceInfos(const json::JsonObject& fancyZonesDataJSON);
|
|
|
|
json::JsonArray SerializeDeviceInfos(const TDeviceInfoMap& deviceInfoMap);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
TCustomZoneSetsMap ParseCustomZoneSets(const json::JsonObject& fancyZonesDataJSON);
|
|
|
|
json::JsonArray SerializeCustomZoneSets(const TCustomZoneSetsMap& customZoneSetsMap);
|
2020-02-10 21:59:51 +08:00
|
|
|
|
2020-07-22 16:39:13 +08:00
|
|
|
void SerializeDeviceInfoToTmpFile(const JSONHelpers::DeviceInfoJSON& deviceInfo, std::wstring_view tmpFilePath);
|
|
|
|
std::optional<DeviceInfoJSON> ParseDeviceInfoFromTmpFile(std::wstring_view tmpFilePath);
|
|
|
|
std::optional<CustomZoneSetJSON> ParseCustomZoneSetFromTmpFile(std::wstring_view tmpFilePath);
|
|
|
|
std::vector<std::wstring> ParseDeletedCustomZoneSetsFromTmpFile(std::wstring_view tmpFilePath);
|
2020-02-10 21:59:51 +08:00
|
|
|
}
|