mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-12-27 04:15:28 +00:00
file_util: Don't expose IOFile internals through the API
This commit is contained in:
parent
bf9945b81b
commit
a4120ca66c
|
@ -824,13 +824,12 @@ size_t WriteStringToFile(bool text_file, const std::string &str, const char *fil
|
||||||
|
|
||||||
size_t ReadFileToString(bool text_file, const char *filename, std::string &str)
|
size_t ReadFileToString(bool text_file, const char *filename, std::string &str)
|
||||||
{
|
{
|
||||||
FileUtil::IOFile file(filename, text_file ? "r" : "rb");
|
IOFile file(filename, text_file ? "r" : "rb");
|
||||||
auto const f = file.GetHandle();
|
|
||||||
|
|
||||||
if (!f)
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
str.resize(static_cast<u32>(GetSize(f)));
|
str.resize(static_cast<u32>(file.GetSize()));
|
||||||
return file.ReadArray(&str[0], str.size());
|
return file.ReadArray(&str[0], str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,10 +879,6 @@ IOFile::IOFile()
|
||||||
: m_file(nullptr), m_good(true)
|
: m_file(nullptr), m_good(true)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
IOFile::IOFile(std::FILE* file)
|
|
||||||
: m_file(file), m_good(true)
|
|
||||||
{}
|
|
||||||
|
|
||||||
IOFile::IOFile(const std::string& filename, const char openmode[])
|
IOFile::IOFile(const std::string& filename, const char openmode[])
|
||||||
: m_file(nullptr), m_good(true)
|
: m_file(nullptr), m_good(true)
|
||||||
{
|
{
|
||||||
|
@ -935,20 +930,6 @@ bool IOFile::Close()
|
||||||
return m_good;
|
return m_good;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::FILE* IOFile::ReleaseHandle()
|
|
||||||
{
|
|
||||||
std::FILE* const ret = m_file;
|
|
||||||
m_file = nullptr;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void IOFile::SetHandle(std::FILE* file)
|
|
||||||
{
|
|
||||||
Close();
|
|
||||||
Clear();
|
|
||||||
m_file = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 IOFile::GetSize()
|
u64 IOFile::GetSize()
|
||||||
{
|
{
|
||||||
if (IsOpen())
|
if (IsOpen())
|
||||||
|
|
|
@ -176,7 +176,6 @@ class IOFile : public NonCopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IOFile();
|
IOFile();
|
||||||
explicit IOFile(std::FILE* file);
|
|
||||||
IOFile(const std::string& filename, const char openmode[]);
|
IOFile(const std::string& filename, const char openmode[]);
|
||||||
|
|
||||||
~IOFile();
|
~IOFile();
|
||||||
|
@ -245,13 +244,7 @@ public:
|
||||||
|
|
||||||
// m_good is set to false when a read, write or other function fails
|
// m_good is set to false when a read, write or other function fails
|
||||||
bool IsGood() const { return m_good; }
|
bool IsGood() const { return m_good; }
|
||||||
operator void*() { return m_good ? m_file : nullptr; }
|
explicit operator bool() const { return IsGood(); }
|
||||||
|
|
||||||
std::FILE* ReleaseHandle();
|
|
||||||
|
|
||||||
std::FILE* GetHandle() { return m_file; }
|
|
||||||
|
|
||||||
void SetHandle(std::FILE* file);
|
|
||||||
|
|
||||||
bool Seek(s64 off, int origin);
|
bool Seek(s64 off, int origin);
|
||||||
u64 Tell();
|
u64 Tell();
|
||||||
|
|
|
@ -586,6 +586,21 @@ TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config,
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_PNG
|
||||||
|
// Adapter functions to libpng to write/flush to File::IOFile instances.
|
||||||
|
static void WriteIOFile(png_structp png_ptr, png_bytep data, png_size_t length) {
|
||||||
|
auto* fp = static_cast<FileUtil::IOFile*>(png_get_io_ptr(png_ptr));
|
||||||
|
if (!fp->WriteBytes(data, length))
|
||||||
|
png_error(png_ptr, "Failed to write to output PNG file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void FlushIOFile(png_structp png_ptr) {
|
||||||
|
auto* fp = static_cast<FileUtil::IOFile*>(png_get_io_ptr(png_ptr));
|
||||||
|
if (!fp->Flush())
|
||||||
|
png_error(png_ptr, "Failed to flush to output PNG file.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
|
void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
|
||||||
#ifndef HAVE_PNG
|
#ifndef HAVE_PNG
|
||||||
return;
|
return;
|
||||||
|
@ -629,7 +644,7 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_init_io(png_ptr, fp.GetHandle());
|
png_set_write_fn(png_ptr, static_cast<void*>(&fp), WriteIOFile, FlushIOFile);
|
||||||
|
|
||||||
// Write header (8 bit color depth)
|
// Write header (8 bit color depth)
|
||||||
png_set_IHDR(png_ptr, info_ptr, texture_config.width, texture_config.height,
|
png_set_IHDR(png_ptr, info_ptr, texture_config.width, texture_config.height,
|
||||||
|
|
Loading…
Reference in a new issue