Android: Restored old file reading behavior for audio stuff

This commit is contained in:
Mario Liebisch 2015-01-30 10:26:12 +01:00
parent 62933114ec
commit 3424467896
2 changed files with 70 additions and 0 deletions

View File

@ -33,6 +33,16 @@
#include <SFML/System/Export.hpp> #include <SFML/System/Export.hpp>
#include <fstream> #include <fstream>
#ifdef ANDROID
namespace sf
{
namespace priv
{
class SFML_SYSTEM_API ResourceStream;
}
}
#endif
namespace sf namespace sf
{ {
@ -43,6 +53,17 @@ namespace sf
class SFML_SYSTEM_API FileInputStream : public InputStream class SFML_SYSTEM_API FileInputStream : public InputStream
{ {
public : public :
////////////////////////////////////////////////////////////
/// \brief Default constructor
///
////////////////////////////////////////////////////////////
FileInputStream();
////////////////////////////////////////////////////////////
/// \brief Default destructor
///
////////////////////////////////////////////////////////////
virtual ~FileInputStream();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Open the stream from a file path /// \brief Open the stream from a file path
@ -99,7 +120,11 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef ANDROID
std::ifstream m_file; ///< Standard file stream std::ifstream m_file; ///< Standard file stream
#else
sf::priv::ResourceStream *m_file;
#endif
}; };
} // namespace sf } // namespace sf

View File

@ -26,51 +26,96 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/FileInputStream.hpp> #include <SFML/System/FileInputStream.hpp>
#ifdef ANDROID
#include <SFML/System/Android/ResourceStream.hpp>
#endif
namespace sf 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) bool FileInputStream::open(const std::string& filename)
{ {
#ifndef ANDROID
m_file.open(filename.c_str(), std::ios::binary); m_file.open(filename.c_str(), std::ios::binary);
return m_file.good(); 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) Int64 FileInputStream::read(void* data, Int64 size)
{ {
#ifndef ANDROID
m_file.read(static_cast<char*>(data), size); m_file.read(static_cast<char*>(data), size);
return m_file.gcount(); return m_file.gcount();
#else
return m_file->read(data, size);
#endif
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 FileInputStream::seek(Int64 position) Int64 FileInputStream::seek(Int64 position)
{ {
#ifndef ANDROID
if (m_file.eof() || m_file.fail()) if (m_file.eof() || m_file.fail())
m_file.clear(); m_file.clear();
m_file.seekg(position); m_file.seekg(position);
return tell(); return tell();
#else
return m_file->seek(position);
#endif
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 FileInputStream::tell() Int64 FileInputStream::tell()
{ {
#ifndef ANDROID
return m_file.tellg(); return m_file.tellg();
#else
return m_file->tell();
#endif
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Int64 FileInputStream::getSize() Int64 FileInputStream::getSize()
{ {
#ifndef ANDROID
std::ifstream::pos_type pos = m_file.tellg(); std::ifstream::pos_type pos = m_file.tellg();
m_file.seekg(0, std::ios::end); m_file.seekg(0, std::ios::end);
std::ifstream::pos_type size = m_file.tellg(); std::ifstream::pos_type size = m_file.tellg();
m_file.seekg(pos); m_file.seekg(pos);
return size; return size;
#else
return m_file->getSize();
#endif
} }
} // namespace sf } // namespace sf