mirror of https://github.com/AxioDL/metaforce.git
Fix memcard path CVars and add menu notifying player when they've been reset
This commit is contained in:
parent
561e54527b
commit
c6db983c41
|
@ -336,6 +336,9 @@ ECardResult CMemoryCardSys::CCardFileInfo::WriteFile() {
|
|||
}
|
||||
|
||||
ECardResult CMemoryCardSys::CCardFileInfo::CloseFile() { return CMemoryCardSys::CloseFile(m_handle); }
|
||||
kabufuda::SystemString CMemoryCardSys::_GetDolphinCardPath(kabufuda::ECardSlot slot) {
|
||||
return g_CardImagePaths[static_cast<u32>(slot)];
|
||||
}
|
||||
|
||||
void CMemoryCardSys::_ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot) {
|
||||
#if CARD_UCS2
|
||||
|
@ -559,19 +562,31 @@ void CMemoryCardSys::CommitToDisk(kabufuda::ECardSlot port) {
|
|||
card.commit();
|
||||
}
|
||||
|
||||
kabufuda::SystemString CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot slot) {
|
||||
kabufuda::SystemString path = _CreateDolphinCard(slot);
|
||||
bool CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot slot) {
|
||||
kabufuda::SystemString path =
|
||||
_CreateDolphinCard(slot, slot == kabufuda::ECardSlot::SlotA ? mc_dolphinAPath->hasDefaultValue()
|
||||
: mc_dolphinBPath->hasDefaultValue());
|
||||
if (CardProbe(slot).x0_error != ECardResult::READY) {
|
||||
return {};
|
||||
return false;
|
||||
}
|
||||
|
||||
MountCard(slot);
|
||||
FormatCard(slot);
|
||||
kabufuda::Card& card = g_CardStates[int(slot)];
|
||||
card.waitForCompletion();
|
||||
return path;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMemoryCardSys::_ResetCVar(kabufuda::ECardSlot slot) {
|
||||
switch(slot) {
|
||||
case kabufuda::ECardSlot::SlotA:
|
||||
mc_dolphinAPath->fromLiteral("");
|
||||
break;
|
||||
case kabufuda::ECardSlot::SlotB:
|
||||
mc_dolphinBPath->fromLiteral("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
void CMemoryCardSys::Shutdown() {
|
||||
UnmountCard(kabufuda::ECardSlot::SlotA);
|
||||
UnmountCard(kabufuda::ECardSlot::SlotB);
|
||||
|
|
|
@ -67,10 +67,12 @@ class CMemoryCardSys {
|
|||
rstl::reserved_vector<u32, 6> x30_scanCategoryCounts;
|
||||
|
||||
public:
|
||||
static void _ResetCVar(kabufuda::ECardSlot slot);
|
||||
static void _ResolveDolphinCardPath(const hecl::CVar* cv, kabufuda::ECardSlot slot);
|
||||
static kabufuda::SystemString ResolveDolphinCardPath(kabufuda::ECardSlot slot);
|
||||
static kabufuda::SystemString CreateDolphinCard(kabufuda::ECardSlot slot);
|
||||
static kabufuda::SystemString _CreateDolphinCard(kabufuda::ECardSlot slot);
|
||||
static bool CreateDolphinCard(kabufuda::ECardSlot slot);
|
||||
static kabufuda::SystemString _GetDolphinCardPath(kabufuda::ECardSlot slot);
|
||||
static kabufuda::SystemString _CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin);
|
||||
|
||||
using ECardResult = kabufuda::ECardResult;
|
||||
struct CardResult {
|
||||
|
|
|
@ -31,8 +31,9 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
|||
return {};
|
||||
}
|
||||
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) {
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||
if (dolphin) {
|
||||
const char* home = getenv("HOME");
|
||||
if (!home || home[0] != '/')
|
||||
return {};
|
||||
|
@ -47,12 +48,23 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
|
|||
|
||||
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 {};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
|||
return {};
|
||||
}
|
||||
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot) {
|
||||
kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot slot, bool dolphin) {
|
||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||
if (dolphin) {
|
||||
const char* home = getenv("HOME");
|
||||
if (!home)
|
||||
return {};
|
||||
|
@ -40,6 +41,19 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ using namespace Windows::Storage;
|
|||
/* Partial path-selection logic from
|
||||
* https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/UICommon/UICommon.cpp
|
||||
* Modified to not use dolphin-binary-relative paths. */
|
||||
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot) {
|
||||
kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot slot, bool dolphin) {
|
||||
if (g_Main->IsUSA() && !g_Main->IsTrilogy()) {
|
||||
if (dolphin) {
|
||||
#if !WINDOWS_STORE
|
||||
/* Detect where the User directory is. There are two different cases
|
||||
* 1. HKCU\Software\Dolphin Emulator\UserConfigPath exists
|
||||
|
@ -61,6 +62,19 @@ kabufuda::SystemString CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlo
|
|||
return {};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -131,6 +131,9 @@ bool CSaveGameScreen::PumpLoad() {
|
|||
}
|
||||
|
||||
CSaveGameScreen::EUIType CSaveGameScreen::SelectUIType() const {
|
||||
if (x10_uiType == EUIType::CreateDolphinCardFailed) {
|
||||
return x10_uiType;
|
||||
}
|
||||
if (x6c_cardDriver->x10_state == EState::NoCard) {
|
||||
return EUIType::NoCardFound;
|
||||
}
|
||||
|
@ -312,6 +315,12 @@ void CSaveGameScreen::SetUIText() {
|
|||
opt1 = 15; // No
|
||||
}
|
||||
break;
|
||||
case EUIType::CreateDolphinCardFailed:
|
||||
msgAStr = u"Attempt to create Dolphin Card failed!\n";
|
||||
msgBStr = u"CVars have been reset to defaults.\nMetaforce will use Dolphin's memory cards if available\n";
|
||||
opt0 = -2;
|
||||
opt0Str = u"Press &image=SI,1.0,0.68,05AF9CAA; to proceed.\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -392,7 +401,12 @@ void CSaveGameScreen::DoAdvance([[maybe_unused]] CGuiTableGroup* caller) {
|
|||
sfx = x84_navConfirmSfx;
|
||||
} else if (userSel == 2 && x10_uiType == EUIType::NoCardFound) {
|
||||
/* Create Dolphin Card */
|
||||
CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot::SlotA);
|
||||
if (!CMemoryCardSys::CreateDolphinCard(kabufuda::ECardSlot::SlotA)) {
|
||||
x10_uiType = EUIType::CreateDolphinCardFailed;
|
||||
sfx = x8c_navBackSfx;
|
||||
x91_uiTextDirty = true;
|
||||
break;
|
||||
}
|
||||
ResetCardDriver();
|
||||
sfx = x84_navConfirmSfx;
|
||||
}
|
||||
|
@ -556,6 +570,15 @@ void CSaveGameScreen::DoAdvance([[maybe_unused]] CGuiTableGroup* caller) {
|
|||
}
|
||||
}
|
||||
break;
|
||||
case EUIType::CreateDolphinCardFailed: {
|
||||
if (userSel == 0) {
|
||||
CMemoryCardSys::_ResetCVar(kabufuda::ECardSlot::SlotA);
|
||||
CMemoryCardSys::ResolveDolphinCardPath(kabufuda::ECardSlot::SlotA);
|
||||
ResetCardDriver();
|
||||
x10_uiType = EUIType::Empty;
|
||||
sfx = x84_navConfirmSfx;
|
||||
}
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -41,7 +41,9 @@ public:
|
|||
ProgressWillBeLost = 13,
|
||||
NotOriginalCard = 14,
|
||||
AllDataWillBeLost = 15,
|
||||
SaveReady = 16
|
||||
SaveReady = 16,
|
||||
// Metaforce Addition
|
||||
CreateDolphinCardFailed
|
||||
};
|
||||
|
||||
bool IsHiddenFromFrontEnd() const {
|
||||
|
|
Loading…
Reference in New Issue