2015-08-17 22:05:00 +00:00
|
|
|
#include "CMemoryCardSys.hpp"
|
2020-04-17 00:19:55 +00:00
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/IMain.hpp"
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
2020-04-17 00:19:55 +00:00
|
|
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
|
|
|
const char* home = getenv("HOME");
|
|
|
|
if (!home || home[0] != '/')
|
2018-12-08 05:30:43 +00:00
|
|
|
return {};
|
2020-04-17 00:19:55 +00:00
|
|
|
const char* dataHome = getenv("XDG_DATA_HOME");
|
|
|
|
|
|
|
|
/* XDG-selected data path */
|
|
|
|
kabufuda::SystemString path =
|
|
|
|
((dataHome && dataHome[0] == '/') ? dataHome : hecl::SystemString(home)) + "/.local/share/dolphin-emu";
|
|
|
|
path += fmt::format(FMT_STRING("/GC/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
|
|
|
|
|
|
|
hecl::Sstat theStat;
|
|
|
|
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode)) {
|
|
|
|
/* legacy case for older dolphin versions */
|
|
|
|
path = home;
|
|
|
|
path += fmt::format(FMT_STRING("/.dolphin-emu/GC/MemoryCard{:c}.USA.raw"),
|
|
|
|
slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
|
|
|
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2020-04-17 00:19:55 +00:00
|
|
|
return {};
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
|
|
|
|
2021-06-02 15:06:22 +00:00
|
|
|
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
2020-04-17 00:19:55 +00:00
|
|
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
2021-06-02 15:06:22 +00:00
|
|
|
if (dolphin) {
|
|
|
|
const char* home = getenv("HOME");
|
|
|
|
if (!home || home[0] != '/')
|
|
|
|
return {};
|
|
|
|
const char* dataHome = getenv("XDG_DATA_HOME");
|
2017-02-05 22:27:26 +00:00
|
|
|
|
2021-06-02 15:06:22 +00:00
|
|
|
/* XDG-selected data path */
|
|
|
|
kabufuda::SystemString path =
|
|
|
|
((dataHome && dataHome[0] == '/') ? dataHome : hecl::SystemString(home)) + "/.local/share/dolphin-emu/GC";
|
2020-04-17 00:19:55 +00:00
|
|
|
|
2021-06-02 15:06:22 +00:00
|
|
|
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
|
|
|
|
return {};
|
2020-04-17 00:19:55 +00:00
|
|
|
|
2021-06-02 15:06:22 +00:00
|
|
|
path += fmt::format(FMT_STRING("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
|
|
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
|
|
|
if (fp != nullptr) {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
kabufuda::SystemString path = _GetDolphinCardPath(slot);
|
|
|
|
hecl::SanitizePath(path);
|
|
|
|
if (path.find('/') == kabufuda::SystemString::npos) {
|
|
|
|
path = hecl::GetcwdStr() + _SYS_STR("/") + _GetDolphinCardPath(slot);
|
|
|
|
}
|
|
|
|
hecl::SystemString tmpPath = path.substr(0, path.find_last_of(_SYS_STR("/")));
|
|
|
|
hecl::RecursiveMakeDir(tmpPath.c_str());
|
|
|
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
|
|
|
if (fp) {
|
|
|
|
return path;
|
|
|
|
}
|
2020-04-17 00:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return {};
|
2017-02-05 22:27:26 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|