metaforce/Runtime/CMemoryCardSysOSX.cpp

62 lines
1.8 KiB
C++
Raw Normal View History

#include "CMemoryCardSys.hpp"
2020-04-17 00:19:55 +00:00
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/IMain.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
std::string 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)
return {};
std::string path = home;
2020-04-17 00:19:55 +00:00
path += fmt::format(FMT_STRING("/Library/Application Support/Dolphin/GC/MemoryCard{:c}.USA.raw"),
slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
2020-04-17 00:19:55 +00:00
hecl::Sstat theStat;
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
return {};
2020-04-17 00:19:55 +00:00
return path;
}
return {};
}
std::string CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
2020-04-17 00:19:55 +00:00
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
if (dolphin) {
const char* home = getenv("HOME");
if (!home)
return {};
std::string path = home;
path += "/Library/Application Support/Dolphin/GC";
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
return {};
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 {};
}
return path;
} else {
std::string path = _GetDolphinCardPath(slot);
hecl::SanitizePath(path);
if (path.find('/') == std::string::npos) {
path = hecl::GetcwdStr() + "/" + _GetDolphinCardPath(slot);
}
std::string tmpPath = path.substr(0, path.find_last_of("/"));
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
}
}
2020-04-17 00:19:55 +00:00
return {};
}
2018-12-08 05:30:43 +00:00
2021-04-10 08:42:06 +00:00
} // namespace metaforce