diff --git a/360/fileio.c b/360/fileio.c
new file mode 100644
index 0000000000..89f4792724
--- /dev/null
+++ b/360/fileio.c
@@ -0,0 +1,103 @@
+/* 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 "fileio.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 "";
+}
+
+void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions)
+{
+ BOOL 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
+ {
+ 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;
+ strlcat(filebrowser->cur[filebrowser->file_count].d_nam, ffd.cFileName, PATH_MAX);
+
+ 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);
+}
\ No newline at end of file
diff --git a/360/fileio.h b/360/fileio.h
new file mode 100644
index 0000000000..fd5115e366
--- /dev/null
+++ b/360/fileio.h
@@ -0,0 +1,33 @@
+/* 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 .
+ */
+
+#define FATX_MAX_FILE_LIMIT 4096
+
+typedef struct {
+ unsigned d_type;
+ char d_nam[XCONTENT_MAX_FILENAME_LENGTH];
+} DirectoryEntry;
+
+typedef struct {
+ unsigned file_count; // amount of files in current directory
+ unsigned currently_selected; // currently selected browser entry
+ DirectoryEntry cur[FATX_MAX_FILE_LIMIT]; // current file listing
+ char extensions[512]; // allowed file extensions
+} filebrowser_t;
+
+void filebrowser_parse_directory(filebrowser_t * filebrowser, const char * path, const char *extensions);
\ No newline at end of file
diff --git a/360/menu.cpp b/360/menu.cpp
index 4b6dea9cc1..10cdfdbd10 100644
--- a/360/menu.cpp
+++ b/360/menu.cpp
@@ -20,6 +20,8 @@
#include
#include
#include
+#include "fileio.h"
+#include "../console/rom_ext.h"
#include "xdk360_video.h"
#include "menu.h"
#include "shared.h"
@@ -28,13 +30,17 @@
CSSNES app;
HXUIOBJ hMainScene;
+HXUIOBJ hFileBrowser;
HXUIOBJ hSSNESSettings;
+filebrowser_t browser;
/* Register custom classes */
HRESULT CSSNES::RegisterXuiClasses (void)
{
CSSNESMain::Register();
+ CSSNESFileBrowser::Register();
CSSNESSettings::Register();
+ filebrowser_parse_directory(&browser, "game:\\roms\\", ssnes_console_get_rom_ext());
return S_OK;
}
@@ -42,10 +48,17 @@ HRESULT CSSNES::RegisterXuiClasses (void)
HRESULT CSSNES::UnregisterXuiClasses (void)
{
CSSNESMain::Unregister();
+ CSSNESFileBrowser::Unregister();
CSSNESSettings::Unregister();
return S_OK;
}
+HRESULT CSSNESFileBrowser::OnInit(XUIMessageInit * pInitData, BOOL& bHandled)
+{
+ GetChildById(L"XuiRomList", &m_romlist);
+ return S_OK;
+}
+
HRESULT CSSNESSettings::OnInit(XUIMessageInit * pInitData, BOOL& bHandled)
{
GetChildById(L"XuiBtnRewind", &m_rewind);
@@ -78,6 +91,12 @@ HRESULT CSSNESMain::OnInit(XUIMessageInit * pInitData, BOOL& bHandled)
return S_OK;
}
+HRESULT CSSNESFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled )
+{
+ bHandled = TRUE;
+ return S_OK;
+}
+
HRESULT CSSNESSettings::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled )
{
if ( hObjPressed == m_rewind)
diff --git a/360/menu.h b/360/menu.h
index d519472277..26b3c4847e 100644
--- a/360/menu.h
+++ b/360/menu.h
@@ -33,6 +33,22 @@ public:
XUI_IMPLEMENT_CLASS(CSSNESMain, L"SSNESMain", XUI_CLASS_SCENE)
};
+class CSSNESFileBrowser: public CXuiSceneImpl
+{
+protected:
+ CXuiList m_romlist;
+public:
+ HRESULT OnInit( XUIMessageInit* pInitData, BOOL& bHandled );
+ HRESULT OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandled );
+
+ XUI_BEGIN_MSG_MAP()
+ XUI_ON_XM_INIT( OnInit)
+ XUI_ON_XM_NOTIFY_PRESS( OnNotifyPress )
+ XUI_END_MSG_MAP();
+
+ XUI_IMPLEMENT_CLASS(CSSNESFileBrowser, L"SSNESFileBrowser", XUI_CLASS_SCENE)
+};
+
class CSSNESSettings: public CXuiSceneImpl
{
protected:
diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj
index e737265f7f..e8cab9c62f 100644
--- a/msvc-360/SSNES-360/SSNES-360.vcxproj
+++ b/msvc-360/SSNES-360/SSNES-360.vcxproj
@@ -263,6 +263,7 @@
+
diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj.filters b/msvc-360/SSNES-360/SSNES-360.vcxproj.filters
index 8be73b2dc1..ac4c16fcb2 100644
--- a/msvc-360/SSNES-360/SSNES-360.vcxproj.filters
+++ b/msvc-360/SSNES-360/SSNES-360.vcxproj.filters
@@ -125,6 +125,9 @@
Source Files\console
+
+ Source Files\360
+