refactor: phase 6 cleanup — RAII handles and io::restore split

- AccountProfileHandle RAII wrapper in handles.hpp; applied in
  account.cpp (getUser, iconPath) replacing manual accountProfileClose
- FILE* in iconPath replaced with existing FileHandle RAII wrapper
- io::restore split into clearSaveRoot + extractAndCommit static helpers;
  public signature unchanged
- sendAll/recvAll kept as bool — callers don't propagate the error string,
  Result<void> would add noise without benefit

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 14:56:38 +03:00
parent 836956394a
commit 6f8ede035f
4 changed files with 187 additions and 43 deletions
+12 -15
View File
@@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <nxst/domain/account.hpp>
#include <nxst/infra/fs/handles.hpp>
static std::map<AccountUid, User> mUsers;
@@ -59,15 +60,15 @@ std::vector<AccountUid> Account::ids(void) {
static User getUser(AccountUid id) {
User user{id, ""};
AccountProfile profile;
nxst::AccountProfileHandle profile;
AccountProfileBase profilebase;
memset(&profilebase, 0, sizeof(profilebase));
if (R_SUCCEEDED(accountGetProfile(&profile, id))) {
if (R_SUCCEEDED(accountProfileGet(&profile, NULL, &profilebase))) {
if (R_SUCCEEDED(accountGetProfile(profile.get(), id))) {
profile.valid = true;
if (R_SUCCEEDED(accountProfileGet(profile.get(), NULL, &profilebase))) {
user.name = std::string(profilebase.nickname);
}
accountProfileClose(&profile);
}
return user;
}
@@ -95,28 +96,24 @@ std::string Account::iconPath(AccountUid id) {
mkdir("sdmc:/switch/NXST", 0755);
mkdir("sdmc:/switch/NXST/cache", 0755);
AccountProfile profile;
if (R_FAILED(accountGetProfile(&profile, id)))
nxst::AccountProfileHandle profile;
if (R_FAILED(accountGetProfile(profile.get(), id)))
return "";
profile.valid = true;
u32 imgSize = 0;
if (R_FAILED(accountProfileGetImageSize(&profile, &imgSize)) || imgSize == 0) {
accountProfileClose(&profile);
if (R_FAILED(accountProfileGetImageSize(profile.get(), &imgSize)) || imgSize == 0)
return "";
}
std::vector<u8> buf(imgSize);
u32 outSize = 0;
Result r = accountProfileLoadImage(&profile, buf.data(), imgSize, &outSize);
accountProfileClose(&profile);
if (R_FAILED(r) || outSize == 0)
if (R_FAILED(accountProfileLoadImage(profile.get(), buf.data(), imgSize, &outSize)) || outSize == 0)
return "";
FILE* f = fopen(path, "wb");
nxst::FileHandle f(fopen(path, "wb"));
if (!f)
return "";
fwrite(buf.data(), 1, outSize, f);
fclose(f);
fwrite(buf.data(), 1, outSize, f.get());
return std::string(path);
}