diff --git a/include/SFML/System/FileInputStream.hpp b/include/SFML/System/FileInputStream.hpp index 1e329415f..10218b446 100644 --- a/include/SFML/System/FileInputStream.hpp +++ b/include/SFML/System/FileInputStream.hpp @@ -33,6 +33,16 @@ #include #include +#ifdef ANDROID +namespace sf +{ +namespace priv +{ +class SFML_SYSTEM_API ResourceStream; +} +} +#endif + namespace sf { @@ -43,6 +53,17 @@ namespace sf class SFML_SYSTEM_API FileInputStream : public InputStream { public : + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + //////////////////////////////////////////////////////////// + FileInputStream(); + + //////////////////////////////////////////////////////////// + /// \brief Default destructor + /// + //////////////////////////////////////////////////////////// + virtual ~FileInputStream(); //////////////////////////////////////////////////////////// /// \brief Open the stream from a file path @@ -99,7 +120,11 @@ private: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// +#ifndef ANDROID std::ifstream m_file; ///< Standard file stream +#else + sf::priv::ResourceStream *m_file; +#endif }; } // namespace sf diff --git a/src/SFML/System/FileInputStream.cpp b/src/SFML/System/FileInputStream.cpp index c9c1a49c2..417890c39 100644 --- a/src/SFML/System/FileInputStream.cpp +++ b/src/SFML/System/FileInputStream.cpp @@ -26,51 +26,96 @@ // Headers //////////////////////////////////////////////////////////// #include +#ifdef ANDROID +#include +#endif namespace sf { +//////////////////////////////////////////////////////////// +FileInputStream::FileInputStream() +#ifdef ANDROID +: m_file(NULL) +#endif +{ + +} + + +//////////////////////////////////////////////////////////// +FileInputStream::~FileInputStream() +{ +#ifdef ANDROID + if (m_file) + delete m_file; +#endif +} + + //////////////////////////////////////////////////////////// bool FileInputStream::open(const std::string& filename) { +#ifndef ANDROID m_file.open(filename.c_str(), std::ios::binary); return m_file.good(); +#else + if (m_file) + delete m_file; + m_file = new sf::priv::ResourceStream(filename); +#endif } //////////////////////////////////////////////////////////// Int64 FileInputStream::read(void* data, Int64 size) { +#ifndef ANDROID m_file.read(static_cast(data), size); return m_file.gcount(); +#else + return m_file->read(data, size); +#endif } //////////////////////////////////////////////////////////// Int64 FileInputStream::seek(Int64 position) { +#ifndef ANDROID if (m_file.eof() || m_file.fail()) m_file.clear(); m_file.seekg(position); return tell(); +#else + return m_file->seek(position); +#endif } //////////////////////////////////////////////////////////// Int64 FileInputStream::tell() { +#ifndef ANDROID return m_file.tellg(); +#else + return m_file->tell(); +#endif } //////////////////////////////////////////////////////////// Int64 FileInputStream::getSize() { +#ifndef ANDROID std::ifstream::pos_type pos = m_file.tellg(); m_file.seekg(0, std::ios::end); std::ifstream::pos_type size = m_file.tellg(); m_file.seekg(pos); return size; +#else + return m_file->getSize(); +#endif } } // namespace sf