refactor: phases 5 & 6 — TransferService, Result<T>, RAII

Phase 5 — TransferService extraction:
- New nxst::TransferService owns all sender/receiver state, threads, and atomics
  (previously 11 file-statics across transfer_sender.cpp + transfer_receiver.cpp)
- startReceive() calls io::restore internally; UI never touches infra/fs or infra/net
- TitlesLayout routes all transfer ops through mainApp->transfer
- g_currentUId removed from global scope; TitlesLayout::InitTitles(AccountUid)
- MainApplication gains transfer member; layout refs renamed to snake_case
- userAppExit() updated to cancel via service

Phase 6 — Result<T> + RAII:
- include/nxst/domain/result.hpp: 85-line tagged-union Result<T,E> + Result<void,E>
- include/nxst/infra/fs/handles.hpp: FsFileSystemHandle (auto fsFsClose),
  FileHandle (auto fclose) — eliminates manual close on every error path
- io::backup / io::restore return nxst::Result<std::string> (was tuple<bool,Result,string>)
- new u8[] + malloc in copyFile/restore replaced with std::vector<u8>
- NACP save-creation extracted to createSaveIfNeeded() helper in io.cpp

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-27 01:27:16 +03:00
parent 895fee6235
commit dc65a4c8a9
6 changed files with 270 additions and 152 deletions
+5 -5
View File
@@ -205,11 +205,11 @@ void TransferService::runSender(size_t title_index, AccountUid uid) {
sender_state.setStatus("Creating backup...");
#ifdef __SWITCH__
auto backup_result = io::backup(title_index, uid);
if (!std::get<0>(backup_result)) {
failSend("Failed to create backup:\n" + std::get<2>(backup_result));
if (!backup_result.isOk()) {
failSend("Failed to create backup:\n" + backup_result.error());
return finish();
}
fs::path directory = std::get<2>(backup_result);
fs::path directory = backup_result.value();
#else
fs::path directory = ".";
(void)title_index; (void)uid;
@@ -414,8 +414,8 @@ void TransferService::runAccept(int server_fd) {
#ifdef __SWITCH__
receiver_state.setStatus("Restoring...");
auto result = io::restore(restore_title_index, restore_uid, 0, restore_title_name);
restore_ok = std::get<0>(result);
restore_error = restore_ok ? "" : std::get<2>(result);
restore_ok = result.isOk();
restore_error = result.isOk() ? "" : result.error();
#else
restore_ok = true;
#endif