2016-12-28 11:39:38 -10:00
|
|
|
#include "CMemoryCardSys.hpp"
|
2020-04-16 17:19:55 -07:00
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
|
#include "Runtime/IMain.hpp"
|
2021-04-10 01:42:06 -07:00
|
|
|
namespace metaforce {
|
2016-12-28 11:39:38 -10:00
|
|
|
|
2021-06-30 14:20:45 -04:00
|
|
|
std::string CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
2020-04-16 17:19:55 -07:00
|
|
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
|
|
|
|
const char* home = getenv("HOME");
|
|
|
|
|
if (!home)
|
|
|
|
|
return {};
|
2016-12-28 11:39:38 -10:00
|
|
|
|
2021-06-30 14:20:45 -04:00
|
|
|
std::string path = home;
|
2025-04-03 21:07:07 -06:00
|
|
|
path += fmt::format("/Library/Application Support/Dolphin/GC/MemoryCard{:c}.USA.raw",
|
2020-04-16 17:19:55 -07:00
|
|
|
slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
2016-12-28 11:39:38 -10:00
|
|
|
|
2020-04-16 17:19:55 -07:00
|
|
|
hecl::Sstat theStat;
|
|
|
|
|
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
|
|
|
|
|
return {};
|
2016-12-28 11:39:38 -10:00
|
|
|
|
2020-04-16 17:19:55 -07:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
2016-12-28 11:39:38 -10:00
|
|
|
}
|
|
|
|
|
|
2021-06-30 14:20:45 -04:00
|
|
|
std::string CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
2020-04-16 17:19:55 -07:00
|
|
|
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
2021-06-02 08:06:22 -07:00
|
|
|
if (dolphin) {
|
|
|
|
|
const char* home = getenv("HOME");
|
|
|
|
|
if (!home)
|
|
|
|
|
return {};
|
2017-02-03 17:46:12 -10:00
|
|
|
|
2021-06-30 14:20:45 -04:00
|
|
|
std::string path = home;
|
2021-06-02 08:06:22 -07:00
|
|
|
path += "/Library/Application Support/Dolphin/GC";
|
|
|
|
|
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
|
|
|
|
|
return {};
|
2017-02-03 17:46:12 -10:00
|
|
|
|
2025-04-03 21:07:07 -06:00
|
|
|
path += fmt::format("/MemoryCard{:c}.USA.raw", slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
2021-06-02 08:06:22 -07:00
|
|
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
|
|
|
|
if (fp == nullptr) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
} else {
|
2021-06-30 14:20:45 -04:00
|
|
|
std::string path = _GetDolphinCardPath(slot);
|
2021-06-02 08:06:22 -07:00
|
|
|
hecl::SanitizePath(path);
|
2021-06-30 14:20:45 -04:00
|
|
|
if (path.find('/') == std::string::npos) {
|
|
|
|
|
path = hecl::GetcwdStr() + "/" + _GetDolphinCardPath(slot);
|
2021-06-02 08:06:22 -07:00
|
|
|
}
|
2021-06-30 14:20:45 -04:00
|
|
|
std::string tmpPath = path.substr(0, path.find_last_of("/"));
|
2021-06-02 08:06:22 -07:00
|
|
|
hecl::RecursiveMakeDir(tmpPath.c_str());
|
|
|
|
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
|
|
|
|
if (fp) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
2020-04-16 17:19:55 -07:00
|
|
|
}
|
2019-08-26 14:37:19 -04:00
|
|
|
}
|
2020-04-16 17:19:55 -07:00
|
|
|
return {};
|
2017-02-03 17:46:12 -10:00
|
|
|
}
|
|
|
|
|
|
2021-04-10 01:42:06 -07:00
|
|
|
} // namespace metaforce
|