diff --git a/desmume/configure.ac b/desmume/configure.ac index d00380c7b..34ad3f1d1 100644 --- a/desmume/configure.ac +++ b/desmume/configure.ac @@ -3,6 +3,12 @@ AC_INIT(desmume, 0.3.3) AC_CANONICAL_HOST AC_CANONICAL_TARGET +case $target in + *linux*) desmume_arch=linux;; + *mingw*) desmume_arch=windows;; +esac +AC_SUBST(desmume_arch) + AM_INIT_AUTOMAKE(desmume, 0.3.3) AC_PROG_CC diff --git a/desmume/src/Makefile.am b/desmume/src/Makefile.am index 8445ed7f6..979f3ff4c 100644 --- a/desmume/src/Makefile.am +++ b/desmume/src/Makefile.am @@ -9,4 +9,5 @@ libdesmume_a_SOURCES = \ GPU.cpp GPU.hpp debug.c debug.h \ MMU.cpp MMU.hpp NDSSystem.cpp NDSSystem.hpp \ thumb_instructions.cpp thumb_instructions.hpp \ - windows/cflash.cpp windows/cflash.h fs.c fs.h + windows/cflash.cpp windows/cflash.h fs.h +libdesmume_a_LIBADD = fs-$(desmume_arch).$(OBJEXT) diff --git a/desmume/src/fs-linux.c b/desmume/src/fs-linux.c new file mode 100644 index 000000000..fef718c64 --- /dev/null +++ b/desmume/src/fs-linux.c @@ -0,0 +1,16 @@ +#include "fs.h" + +void * FsReadFirst(const char * path, FsEntry * entry) { + return 0; +} + +int FsReadNext(void * search, FsEntry * entry) { + return 0; +} + +void FsClose(void * search) { +} + +int FsError(void) { + return 0; +} diff --git a/desmume/src/fs-windows.c b/desmume/src/fs-windows.c new file mode 100644 index 000000000..2836433c0 --- /dev/null +++ b/desmume/src/fs-windows.c @@ -0,0 +1,50 @@ +#include "fs.h" + +#include + +void * FsReadFirst(const char * path, FsEntry * entry) { + WIN32_FIND_DATA FindFileData; + HANDLE hFind; + HANDLE * ret; + + hFind = FindFirstFile(path, &FindFileData); + if (hFind == INVALID_HANDLE_VALUE) + return NULL; + + strcpy(entry->cFileName, FindFileData.cFileName); + strcpy(entry->cAlternateFileName, FindFileData.cAlternateFileName); + entry->flags = 0; + if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + entry->flags = FS_IS_DIR; + } + + ret = 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); + + strcpy(entry->cFileName, FindFileData.cFileName); + strcpy(entry->cAlternateFileName, FindFileData.cAlternateFileName); + entry->flags = 0; + if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + entry->flags = FS_IS_DIR; + } + + return ret; +} + +void FsClose(void * search) { + FindClose(*((HANDLE *) search)); +} + +int FsError(void) { + if (GetLastError() == ERROR_NO_MORE_FILES) + return FS_ERR_NO_MORE_FILES; +}