Skip to content

Commit b6f05e0

Browse files
committed
Fix save file path separator
1 parent 83a20b6 commit b6f05e0

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/GearsystemCore.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ void GearsystemCore::SaveRam(const char* szPath, bool fullPath)
569569

570570
if (!fullPath)
571571
{
572-
path += "/";
573-
path += m_pCartridge->GetFileName();
572+
append_path_component(path, m_pCartridge->GetFileName());
574573
}
575574
}
576575
else
@@ -602,7 +601,7 @@ void GearsystemCore::LoadRam()
602601

603602
void GearsystemCore::LoadRam(const char* szPath, bool fullPath)
604603
{
605-
if (m_pCartridge->IsReady() && IsValidPointer(m_pMemory->GetCurrentRule()))
604+
if (m_pCartridge->IsReady() && IsValidPointer(m_pMemory->GetCurrentRule()) && m_pMemory->GetCurrentRule()->PersistedRAM())
606605
{
607606
Log("Loading RAM...");
608607

@@ -616,8 +615,7 @@ void GearsystemCore::LoadRam(const char* szPath, bool fullPath)
616615

617616
if (!fullPath)
618617
{
619-
sav_path += "/";
620-
sav_path += m_pCartridge->GetFileName();
618+
append_path_component(sav_path, m_pCartridge->GetFileName());
621619
}
622620
}
623621
else
@@ -682,8 +680,7 @@ std::string GearsystemCore::GetSaveStatePath(const char* path, int index)
682680
if (IsValidPointer(path))
683681
{
684682
full_path = path;
685-
full_path += "/";
686-
full_path += m_pCartridge->GetFileName();
683+
append_path_component(full_path, m_pCartridge->GetFileName());
687684
}
688685
else
689686
full_path = m_pCartridge->GetFilePath();

src/common.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,24 @@ inline char* strncat_fit(char* dest, const char* src, size_t dest_size)
208208
return strncat(dest, src, dest_size - len - 1);
209209
}
210210

211+
inline void append_path_component(std::string& path, const char* component)
212+
{
213+
if (path.length() > 0)
214+
{
215+
char last = path[path.length() - 1];
216+
if (last != '/' && last != '\\')
217+
{
218+
#if defined(_WIN32)
219+
path += "\\";
220+
#else
221+
path += "/";
222+
#endif
223+
}
224+
}
225+
226+
path += component;
227+
}
228+
211229
inline bool create_directory_if_not_exists(const char* path)
212230
{
213231
#if defined(_WIN32)

0 commit comments

Comments
 (0)