diff options
Diffstat (limited to 'src/common/file_util.cpp')
| -rw-r--r-- | src/common/file_util.cpp | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 9ada09f8a..53700c865 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 | ||
| @@ -877,15 +876,10 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam | |||
| 877 | } | 876 | } |
| 878 | 877 | ||
| 879 | IOFile::IOFile() | 878 | IOFile::IOFile() |
| 880 | : m_file(nullptr), m_good(true) | 879 | { |
| 881 | {} | 880 | } |
| 882 | |||
| 883 | IOFile::IOFile(std::FILE* file) | ||
| 884 | : m_file(file), m_good(true) | ||
| 885 | {} | ||
| 886 | 881 | ||
| 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) | ||
| 889 | { | 883 | { |
| 890 | Open(filename, openmode); | 884 | Open(filename, openmode); |
| 891 | } | 885 | } |
| @@ -896,7 +890,6 @@ IOFile::~IOFile() | |||
| 896 | } | 890 | } |
| 897 | 891 | ||
| 898 | IOFile::IOFile(IOFile&& other) | 892 | IOFile::IOFile(IOFile&& other) |
| 899 | : m_file(nullptr), m_good(true) | ||
| 900 | { | 893 | { |
| 901 | Swap(other); | 894 | Swap(other); |
| 902 | } | 895 | } |
| @@ -935,26 +928,12 @@ bool IOFile::Close() | |||
| 935 | return m_good; | 928 | return m_good; |
| 936 | } | 929 | } |
| 937 | 930 | ||
| 938 | std::FILE* IOFile::ReleaseHandle() | 931 | u64 IOFile::GetSize() const |
| 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() | ||
| 953 | { | 932 | { |
| 954 | if (IsOpen()) | 933 | if (IsOpen()) |
| 955 | return FileUtil::GetSize(m_file); | 934 | return FileUtil::GetSize(m_file); |
| 956 | else | 935 | |
| 957 | return 0; | 936 | return 0; |
| 958 | } | 937 | } |
| 959 | 938 | ||
| 960 | bool IOFile::Seek(s64 off, int origin) | 939 | bool IOFile::Seek(s64 off, int origin) |
| @@ -965,12 +944,12 @@ bool IOFile::Seek(s64 off, int origin) | |||
| 965 | return m_good; | 944 | return m_good; |
| 966 | } | 945 | } |
| 967 | 946 | ||
| 968 | u64 IOFile::Tell() | 947 | u64 IOFile::Tell() const |
| 969 | { | 948 | { |
| 970 | if (IsOpen()) | 949 | if (IsOpen()) |
| 971 | return ftello(m_file); | 950 | return ftello(m_file); |
| 972 | else | 951 | |
| 973 | return -1; | 952 | return -1; |
| 974 | } | 953 | } |
| 975 | 954 | ||
| 976 | bool IOFile::Flush() | 955 | bool IOFile::Flush() |