From c5d69392476dacee83a85d35f6bae47a203aeda0 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sat, 15 Jul 2023 23:29:15 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#3554=20=E3=83=99=E3=83=BC=E3=82=B9?= =?utf8?q?=E3=82=A2=E3=82=A4=E3=83=86=E3=83=A0=E3=81=AE=E3=82=B9=E3=83=9D?= =?utf8?q?=E3=82=A4=E3=83=A9=E3=83=BC=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?utf8?q?=E5=87=BA=E5=8A=9B=E5=87=A6=E7=90=86=E3=81=8B=E3=82=89spoiler=5F?= =?utf8?q?file=20=E3=82=92=E6=B6=88=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/wizard/items-spoiler.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/wizard/items-spoiler.cpp b/src/wizard/items-spoiler.cpp index 0c2f075f5..239acf6d8 100644 --- a/src/wizard/items-spoiler.cpp +++ b/src/wizard/items-spoiler.cpp @@ -118,14 +118,14 @@ static ItemEntity prepare_item_for_obj_desc(short bi_id) SpoilerOutputResultType spoil_obj_desc() { const auto &path = path_build(ANGBAND_DIR_USER, "obj-desc.txt"); - spoiler_file = angband_fopen(path, FileOpenMode::WRITE); - if (!spoiler_file) { + std::ofstream ofs(path); + if (!ofs) { return SpoilerOutputResultType::FILE_OPEN_FAILED; } - fprintf(spoiler_file, "Spoiler File -- Basic Items (%s)\n\n\n", get_version().data()); - fprintf(spoiler_file, "%-37s%8s%7s%5s %40s%9s\n", "Description", "Dam/AC", "Wgt", "Lev", "Chance", "Cost"); - fprintf(spoiler_file, "%-37s%8s%7s%5s %40s%9s\n", "-------------------------------------", "------", "---", "---", "----------------", "----"); + ofs << format("Spoiler File -- Basic Items (%s)\n\n\n", get_version().data()); + ofs << format("%-37s%8s%7s%5s %40s%9s\n", "Description", "Dam/AC", "Wgt", "Lev", "Chance", "Cost"); + ofs << format("%-37s%8s%7s%5s %40s%9s\n", "-------------------------------------", "------", "---", "---", "----------------", "----"); for (const auto &[tval_list, name] : group_item_list) { std::vector whats; @@ -148,7 +148,8 @@ SpoilerOutputResultType spoil_obj_desc() return (price1 != price2) ? price1 < price2 : depth1 < depth2; }); - fprintf(spoiler_file, "\n\n%s\n\n", name); + ofs << "\n\n" + << name << "\n\n"; for (const auto &bi_id : whats) { PlayerType dummy; const auto item = prepare_item_for_obj_desc(bi_id); @@ -157,12 +158,9 @@ SpoilerOutputResultType spoil_obj_desc() const auto dam_or_ac = describe_dam_or_ac(item); const auto weight = describe_weight(item); const auto chance = describe_chance(item); - fprintf(spoiler_file, " %-35s%8s%7s%5d %-40s%9ld\n", item_name.data(), - dam_or_ac.data(), weight.data(), static_cast(depth), chance.data(), - static_cast(price)); + ofs << format(" %-35s%8s%7s%5d %-40s%9d\n", item_name.data(), dam_or_ac.data(), weight.data(), depth, chance.data(), price); } } - return ferror(spoiler_file) || angband_fclose(spoiler_file) ? SpoilerOutputResultType::FILE_CLOSE_FAILED - : SpoilerOutputResultType::SUCCESSFUL; + return ofs.good() ? SpoilerOutputResultType::SUCCESSFUL : SpoilerOutputResultType::FILE_CLOSE_FAILED; } -- 2.11.0