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 687b7ae5a..6e2867658 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -833,13 +833,12 @@ size_t WriteStringToFile(bool text_file, const std::string &str, const char *fil | |||
| 833 | 833 | ||
| 834 | size_t ReadFileToString(bool text_file, const char *filename, std::string &str) | 834 | size_t ReadFileToString(bool text_file, const char *filename, std::string &str) |
| 835 | { | 835 | { |
| 836 | FileUtil::IOFile file(filename, text_file ? "r" : "rb"); | 836 | IOFile file(filename, text_file ? "r" : "rb"); |
| 837 | auto const f = file.GetHandle(); | ||
| 838 | 837 | ||
| 839 | if (!f) | 838 | if (!file) |
| 840 | return false; | 839 | return false; |
| 841 | 840 | ||
| 842 | str.resize(static_cast<u32>(GetSize(f))); | 841 | str.resize(static_cast<u32>(file.GetSize())); |
| 843 | return file.ReadArray(&str[0], str.size()); | 842 | return file.ReadArray(&str[0], str.size()); |
| 844 | } | 843 | } |
| 845 | 844 | ||
| @@ -886,15 +885,10 @@ void SplitFilename83(const std::string& filename, std::array<char, 9>& short_nam | |||
| 886 | } | 885 | } |
| 887 | 886 | ||
| 888 | IOFile::IOFile() | 887 | IOFile::IOFile() |
| 889 | : m_file(nullptr), m_good(true) | 888 | { |
| 890 | {} | 889 | } |
| 891 | |||
| 892 | IOFile::IOFile(std::FILE* file) | ||
| 893 | : m_file(file), m_good(true) | ||
| 894 | {} | ||
| 895 | 890 | ||
| 896 | IOFile::IOFile(const std::string& filename, const char openmode[]) | 891 | IOFile::IOFile(const std::string& filename, const char openmode[]) |
| 897 | : m_file(nullptr), m_good(true) | ||
| 898 | { | 892 | { |
| 899 | Open(filename, openmode); | 893 | Open(filename, openmode); |
| 900 | } | 894 | } |
| @@ -905,7 +899,6 @@ IOFile::~IOFile() | |||
| 905 | } | 899 | } |
| 906 | 900 | ||
| 907 | IOFile::IOFile(IOFile&& other) | 901 | IOFile::IOFile(IOFile&& other) |
| 908 | : m_file(nullptr), m_good(true) | ||
| 909 | { | 902 | { |
| 910 | Swap(other); | 903 | Swap(other); |
| 911 | } | 904 | } |
| @@ -944,26 +937,12 @@ bool IOFile::Close() | |||
| 944 | return m_good; | 937 | return m_good; |
| 945 | } | 938 | } |
| 946 | 939 | ||
| 947 | std::FILE* IOFile::ReleaseHandle() | 940 | u64 IOFile::GetSize() const |
| 948 | { | ||
| 949 | std::FILE* const ret = m_file; | ||
| 950 | m_file = nullptr; | ||
| 951 | return ret; | ||
| 952 | } | ||
| 953 | |||
| 954 | void IOFile::SetHandle(std::FILE* file) | ||
| 955 | { | ||
| 956 | Close(); | ||
| 957 | Clear(); | ||
| 958 | m_file = file; | ||
| 959 | } | ||
| 960 | |||
| 961 | u64 IOFile::GetSize() | ||
| 962 | { | 941 | { |
| 963 | if (IsOpen()) | 942 | if (IsOpen()) |
| 964 | return FileUtil::GetSize(m_file); | 943 | return FileUtil::GetSize(m_file); |
| 965 | else | 944 | |
| 966 | return 0; | 945 | return 0; |
| 967 | } | 946 | } |
| 968 | 947 | ||
| 969 | bool IOFile::Seek(s64 off, int origin) | 948 | bool IOFile::Seek(s64 off, int origin) |
| @@ -974,12 +953,12 @@ bool IOFile::Seek(s64 off, int origin) | |||
| 974 | return m_good; | 953 | return m_good; |
| 975 | } | 954 | } |
| 976 | 955 | ||
| 977 | u64 IOFile::Tell() | 956 | u64 IOFile::Tell() const |
| 978 | { | 957 | { |
| 979 | if (IsOpen()) | 958 | if (IsOpen()) |
| 980 | return ftello(m_file); | 959 | return ftello(m_file); |
| 981 | else | 960 | |
| 982 | return -1; | 961 | return -1; |
| 983 | } | 962 | } |
| 984 | 963 | ||
| 985 | bool IOFile::Flush() | 964 | bool IOFile::Flush() |