Skip to content

Commit c891b3b

Browse files
committed
Properly check if the settings file exists or not before creating it
1 parent e211e3f commit c891b3b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

ttyd-tools/rel/source/memcard.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ int32_t loadSettings(const char *fileName, gc::card::card_file *fileInfo, uint8_
154154

155155
delete[] (MiscData);
156156
return CARD_ERROR_READY;
157-
158157
}
159158

160159
int32_t writeSettings(const char *description, const char *fileName,
@@ -176,12 +175,24 @@ int32_t writeSettings(const char *description, const char *fileName,
176175

177176
// Open the settings file if it exists
178177
ReturnCode = gc::card::CARDOpen(CARD_SLOTA, fileName, fileInfo);
179-
if (ReturnCode != CARD_ERROR_READY)
178+
switch (ReturnCode)
180179
{
181-
// Settings file does not exist, so create it
182-
// createSettingsFile keeps the file open, but closes and unmounts if it fails to create the file
183-
ReturnCode = createSettingsFile(fileName, description, fileInfo);
184-
if (ReturnCode != CARD_ERROR_READY)
180+
case CARD_ERROR_READY:
181+
{
182+
break;
183+
}
184+
case CARD_ERROR_NOFILE:
185+
{
186+
// Settings file does not exist, so create it
187+
// createSettingsFile keeps the file open, but closes and unmounts if it fails to create the file
188+
ReturnCode = createSettingsFile(fileName, description, fileInfo);
189+
if (ReturnCode != CARD_ERROR_READY)
190+
{
191+
return ReturnCode;
192+
}
193+
break;
194+
}
195+
default:
185196
{
186197
return ReturnCode;
187198
}
@@ -199,7 +210,7 @@ int32_t writeSettings(const char *description, const char *fileName,
199210
char *MiscData = new char[MiscDataSize];
200211
clearMemory(MiscData, MiscDataSize);
201212

202-
// Copy the name and description to display into the memory
213+
// Copy the name, description, and file size into the memory
203214
ttyd::string::strcpy(MiscData, "Paper Mario");
204215
ttyd::string::strcpy(&MiscData[0x20], description);
205216

0 commit comments

Comments
 (0)