From 75661e752715a117f38230bea925aeef16df78ca Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Thu, 29 Mar 2012 16:18:23 +0200 Subject: [PATCH] (360/PS3) Moved file_browser.c to console/ - 360/PS3 now use the same file browser code --- 360/file_browser.c | 132 ------------------------- 360/file_browser.h | 47 --------- 360/menu.cpp | 2 +- {ps3 => console/fileio}/file_browser.c | 0 {ps3 => console/fileio}/file_browser.h | 0 console/griffin/griffin.c | 2 +- ps3/menu.c | 2 +- 7 files changed, 3 insertions(+), 182 deletions(-) delete mode 100644 360/file_browser.c delete mode 100644 360/file_browser.h rename {ps3 => console/fileio}/file_browser.c (100%) rename {ps3 => console/fileio}/file_browser.h (100%) diff --git a/360/file_browser.c b/360/file_browser.c deleted file mode 100644 index bbf8eda232..0000000000 --- a/360/file_browser.c +++ /dev/null @@ -1,132 +0,0 @@ -/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis - * - * Some code herein may be based on code found in BSNES. - * - * SSNES is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with SSNES. - * If not, see . - */ - -#include -#include "file_browser.h" -#include "../general.h" -#include "../file.h" - -static const char * filebrowser_get_extension(const char * filename) -{ - const char * ext = strrchr(filename, '.'); - if (ext) - return ext+1; - else - return ""; -} - -static void filebrowser_clear_current_entries(filebrowser_t * filebrowser) -{ - for(uint32_t i = 0; i < MAX_FILE_LIMIT; i++) - { - filebrowser->cur[filebrowser->file_count].d_type = 0; - filebrowser->cur[filebrowser->file_count].d_namlen = 0; - strcpy(filebrowser->cur[filebrowser->file_count].d_name, "\0"); - } -} - -void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions) -{ - int error = FALSE; - filebrowser->file_count = 0; - - WIN32_FIND_DATA ffd; - HANDLE hFind = INVALID_HANDLE_VALUE; - - char path_buf[PATH_MAX]; - - if (strlcpy(path_buf, path, sizeof(path_buf)) >= sizeof(path_buf)) - { - error = TRUE; - goto error; - } - if (strlcat(path_buf, "\\*", sizeof(path_buf)) >= sizeof(path_buf)) - { - error = TRUE; - goto error; - } - - hFind = FindFirstFile(path_buf, &ffd); - if (hFind == INVALID_HANDLE_VALUE) - { - error = TRUE; - goto error; - } - - do - { - strcpy(filebrowser->dir[filebrowser->directory_stack_size], path); - bool found_dir = false; - if(!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - char tmp_extensions[512]; - strncpy(tmp_extensions, extensions, sizeof(tmp_extensions)); - const char * current_extension = filebrowser_get_extension(ffd.cFileName); - bool found_rom = false; - - if(current_extension) - { - char * pch = strtok(tmp_extensions, "|"); - while (pch != NULL) - { - if(strcmp(current_extension, pch) == 0) - { - found_rom = true; - break; - } - pch = strtok(NULL, "|"); - } - } - - if(!found_rom) - continue; - } - else if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - found_dir = true; - - filebrowser->cur[filebrowser->file_count].d_type = found_dir ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL; - sprintf(filebrowser->cur[filebrowser->file_count].d_name, ffd.cFileName); - - filebrowser->file_count++; - }while (FindNextFile(hFind, &ffd) != 0 && (filebrowser->file_count + 1) < FATX_MAX_FILE_LIMIT); - -error: - if(error) - { - SSNES_ERR("Failed to open directory: \"%s\"\n", path); - } - FindClose(hFind); -} - -void filebrowser_new(filebrowser_t * filebrowser, const char * start_dir, const char * extensions) -{ - filebrowser_clear_current_entries(filebrowser); - filebrowser->directory_stack_size = 0; - strcpy(filebrowser->extensions, extensions); - - filebrowser_parse_directory(filebrowser, start_dir, filebrowser->extensions); -} - -void filebrowser_push_directory(filebrowser_t * filebrowser, const char * path, bool with_extension) -{ - filebrowser->directory_stack_size++; - if(with_extension) - filebrowser_parse_directory(filebrowser, path, filebrowser->extensions); - else - filebrowser_parse_directory(filebrowser, path, "empty"); -} \ No newline at end of file diff --git a/360/file_browser.h b/360/file_browser.h deleted file mode 100644 index 67ba6160b0..0000000000 --- a/360/file_browser.h +++ /dev/null @@ -1,47 +0,0 @@ -/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis - * - * Some code herein may be based on code found in BSNES. - * - * SSNES is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with SSNES. - * If not, see . - */ -#ifndef FILEBROWSER_H_ -#define FILEBROWSER_H_ - -#include - -#define FATX_MAX_FILE_LIMIT 4096 -#define MAX_FILE_LIMIT FATX_MAX_FILE_LIMIT - -typedef struct { - unsigned d_type; - unsigned d_namlen; - CHAR d_name[MAX_PATH]; -} DirectoryEntry; - -typedef struct { - unsigned file_count; // amount of files in current directory - unsigned currently_selected; // currently selected browser entry - uint32_t directory_stack_size; - char dir[128][2048]; /* info on the current directory */ - DirectoryEntry cur[MAX_FILE_LIMIT]; // current file listing - char extensions[512]; // allowed file extensions -} filebrowser_t; - -void filebrowser_new(filebrowser_t * filebrowser, const char * start_dir, const char * extensions); -void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions); -void filebrowser_push_directory(filebrowser_t * filebrowser, const char * path, bool with_extension); - -#define FILEBROWSER_GET_CURRENT_DIRECTORY_NAME(filebrowser) (filebrowser.dir[filebrowser.directory_stack_size]) - -#endif \ No newline at end of file diff --git a/360/menu.cpp b/360/menu.cpp index 7e1d868b19..bbfd6f80d9 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -20,7 +20,7 @@ #include #include #include -#include "file_browser.h" +#include "../console/fileio/file_browser.h" #include "../console/console_ext.h" #include "xdk360_video.h" #include "menu.h" diff --git a/ps3/file_browser.c b/console/fileio/file_browser.c similarity index 100% rename from ps3/file_browser.c rename to console/fileio/file_browser.c diff --git a/ps3/file_browser.h b/console/fileio/file_browser.h similarity index 100% rename from ps3/file_browser.h rename to console/fileio/file_browser.h diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index e57806cb6b..27cdd5db17 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -113,7 +113,7 @@ FILE ============================================================ */ #if defined(__CELLOS_LV2__) || defined(_XBOX) -#include "../../ps3/file_browser.c" +#include "../fileio/file_browser.c" #endif #include "../../file.c" diff --git a/ps3/menu.c b/ps3/menu.c index 22b9a2e428..20734d9d97 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -26,7 +26,7 @@ #endif #include "ps3_input.h" -#include "file_browser.h" +#include "../console/fileio/file_browser.h" #include "../console/console_ext.h"