From a64f94d580c8d203da5d0d9a30fffd0942a56b1e Mon Sep 17 00:00:00 2001 From: obligaron Date: Sun, 9 May 2021 23:56:26 +0200 Subject: [PATCH] Move creation of file stream to new helper CreateFileStream --- Source/mpqapi.cpp | 2 +- Source/utils/file_util.cpp | 5 +++++ Source/utils/file_util.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index f5f13afe0..f414037c2 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -90,7 +90,7 @@ struct FStreamWrapper { public: bool Open(const char *path, std::ios::openmode mode) { - s_ = std::make_unique(path, mode); + s_ = CreateFileStream(path, mode); return CheckError("new std::fstream(\"%s\", %s)", path, OpenModeToString(mode).c_str()); } diff --git a/Source/utils/file_util.cpp b/Source/utils/file_util.cpp index 75b1b73fb..46409fc8d 100644 --- a/Source/utils/file_util.cpp +++ b/Source/utils/file_util.cpp @@ -156,4 +156,9 @@ void RemoveFile(const char *lpFileName) #endif } +std::unique_ptr CreateFileStream(const char *path, std::ios::openmode mode) +{ + return std::make_unique(path, mode); +} + } // namespace devilution diff --git a/Source/utils/file_util.h b/Source/utils/file_util.h index 61b3a9320..555c3fa9c 100644 --- a/Source/utils/file_util.h +++ b/Source/utils/file_util.h @@ -1,11 +1,14 @@ #pragma once #include +#include +#include namespace devilution { bool FileExists(const char *path); bool GetFileSize(const char *path, std::uintmax_t *size); bool ResizeFile(const char *path, std::uintmax_t size); void RemoveFile(const char *lpFileName); +std::unique_ptr CreateFileStream(const char *path, std::ios::openmode mode); } // namespace devilution