metaforce/Runtime/CMemoryCardSysNix.cpp

51 lines
1.6 KiB
C++
Raw Normal View History

#include "CMemoryCardSys.hpp"
2018-12-07 21:30:43 -08:00
namespace urde {
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
const char* home = getenv("HOME");
if (!home || home[0] != '/')
return {};
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";
2020-04-11 15:51:39 -07:00
path += fmt::format(FMT_STRING("/GC/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
2018-12-07 21:30:43 -08:00
hecl::Sstat theStat;
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode)) {
/* legacy case for older dolphin versions */
path = home;
2020-04-11 15:51:39 -07:00
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))
2018-12-07 21:30:43 -08:00
return {};
}
return path;
}
2018-12-07 21:30:43 -08:00
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) {
const char* home = getenv("HOME");
if (!home || home[0] != '/')
return {};
const char* dataHome = getenv("XDG_DATA_HOME");
2017-02-05 14:27:26 -08:00
2018-12-07 21:30:43 -08:00
/* XDG-selected data path */
kabufuda::SystemString path =
((dataHome && dataHome[0] == '/') ? dataHome : hecl::SystemString(home)) + "/.local/share/dolphin-emu/GC";
2017-02-05 14:27:26 -08:00
2018-12-07 21:30:43 -08:00
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
return {};
2017-02-05 14:27:26 -08:00
2020-04-11 15:51:39 -07: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) {
2018-12-07 21:30:43 -08:00
return {};
}
2017-02-05 14:27:26 -08:00
2018-12-07 21:30:43 -08:00
return path;
2017-02-05 14:27:26 -08:00
}
2018-12-07 21:30:43 -08:00
} // namespace urde