Replace more instances of fopen() with FileSystem::OpenFile()
This commit is contained in:
parent
2885d2e547
commit
2eb9384275
|
@ -1,6 +1,8 @@
|
||||||
#include "byte_stream.h"
|
#include "byte_stream.h"
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
#include "file_system.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "string_util.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
@ -958,16 +960,14 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
|
||||||
|
|
||||||
// fill in random characters
|
// fill in random characters
|
||||||
_mktemp_s(temporaryFileName, fileNameLength + 8);
|
_mktemp_s(temporaryFileName, fileNameLength + 8);
|
||||||
|
const std::wstring wideTemporaryFileName(StringUtil::UTF8StringToWideString(temporaryFileName));
|
||||||
// open the file
|
|
||||||
errno_t err;
|
|
||||||
FILE* pTemporaryFile;
|
|
||||||
|
|
||||||
// massive hack here
|
// massive hack here
|
||||||
DWORD desiredAccess = GENERIC_WRITE;
|
DWORD desiredAccess = GENERIC_WRITE;
|
||||||
if (openMode & BYTESTREAM_OPEN_READ)
|
if (openMode & BYTESTREAM_OPEN_READ)
|
||||||
desiredAccess |= GENERIC_READ;
|
desiredAccess |= GENERIC_READ;
|
||||||
HANDLE hFile = CreateFileA(temporaryFileName, desiredAccess, FILE_SHARE_DELETE, NULL, CREATE_NEW, 0, NULL);
|
HANDLE hFile =
|
||||||
|
CreateFileW(wideTemporaryFileName.c_str(), desiredAccess, FILE_SHARE_DELETE, NULL, CREATE_NEW, 0, NULL);
|
||||||
if (hFile == INVALID_HANDLE_VALUE)
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -976,16 +976,16 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
DeleteFileA(temporaryFileName);
|
DeleteFileW(wideTemporaryFileName.c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert to a stream
|
// convert to a stream
|
||||||
pTemporaryFile = _fdopen(fd, modeString);
|
FILE* pTemporaryFile = _fdopen(fd, modeString);
|
||||||
if (pTemporaryFile == nullptr)
|
if (!pTemporaryFile)
|
||||||
{
|
{
|
||||||
_close(fd);
|
_close(fd);
|
||||||
DeleteFileA(temporaryFileName);
|
DeleteFileW(wideTemporaryFileName.c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -996,9 +996,8 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
|
||||||
// do we need to copy the existing file into this one?
|
// do we need to copy the existing file into this one?
|
||||||
if (!(openMode & BYTESTREAM_OPEN_TRUNCATE))
|
if (!(openMode & BYTESTREAM_OPEN_TRUNCATE))
|
||||||
{
|
{
|
||||||
FILE* pOriginalFile;
|
FILE* pOriginalFile = FileSystem::OpenCFile(fileName, "rb");
|
||||||
err = fopen_s(&pOriginalFile, fileName, "rb");
|
if (!pOriginalFile)
|
||||||
if (err != 0 || pOriginalFile == nullptr)
|
|
||||||
{
|
{
|
||||||
// this will delete the temporary file
|
// this will delete the temporary file
|
||||||
pStream->Discard();
|
pStream->Discard();
|
||||||
|
@ -1031,9 +1030,8 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// forward through
|
// forward through
|
||||||
FILE* pFile;
|
FILE* pFile = FileSystem::OpenCFile(fileName, modeString);
|
||||||
errno_t err = fopen_s(&pFile, fileName, modeString);
|
if (!pFile)
|
||||||
if (err != 0 || pFile == NULL)
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return std::make_unique<FileByteStream>(pFile);
|
return std::make_unique<FileByteStream>(pFile);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cpu_core.h"
|
#include "cpu_core.h"
|
||||||
#include "common/align.h"
|
#include "common/align.h"
|
||||||
|
#include "common/file_system.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/state_wrapper.h"
|
#include "common/state_wrapper.h"
|
||||||
#include "cpu_disasm.h"
|
#include "cpu_disasm.h"
|
||||||
|
@ -53,7 +54,7 @@ void WriteToExecutionLog(const char* format, ...)
|
||||||
|
|
||||||
if (!log_file_opened)
|
if (!log_file_opened)
|
||||||
{
|
{
|
||||||
log_file = std::fopen("cpu_log.txt", "wb");
|
log_file = FileSystem::OpenCFile("cpu_log.txt", "wb");
|
||||||
log_file_opened = true;
|
log_file_opened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -307,7 +307,7 @@ bool GameList::GetExeListEntry(const char* path, GameListEntry* entry)
|
||||||
if (!FileSystem::StatFile(path, &ffd))
|
if (!FileSystem::StatFile(path, &ffd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::FILE* fp = std::fopen(path, "rb");
|
std::FILE* fp = FileSystem::OpenCFile(path, "rb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "cdrom.h"
|
#include "cdrom.h"
|
||||||
#include "common/audio_stream.h"
|
#include "common/audio_stream.h"
|
||||||
|
#include "common/file_system.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/state_wrapper.h"
|
#include "common/state_wrapper.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
|
@ -878,7 +879,7 @@ void ResetPerformanceCounters()
|
||||||
|
|
||||||
bool LoadEXE(const char* filename, std::vector<u8>& bios_image)
|
bool LoadEXE(const char* filename, std::vector<u8>& bios_image)
|
||||||
{
|
{
|
||||||
std::FILE* fp = std::fopen(filename, "rb");
|
std::FILE* fp = FileSystem::OpenCFile(filename, "rb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -997,7 +998,7 @@ bool LoadPSF(const char* filename, std::vector<u8>& bios_image)
|
||||||
|
|
||||||
bool SetExpansionROM(const char* filename)
|
bool SetExpansionROM(const char* filename)
|
||||||
{
|
{
|
||||||
std::FILE* fp = std::fopen(filename, "rb");
|
std::FILE* fp = FileSystem::OpenCFile(filename, "rb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("Failed to open '%s'", filename);
|
Log_ErrorPrintf("Failed to open '%s'", filename);
|
||||||
|
|
Loading…
Reference in New Issue