From 5373f3d9787cb68fe9ed6635581b1967ccb1164e Mon Sep 17 00:00:00 2001 From: Jamie Dickson Date: Fri, 6 Dec 2019 01:01:49 -0600 Subject: [PATCH] add smart usb and cifs searches to game folder paths --- file_io.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- file_io.h | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/file_io.cpp b/file_io.cpp index d1784a0..043892e 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -703,13 +703,53 @@ uint32_t getFileType(const char *name) void prefixGameDir(char *dir, size_t dir_len) { + // Searches for the core's folder in the following order: + // /media/fat + // /media/usb<0..5> + // /media/usb<0..5>/games + // /media/fat/cifs + // /media/fat/cifs/games + // /media/fat/games/ + // if the core folder is not found anywhere, + // it will be created in /media/fat/games/ if (isPathDirectory(dir)) { printf("Found existing: %s\n", dir); return; } - FileCreatePath((char *) GAMES_DIR); static char temp_dir[1024]; + + for (int x = 0; x < 6; x++) { + snprintf(temp_dir, 1024, "%s%d/%s", "../usb", x, dir); + if (isPathDirectory(temp_dir)) { + printf("Found USB dir: %s\n", temp_dir); + strncpy(dir, temp_dir, dir_len); + return; + } + + snprintf(temp_dir, 1024, "%s%d/%s/%s", "../usb", x, GAMES_DIR, dir); + if (isPathDirectory(temp_dir)) { + printf("Found USB dir: %s\n", temp_dir); + strncpy(dir, temp_dir, dir_len); + return; + } + } + + snprintf(temp_dir, 1024, "%s/%s", CIFS_DIR, dir); + if (isPathDirectory(temp_dir)) { + printf("Found CIFS dir: %s\n", temp_dir); + strncpy(dir, temp_dir, dir_len); + return; + } + + snprintf(temp_dir, 1024, "%s/%s/%s", CIFS_DIR, GAMES_DIR, dir); + if (isPathDirectory(temp_dir)) { + printf("Found CIFS dir: %s\n", temp_dir); + strncpy(dir, temp_dir, dir_len); + return; + } + + FileCreatePath((char *) GAMES_DIR); snprintf(temp_dir, 1024, "%s/%s", GAMES_DIR, dir); strncpy(dir, temp_dir, dir_len); printf("Prefixed dir to %s\n", temp_dir); diff --git a/file_io.h b/file_io.h index b0bcb36..cdbc022 100644 --- a/file_io.h +++ b/file_io.h @@ -109,5 +109,6 @@ uint32_t getFileType(const char *name); #define COEFF_DIR "filters" #define GAMMA_DIR "gamma" #define GAMES_DIR "games" +#define CIFS_DIR "cifs" #endif