diff --git a/JGE/include/JFileSystem.h b/JGE/include/JFileSystem.h index 036848195..575f4e858 100644 --- a/JGE/include/JFileSystem.h +++ b/JGE/include/JFileSystem.h @@ -28,6 +28,61 @@ using namespace std; + +class JFile +{ +public: + + JFile(); + virtual ~JFile(); + + + virtual bool OpenFile(const string &filename); + + virtual int ReadFile(void *buffer, int size); + + virtual int GetFileSize(); + + virtual void CloseFile(); + +protected: + + std::string mFilename; + +#if defined (PSP) + SceUID mFile; +#else + FILE *mFile; +#endif + int mFileSize; +}; + +class JZipFile : public JFile +{ +public: + + JZipFile(const std::string& inZipFilename); + virtual ~JZipFile(); + + + /* + ** Access filename within the zip. + */ + virtual bool OpenFile(const string &filename); + + virtual int ReadFile(void *buffer, int size); + + virtual int GetFileSize(); + + virtual void CloseFile(); + +private: + + std::string mZipFilename; + unzFile mZipFile; +}; + + ////////////////////////////////////////////////////////////////////////// /// Interface for low level file access with ZIP archive support. All /// file operations in JGE are handled through this class so if a ZIP diff --git a/JGE/src/JFileSystem.cpp b/JGE/src/JFileSystem.cpp index 718f4ce2a..ca3dd96d3 100644 --- a/JGE/src/JFileSystem.cpp +++ b/JGE/src/JFileSystem.cpp @@ -24,6 +24,136 @@ #include #include +#include "../include/DebugRoutines.h" +#include + + +JFile::JFile() : mFile(0), mFileSize(0) +{ +} + +JFile::~JFile() +{ +} + +bool JFile::OpenFile(const string &filename) +{ + bool result = false; + mFilename = JFileSystem::GetInstance()->GetResourceRoot() + filename; + +#if defined (PSP) + mFile = sceIoOpen(mFilename.c_str(), PSP_O_RDONLY, 0777); + if (mFile > 0) + { + mFileSize = sceIoLseek(mFile, 0, PSP_SEEK_END); + sceIoLseek(mFile, 0, PSP_SEEK_SET); + result = true; + } +#else + mFile = fopen(mFilename.c_str(), "rb"); + if (mFile != NULL) + { + fseek(mFile, 0, SEEK_END); + mFileSize = ftell(mFile); + fseek(mFile, 0, SEEK_SET); + result = true; + } +#endif + + return result; +} + +int JFile::ReadFile(void *buffer, int size) +{ +#if defined (PSP) + return sceIoRead(mFile, buffer, size); +#else + return fread(buffer, 1, size, mFile); +#endif +} + +int JFile::GetFileSize() +{ + return mFileSize; +} + +void JFile::CloseFile() +{ + +#if defined (PSP) + if (mFile > 0) + sceIoClose(mFile); +#else + if (mFile != NULL) + fclose(mFile); +#endif + + mFile = 0; + mFileSize = 0; +} + + +JZipFile::JZipFile(const std::string& inZipFilename) + : mZipFilename(inZipFilename) +{ + mZipFile = unzOpen(mZipFilename.c_str()); + assert(mZipFile); + + if (mZipFile == NULL) + throw; +} + +JZipFile::~JZipFile() +{ + unzClose(mZipFile); +} + +const int kCaseInsensitive = 2; + +bool JZipFile::OpenFile(const string &filename) +{ + bool result = false; + mFilename = JFileSystem::GetInstance()->GetResourceRoot() + filename; + + if (mZipFile) + { + int fileAttempt = unzLocateFile(mZipFile, mFilename.c_str(), kCaseInsensitive); + if (fileAttempt != UNZ_END_OF_LIST_OF_FILE) + { + result = (unzOpenCurrentFile(mZipFile) == UNZ_OK); + } + } + + return result; +} + +int JZipFile::ReadFile(void *buffer, int size) +{ + return unzReadCurrentFile(mZipFile, buffer, size); +} + +int JZipFile::GetFileSize() +{ + int result = 0; + if (mZipFile != NULL) + { + unz_file_info info; + unzGetCurrentFileInfo(mZipFile, &info, NULL, 0, NULL, 0, NULL, 0); + result = info.uncompressed_size; + } + return result; +} + +void JZipFile::CloseFile() +{ + if (mZipFile != NULL) + { + unzCloseCurrentFile(mZipFile); + } +} + + + JZipCache::JZipCache() {} @@ -281,7 +411,16 @@ void JFileSystem::SetResourceRoot(const string& resourceRoot) mResourceRoot = [documentsDirectory cStringUsingEncoding:1]; mResourceRoot += "/"; #elif defined (ANDROID) - mResourceRoot = "/sdcard/Wagic/Res/"; + mResourceRoot = "/mnt/sdcard-ext/Wagic/Res/"; + + DebugTrace("test: writing to /sdcard-ext/ "); + std::ofstream file("/mnt/sdcard-ext/Foo.txt"); + if (file) + { + DebugTrace("successfully opened foo.txt..."); + file << "test"; + file.close(); + } #else mResourceRoot = resourceRoot; #endif diff --git a/projects/mtg/include/ActionStack.h b/projects/mtg/include/ActionStack.h index e394e374d..3dd144cf8 100644 --- a/projects/mtg/include/ActionStack.h +++ b/projects/mtg/include/ActionStack.h @@ -83,11 +83,9 @@ public: return TARGET_STACKACTION; } - Interruptible(bool hasFocus = false) : PlayGuiObject(40,x,y,hasFocus) + Interruptible(int inID = 0, bool hasFocus = false) + : PlayGuiObject(40, x, y, inID, hasFocus), state(NOT_RESOLVED), display(0), source(NULL) { - state = NOT_RESOLVED; - display = 0; - source = NULL; } virtual const string getDisplayName() const; diff --git a/projects/mtg/include/PlayGuiObject.h b/projects/mtg/include/PlayGuiObject.h index 7e3952335..f42011897 100644 --- a/projects/mtg/include/PlayGuiObject.h +++ b/projects/mtg/include/PlayGuiObject.h @@ -51,8 +51,11 @@ public: ; virtual void Render(); virtual void Update(float dt); - PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus); - PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus); + + PlayGuiObject(float desiredHeight, float x, float y, int inID, bool hasFocus); + + PlayGuiObject(float desiredHeight, const Pos& ref, int inID, bool hasFocus); + virtual void ButtonPressed(int controllerId, int controlId) {} virtual bool getTopLeft(float& top, float& left) { diff --git a/projects/mtg/src/GuiStatic.cpp b/projects/mtg/src/GuiStatic.cpp index 0844befef..0fda6ed12 100644 --- a/projects/mtg/src/GuiStatic.cpp +++ b/projects/mtg/src/GuiStatic.cpp @@ -4,7 +4,7 @@ #include "GuiStatic.h" GuiStatic::GuiStatic(float desiredHeight, float x, float y, bool hasFocus, GuiAvatars* parent) : - PlayGuiObject(desiredHeight, x, y, hasFocus), parent(parent) + PlayGuiObject(desiredHeight, x, y, 0, hasFocus), parent(parent) { } diff --git a/projects/mtg/src/PlayGuiObject.cpp b/projects/mtg/src/PlayGuiObject.cpp index 79748f289..5d84ca3a8 100644 --- a/projects/mtg/src/PlayGuiObject.cpp +++ b/projects/mtg/src/PlayGuiObject.cpp @@ -4,8 +4,8 @@ using namespace std; -PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, bool hasFocus) : - JGuiObject(0), Pos(x, y, 1.0, 0.0, 255) +PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, int inID, bool hasFocus) + : JGuiObject(inID), Pos(x, y, 1.0, 0.0, 255) { defaultHeight = desiredHeight; mHeight = desiredHeight; @@ -13,8 +13,8 @@ PlayGuiObject::PlayGuiObject(float desiredHeight, float x, float y, bool hasFocu type = 0; wave = 0; } -PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, bool hasFocus) : - JGuiObject(0), Pos(ref) +PlayGuiObject::PlayGuiObject(float desiredHeight, const Pos& ref, int inID, bool hasFocus) + : JGuiObject(inID), Pos(ref) { defaultHeight = desiredHeight; mHeight = desiredHeight;