Skip to content

Commit b3381ad

Browse files
committed
Fix save file path separator
1 parent fe362ff commit b3381ad

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/common.h

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

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

src/geargrafx_core.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ void GeargrafxCore::SaveRam(const char* path, bool full_path)
263263
final_path = path;
264264
if (!full_path)
265265
{
266-
final_path += "/";
267-
final_path += m_media->GetFileName();
266+
append_path_component(final_path, m_media->GetFileName());
268267
}
269268
}
270269
else
@@ -303,7 +302,7 @@ void GeargrafxCore::SaveMB128(const char* path, bool full_path)
303302
{
304303
final_path = path;
305304
if (!full_path)
306-
final_path += "/mb128.sav";
305+
append_path_component(final_path, "mb128.sav");
307306
}
308307
else
309308
{
@@ -332,7 +331,7 @@ void GeargrafxCore::LoadMB128(const char* path, bool full_path)
332331
{
333332
final_path = path;
334333
if (!full_path)
335-
final_path += "/mb128.sav";
334+
append_path_component(final_path, "mb128.sav");
336335
}
337336
else
338337
{
@@ -371,7 +370,7 @@ void GeargrafxCore::LoadMB128(const char* path, bool full_path)
371370

372371
void GeargrafxCore::LoadRam(const char* path, bool full_path)
373372
{
374-
if (m_media->IsReady())
373+
if (m_media->IsReady() && m_memory->IsBackupRamEnabled())
375374
{
376375
using namespace std;
377376
string final_path;
@@ -381,8 +380,7 @@ void GeargrafxCore::LoadRam(const char* path, bool full_path)
381380
final_path = path;
382381
if (!full_path)
383382
{
384-
final_path += "/";
385-
final_path += m_media->GetFileName();
383+
append_path_component(final_path, m_media->GetFileName());
386384
}
387385
}
388386
else
@@ -434,8 +432,7 @@ std::string GeargrafxCore::GetSaveStatePath(const char* path, int index)
434432
if (IsValidPointer(path))
435433
{
436434
full_path = path;
437-
full_path += "/";
438-
full_path += m_media->GetFileName();
435+
append_path_component(full_path, m_media->GetFileName());
439436
}
440437
else
441438
full_path = m_media->GetFilePath();

0 commit comments

Comments
 (0)