OSDN Git Service

[Refactor] savefile_base をstring からpath に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 26 May 2024 04:56:37 +0000 (13:56 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 26 May 2024 13:44:53 +0000 (22:44 +0900)
変更当初はstring として扱うべきかpath として扱うべきか不明瞭だったので一旦string にしていた
改めて影響範囲を確認したところ、path で問題なさそうだと判断したのでpath に変えた

src/cmd-io/cmd-diary.cpp
src/io/files-util.cpp
src/io/files-util.h
src/io/write-diary.cpp
src/player/process-name.cpp

index 5fc003a..318f281 100644 (file)
@@ -36,7 +36,7 @@ static void display_diary(PlayerType *player_ptr)
 #endif
 
     std::stringstream ss;
-    ss << _("playrecord-", "playrec-") << savefile_base << ".txt";
+    ss << _("playrecord-", "playrec-") << savefile_base.string() << ".txt";
     const auto path = path_build(ANGBAND_DIR_USER, ss.str());
     FileDisplayer(player_ptr->name).display(false, path.string(), -1, 0, diary_title);
 }
@@ -83,7 +83,7 @@ static void do_cmd_erase_diary()
     }
 
     std::stringstream ss;
-    ss << _("playrecord-", "playrec-") << savefile_base << ".txt";
+    ss << _("playrecord-", "playrec-") << savefile_base.string() << ".txt";
     const auto path = path_build(ANGBAND_DIR_USER, ss.str());
     fd_kill(path);
 
index 5864660..45997a9 100644 (file)
@@ -44,7 +44,7 @@ std::filesystem::path ANGBAND_DIR_USER; //!< User "preference" files (ascii) The
 std::filesystem::path ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rarely portable between platforms
 
 std::filesystem::path savefile;
-std::string savefile_base;
+std::filesystem::path savefile_base;
 
 /*!
  * @brief プレイヤーステータスをファイルダンプ出力する
@@ -233,9 +233,9 @@ static errr counts_seek(PlayerType *player_ptr, int fd, uint32_t where, bool fla
     auto short_pclass = enum2i(player_ptr->pclass);
 #ifdef SAVEFILE_USE_UID
     const auto user_id = UnixUserIds::get_instance().get_user_id();
-    strnfmt(temp1, sizeof(temp1), "%d.%s.%d%d%d", user_id, savefile_base.data(), short_pclass, player_ptr->ppersonality, player_ptr->age);
+    strnfmt(temp1, sizeof(temp1), "%d.%s.%d%d%d", user_id, savefile_base.string().data(), short_pclass, player_ptr->ppersonality, player_ptr->age);
 #else
-    strnfmt(temp1, sizeof(temp1), "%s.%d%d%d", savefile_base.data(), short_pclass, player_ptr->ppersonality, player_ptr->age);
+    strnfmt(temp1, sizeof(temp1), "%s.%d%d%d", savefile_base.string().data(), short_pclass, player_ptr->ppersonality, player_ptr->age);
 #endif
     for (int i = 0; temp1[i]; i++) {
         temp1[i] ^= (i + 1) * 63;
index 77a21a9..a5b333c 100644 (file)
@@ -7,7 +7,7 @@
 #include <string_view>
 
 extern std::filesystem::path savefile; //!< セーブファイルのフルパス
-extern std::string savefile_base; //!< セーブファイル名
+extern std::filesystem::path savefile_base; //!< セーブファイル名
 
 extern std::filesystem::path ANGBAND_DIR;
 extern std::filesystem::path ANGBAND_DIR_APEX;
index 3ffe7c9..4eb66c2 100644 (file)
@@ -57,7 +57,7 @@ std::string get_ordinal_number_suffix(int num)
 static bool open_diary_file(FILE **fff, bool *disable_diary)
 {
     std::stringstream ss;
-    ss << _("playrecord-", "playrec-") << savefile_base << ".txt";
+    ss << _("playrecord-", "playrec-") << savefile_base.string() << ".txt";
     const auto path = path_build(ANGBAND_DIR_USER, ss.str());
     *fff = angband_fopen(path, FileOpenMode::APPEND);
     if (*fff) {
index d25c596..333e8b0 100644 (file)
@@ -107,11 +107,11 @@ void process_player_name(PlayerType *player_ptr, bool is_new_savefile)
 
     if (is_modified || savefile_base.empty()) {
 #ifdef SAVEFILE_USE_UID
-        const auto &savefile_str = savefile.filename().string();
+        const auto savefile_str = savefile.filename().string();
         const auto split = str_split(savefile_str, '.');
         savefile_base = split[1];
 #else
-        savefile_base = savefile.filename().string();
+        savefile_base = savefile.filename();
 #endif
     }