diff --git a/source/utils/storage/StorageItemRoot.cpp b/source/utils/storage/StorageItemRoot.cpp index d6a4a66..95ed41e 100644 --- a/source/utils/storage/StorageItemRoot.cpp +++ b/source/utils/storage/StorageItemRoot.cpp @@ -10,4 +10,10 @@ StorageItemRoot::StorageItemRoot(const std::string_view plugin_name) : StorageSu void StorageItemRoot::wipe() { mSubCategories.clear(); mItems.clear(); +} + +void StorageItemRoot::migrate(StorageItemRoot &&other) { + mPluginName = std::move(other.mPluginName); + mSubCategories = std::move(other.mSubCategories); + mItems = std::move(other.mItems); } \ No newline at end of file diff --git a/source/utils/storage/StorageItemRoot.h b/source/utils/storage/StorageItemRoot.h index f8ec6bc..af6d57a 100644 --- a/source/utils/storage/StorageItemRoot.h +++ b/source/utils/storage/StorageItemRoot.h @@ -12,6 +12,8 @@ public: void wipe(); + void migrate(StorageItemRoot &&other); + private: std::string mPluginName; }; diff --git a/source/utils/storage/StorageUtils.cpp b/source/utils/storage/StorageUtils.cpp index 3450923..e3d4f76 100644 --- a/source/utils/storage/StorageUtils.cpp +++ b/source/utils/storage/StorageUtils.cpp @@ -196,16 +196,16 @@ namespace StorageUtils { return err; } - std::unique_ptr storage; + std::unique_ptr newStorage; if (j.empty() || !j.is_object() || !j.contains("storageitems") || j["storageitems"].empty() || !j["storageitems"].is_object()) { - storage = make_unique_nothrow(plugin_id); + newStorage = make_unique_nothrow(plugin_id); } else { - storage = StorageUtils::Helper::deserializeFromJson(j["storageitems"], plugin_id); - if (!storage) { - storage = make_unique_nothrow(plugin_id); + newStorage = deserializeFromJson(j["storageitems"], plugin_id); + if (!newStorage) { + newStorage = make_unique_nothrow(plugin_id); } } - rootItem = std::move(*storage); + rootItem.migrate(std::move(*newStorage)); return WUPS_STORAGE_ERROR_SUCCESS; }