diff --git a/desmume/src/fs-linux.cpp b/desmume/src/fs-linux.cpp deleted file mode 100644 index 27039d9ef..000000000 --- a/desmume/src/fs-linux.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* Copyright (C) 2006 Guillaume Duhamel - - This file is part of DeSmuME - - DeSmuME 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 Foundation; either version 2 of the License, or - (at your option) any later version. - - DeSmuME 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 DeSmuME; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#include "fs.h" - -#include -#include -#include -#include -#include -#include - -typedef struct { - DIR * dir; - char * path; -} FsLinuxDir; - -const char FS_SEPARATOR = '/'; - -void * FsReadFirst(const char * path, FsEntry * entry) { - FsLinuxDir * dir; - struct dirent * e; - struct stat s; - char buffer[512+1]; /* DirSpec[256] + '/' + dirent.d_name[256] */ - DIR * tmp; - - dir = (FsLinuxDir*)malloc(sizeof(FsLinuxDir)); - if (!dir) - return NULL; - - tmp = opendir(path); - if (!tmp) { - free(dir); - return NULL; - } - dir->dir = tmp; - - e = readdir(tmp); - if (!e) { - closedir(tmp); - free(dir); - return NULL; - } - strcpy(entry->cFileName, e->d_name); - // there's no 8.3 file names support on linux :) - strcpy(entry->cAlternateFileName, ""); - entry->flags = 0; - - dir->path = strdup(path); - sprintf(buffer, "%s/%s", dir->path, e->d_name); - - stat(buffer, &s); - if (S_ISDIR(s.st_mode)) { - entry->flags = FS_IS_DIR; - entry->fileSize = 0; - } else { - entry->fileSize = s.st_size; - } - - return dir; -} - -int FsReadNext(void * search, FsEntry * entry) { - FsLinuxDir * dir = (FsLinuxDir*)search; - struct dirent * e; - struct stat s; - char buffer[1024]; - - e = readdir(dir->dir); - if (!e) - return 0; - - strcpy(entry->cFileName, e->d_name); - // there's no 8.3 file names support on linux :) - strcpy(entry->cAlternateFileName, ""); - entry->flags = 0; - - sprintf(buffer, "%s/%s", dir->path, e->d_name); - - stat(buffer, &s); - if (S_ISDIR(s.st_mode)) { - entry->flags = FS_IS_DIR; - entry->fileSize = 0; - } else { - entry->fileSize = s.st_size; - } - - return 1; -} - -void FsClose(void * search) { - FsLinuxDir *linuxdir = (FsLinuxDir *) search; - DIR * dir = linuxdir->dir; - - closedir(dir); - free(linuxdir->path); - free(search); -} - -int FsError(void) { - return 0; -} diff --git a/desmume/src/fs-windows.cpp b/desmume/src/fs-windows.cpp deleted file mode 100644 index 0be1ad571..000000000 --- a/desmume/src/fs-windows.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - Copyright (C) 2006 Guillaume Duhamel - Copyright (C) 2006-2009 DeSmuME team - - This file 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 Foundation, either version 2 of the License, or - (at your option) any later version. - - This file 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 the this software. If not, see . -*/ - -#include "fs.h" - -#include -#include -#include -#include - -const char FS_SEPARATOR = '\\'; - -void * FsReadFirst(const char * p, FsEntry * entry) { - WIN32_FIND_DATA FindFileData; - HANDLE hFind; - HANDLE * ret; - char path[1024]; - if (strlen(p)+3 >sizeof(path)) return NULL ; - - sprintf(path, "%s\\*", p); - - hFind = FindFirstFile(path, &FindFileData); - if (hFind == INVALID_HANDLE_VALUE) - return NULL; - - strncpy(entry->cFileName, FindFileData.cFileName,256); - entry->cFileName[255] = 0 ; - strncpy(entry->cAlternateFileName, FindFileData.cAlternateFileName,14); - entry->cAlternateFileName[13] = 0 ; - entry->flags = 0; - if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - entry->flags = FS_IS_DIR; - entry->fileSize = 0; - } else { - entry->fileSize = FindFileData.nFileSizeLow; - } - - ret = (void**)malloc(sizeof(HANDLE)); - *ret = hFind; - return ret; -} - -int FsReadNext(void * search, FsEntry * entry) { - WIN32_FIND_DATA FindFileData; - HANDLE * h = (HANDLE *) search; - int ret; - - ret = FindNextFile(*h, &FindFileData); - - strncpy(entry->cFileName, FindFileData.cFileName,256); - entry->cFileName[255] = 0 ; - strncpy(entry->cAlternateFileName, FindFileData.cAlternateFileName,14); - entry->cAlternateFileName[13] = 0 ; - entry->flags = 0; - if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - entry->flags = FS_IS_DIR; - entry->fileSize = 0; - } else { - entry->fileSize = FindFileData.nFileSizeLow; - } - - return ret; -} - -void FsClose(void * search) { - FindClose(*((HANDLE *) search)); -} - -int FsError(void) { - if (GetLastError() == ERROR_NO_MORE_FILES) - return FS_ERR_NO_MORE_FILES; - - return FS_ERR_UNKNOWN; -} diff --git a/desmume/src/fs.h b/desmume/src/fs.h deleted file mode 100644 index d1a9a05e9..000000000 --- a/desmume/src/fs.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (C) 2006 Guillaume Duhamel - Copyright (C) 2007-2010 DeSmuME team - - This file 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 Foundation, either version 2 of the License, or - (at your option) any later version. - - This file 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 the this software. If not, see . -*/ - -#ifndef FS_H -#define FS_H - -#include "types.h" - -#define FS_IS_DIR 1 - -#define FS_ERR_UNKNOWN -1 -#define FS_ERR_NO_MORE_FILES 1 - -extern const char FS_SEPARATOR; - -typedef struct { - char cFileName[256]; - char cAlternateFileName[14]; - u32 flags; - u32 fileSize; -} FsEntry; - -void * FsReadFirst(const char * path, FsEntry * entry); -int FsReadNext(void * search, FsEntry * entry); -void FsClose(void * search); -int FsError(void); - -#endif diff --git a/desmume/src/utils/vfat.cpp b/desmume/src/utils/vfat.cpp index e05b81758..17853c08a 100644 --- a/desmume/src/utils/vfat.cpp +++ b/desmume/src/utils/vfat.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2006 yopyop Copyright (C) 2006 Mic - Copyright (C) 2010-2015 DeSmuME team + Copyright (C) 2010-2016 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,9 @@ #include "../types.h" #include "../debug.h" #include "../emufile.h" -#include "../fs.h" +#include "retro_dirent.h" +#include "retro_stat.h" +#include "file/file_path.h" #include "emufat.h" #include "vfat.h" @@ -38,54 +40,56 @@ enum EListCallbackArg { EListCallbackArg_Item, EListCallbackArg_Pop }; -typedef void (*ListCallback)(FsEntry* fs, EListCallbackArg); +typedef void (*ListCallback)(RDIR* rdir, EListCallbackArg); // List all files and subdirectories recursively static void list_files(const char *filepath, ListCallback list_callback) { - char DirSpec[255+1], SubDir[255+1]; - FsEntry entry; void * hFind; char *fname; u32 dwError; - strncpy(DirSpec, filepath, ARRAY_SIZE(DirSpec)); - DirSpec[255] = 0 ; // hard limit the string here + RDIR* rdir = retro_opendir(filepath); + if(!rdir) return; + if(retro_dirent_error(rdir)) + { + retro_closedir(rdir); + return; + } - hFind = FsReadFirst(DirSpec, &entry); - if (hFind == NULL) return; + for(;;) + { + if(!retro_readdir(rdir)) + break; - do { - fname = (strlen(entry.cAlternateFileName)>0) ? entry.cAlternateFileName : entry.cFileName; - list_callback(&entry,EListCallbackArg_Item); - printf("cflash added %s\n",entry.cFileName); + const char* fname = retro_dirent_get_name(rdir); + list_callback(rdir,EListCallbackArg_Item); - if ((entry.flags & FS_IS_DIR) && (strcmp(fname, ".")) && (strcmp(fname, ".."))) + if(retro_dirent_is_dir(rdir) && (strcmp(fname, ".")) && (strcmp(fname, ".."))) { - if (strlen(fname)+strlen(filepath)+2 < 256) - { - sprintf(SubDir, "%s%c%s", filepath, FS_SEPARATOR, fname); - list_files(SubDir, list_callback); - list_callback(&entry, EListCallbackArg_Pop); - } + std::string subdir = (std::string)filepath + path_default_slash() + fname; + list_files(subdir.c_str(), list_callback); + list_callback(rdir, EListCallbackArg_Pop); } - } while (FsReadNext(hFind, &entry) != 0); + } - dwError = FsError(); - FsClose(hFind); - if (dwError != FS_ERR_NO_MORE_FILES) return; + retro_closedir(rdir); } static u64 dataSectors = 0; -void count_ListCallback(FsEntry* fs, EListCallbackArg arg) +void count_ListCallback(RDIR* rdir, EListCallbackArg arg) { if(arg == EListCallbackArg_Pop) return; u32 sectors = 1; - if(fs->flags & FS_IS_DIR) + if(retro_dirent_is_dir(rdir)) { } else - sectors += (fs->fileSize+511)/512 + 1; + { + //allocate sectors for file + int32_t fileSize = path_get_size(retro_dirent_get_name(rdir)); + sectors += (fileSize+511)/512 + 1; + } dataSectors += sectors; } @@ -93,12 +97,9 @@ static std::string currPath; static std::stack pathStack; static std::stack virtPathStack; static std::string currVirtPath; -void build_ListCallback(FsEntry* fs, EListCallbackArg arg) +void build_ListCallback(RDIR* rdir, EListCallbackArg arg) { - char* fname = (strlen(fs->cAlternateFileName)>0) ? fs->cAlternateFileName : fs->cFileName; - - //we use cFileName always because it is a LFN and we are making sure that we always make a fat32 image - fname = fs->cFileName; + const char* fname = retro_dirent_get_name(rdir); if(arg == EListCallbackArg_Pop) { @@ -109,7 +110,7 @@ void build_ListCallback(FsEntry* fs, EListCallbackArg arg) return; } - if(fs->flags & FS_IS_DIR) + if(retro_dirent_is_dir(rdir)) { if(!strcmp(fname,".")) return; if(!strcmp(fname,"..")) return; @@ -123,12 +124,12 @@ void build_ListCallback(FsEntry* fs, EListCallbackArg arg) if(!ok) printf("ERROR adding dir %s via libfat\n",currVirtPath.c_str()); - currPath = currPath + std::string(1,FS_SEPARATOR) + fname; + currPath = currPath + path_default_slash() + fname; return; } else { - std::string path = currPath + std::string(1,FS_SEPARATOR) + fname; + std::string path = currPath + path_default_slash() + fname; FILE* inf = fopen(path.c_str(),"rb"); if(inf) @@ -141,7 +142,7 @@ void build_ListCallback(FsEntry* fs, EListCallbackArg arg) fclose(inf); std::string path = currVirtPath + "/" + fname; - printf("adding path %s for libfat\n",path.c_str()); + printf("FAT + (%10.2f KB) %s \n",len/1024.f,path.c_str()); bool ok = LIBFAT::WriteFile(path.c_str(),buf,len); if(!ok) printf("ERROR adding file to fat\n"); diff --git a/desmume/src/windows/DeSmuME.vcxproj b/desmume/src/windows/DeSmuME.vcxproj index 538921a3a..5354571f2 100644 --- a/desmume/src/windows/DeSmuME.vcxproj +++ b/desmume/src/windows/DeSmuME.vcxproj @@ -95,7 +95,6 @@ - @@ -364,7 +363,6 @@ - diff --git a/desmume/src/windows/DeSmuME.vcxproj.filters b/desmume/src/windows/DeSmuME.vcxproj.filters index fe9ccf22b..2e317d9d3 100644 --- a/desmume/src/windows/DeSmuME.vcxproj.filters +++ b/desmume/src/windows/DeSmuME.vcxproj.filters @@ -165,9 +165,6 @@ Core - - Core - Core @@ -1010,9 +1007,6 @@ Core - - Core - Core