mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-18 14:50:56 +00:00
Add support for SDL_GAMECONTROLLERCONFIG environment variable
This commit is contained in:
+26
-23
@@ -24,35 +24,18 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
struct mapping* mapping_load(char* fileName, bool verbose) {
|
||||
struct mapping* mappings = NULL;
|
||||
struct mapping* map = NULL;
|
||||
FILE* fd = fopen(fileName, "r");
|
||||
if (fd == NULL) {
|
||||
fprintf(stderr, "Can't open mapping file: %s\n", fileName);
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (verbose)
|
||||
printf("Loading mappingfile %s\n", fileName);
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
while (getline(&line, &len, fd) != -1) {
|
||||
struct mapping* mapping_parse(char* mapping) {
|
||||
char* strpoint;
|
||||
char* guid = strtok_r(line, ",", &strpoint);
|
||||
char* guid = strtok_r(mapping, ",", &strpoint);
|
||||
char* name = strtok_r(NULL, ",", &strpoint);
|
||||
if (guid == NULL || name == NULL)
|
||||
continue;
|
||||
return NULL;
|
||||
|
||||
struct mapping* newmap = malloc(sizeof(struct mapping));
|
||||
if (newmap == NULL) {
|
||||
struct mapping* map = malloc(sizeof(struct mapping));
|
||||
if (map == NULL) {
|
||||
fprintf(stderr, "Not enough memory");
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (mappings == NULL)
|
||||
mappings = newmap;
|
||||
else
|
||||
map->next = newmap;
|
||||
|
||||
map = newmap;
|
||||
}
|
||||
|
||||
strncpy(map->guid, guid, sizeof(map->guid));
|
||||
strncpy(map->name, name, sizeof(map->name));
|
||||
@@ -146,6 +129,26 @@ struct mapping* mapping_load(char* fileName, bool verbose) {
|
||||
map->guid[32] = '\0';
|
||||
map->name[256] = '\0';
|
||||
map->platform[32] = '\0';
|
||||
return map;
|
||||
}
|
||||
|
||||
struct mapping* mapping_load(char* fileName, bool verbose) {
|
||||
struct mapping* mappings = NULL;
|
||||
FILE* fd = fopen(fileName, "r");
|
||||
if (fd == NULL) {
|
||||
fprintf(stderr, "Can't open mapping file: %s\n", fileName);
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (verbose)
|
||||
printf("Loading mappingfile %s\n", fileName);
|
||||
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
while (getline(&line, &len, fd) != -1) {
|
||||
struct mapping* map = mapping_parse(line);
|
||||
if (map) {
|
||||
map->next = mappings;
|
||||
mappings = map;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
|
||||
|
||||
@@ -47,4 +47,5 @@ struct mapping {
|
||||
struct mapping* next;
|
||||
};
|
||||
|
||||
struct mapping* mapping_parse(char* mapping);
|
||||
struct mapping* mapping_load(char* fileName, bool verbose);
|
||||
|
||||
+12
-2
@@ -252,11 +252,21 @@ int main(int argc, char* argv[]) {
|
||||
config.stream.supportsHevc = config.codec != CODEC_H264 && (config.codec == CODEC_HEVC || platform_supports_hevc(system));
|
||||
|
||||
if (IS_EMBEDDED(system)) {
|
||||
if (config.mapping == NULL) {
|
||||
char* mapping_env = getenv("SDL_GAMECONTROLLERCONFIG");
|
||||
if (config.mapping == NULL && mapping_env == NULL) {
|
||||
fprintf(stderr, "Please specify mapping file as default mapping could not be found.\n");
|
||||
exit(-1);
|
||||
}
|
||||
struct mapping* mappings = mapping_load(config.mapping, config.debug_level > 0);
|
||||
|
||||
struct mapping* mappings;
|
||||
if (config.mapping != NULL)
|
||||
mappings = mapping_load(config.mapping, config.debug_level > 0);
|
||||
|
||||
if (mapping_env != NULL) {
|
||||
struct mapping* map = mapping_parse(mapping_env);
|
||||
map->next = mappings;
|
||||
mappings = map;
|
||||
}
|
||||
|
||||
for (int i=0;i<config.inputsCount;i++) {
|
||||
if (config.debug_level > 0)
|
||||
|
||||
Reference in New Issue
Block a user