diff options
| author | 2016-04-13 19:29:16 -0400 | |
|---|---|---|
| committer | 2016-04-13 20:17:17 -0400 | |
| commit | a4120ca66cc6c0f3a8056c6ea247c15f63c7feff (patch) | |
| tree | a0db95eee61ce8070add52e3abd55971be6458df | |
| parent | file_util: Check for is_trivially_copyable (diff) | |
| download | yuzu-a4120ca66cc6c0f3a8056c6ea247c15f63c7feff.tar.gz yuzu-a4120ca66cc6c0f3a8056c6ea247c15f63c7feff.tar.xz yuzu-a4120ca66cc6c0f3a8056c6ea247c15f63c7feff.zip | |
file_util: Don't expose IOFile internals through the API
| -rw-r--r-- | src/common/file_util.cpp | 25 | ||||
| -rw-r--r-- | src/common/file_util.h | 9 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 17 |
3 files changed, 20 insertions, 31 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 9ada09f8a..578c673b9 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -824,13 +824,12 @@ size_t WriteStringToFile(bool text_file, const std::string &str, const char *fil | |||
| 824 | 824 | ||
| 825 | size_t ReadFileToString(bool text_file, const char *filename, std::string &str) | 825 | size_t ReadFileToString(bool text_file, const char *filename, std::string &str) |
| 826 | { | 826 | { |
| 827 | FileUtil::IOFile file(filename, text_file ? "r" : "rb"); | 827 | IOFile file(filename, text_file ? "r" : "rb"); |
| 828 | auto const f = file.GetHandle(); | ||
| 829 | 828 | ||
| 830 | if (!f) | 829 | if (!file) |
| 831 | return false; | 830 | return false; |
| 832 | 831 | ||
| 833 | str.resize(static_cast<u32>(GetSize(f))); | 832 | str.resize(static_cast<u32>(file.GetSize())); |
| 834 | return file.ReadArray(&str[0], str.size()); | 833 | return file.ReadArray(&str[0], str.size()); |
| 835 | } | 834 | } |
| 836 | 835 | ||
| @@ -880,10 +879,6 @@ IOFile::IOFile() | |||
| 880 | : m_file(nullptr), m_good(true) | 879 | : m_file(nullptr), m_good(true) |
| 881 | {} | 880 | {} |
| 882 | 881 | ||
| 883 | IOFile::IOFile(std::FILE* file) | ||
| 884 | : m_file(file), m_good(true) | ||
| 885 | {} | ||
| 886 | |||
| 887 | IOFile::IOFile(const std::string& filename, const char openmode[]) | 882 | IOFile::IOFile(const std::string& filename, const char openmode[]) |
| 888 | : m_file(nullptr), m_good(true) | 883 | : m_file(nullptr), m_good(true) |
| 889 | { | 884 | { |
| @@ -935,20 +930,6 @@ bool IOFile::Close() | |||
| 935 | return m_good; | 930 | return m_good; |
| 936 | } | 931 | } |
| 937 | 932 | ||
| 938 | std::FILE* IOFile::ReleaseHandle() | ||
| 939 | { | ||
| 940 | std::FILE* const ret = m_file; | ||
| 941 | m_file = nullptr; | ||
| 942 | return ret; | ||
| 943 | } | ||
| 944 | |||
| 945 | void IOFile::SetHandle(std::FILE* file) | ||
| 946 | { | ||
| 947 | Close(); | ||
| 948 | Clear(); | ||
| 949 | m_file = file; | ||
| 950 | } | ||
| 951 | |||
| 952 | u64 IOFile::GetSize() | 933 | u64 IOFile::GetSize() |
| 953 | { | 934 | { |
| 954 | if (IsOpen()) | 935 | if (IsOpen()) |
diff --git a/src/common/file_util.h b/src/common/file_util.h index dd151575f..8f72fb4e2 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -176,7 +176,6 @@ class IOFile : public NonCopyable | |||
| 176 | { | 176 | { |
| 177 | public: | 177 | public: |
| 178 | IOFile(); | 178 | IOFile(); |
| 179 | explicit IOFile(std::FILE* file); | ||
| 180 | IOFile(const std::string& filename, const char openmode[]); | 179 | IOFile(const std::string& filename, const char openmode[]); |
| 181 | 180 | ||
| 182 | ~IOFile(); | 181 | ~IOFile(); |
| @@ -245,13 +244,7 @@ public: | |||
| 245 | 244 | ||
| 246 | // m_good is set to false when a read, write or other function fails | 245 | // m_good is set to false when a read, write or other function fails |
| 247 | bool IsGood() const { return m_good; } | 246 | bool IsGood() const { return m_good; } |
| 248 | operator void*() { return m_good ? m_file : nullptr; } | 247 | explicit operator bool() const { return IsGood(); } |
| 249 | |||
| 250 | std::FILE* ReleaseHandle(); | ||
| 251 | |||
| 252 | std::FILE* GetHandle() { return m_file; } | ||
| 253 | |||
| 254 | void SetHandle(std::FILE* file); | ||
| 255 | 248 | ||
| 256 | bool Seek(s64 off, int origin); | 249 | bool Seek(s64 off, int origin); |
| 257 | u64 Tell(); | 250 | u64 Tell(); |
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 693f93597..c8752c003 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -586,6 +586,21 @@ TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, | |||
| 586 | return info; | 586 | return info; |
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | #ifdef HAVE_PNG | ||
| 590 | // Adapter functions to libpng to write/flush to File::IOFile instances. | ||
| 591 | static void WriteIOFile(png_structp png_ptr, png_bytep data, png_size_t length) { | ||
| 592 | auto* fp = static_cast<FileUtil::IOFile*>(png_get_io_ptr(png_ptr)); | ||
| 593 | if (!fp->WriteBytes(data, length)) | ||
| 594 | png_error(png_ptr, "Failed to write to output PNG file."); | ||
| 595 | } | ||
| 596 | |||
| 597 | static void FlushIOFile(png_structp png_ptr) { | ||
| 598 | auto* fp = static_cast<FileUtil::IOFile*>(png_get_io_ptr(png_ptr)); | ||
| 599 | if (!fp->Flush()) | ||
| 600 | png_error(png_ptr, "Failed to flush to output PNG file."); | ||
| 601 | } | ||
| 602 | #endif | ||
| 603 | |||
| 589 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | 604 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { |
| 590 | #ifndef HAVE_PNG | 605 | #ifndef HAVE_PNG |
| 591 | return; | 606 | return; |
| @@ -629,7 +644,7 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | |||
| 629 | goto finalise; | 644 | goto finalise; |
| 630 | } | 645 | } |
| 631 | 646 | ||
| 632 | png_init_io(png_ptr, fp.GetHandle()); | 647 | png_set_write_fn(png_ptr, static_cast<void*>(&fp), WriteIOFile, FlushIOFile); |
| 633 | 648 | ||
| 634 | // Write header (8 bit color depth) | 649 | // Write header (8 bit color depth) |
| 635 | png_set_IHDR(png_ptr, info_ptr, texture_config.width, texture_config.height, | 650 | png_set_IHDR(png_ptr, info_ptr, texture_config.width, texture_config.height, |