Skip to content

Commit

Permalink
allow unicode characters in file paths (#104)
Browse files Browse the repository at this point in the history
allow unicode characters in file paths
  • Loading branch information
Jamiras authored Sep 8, 2018
1 parent 4a49156 commit 00f0be5
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 136 deletions.
6 changes: 3 additions & 3 deletions src/RA_AchievementOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void AchievementOverlay::Initialize(HINSTANCE hInst)

m_LatestNews.clear();

m_hOverlayBackground.ChangeReference(ra::services::ImageType::Local, RA_DIR_OVERLAY "overlayBG.png");
m_hOverlayBackground.ChangeReference(ra::services::ImageType::Local, "Overlay\\overlayBG.png");
m_hUserImage.ChangeReference(ra::services::ImageType::UserPic, RAUsers::LocalUser().Username());
}

Expand Down Expand Up @@ -1506,9 +1506,9 @@ void AchievementOverlay::InstallNewsArticlesFromFile()
{
m_LatestNews.clear();

std::string sNewsFile = g_sHomeDir + RA_NEWS_FILENAME;
std::wstring sNewsFile = g_sHomeDir + RA_NEWS_FILENAME;
FILE* pf = nullptr;
fopen_s(&pf, sNewsFile.c_str(), "rb");
_wfopen_s(&pf, sNewsFile.c_str(), L"rb");
if (pf != nullptr)
{
Document doc;
Expand Down
20 changes: 10 additions & 10 deletions src/RA_AchievementPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const float APPEAR_AT = 0.8f;
const float FADEOUT_AT = 4.2f;
const float FINISH_AT = 5.0f;

const char* MSG_SOUND[] =
const wchar_t* MSG_SOUND[] =
{
"login.wav",
"info.wav",
"unlock.wav",
"acherror.wav",
"lb.wav",
"lbcancel.wav",
"message.wav",
L"login.wav",
L"info.wav",
L"unlock.wav",
L"acherror.wav",
L"lb.wav",
L"lbcancel.wav",
L"message.wav",
};
static_assert(SIZEOF_ARRAY(MSG_SOUND) == NumMessageTypes, "Must match!");
}
Expand All @@ -43,8 +43,8 @@ AchievementPopup::AchievementPopup() :
void AchievementPopup::PlayAudio()
{
ASSERT(MessagesPresent()); // ActiveMessage() dereferences!
std::string sSoundPath = g_sHomeDir + RA_DIR_OVERLAY + MSG_SOUND[ActiveMessage().Type()];
PlaySoundA(sSoundPath.c_str(), nullptr, SND_FILENAME | SND_ASYNC);
std::wstring sSoundPath = g_sHomeDir + RA_DIR_OVERLAY + MSG_SOUND[ActiveMessage().Type()];
PlaySoundW(sSoundPath.c_str(), nullptr, SND_FILENAME | SND_ASYNC);
}

void AchievementPopup::AddMessage(const MessagePopup& msg)
Expand Down
36 changes: 17 additions & 19 deletions src/RA_AchievementSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ void RASetAchievementCollection(AchievementSetType Type)
g_pActiveAchievements = *ACH_SETS[Type];
}

std::string AchievementSet::GetAchievementSetFilename(ra::GameID nGameID)
std::wstring AchievementSet::GetAchievementSetFilename(ra::GameID nGameID)
{
switch (m_nSetType)
{
case Core:
return g_sHomeDir + RA_DIR_DATA + std::to_string(nGameID) + ".txt";
return g_sHomeDir + RA_DIR_DATA + std::to_wstring(nGameID) + L".txt";
case Unofficial:
return g_sHomeDir + RA_DIR_DATA + std::to_string(nGameID) + ".txt"; // Same as Core
return g_sHomeDir + RA_DIR_DATA + std::to_wstring(nGameID) + L".txt"; // Same as Core
case Local:
return g_sHomeDir + RA_DIR_DATA + std::to_string(nGameID) + "-User.txt";
return g_sHomeDir + RA_DIR_DATA + std::to_wstring(nGameID) + L"-User.txt";
default:
return "";
return L"";
}
}

Expand All @@ -59,8 +59,8 @@ BOOL AchievementSet::DeletePatchFile(ra::GameID nGameID)
}

// Remove the text file
std::string sFilename = GetAchievementSetFilename(nGameID);
return RemoveFileIfExists(g_sHomeDir + "\\" + sFilename);
std::wstring sFilename = GetAchievementSetFilename(nGameID);
return RemoveFileIfExists(g_sHomeDir + L"\\" + sFilename);
}

//static
Expand Down Expand Up @@ -267,9 +267,9 @@ BOOL AchievementSet::SaveToFile()
char sMem[2048];
unsigned int i = 0;

const std::string sFilename = GetAchievementSetFilename(g_pCurrentGameData->GetGameID());
const std::wstring sFilename = GetAchievementSetFilename(g_pCurrentGameData->GetGameID());

fopen_s(&pFile, sFilename.c_str(), "w");
_wfopen_s(&pFile, sFilename.c_str(), L"w");
if (pFile != nullptr)
{
sprintf_s(sNextLine, 2048, "0.030\n"); // Min ver
Expand Down Expand Up @@ -399,7 +399,7 @@ BOOL AchievementSet::FetchFromWebBlocking(ra::GameID nGameID)
{
const Value& PatchData = doc["PatchData"];
FILE* pf = nullptr;
fopen_s(&pf, std::string(g_sHomeDir + RA_DIR_DATA + std::to_string(nGameID) + ".txt").c_str(), "wb");
_wfopen_s(&pf, std::wstring(g_sHomeDir + RA_DIR_DATA + std::to_wstring(nGameID) + L".txt").c_str(), L"wb");
if (pf != nullptr)
{
FileStream fs(pf);
Expand Down Expand Up @@ -435,10 +435,10 @@ BOOL AchievementSet::LoadFromFile(ra::GameID nGameID)
return TRUE;
}

const std::string sFilename = GetAchievementSetFilename(nGameID);
const std::wstring sFilename = GetAchievementSetFilename(nGameID);

FILE* pFile = nullptr;
errno_t nErr = fopen_s(&pFile, sFilename.c_str(), "r");
errno_t nErr = _wfopen_s(&pFile, sFilename.c_str(), L"r");
if (pFile != nullptr)
{
// Store this: we are now assuming this is the correct checksum if we have a file for it
Expand Down Expand Up @@ -502,7 +502,7 @@ BOOL AchievementSet::LoadFromFile(ra::GameID nGameID)
ra::GameID nGameID = g_pCurrentGameData->GetGameID();

// Rich Presence
_WriteBufferToFile(g_sHomeDir + RA_DIR_DATA + std::to_string(nGameID) + "-Rich.txt", g_pCurrentGameData->RichPresencePatch());
_WriteBufferToFile(g_sHomeDir + RA_DIR_DATA + std::to_wstring(nGameID) + L"-Rich.txt", g_pCurrentGameData->RichPresencePatch());
g_RichPresenceInterpreter.ParseFromString(g_pCurrentGameData->RichPresencePatch().c_str());

const Value& AchievementsData = doc["Achievements"];
Expand Down Expand Up @@ -603,10 +603,9 @@ void AchievementSet::SaveProgress(const char* sSaveStateFilename)
if (sSaveStateFilename == nullptr)
return;

char buffer[4096];
sprintf_s(buffer, 4096, "%s.rap", sSaveStateFilename);
std::wstring sAchievementStateFile = ra::Widen(sSaveStateFilename) + L".rap";
FILE* pf = nullptr;
fopen_s(&pf, buffer, "w");
_wfopen_s(&pf, sAchievementStateFile.c_str(), L"w");
if (pf == nullptr)
{
ASSERT(!"Could not save progress!");
Expand All @@ -628,7 +627,6 @@ void AchievementSet::SaveProgress(const char* sSaveStateFilename)

void AchievementSet::LoadProgress(const char* sLoadStateFilename)
{
char buffer[4096];
long nFileSize;

if (!RAUsers::LocalUser().IsLoggedIn())
Expand All @@ -637,9 +635,9 @@ void AchievementSet::LoadProgress(const char* sLoadStateFilename)
if (sLoadStateFilename == nullptr)
return;

sprintf_s(buffer, sizeof(buffer), "%s.rap", sLoadStateFilename);
std::wstring sAchievementStateFile = ra::Widen(sLoadStateFilename) + L".rap";

char* pRawFile = _MallocAndBulkReadFileToBuffer(buffer, nFileSize);
char* pRawFile = _MallocAndBulkReadFileToBuffer(sAchievementStateFile.c_str(), nFileSize);
if (pRawFile != nullptr)
{
const char* pIter = pRawFile;
Expand Down
2 changes: 1 addition & 1 deletion src/RA_AchievementSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AchievementSet

BOOL DeletePatchFile(ra::GameID nGameID);

std::string GetAchievementSetFilename(ra::GameID nGameID);
std::wstring GetAchievementSetFilename(ra::GameID nGameID);

// Get Achievement at offset
Achievement& GetAchievement(size_t nIter) { return m_Achievements[nIter]; }
Expand Down
8 changes: 4 additions & 4 deletions src/RA_CodeNotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ void CodeNotes::Clear()
m_CodeNotes.clear();
}

size_t CodeNotes::Load(const std::string& sFile)
size_t CodeNotes::Load(const std::wstring& sFile)
{
Clear();

FILE* pf = nullptr;
if (fopen_s(&pf, sFile.c_str(), "rb") == 0)
if (_wfopen_s(&pf, sFile.c_str(), L"rb") == 0)
{
Document doc;
doc.ParseStream(FileStream(pf));
Expand Down Expand Up @@ -50,7 +50,7 @@ size_t CodeNotes::Load(const std::string& sFile)
return m_CodeNotes.size();
}

BOOL CodeNotes::Save(const std::string& sFile)
BOOL CodeNotes::Save(const std::wstring& sFile)
{
return FALSE;
// All saving should be cloud-based!
Expand All @@ -73,7 +73,7 @@ void CodeNotes::OnCodeNotesResponse(Document& doc)
// Persist then reload
const ra::GameID nGameID = doc["GameID"].GetUint();

_WriteBufferToFile(g_sHomeDir + std::string(RA_DIR_DATA) + std::to_string(nGameID) + "-Notes2.txt", doc);
_WriteBufferToFile(g_sHomeDir + RA_DIR_DATA + std::to_wstring(nGameID) + L"-Notes2.txt", doc);

g_MemoryDialog.RepopulateMemNotesFromFile();
}
Expand Down
4 changes: 2 additions & 2 deletions src/RA_CodeNotes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CodeNotes
public:
void Clear();

BOOL Save(const std::string& sFile);
size_t Load(const std::string& sFile);
BOOL Save(const std::wstring& sFile);
size_t Load(const std::wstring& sFile);

BOOL ReloadFromWeb(ra::GameID nID);
static void OnCodeNotesResponse(Document& doc);
Expand Down
Loading

0 comments on commit 00f0be5

Please sign in to comment.