GCMemcardUtils: Implement GenerateFilename() as a cleaner variant of GCMemcard::GCI_FileName().
This commit is contained in:
parent
3e7f537a9d
commit
ec4fc7171f
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/IOFile.h"
|
#include "Common/IOFile.h"
|
||||||
|
#include "Common/NandPaths.h"
|
||||||
|
|
||||||
#include "Core/HW/GCMemcard/GCMemcard.h"
|
#include "Core/HW/GCMemcard/GCMemcard.h"
|
||||||
|
|
||||||
|
@ -283,4 +284,24 @@ bool WriteSavefile(const std::string& filename, const Savefile& savefile, Savefi
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GenerateFilename(const DEntry& entry)
|
||||||
|
{
|
||||||
|
std::string maker(reinterpret_cast<const char*>(entry.m_makercode.data()),
|
||||||
|
entry.m_makercode.size());
|
||||||
|
std::string gamecode(reinterpret_cast<const char*>(entry.m_gamecode.data()),
|
||||||
|
entry.m_gamecode.size());
|
||||||
|
|
||||||
|
// prevent going out of bounds when all bytes of m_filename are non-null
|
||||||
|
size_t length = 0;
|
||||||
|
for (size_t i = 0; i < entry.m_filename.size(); ++i)
|
||||||
|
{
|
||||||
|
if (entry.m_filename[i] == 0)
|
||||||
|
break;
|
||||||
|
++length;
|
||||||
|
}
|
||||||
|
std::string filename(reinterpret_cast<const char*>(entry.m_filename.data()), length);
|
||||||
|
|
||||||
|
return Common::EscapeFileName(maker + '-' + gamecode + '-' + filename);
|
||||||
|
}
|
||||||
} // namespace Memcard
|
} // namespace Memcard
|
||||||
|
|
|
@ -33,4 +33,7 @@ enum class SavefileFormat
|
||||||
|
|
||||||
// Writes a Gamecube memory card savefile to a file.
|
// Writes a Gamecube memory card savefile to a file.
|
||||||
bool WriteSavefile(const std::string& filename, const Savefile& savefile, SavefileFormat format);
|
bool WriteSavefile(const std::string& filename, const Savefile& savefile, SavefileFormat format);
|
||||||
|
|
||||||
|
// Generates a filename (without extension) for the given directory entry.
|
||||||
|
std::string GenerateFilename(const DEntry& entry);
|
||||||
} // namespace Memcard
|
} // namespace Memcard
|
||||||
|
|
Loading…
Reference in New Issue