winport - fix some unicode file opening crap

This commit is contained in:
zeromus 2020-05-05 01:49:14 -04:00
parent 1cc14031c9
commit d4c17e5f8d
4 changed files with 27 additions and 13 deletions

View File

@ -23,6 +23,7 @@ THE SOFTWARE.
*/ */
#include "emufile.h" #include "emufile.h"
#include "utils/xstring.h"
#include <vector> #include <vector>
@ -509,3 +510,19 @@ size_t EMUFILE::read_MemoryStream(EMUFILE_MEMORY &ms)
return 1; return 1;
} }
void EMUFILE_FILE::open(const char* fname, const char* mode)
{
mPositionCacheEnabled = false;
mCondition = eCondition_Clean;
mFilePosition = 0;
#ifdef HOST_WINDOWS
fp = _wfopen(mbstowcs((std::string)fname).c_str(),mbstowcs(mode).c_str());
#else
fp = fopen(fname,mode);
#endif
if(!fp)
failbit = true;
this->fname = fname;
strcpy(this->mode,mode);
}

View File

@ -294,17 +294,7 @@ protected:
} mCondition; } mCondition;
private: private:
void open(const char* fname, const char* mode) void open(const char* fname, const char* mode);
{
mPositionCacheEnabled = false;
mCondition = eCondition_Clean;
mFilePosition = 0;
fp = fopen(fname,mode);
if(!fp)
failbit = true;
this->fname = fname;
strcpy(this->mode,mode);
}
public: public:

View File

@ -3088,7 +3088,10 @@ static BOOL OpenCore(const char* filename)
memset(batteryPath, 0, MAX_PATH); memset(batteryPath, 0, MAX_PATH);
path.getpathnoext(path.BATTERY, batteryPath); path.getpathnoext(path.BATTERY, batteryPath);
std::string batteryPathString = std::string(batteryPath) + ".dsv"; std::string batteryPathString = std::string(batteryPath) + ".dsv";
FILE *testFs = fopen(batteryPathString.c_str(), "rb+"); std::wstring batteryPathStringW = mbstowcs(batteryPathString);
FILE *testFs = _wfopen(batteryPathStringW.c_str(), L"rb");
if (testFs == NULL)
testFs = _wfopen(batteryPathStringW.c_str(), L"wb");
if (testFs == NULL) if (testFs == NULL)
{ {
msgbox->warn("\ msgbox->warn("\

View File

@ -234,7 +234,11 @@ BackupDevice::BackupDevice()
MCLOG("MC: %s\n", _fileName.c_str()); MCLOG("MC: %s\n", _fileName.c_str());
bool fexists = (access(_fileName.c_str(), 0) == 0)?true:false; bool fexists = false;
{
EMUFILE_FILE testfile(_fileName, "rb");
fexists = testfile.is_open();
}
if (fexists && CommonSettings.backupSave) if (fexists && CommonSettings.backupSave)
{ {