2015-08-17 22:05:00 +00:00
|
|
|
#include "CMemoryCardSys.hpp"
|
|
|
|
|
2018-12-08 05:30:43 +00: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";
|
2019-07-20 04:27:21 +00:00
|
|
|
path += fmt::format(fmt("/GC/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
hecl::Sstat theStat;
|
|
|
|
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode)) {
|
|
|
|
/* legacy case for older dolphin versions */
|
|
|
|
path = home;
|
2019-07-20 04:27:21 +00:00
|
|
|
path += fmt::format(fmt("/.dolphin-emu/GC/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
2016-12-28 21:39:38 +00:00
|
|
|
if (hecl::Stat(path.c_str(), &theStat) || !S_ISREG(theStat.st_mode))
|
2018-12-08 05:30:43 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
2016-12-28 21:39:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00: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 22:27:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
/* XDG-selected data path */
|
|
|
|
kabufuda::SystemString path =
|
|
|
|
((dataHome && dataHome[0] == '/') ? dataHome : hecl::SystemString(home)) + "/.local/share/dolphin-emu/GC";
|
2017-02-05 22:27:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (hecl::RecursiveMakeDir(path.c_str()) < 0)
|
|
|
|
return {};
|
2017-02-05 22:27:26 +00:00
|
|
|
|
2019-07-20 04:27:21 +00:00
|
|
|
path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
|
2019-08-26 18:37:19 +00:00
|
|
|
const auto fp = hecl::FopenUnique(path.c_str(), "wb");
|
|
|
|
if (fp == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return {};
|
2019-08-26 18:37:19 +00:00
|
|
|
}
|
2017-02-05 22:27:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return path;
|
2017-02-05 22:27:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|