General: Make use of FopenUnique where applicable

Migrates to the hecl Fopen variant that automatically closes its
contained file handle if it goes out of scope.
This commit is contained in:
Lioncash 2019-08-26 14:37:19 -04:00
parent f48ebefa84
commit 1d3062b33f
9 changed files with 60 additions and 73 deletions

View File

@ -466,9 +466,8 @@ bool PAKRouter<BRIDGETYPE>::extractResources(const BRIDGETYPE& pakBridge, bool f
if (force || cooked.isNone()) { if (force || cooked.isNone()) {
cooked.makeDirChain(false); cooked.makeDirChain(false);
PAKEntryReadStream s = entryPtr->beginReadStream(*node); PAKEntryReadStream s = entryPtr->beginReadStream(*node);
FILE* fout = hecl::Fopen(cooked.getAbsolutePath().data(), _SYS_STR("wb")); const auto fout = hecl::FopenUnique(cooked.getAbsolutePath().data(), _SYS_STR("wb"));
fwrite(s.data(), 1, s.length(), fout); std::fwrite(s.data(), 1, s.length(), fout.get());
fclose(fout);
} }
if (extractor.func_a) /* Doesn't need PAKRouter access */ if (extractor.func_a) /* Doesn't need PAKRouter access */

View File

@ -812,13 +812,13 @@ bool TXTR::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) {
uint16_t height = rs.readUint16Big(); uint16_t height = rs.readUint16Big();
uint32_t numMips = rs.readUint32Big(); uint32_t numMips = rs.readUint32Big();
FILE* fp = hecl::Fopen(outPath.getAbsolutePath().data(), _SYS_STR("wb")); auto fp = hecl::FopenUnique(outPath.getAbsolutePath().data(), _SYS_STR("wb"));
if (!fp) { if (fp == nullptr) {
Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for writing")), outPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for writing")), outPath.getAbsolutePath());
return false; return false;
} }
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGErr, PNGWarn); png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGErr, PNGWarn);
png_init_io(png, fp); png_init_io(png, fp.get());
png_infop info = png_create_info_struct(png); png_infop info = png_create_info_struct(png);
png_text textStruct = {}; png_text textStruct = {};
@ -862,7 +862,6 @@ bool TXTR::Extract(PAKEntryReadStream& rs, const hecl::ProjectPath& outPath) {
png_write_end(png, info); png_write_end(png, info);
png_write_flush(png); png_write_flush(png);
png_destroy_write_struct(&png, &info); png_destroy_write_struct(&png, &info);
fclose(fp);
return true; return true;
} }
@ -1017,18 +1016,17 @@ static int GetNumPaletteEntriesForGCN(png_structp png, png_infop info) {
} }
bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) { bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) {
FILE* inf = hecl::Fopen(inPath.getAbsolutePath().data(), _SYS_STR("rb")); auto inf = hecl::FopenUnique(inPath.getAbsolutePath().data(), _SYS_STR("rb"));
if (!inf) { if (inf == nullptr) {
Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for reading")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for reading")), inPath.getAbsolutePath());
return false; return false;
} }
/* Validate PNG */ /* Validate PNG */
char header[8]; char header[8];
fread(header, 1, 8, inf); std::fread(header, 1, sizeof(header), inf.get());
if (png_sig_cmp((png_const_bytep)header, 0, 8)) { if (png_sig_cmp((png_const_bytep)header, 0, 8)) {
Log.report(logvisor::Error, fmt(_SYS_STR("invalid PNG signature in '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("invalid PNG signature in '{}'")), inPath.getAbsolutePath());
fclose(inf);
return false; return false;
} }
@ -1036,25 +1034,22 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
png_structp pngRead = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); png_structp pngRead = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (!pngRead) { if (!pngRead) {
Log.report(logvisor::Error, fmt("unable to initialize libpng")); Log.report(logvisor::Error, fmt("unable to initialize libpng"));
fclose(inf);
return false; return false;
} }
png_infop info = png_create_info_struct(pngRead); png_infop info = png_create_info_struct(pngRead);
if (!info) { if (!info) {
Log.report(logvisor::Error, fmt("unable to initialize libpng info")); Log.report(logvisor::Error, fmt("unable to initialize libpng info"));
fclose(inf);
png_destroy_read_struct(&pngRead, nullptr, nullptr); png_destroy_read_struct(&pngRead, nullptr, nullptr);
return false; return false;
} }
if (setjmp(png_jmpbuf(pngRead))) { if (setjmp(png_jmpbuf(pngRead))) {
Log.report(logvisor::Error, fmt(_SYS_STR("unable to initialize libpng I/O for '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("unable to initialize libpng I/O for '{}'")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
png_init_io(pngRead, inf); png_init_io(pngRead, inf.get());
png_set_sig_bytes(pngRead, 8); png_set_sig_bytes(pngRead, 8);
png_read_info(pngRead, info); png_read_info(pngRead, info);
@ -1066,7 +1061,6 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
if (width < 4 || height < 4) { if (width < 4 || height < 4) {
Log.report(logvisor::Error, fmt("image must be 4x4 or larger")); Log.report(logvisor::Error, fmt("image must be 4x4 or larger"));
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1092,7 +1086,6 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
if (bitDepth != 8) { if (bitDepth != 8) {
Log.report(logvisor::Error, fmt(_SYS_STR("'{}' is not 8 bits-per-channel")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("'{}' is not 8 bits-per-channel")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1124,7 +1117,6 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
break; break;
default: default:
Log.report(logvisor::Error, fmt(_SYS_STR("unsupported color type in '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("unsupported color type in '{}'")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1145,7 +1137,6 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
if (setjmp(png_jmpbuf(pngRead))) { if (setjmp(png_jmpbuf(pngRead))) {
Log.report(logvisor::Fatal, fmt(_SYS_STR("unable to read image in '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Fatal, fmt(_SYS_STR("unable to read image in '{}'")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1178,7 +1169,7 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
} }
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
fclose(inf); inf.reset();
/* Reduce mipmaps to minimum allowed dimensions */ /* Reduce mipmaps to minimum allowed dimensions */
unsigned minDimX, minDimY; unsigned minDimX, minDimY;
@ -1338,18 +1329,17 @@ bool TXTR::Cook(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPat
} }
bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) { bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outPath) {
FILE* inf = hecl::Fopen(inPath.getAbsolutePath().data(), _SYS_STR("rb")); auto inf = hecl::FopenUnique(inPath.getAbsolutePath().data(), _SYS_STR("rb"));
if (!inf) { if (inf == nullptr) {
Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for reading")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for reading")), inPath.getAbsolutePath());
return false; return false;
} }
/* Validate PNG */ /* Validate PNG */
char header[8]; char header[8];
fread(header, 1, 8, inf); std::fread(header, 1, sizeof(header), inf.get());
if (png_sig_cmp((png_const_bytep)header, 0, 8)) { if (png_sig_cmp((png_const_bytep)header, 0, 8)) {
Log.report(logvisor::Error, fmt(_SYS_STR("invalid PNG signature in '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("invalid PNG signature in '{}'")), inPath.getAbsolutePath());
fclose(inf);
return false; return false;
} }
@ -1357,25 +1347,22 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP
png_structp pngRead = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); png_structp pngRead = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (!pngRead) { if (!pngRead) {
Log.report(logvisor::Error, fmt("unable to initialize libpng")); Log.report(logvisor::Error, fmt("unable to initialize libpng"));
fclose(inf);
return false; return false;
} }
png_infop info = png_create_info_struct(pngRead); png_infop info = png_create_info_struct(pngRead);
if (!info) { if (!info) {
Log.report(logvisor::Error, fmt("unable to initialize libpng info")); Log.report(logvisor::Error, fmt("unable to initialize libpng info"));
fclose(inf);
png_destroy_read_struct(&pngRead, nullptr, nullptr); png_destroy_read_struct(&pngRead, nullptr, nullptr);
return false; return false;
} }
if (setjmp(png_jmpbuf(pngRead))) { if (setjmp(png_jmpbuf(pngRead))) {
Log.report(logvisor::Error, fmt(_SYS_STR("unable to initialize libpng I/O for '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("unable to initialize libpng I/O for '{}'")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
png_init_io(pngRead, inf); png_init_io(pngRead, inf.get());
png_set_sig_bytes(pngRead, 8); png_set_sig_bytes(pngRead, 8);
png_read_info(pngRead, info); png_read_info(pngRead, info);
@ -1406,7 +1393,6 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP
if (bitDepth != 8) { if (bitDepth != 8) {
Log.report(logvisor::Error, fmt(_SYS_STR("'{}' is not 8 bits-per-channel")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("'{}' is not 8 bits-per-channel")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1436,7 +1422,6 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP
break; break;
default: default:
Log.report(logvisor::Error, fmt(_SYS_STR("unsupported color type in '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("unsupported color type in '{}'")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1455,7 +1440,6 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP
if (setjmp(png_jmpbuf(pngRead))) { if (setjmp(png_jmpbuf(pngRead))) {
Log.report(logvisor::Fatal, fmt(_SYS_STR("unable to read image in '{}'")), inPath.getAbsolutePath()); Log.report(logvisor::Fatal, fmt(_SYS_STR("unable to read image in '{}'")), inPath.getAbsolutePath());
fclose(inf);
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
return false; return false;
} }
@ -1521,7 +1505,7 @@ bool TXTR::CookPC(const hecl::ProjectPath& inPath, const hecl::ProjectPath& outP
} }
png_destroy_read_struct(&pngRead, &info, nullptr); png_destroy_read_struct(&pngRead, &info, nullptr);
fclose(inf); inf.reset();
/* Perform box-filter mipmap */ /* Perform box-filter mipmap */
if (numMips > 1) { if (numMips > 1) {

View File

@ -42,8 +42,8 @@ void SCLY::exportToLayerDirectories(const PAK::Entry& entry, PAKRouter<PAKBridge
layerPath.makeDirChain(true); layerPath.makeDirChain(true);
if (active) { if (active) {
hecl::ProjectPath activePath(layerPath, "!defaultactive"); const hecl::ProjectPath activePath(layerPath, "!defaultactive");
fclose(hecl::Fopen(activePath.getAbsolutePath().data(), _SYS_STR("wb"))); [[maybe_unused]] const auto fp = hecl::FopenUnique(activePath.getAbsolutePath().data(), _SYS_STR("wb"));
} }
hecl::ProjectPath yamlFile(layerPath, _SYS_STR("!objects.yaml")); hecl::ProjectPath yamlFile(layerPath, _SYS_STR("!objects.yaml"));

View File

@ -721,18 +721,17 @@ void SpecBase::extractRandomStaticEntropy(const uint8_t* buf, const hecl::Projec
hecl::ProjectPath entropyPath(noAramPath, _SYS_STR("RandomStaticEntropy.png")); hecl::ProjectPath entropyPath(noAramPath, _SYS_STR("RandomStaticEntropy.png"));
hecl::ProjectPath catalogPath(noAramPath, _SYS_STR("!catalog.yaml")); hecl::ProjectPath catalogPath(noAramPath, _SYS_STR("!catalog.yaml"));
if (FILE* fp = hecl::Fopen(catalogPath.getAbsolutePath().data(), _SYS_STR("a"))) { if (const auto fp = hecl::FopenUnique(catalogPath.getAbsolutePath().data(), _SYS_STR("a"))) {
fmt::print(fp, fmt("RandomStaticEntropy: {}\n"), entropyPath.getRelativePathUTF8()); fmt::print(fp.get(), fmt("RandomStaticEntropy: {}\n"), entropyPath.getRelativePathUTF8());
fclose(fp);
} }
FILE* fp = hecl::Fopen(entropyPath.getAbsolutePath().data(), _SYS_STR("wb")); auto fp = hecl::FopenUnique(entropyPath.getAbsolutePath().data(), _SYS_STR("wb"));
if (!fp) { if (fp == nullptr) {
Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for writing")), entropyPath.getAbsolutePath()); Log.report(logvisor::Error, fmt(_SYS_STR("Unable to open '{}' for writing")), entropyPath.getAbsolutePath());
return; return;
} }
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGErr, PNGWarn); png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, PNGErr, PNGWarn);
png_init_io(png, fp); png_init_io(png, fp.get());
png_infop info = png_create_info_struct(png); png_infop info = png_create_info_struct(png);
png_text textStruct = {}; png_text textStruct = {};
@ -756,7 +755,6 @@ void SpecBase::extractRandomStaticEntropy(const uint8_t* buf, const hecl::Projec
png_write_end(png, info); png_write_end(png, info);
png_write_flush(png); png_write_flush(png);
png_destroy_write_struct(&png, &info); png_destroy_write_struct(&png, &info);
fclose(fp);
} }
void SpecBase::clearTagCache() { void SpecBase::clearTagCache() {

View File

@ -613,12 +613,13 @@ struct SpecMP1 : SpecBase {
} else if (hecl::IsPathPNG(path)) { } else if (hecl::IsPathPNG(path)) {
return {SBIG('TXTR'), path.hash().val32()}; return {SBIG('TXTR'), path.hash().val32()};
} else if (hecl::IsPathYAML(path)) { } else if (hecl::IsPathYAML(path)) {
FILE* fp = hecl::Fopen(path.getAbsolutePath().data(), _SYS_STR("r")); auto fp = hecl::FopenUnique(path.getAbsolutePath().data(), _SYS_STR("r"));
if (!fp) if (fp == nullptr) {
return {}; return {};
}
athena::io::YAMLDocReader reader; athena::io::YAMLDocReader reader;
yaml_parser_set_input_file(reader.getParser(), fp); yaml_parser_set_input_file(reader.getParser(), fp.get());
urde::SObjectTag resTag; urde::SObjectTag resTag;
if (reader.ClassTypeOperation([&](const char* className) -> bool { if (reader.ClassTypeOperation([&](const char* className) -> bool {
@ -700,10 +701,9 @@ struct SpecMP1 : SpecBase {
return false; return false;
})) { })) {
resTag.id = path.hash().val32(); resTag.id = path.hash().val32();
fclose(fp); fp.reset();
return resTag; return resTag;
} }
fclose(fp);
} }
return {}; return {};
} }

View File

@ -198,28 +198,28 @@ ViewManager::ViewManager(hecl::Runtime::FileStoreManager& fileMgr, hecl::CVarMan
char path[2048]; char path[2048];
hecl::Sstat theStat; hecl::Sstat theStat;
FILE* fp = hecl::Fopen(m_recentProjectsPath.c_str(), _SYS_STR("r"), hecl::FileLockType::Read); auto fp = hecl::FopenUnique(m_recentProjectsPath.c_str(), _SYS_STR("r"), hecl::FileLockType::Read);
if (fp) { if (fp) {
while (fgets(path, 2048, fp)) { while (std::fgets(path, std::size(path), fp.get())) {
std::string pathStr(path); std::string pathStr(path);
pathStr.pop_back(); pathStr.pop_back();
hecl::SystemStringConv pathStrView(pathStr); hecl::SystemStringConv pathStrView(pathStr);
if (!hecl::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) if (!hecl::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) {
m_recentProjects.emplace_back(pathStrView.sys_str()); m_recentProjects.emplace_back(pathStrView.sys_str());
} }
fclose(fp); }
} }
fp = hecl::Fopen(m_recentFilesPath.c_str(), _SYS_STR("r"), hecl::FileLockType::Read); fp = hecl::FopenUnique(m_recentFilesPath.c_str(), _SYS_STR("r"), hecl::FileLockType::Read);
if (fp) { if (fp) {
while (fgets(path, 2048, fp)) { while (std::fgets(path, std::size(path), fp.get())) {
std::string pathStr(path); std::string pathStr(path);
pathStr.pop_back(); pathStr.pop_back();
hecl::SystemStringConv pathStrView(pathStr); hecl::SystemStringConv pathStrView(pathStr);
if (!hecl::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) if (!hecl::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) {
m_recentFiles.emplace_back(pathStrView.sys_str()); m_recentFiles.emplace_back(pathStrView.sys_str());
} }
fclose(fp); }
} }
} }
@ -231,11 +231,14 @@ void ViewManager::pushRecentProject(hecl::SystemStringView path) {
return; return;
} }
m_recentProjects.emplace_back(path); m_recentProjects.emplace_back(path);
FILE* fp = hecl::Fopen(m_recentProjectsPath.c_str(), _SYS_STR("w"), hecl::FileLockType::Write);
if (fp) { const auto fp = hecl::FopenUnique(m_recentProjectsPath.c_str(), _SYS_STR("w"), hecl::FileLockType::Write);
for (hecl::SystemString& pPath : m_recentProjects) if (fp == nullptr) {
fmt::print(fp, fmt("{}\n"), hecl::SystemUTF8Conv(pPath)); return;
fclose(fp); }
for (const hecl::SystemString& pPath : m_recentProjects) {
fmt::print(fp.get(), fmt("{}\n"), hecl::SystemUTF8Conv(pPath));
} }
} }
@ -245,11 +248,14 @@ void ViewManager::pushRecentFile(hecl::SystemStringView path) {
return; return;
} }
m_recentFiles.emplace_back(path); m_recentFiles.emplace_back(path);
FILE* fp = hecl::Fopen(m_recentFilesPath.c_str(), _SYS_STR("w"), hecl::FileLockType::Write);
if (fp) { const auto fp = hecl::FopenUnique(m_recentFilesPath.c_str(), _SYS_STR("w"), hecl::FileLockType::Write);
for (hecl::SystemString& pPath : m_recentFiles) if (fp == nullptr) {
fmt::print(fp, fmt("{}\n"), hecl::SystemUTF8Conv(pPath)); return;
fclose(fp); }
for (const hecl::SystemString& pPath : m_recentFiles) {
fmt::print(fp.get(), fmt("{}\n"), hecl::SystemUTF8Conv(pPath));
} }
} }

View File

@ -39,10 +39,10 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
return {}; return {};
path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B'); path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
FILE* fp = hecl::Fopen(path.c_str(), "wb"); const auto fp = hecl::FopenUnique(path.c_str(), "wb");
if (!fp) if (fp == nullptr) {
return {}; return {};
fclose(fp); }
return path; return path;
} }

View File

@ -29,10 +29,10 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
return {}; return {};
path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B'); path += fmt::format(fmt("/MemoryCard{:c}.USA.raw"), slot == kabufuda::ECardSlot::SlotA ? 'A' : 'B');
FILE* fp = hecl::Fopen(path.c_str(), "wb"); const auto fp = hecl::FopenUnique(path.c_str(), "wb");
if (!fp) if (fp == nullptr) {
return {}; return {};
fclose(fp); }
return path; return path;
} }

View File

@ -100,10 +100,10 @@ kabufuda::SystemString CMemoryCardSys::_CreateDolphinCard(kabufuda::ECardSlot sl
path += fmt::format(fmt(_SYS_STR("/MemoryCard{}.USA.raw")), path += fmt::format(fmt(_SYS_STR("/MemoryCard{}.USA.raw")),
slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B')); slot == kabufuda::ECardSlot::SlotA ? _SYS_STR('A') : _SYS_STR('B'));
FILE* fp = hecl::Fopen(path.c_str(), _SYS_STR("wb")); const auto fp = hecl::FopenUnique(path.c_str(), _SYS_STR("wb"));
if (!fp) if (fp == nullptr) {
return {}; return {};
fclose(fp); }
return path; return path;
} }