mirror of
https://github.com/izzy2lost/WeeU.git
synced 2026-07-06 00:19:59 -07:00
Refactored contenturi stream
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#include "Common/FileStream.h"
|
||||
|
||||
#if __ANDROID__
|
||||
#include "Common/unix/ContentUriIStream.h"
|
||||
#include "Common/unix/ContentUriStream.h"
|
||||
#endif // __ANDROID__
|
||||
|
||||
#include <zarchive/zarchivereader.h>
|
||||
@@ -228,7 +228,7 @@ bool TitleInfo::DetectFormat(const fs::path& path, fs::path& pathOut, TitleDataF
|
||||
ZArchiveReader* zar = nullptr;
|
||||
#if __ANDROID__
|
||||
if(FilesystemAndroid::isContentUri(path))
|
||||
zar = ZArchiveReader::OpenFromStream(std::make_unique<ContentUriIStream>(path));
|
||||
zar = ZArchiveReader::OpenFromStream(std::make_unique<ContentUriStream>(path));
|
||||
else
|
||||
#endif // __ANDROID__
|
||||
zar = ZArchiveReader::OpenFromFile(path);
|
||||
@@ -369,7 +369,7 @@ ZArchiveReader* _ZArchivePool_AcquireInstance(const fs::path& path)
|
||||
ZArchiveReader* zar = nullptr;
|
||||
#if __ANDROID__
|
||||
if(FilesystemAndroid::isContentUri(path))
|
||||
zar = ZArchiveReader::OpenFromStream(std::make_unique<ContentUriIStream>(path));
|
||||
zar = ZArchiveReader::OpenFromStream(std::make_unique<ContentUriStream>(path));
|
||||
else
|
||||
#endif // __ANDROID__
|
||||
zar = ZArchiveReader::OpenFromFile(path);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#if __ANDROID__
|
||||
#include "Common/unix/FilesystemAndroid.h"
|
||||
#include "Common/unix/ContentUriIStream.h"
|
||||
#include "Common/unix/ContentUriStream.h"
|
||||
#endif // __ANDROID__
|
||||
|
||||
#include <zarchive/zarchivereader.h>
|
||||
@@ -224,7 +224,7 @@ void CafeTitleList::AddTitleFromPath(fs::path path)
|
||||
ZArchiveReader* zar = nullptr;
|
||||
#if __ANDROID__
|
||||
if(FilesystemAndroid::isContentUri(path))
|
||||
zar = ZArchiveReader::OpenFromStream(std::make_unique<ContentUriIStream>(path));
|
||||
zar = ZArchiveReader::OpenFromStream(std::make_unique<ContentUriStream>(path));
|
||||
else
|
||||
#endif // __ANDROID__
|
||||
zar = ZArchiveReader::OpenFromFile(path);
|
||||
|
||||
@@ -56,7 +56,7 @@ endif()
|
||||
|
||||
if(ANDROID)
|
||||
target_sources(CemuCommon PRIVATE
|
||||
unix/ContentUriIStream.h
|
||||
unix/ContentUriStream.h
|
||||
unix/FilesystemAndroid.cpp
|
||||
unix/FilesystemAndroid.h
|
||||
unix/FileStream_contentUri.cpp
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/iostreams/stream_buffer.hpp>
|
||||
|
||||
#include "Common/unix/FilesystemAndroid.h"
|
||||
|
||||
class ContentUriIStream : public std::istream
|
||||
{
|
||||
public:
|
||||
ContentUriIStream(const std::filesystem::path& path)
|
||||
: m_fd(FilesystemAndroid::openContentUri(path)),
|
||||
m_fileDescriptorStreamBuffer(m_fd, boost::iostreams::close_handle),
|
||||
std::istream(&m_fileDescriptorStreamBuffer) {}
|
||||
|
||||
virtual ~ContentUriIStream() = default;
|
||||
|
||||
inline bool isOpen() const
|
||||
{
|
||||
return m_fd != -1;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_fd;
|
||||
boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source> m_fileDescriptorStreamBuffer;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/iostreams/device/file_descriptor.hpp>
|
||||
#include <boost/iostreams/stream_buffer.hpp>
|
||||
|
||||
#include "Common/unix/FilesystemAndroid.h"
|
||||
|
||||
using fd_streambuf = boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_source>;
|
||||
|
||||
class ContentUriStream : public fd_streambuf, public std::istream
|
||||
{
|
||||
public:
|
||||
explicit ContentUriStream(const std::filesystem::path& path)
|
||||
: fd_streambuf(FilesystemAndroid::openContentUri(path), boost::iostreams::close_handle), std::istream(this) {}
|
||||
|
||||
bool is_open()
|
||||
{
|
||||
return component()->is_open();
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "FileStream_contentUri.h"
|
||||
|
||||
#include "unix/ContentUriIStream.h"
|
||||
#include "unix/ContentUriStream.h"
|
||||
|
||||
void ThrowWriteNotSupportedError()
|
||||
{
|
||||
@@ -11,16 +11,16 @@ void FileStreamContentUri::SetPosition(uint64 pos)
|
||||
{
|
||||
if (!m_isValid)
|
||||
return;
|
||||
m_contentUriIStream.seekg((std::streampos)pos);
|
||||
m_contentUriStream.seekg((std::streampos)pos);
|
||||
}
|
||||
|
||||
uint64 FileStreamContentUri::GetSize()
|
||||
{
|
||||
cemu_assert(m_isValid);
|
||||
auto currentPos = m_contentUriIStream.tellg();
|
||||
m_contentUriIStream.seekg(0, std::ios::end);
|
||||
auto fileSize = m_contentUriIStream.tellg();
|
||||
m_contentUriIStream.seekg(currentPos, std::ios::beg);
|
||||
auto currentPos = m_contentUriStream.tellg();
|
||||
m_contentUriStream.seekg(0, std::ios::end);
|
||||
auto fileSize = m_contentUriStream.tellg();
|
||||
m_contentUriStream.seekg(currentPos, std::ios::beg);
|
||||
uint64 fs = (uint64)fileSize;
|
||||
return fs;
|
||||
}
|
||||
@@ -42,8 +42,8 @@ void FileStreamContentUri::extract(std::vector<uint8>& data)
|
||||
|
||||
uint32 FileStreamContentUri::readData(void* data, uint32 length)
|
||||
{
|
||||
m_contentUriIStream.read((char*)data, length);
|
||||
size_t bytesRead = m_contentUriIStream.gcount();
|
||||
m_contentUriStream.read((char*)data, length);
|
||||
size_t bytesRead = m_contentUriStream.gcount();
|
||||
return (uint32)bytesRead;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ void FileStreamContentUri::writeLine(const char* str)
|
||||
}
|
||||
|
||||
FileStreamContentUri::FileStreamContentUri(const std::string& uri)
|
||||
: m_contentUriIStream(uri)
|
||||
: m_contentUriStream(uri)
|
||||
{
|
||||
m_isValid = m_contentUriIStream.isOpen();
|
||||
m_isValid = m_contentUriStream.is_open();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Common/FileStream.h"
|
||||
#include "Common/unix/ContentUriIStream.h"
|
||||
#include "Common/unix/ContentUriStream.h"
|
||||
|
||||
class FileStreamContentUri : public FileStream
|
||||
{
|
||||
@@ -32,6 +32,6 @@ class FileStreamContentUri : public FileStream
|
||||
private:
|
||||
friend class FileStream;
|
||||
FileStreamContentUri(const std::string& uri);
|
||||
ContentUriIStream m_contentUriIStream;
|
||||
ContentUriStream m_contentUriStream;
|
||||
bool m_isValid = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user