mirror of
https://github.com/wiiu-env/WiiUPluginSystem.git
synced 2026-10-03 06:16:52 -05:00
Add clang-format for formatting, check building the example in CI
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include <wups.h>
|
||||
#include "wups/config/WUPSConfigItemBoolean.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "wups/config/WUPSConfigItemBoolean.h"
|
||||
#include <wups.h>
|
||||
|
||||
void WUPSConfigItemBoolean_onDelete(void *context);
|
||||
|
||||
@@ -50,7 +50,7 @@ int32_t WUPSConfigItemBoolean_getCurrentValueSelectedDisplay(void *context, char
|
||||
}
|
||||
|
||||
void WUPSConfigItemBoolean_restoreDefault(void *context) {
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
auto *item = (ConfigItemBoolean *) context;
|
||||
item->value = item->defaultValue;
|
||||
}
|
||||
|
||||
@@ -69,21 +69,20 @@ WUPSConfigItemBoolean_AddToCategoryEx(WUPSConfigCategoryHandle cat, const char *
|
||||
}
|
||||
|
||||
item->defaultValue = defaultValue;
|
||||
item->value = defaultValue;
|
||||
item->callback = (void *) callback;
|
||||
item->value = defaultValue;
|
||||
item->callback = (void *) callback;
|
||||
snprintf(item->trueValue, sizeof(item->trueValue), "%s", trueValue);
|
||||
snprintf(item->falseValue, sizeof(item->falseValue), "%s", falseValue);
|
||||
|
||||
WUPSConfigCallbacks_t callbacks = {
|
||||
.getCurrentValueDisplay = &WUPSConfigItemBoolean_getCurrentValueDisplay,
|
||||
.getCurrentValueDisplay = &WUPSConfigItemBoolean_getCurrentValueDisplay,
|
||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemBoolean_getCurrentValueSelectedDisplay,
|
||||
.onSelected = &WUPSConfigItemBoolean_onSelected,
|
||||
.restoreDefault = &WUPSConfigItemBoolean_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemBoolean_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemBoolean_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemBoolean_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemBoolean_onDelete
|
||||
};
|
||||
.onSelected = &WUPSConfigItemBoolean_onSelected,
|
||||
.restoreDefault = &WUPSConfigItemBoolean_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemBoolean_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemBoolean_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemBoolean_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemBoolean_onDelete};
|
||||
|
||||
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) {
|
||||
free(item);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <wups.h>
|
||||
#include "wups/config/WUPSConfigItemIntegerRange.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "wups/config/WUPSConfigItemIntegerRange.h"
|
||||
#include <wups.h>
|
||||
|
||||
int32_t WUPSConfigItemIntegerRange_getCurrentValueDisplay(void *context, char *out_buf, int32_t out_size) {
|
||||
auto *item = (ConfigItemIntegerRange *) context;
|
||||
@@ -54,7 +54,7 @@ int32_t WUPSConfigItemIntegerRange_getCurrentValueSelectedDisplay(void *context,
|
||||
}
|
||||
|
||||
void WUPSConfigItemIntegerRange_restoreDefault(void *context) {
|
||||
auto *item = (ConfigItemIntegerRange *) context;
|
||||
auto *item = (ConfigItemIntegerRange *) context;
|
||||
item->value = item->defaultValue;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,6 @@ void WUPSConfigItemIntegerRange_onDelete(void *context) {
|
||||
}
|
||||
|
||||
void WUPSConfigItemIntegerRange_onSelected(void *context, bool isSelected) {
|
||||
|
||||
}
|
||||
|
||||
extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandle cat, const char *configID, const char *displayName, int32_t defaultValue, int32_t minValue, int32_t maxValue,
|
||||
@@ -78,21 +77,20 @@ extern "C" bool WUPSConfigItemIntegerRange_AddToCategory(WUPSConfigCategoryHandl
|
||||
}
|
||||
|
||||
item->defaultValue = defaultValue;
|
||||
item->value = defaultValue;
|
||||
item->minValue = minValue;
|
||||
item->maxValue = maxValue;
|
||||
item->callback = (void *) callback;
|
||||
item->value = defaultValue;
|
||||
item->minValue = minValue;
|
||||
item->maxValue = maxValue;
|
||||
item->callback = (void *) callback;
|
||||
|
||||
WUPSConfigCallbacks_t callbacks = {
|
||||
.getCurrentValueDisplay = &WUPSConfigItemIntegerRange_getCurrentValueDisplay,
|
||||
.getCurrentValueDisplay = &WUPSConfigItemIntegerRange_getCurrentValueDisplay,
|
||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemIntegerRange_getCurrentValueSelectedDisplay,
|
||||
.onSelected = &WUPSConfigItemIntegerRange_onSelected,
|
||||
.restoreDefault = &WUPSConfigItemIntegerRange_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemIntegerRange_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemIntegerRange_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemIntegerRange_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemIntegerRange_onDelete
|
||||
};
|
||||
.onSelected = &WUPSConfigItemIntegerRange_onSelected,
|
||||
.restoreDefault = &WUPSConfigItemIntegerRange_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemIntegerRange_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemIntegerRange_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemIntegerRange_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemIntegerRange_onDelete};
|
||||
|
||||
if (WUPSConfigItem_Create(&(item->handle), configID, displayName, callbacks, item) < 0) {
|
||||
free(item);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <wups.h>
|
||||
#include "wups/config/WUPSConfigItemMultipleValues.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include "wups/config/WUPSConfigItemMultipleValues.h"
|
||||
#include <wups.h>
|
||||
|
||||
void WUPSConfigItemMultipleValues_onDelete(void *context);
|
||||
|
||||
@@ -65,7 +65,7 @@ int32_t WUPSConfigItemMultipleValues_getCurrentValueSelectedDisplay(void *contex
|
||||
}
|
||||
|
||||
void WUPSConfigItemMultipleValues_restoreDefault(void *context) {
|
||||
auto *item = (ConfigItemMultipleValues *) context;
|
||||
auto *item = (ConfigItemMultipleValues *) context;
|
||||
item->valueIndex = item->defaultValueIndex;
|
||||
}
|
||||
|
||||
@@ -92,35 +92,34 @@ WUPSConfigItemMultipleValues_AddToCategory(WUPSConfigCategoryHandle cat, const c
|
||||
values[i].valueName = nullptr;
|
||||
continue;
|
||||
}
|
||||
auto bufLen = strlen(possibleValues[i].valueName) + 1;
|
||||
auto bufLen = strlen(possibleValues[i].valueName) + 1;
|
||||
values[i].valueName = (char *) malloc(bufLen);
|
||||
strncpy(values[i].valueName, possibleValues[i].valueName, bufLen);
|
||||
}
|
||||
|
||||
item->valueCount = pairCount;
|
||||
item->values = values;
|
||||
item->valueIndex = defaultValueIndex;
|
||||
item->valueCount = pairCount;
|
||||
item->values = values;
|
||||
item->valueIndex = defaultValueIndex;
|
||||
item->defaultValueIndex = defaultValueIndex;
|
||||
item->callback = (void *) callback;
|
||||
item->callback = (void *) callback;
|
||||
|
||||
if (configID != nullptr) {
|
||||
auto configIDLen = strlen(configID) + 1;
|
||||
item->configID = (char *) malloc(configIDLen);
|
||||
item->configID = (char *) malloc(configIDLen);
|
||||
strncpy(item->configID, configID, configIDLen);
|
||||
} else {
|
||||
item->configID = nullptr;
|
||||
}
|
||||
|
||||
WUPSConfigCallbacks_t callbacks = {
|
||||
.getCurrentValueDisplay = &WUPSConfigItemMultipleValues_getCurrentValueDisplay,
|
||||
.getCurrentValueDisplay = &WUPSConfigItemMultipleValues_getCurrentValueDisplay,
|
||||
.getCurrentValueSelectedDisplay = &WUPSConfigItemMultipleValues_getCurrentValueSelectedDisplay,
|
||||
.onSelected = &WUPSConfigItemMultipleValues_onSelected,
|
||||
.restoreDefault = &WUPSConfigItemMultipleValues_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemMultipleValues_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemMultipleValues_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemMultipleValues_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemMultipleValues_onDelete
|
||||
};
|
||||
.onSelected = &WUPSConfigItemMultipleValues_onSelected,
|
||||
.restoreDefault = &WUPSConfigItemMultipleValues_restoreDefault,
|
||||
.isMovementAllowed = &WUPSConfigItemMultipleValues_isMovementAllowed,
|
||||
.callCallback = &WUPSConfigItemMultipleValues_callCallback,
|
||||
.onButtonPressed = &WUPSConfigItemMultipleValues_onButtonPressed,
|
||||
.onDelete = &WUPSConfigItemMultipleValues_onDelete};
|
||||
|
||||
if (WUPSConfigItem_Create(&item->handle, configID, displayName, callbacks, item) < 0) {
|
||||
free(item);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include <wups.h>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <wups.h>
|
||||
|
||||
#include "utils/base64.h"
|
||||
|
||||
static OpenStorageFunction openfunction_ptr __attribute__((section(".data"))) = nullptr;
|
||||
static OpenStorageFunction openfunction_ptr __attribute__((section(".data"))) = nullptr;
|
||||
static CloseStorageFunction closefunction_ptr __attribute__((section(".data"))) = nullptr;
|
||||
static const char *plugin_id __attribute__((section(".data"))) = nullptr;
|
||||
static const char *plugin_id __attribute__((section(".data"))) = nullptr;
|
||||
|
||||
static uint32_t storage_initialized __attribute__((section(".data"))) = false;
|
||||
static uint32_t isOpened __attribute__((section(".data")));
|
||||
@@ -14,19 +14,19 @@ static uint32_t isDirty __attribute__((section(".data")));
|
||||
static wups_storage_item_t rootItem __attribute__((section(".data")));
|
||||
|
||||
void WUPS_InitStorage(wups_loader_init_storage_args_t args) {
|
||||
openfunction_ptr = args.open_storage_ptr;
|
||||
openfunction_ptr = args.open_storage_ptr;
|
||||
closefunction_ptr = args.close_storage_ptr;
|
||||
plugin_id = args.plugin_id;
|
||||
plugin_id = args.plugin_id;
|
||||
|
||||
storage_initialized = true;
|
||||
isOpened = false;
|
||||
isDirty = false;
|
||||
isOpened = false;
|
||||
isDirty = false;
|
||||
|
||||
rootItem.key = nullptr;
|
||||
rootItem.data = nullptr;
|
||||
rootItem.data_size = 0;
|
||||
rootItem.key = nullptr;
|
||||
rootItem.data = nullptr;
|
||||
rootItem.data_size = 0;
|
||||
rootItem.pending_delete = false;
|
||||
rootItem.type = WUPS_STORAGE_TYPE_ITEM;
|
||||
rootItem.type = WUPS_STORAGE_TYPE_ITEM;
|
||||
}
|
||||
|
||||
int32_t WUPS_OpenStorage(void) {
|
||||
@@ -42,7 +42,7 @@ int32_t WUPS_OpenStorage(void) {
|
||||
|
||||
if (result == WUPS_STORAGE_ERROR_SUCCESS || result == WUPS_STORAGE_ERROR_INVALID_JSON) {
|
||||
isOpened = true;
|
||||
isDirty = false;
|
||||
isDirty = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -80,12 +80,12 @@ int32_t WUPS_CloseStorage(void) {
|
||||
|
||||
if (result == 0) {
|
||||
isOpened = false;
|
||||
isDirty = false;
|
||||
isDirty = false;
|
||||
|
||||
closeItem(&rootItem);
|
||||
free(rootItem.data);
|
||||
rootItem.data_size = 0;
|
||||
rootItem.data = nullptr;
|
||||
rootItem.data = nullptr;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -183,10 +183,10 @@ static wups_storage_item_t *addItem(wups_storage_item_t *parent, const char *key
|
||||
strcpy(foundItem->key, key);
|
||||
}
|
||||
|
||||
foundItem->type = type;
|
||||
foundItem->type = type;
|
||||
foundItem->pending_delete = false;
|
||||
foundItem->data = nullptr;
|
||||
foundItem->data_size = 0;
|
||||
foundItem->data = nullptr;
|
||||
foundItem->data_size = 0;
|
||||
return foundItem;
|
||||
}
|
||||
|
||||
@@ -269,8 +269,8 @@ int32_t WUPS_StoreString(wups_storage_item_t *parent, const char *key, const cha
|
||||
|
||||
wups_storage_item_t *item = addItem(parent, key, WUPS_STORAGE_TYPE_STRING);
|
||||
|
||||
uint32_t size = strlen(string) + 1;
|
||||
item->data = malloc(size);
|
||||
uint32_t size = strlen(string) + 1;
|
||||
item->data = malloc(size);
|
||||
item->data_size = size;
|
||||
strcpy((char *) item->data, string);
|
||||
|
||||
@@ -302,8 +302,8 @@ int32_t WUPS_StoreInt(wups_storage_item_t *parent, const char *key, int32_t valu
|
||||
|
||||
wups_storage_item_t *item = addItem(parent, key, WUPS_STORAGE_TYPE_INT);
|
||||
|
||||
item->data = malloc(sizeof(int32_t));
|
||||
item->data_size = sizeof(int32_t);
|
||||
item->data = malloc(sizeof(int32_t));
|
||||
item->data_size = sizeof(int32_t);
|
||||
*(int32_t *) item->data = value;
|
||||
|
||||
return WUPS_STORAGE_ERROR_SUCCESS;
|
||||
@@ -328,7 +328,7 @@ int32_t WUPS_StoreBinary(wups_storage_item_t *parent, const char *key, const voi
|
||||
|
||||
wups_storage_item_t *item = addItem(parent, key, WUPS_STORAGE_TYPE_STRING);
|
||||
|
||||
item->data = b64_encode((const uint8_t *) data, size);
|
||||
item->data = b64_encode((const uint8_t *) data, size);
|
||||
item->data_size = strlen((char *) data) + 1;
|
||||
|
||||
return WUPS_STORAGE_ERROR_SUCCESS;
|
||||
|
||||
@@ -26,8 +26,8 @@ char *b64_encode(const uint8_t *in, size_t len) {
|
||||
if (in == NULL || len == 0)
|
||||
return NULL;
|
||||
|
||||
elen = b64_encoded_size(len);
|
||||
out = (char *) malloc(elen + 1);
|
||||
elen = b64_encoded_size(len);
|
||||
out = (char *) malloc(elen + 1);
|
||||
out[elen] = '\0';
|
||||
|
||||
for (i = 0, j = 0; i < len; i += 3, j += 4) {
|
||||
@@ -35,7 +35,7 @@ char *b64_encode(const uint8_t *in, size_t len) {
|
||||
v = i + 1 < len ? v << 8 | in[i + 1] : v << 8;
|
||||
v = i + 2 < len ? v << 8 | in[i + 2] : v << 8;
|
||||
|
||||
out[j] = b64chars[(v >> 18) & 0x3F];
|
||||
out[j] = b64chars[(v >> 18) & 0x3F];
|
||||
out[j + 1] = b64chars[(v >> 12) & 0x3F];
|
||||
if (i + 1 < len) {
|
||||
out[j + 2] = b64chars[(v >> 6) & 0x3F];
|
||||
@@ -77,8 +77,7 @@ size_t b64_decoded_size(const char *in) {
|
||||
static const int b64invs[] = {
|
||||
62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3,
|
||||
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
||||
};
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
|
||||
|
||||
static int b64_isvalidchar(char c) {
|
||||
if (c >= '0' && c <= '9')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// based on https://nachtimwald.com/2017/11/18/base64-encode-and-decode-in-c/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user