mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-08-11 12:16:06 -05:00
Formatting and cleanup
This commit is contained in:
@@ -6,23 +6,23 @@
|
||||
#include "fs/CFile.hpp"
|
||||
#include "fs/FSUtils.h"
|
||||
|
||||
static void processJson(wups_storage_item_t* items, nlohmann::json json) {
|
||||
static void processJson(wups_storage_item_t *items, nlohmann::json json) {
|
||||
if (items == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
items->data = (wups_storage_item_t*) malloc(json.size() * sizeof(wups_storage_item_t));
|
||||
items->data = (wups_storage_item_t *) malloc(json.size() * sizeof(wups_storage_item_t));
|
||||
items->data_size = json.size();
|
||||
|
||||
uint32_t index = 0;
|
||||
for (auto it = json.begin(); it != json.end(); ++it) {
|
||||
wups_storage_item_t* item = &((wups_storage_item_t*) items->data)[index];
|
||||
wups_storage_item_t *item = &((wups_storage_item_t *) items->data)[index];
|
||||
item->type = WUPS_STORAGE_TYPE_INVALID;
|
||||
item->pending_delete = false;
|
||||
item->data = nullptr;
|
||||
item->key = nullptr;
|
||||
|
||||
item->key = (char*) malloc(it.key().size() + 1);
|
||||
item->key = (char *) malloc(it.key().size() + 1);
|
||||
strcpy(item->key, it.key().c_str());
|
||||
|
||||
if (it.value().is_string()) {
|
||||
@@ -30,12 +30,12 @@ static void processJson(wups_storage_item_t* items, nlohmann::json json) {
|
||||
uint32_t size = it.value().get<std::string>().size() + 1;
|
||||
item->data = malloc(size);
|
||||
item->data_size = size;
|
||||
strcpy((char*) item->data, it.value().get<std::string>().c_str());
|
||||
strcpy((char *) item->data, it.value().get<std::string>().c_str());
|
||||
} else if (it.value().is_number_integer()) {
|
||||
item->type = WUPS_STORAGE_TYPE_INT;
|
||||
item->data = malloc(sizeof(int32_t));
|
||||
item->data_size = sizeof(int32_t);
|
||||
*(int32_t*) item->data = it.value().get<int32_t>();
|
||||
*(int32_t *) item->data = it.value().get<int32_t>();
|
||||
} else if (it.value().is_object()) {
|
||||
if (it.value().size() > 0) {
|
||||
item->type = WUPS_STORAGE_TYPE_ITEM;
|
||||
@@ -48,7 +48,7 @@ static void processJson(wups_storage_item_t* items, nlohmann::json json) {
|
||||
}
|
||||
}
|
||||
|
||||
int StorageUtils::OpenStorage(const char* plugin_id, wups_storage_item_t* items) {
|
||||
int StorageUtils::OpenStorage(const char *plugin_id, wups_storage_item_t *items) {
|
||||
if (!plugin_id || !items) {
|
||||
return WUPS_STORAGE_ERROR_INVALID_BACKEND_PARAMS;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ int StorageUtils::OpenStorage(const char* plugin_id, wups_storage_item_t* items)
|
||||
nlohmann::json j;
|
||||
CFile file(filePath, CFile::ReadOnly);
|
||||
if (file.isOpen() && file.size() > 0) {
|
||||
uint8_t* json_data = new uint8_t[file.size() + 1];
|
||||
uint8_t *json_data = new uint8_t[file.size() + 1];
|
||||
json_data[file.size()] = '\0';
|
||||
|
||||
file.read(json_data, file.size());
|
||||
@@ -80,7 +80,7 @@ int StorageUtils::OpenStorage(const char* plugin_id, wups_storage_item_t* items)
|
||||
return WUPS_STORAGE_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
static nlohmann::json processItems(wups_storage_item_t* items) {
|
||||
static nlohmann::json processItems(wups_storage_item_t *items) {
|
||||
nlohmann::json json;
|
||||
|
||||
if (!items) {
|
||||
@@ -88,16 +88,16 @@ static nlohmann::json processItems(wups_storage_item_t* items) {
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < items->data_size; i++) {
|
||||
wups_storage_item_t* item = &((wups_storage_item_t*) items->data)[i];
|
||||
wups_storage_item_t *item = &((wups_storage_item_t *) items->data)[i];
|
||||
|
||||
if (item->pending_delete || item->type == WUPS_STORAGE_TYPE_INVALID || !item->data || !item->key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item->type == WUPS_STORAGE_TYPE_STRING) {
|
||||
json[item->key] = (const char*) item->data;
|
||||
json[item->key] = (const char *) item->data;
|
||||
} else if (item->type == WUPS_STORAGE_TYPE_INT) {
|
||||
json[item->key] = *(int32_t*) item->data;
|
||||
json[item->key] = *(int32_t *) item->data;
|
||||
} else if (item->type == WUPS_STORAGE_TYPE_ITEM) {
|
||||
json[item->key] = processItems(item);
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ static nlohmann::json processItems(wups_storage_item_t* items) {
|
||||
return json;
|
||||
}
|
||||
|
||||
int StorageUtils::CloseStorage(const char* plugin_id, wups_storage_item_t* items) {
|
||||
int StorageUtils::CloseStorage(const char *plugin_id, wups_storage_item_t *items) {
|
||||
if (!plugin_id || !items) {
|
||||
return WUPS_STORAGE_ERROR_INVALID_BACKEND_PARAMS;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ int StorageUtils::CloseStorage(const char* plugin_id, wups_storage_item_t* items
|
||||
j["storageitems"] = processItems(items);
|
||||
|
||||
std::string jsonString = j.dump(4);
|
||||
file.write((const uint8_t*) jsonString.c_str(), jsonString.size());
|
||||
file.write((const uint8_t *) jsonString.c_str(), jsonString.size());
|
||||
file.close();
|
||||
return WUPS_STORAGE_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user