Skip to content

Commit

Permalink
Android: Restored old file reading behavior for audio stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioLiebisch committed Mar 4, 2015
1 parent 6293311 commit 3424467
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/SFML/System/FileInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
#include <SFML/System/Export.hpp>
#include <fstream>

#ifdef ANDROID
namespace sf
{
namespace priv
{
class SFML_SYSTEM_API ResourceStream;
}
}
#endif


namespace sf
{
Expand All @@ -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
Expand Down Expand Up @@ -99,7 +120,11 @@ public :
////////////////////////////////////////////////////////////
// Member data
////////////////////////////////////////////////////////////
#ifndef ANDROID
std::ifstream m_file; ///< Standard file stream
#else
sf::priv::ResourceStream *m_file;
#endif
};

} // namespace sf
Expand Down
45 changes: 45 additions & 0 deletions src/SFML/System/FileInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,96 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/FileInputStream.hpp>
#ifdef ANDROID
#include <SFML/System/Android/ResourceStream.hpp>
#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<char*>(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

0 comments on commit 3424467

Please sign in to comment.