mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-12 14:57:14 +00:00
Use portable file writes for debug save dumps
This commit is contained in:
parent
62a5c364f2
commit
37d9439be3
|
|
@ -1,5 +1,6 @@
|
|||
#include "../../Platform/stdafx.h"
|
||||
#include "../../Util/StringHelpers.h"
|
||||
#include "../../Util/PortableFileIO.h"
|
||||
#include "ConsoleSaveFileOriginal.h"
|
||||
#include "File.h"
|
||||
#include <xuiapp.h>
|
||||
|
|
@ -859,23 +860,19 @@ void ConsoleSaveFileOriginal::DebugFlushToFile(void *compressedData /*= NULL*/,
|
|||
}
|
||||
swprintf(fileName, XCONTENT_MAX_FILENAME_LENGTH+1, L"\\v%04d-%ls%02d.%02d.%02d.%02d.%02d.mcs",VER_PRODUCTBUILD,cutFileName.c_str(), t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
|
||||
|
||||
#ifdef _UNICODE
|
||||
std::wstring wtemp = targetFileDir.getPath() + std::wstring(fileName);
|
||||
LPCWSTR lpFileName = wtemp.c_str();
|
||||
#else
|
||||
LPCSTR lpFileName = wstringtofilename( targetFileDir.getPath() + std::wstring(fileName) );
|
||||
#endif
|
||||
const std::wstring outputPath = targetFileDir.getPath() + std::wstring(fileName);
|
||||
#ifndef __PSVITA__
|
||||
HANDLE hSaveFile = CreateFile( lpFileName, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
bool writeSucceeded = false;
|
||||
#endif
|
||||
|
||||
if(compressedData != NULL && compressedDataSize > 0)
|
||||
{
|
||||
#ifdef __PSVITA__
|
||||
// AP - Use the access function to save
|
||||
VirtualWriteFile( lpFileName, compressedData, compressedDataSize, &numberOfBytesWritten, NULL);
|
||||
VirtualWriteFile( outputPath.c_str(), compressedData, compressedDataSize, &numberOfBytesWritten, NULL);
|
||||
#else
|
||||
WriteFile( hSaveFile,compressedData,compressedDataSize,&numberOfBytesWritten,NULL);
|
||||
writeSucceeded = PortableFileIO::WriteBinaryFile(outputPath, compressedData, compressedDataSize);
|
||||
numberOfBytesWritten = writeSucceeded ? compressedDataSize : 0;
|
||||
#endif
|
||||
assert(numberOfBytesWritten == compressedDataSize);
|
||||
}
|
||||
|
|
@ -883,15 +880,13 @@ void ConsoleSaveFileOriginal::DebugFlushToFile(void *compressedData /*= NULL*/,
|
|||
{
|
||||
#ifdef __PSVITA__
|
||||
// AP - Use the access function to save
|
||||
VirtualWriteFile( lpFileName, compressedData, compressedDataSize, &numberOfBytesWritten, NULL);
|
||||
VirtualWriteFile( outputPath.c_str(), compressedData, compressedDataSize, &numberOfBytesWritten, NULL);
|
||||
#else
|
||||
WriteFile(hSaveFile,pvSaveMem,fileSize,&numberOfBytesWritten,NULL);
|
||||
writeSucceeded = PortableFileIO::WriteBinaryFile(outputPath, pvSaveMem, fileSize);
|
||||
numberOfBytesWritten = writeSucceeded ? fileSize : 0;
|
||||
#endif
|
||||
assert(numberOfBytesWritten == fileSize);
|
||||
}
|
||||
#ifndef __PSVITA__
|
||||
CloseHandle( hSaveFile );
|
||||
#endif
|
||||
|
||||
delete[] fileName;
|
||||
|
||||
|
|
@ -1064,4 +1059,4 @@ void ConsoleSaveFileOriginal::ConvertToLocalPlatform()
|
|||
void *ConsoleSaveFileOriginal::getWritePointer(FileEntry *file)
|
||||
{
|
||||
return (char *)pvSaveMem + file->currentFilePointer;;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "../../Platform/stdafx.h"
|
||||
#include "../../Util/StringHelpers.h"
|
||||
#include "../../Util/PortableFileIO.h"
|
||||
#include "ConsoleSaveFileSplit.h"
|
||||
#include "ConsoleSaveFileConverter.h"
|
||||
#include "File.h"
|
||||
|
|
@ -1510,26 +1511,21 @@ void ConsoleSaveFileSplit::DebugFlushToFile(void *compressedData /*= NULL*/, uns
|
|||
}
|
||||
swprintf(fileName, XCONTENT_MAX_FILENAME_LENGTH+1, L"\\v%04d-%ls%02d.%02d.%02d.%02d.%02d.mcs",VER_PRODUCTBUILD,cutFileName.c_str(), t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
|
||||
|
||||
#ifdef _UNICODE
|
||||
std::wstring wtemp = targetFileDir.getPath() + std::wstring(fileName);
|
||||
LPCWSTR lpFileName = wtemp.c_str();
|
||||
#else
|
||||
LPCSTR lpFileName = wstringtofilename( targetFileDir.getPath() + std::wstring(fileName) );
|
||||
#endif
|
||||
|
||||
HANDLE hSaveFile = CreateFile( lpFileName, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_FLAG_RANDOM_ACCESS, NULL);
|
||||
const std::wstring outputPath = targetFileDir.getPath() + std::wstring(fileName);
|
||||
bool writeSucceeded = false;
|
||||
|
||||
if(compressedData != NULL && compressedDataSize > 0)
|
||||
{
|
||||
WriteFile(hSaveFile,compressedData,compressedDataSize,&numberOfBytesWritten,NULL);
|
||||
writeSucceeded = PortableFileIO::WriteBinaryFile(outputPath, compressedData, compressedDataSize);
|
||||
numberOfBytesWritten = writeSucceeded ? compressedDataSize : 0;
|
||||
assert(numberOfBytesWritten == compressedDataSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteFile(hSaveFile,pvSaveMem,fileSize,&numberOfBytesWritten,NULL);
|
||||
writeSucceeded = PortableFileIO::WriteBinaryFile(outputPath, pvSaveMem, fileSize);
|
||||
numberOfBytesWritten = writeSucceeded ? fileSize : 0;
|
||||
assert(numberOfBytesWritten == fileSize);
|
||||
}
|
||||
CloseHandle( hSaveFile );
|
||||
|
||||
delete[] fileName;
|
||||
|
||||
|
|
|
|||
|
|
@ -140,4 +140,23 @@ namespace PortableFileIO
|
|||
|
||||
return { BinaryReadStatus::ok, bytesRead, fileSize };
|
||||
}
|
||||
|
||||
inline bool WriteBinaryFile(const std::wstring &path, const void *buffer, std::size_t bytesToWrite)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
std::FILE *stream = _wfopen(path.c_str(), L"wb");
|
||||
#else
|
||||
const std::string nativePath = wstringtofilename(path);
|
||||
std::FILE *stream = std::fopen(nativePath.c_str(), "wb");
|
||||
#endif
|
||||
if (stream == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t bytesWritten = std::fwrite(buffer, 1, bytesToWrite, stream);
|
||||
const bool failed = std::ferror(stream) != 0 || bytesWritten != bytesToWrite;
|
||||
const bool closeFailed = std::fclose(stream) != 0;
|
||||
return !failed && !closeFailed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue