diff --git a/src/xenia/base/filesystem.h b/src/xenia/base/filesystem.h index fdc6b08b0..ebceb5fd3 100644 --- a/src/xenia/base/filesystem.h +++ b/src/xenia/base/filesystem.h @@ -42,6 +42,9 @@ bool DeleteFolder(const std::wstring& path); // Returns true if the given path exists and is a folder. bool IsFolder(const std::wstring& path); +// Creates an empty file at the given path. +bool CreateFile(const std::wstring& path); + // Opens the file at the given path with the specified mode. // This behaves like fopen and the returned handle can be used with stdio. FILE* OpenFile(const std::wstring& path, const char* mode); diff --git a/src/xenia/base/filesystem_win.cc b/src/xenia/base/filesystem_win.cc index 4963c13b3..3b26eba9b 100644 --- a/src/xenia/base/filesystem_win.cc +++ b/src/xenia/base/filesystem_win.cc @@ -47,6 +47,18 @@ bool IsFolder(const std::wstring& path) { (attrib & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY; } +#undef CreateFile +bool CreateFile(const std::wstring& path) { + auto handle = CreateFileW(path.c_str(), 0, 0, nullptr, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, nullptr); + if (handle == INVALID_HANDLE_VALUE) { + return false; + } + + CloseHandle(handle); + return true; +} + FILE* OpenFile(const std::wstring& path, const char* mode) { auto fixed_path = xe::fix_path_separators(path); return _wfopen(fixed_path.c_str(), xe::to_wstring(mode).c_str());