OSDN Git Service

[Implement] 自動デバッグセーブの保存先をlib/save/log/に変更
authordis- <dis.rogue@gmail.com>
Sun, 31 Jan 2021 15:12:38 +0000 (00:12 +0900)
committerdis- <dis.rogue@gmail.com>
Sun, 31 Jan 2021 15:12:38 +0000 (00:12 +0900)
自動デバッグセーブをlib/save/log以下に保存するよう変更した。
また、ファイルネームをyyyy-mm-dd-hh-mm-ssにして履歴を残すようにした。

src/io/files-util.c
src/io/files-util.h
src/main-win.c
src/main/angband-initializer.c
src/player/process-name.c
src/save/save.c

index d400d28..c09656f 100644 (file)
@@ -33,6 +33,7 @@ concptr ANGBAND_DIR_HELP; //!< Help files (normal) for the online help (ascii) T
 concptr ANGBAND_DIR_INFO; //!< Help files (spoilers) for the online help (ascii) These files are portable between platforms
 concptr ANGBAND_DIR_PREF; //!< Default user "preference" files (ascii) These files are rarely portable between platforms
 concptr ANGBAND_DIR_SAVE; //!< Savefiles for current characters (binary)
+concptr ANGBAND_DIR_DEBUG_SAVE; //*< Savefiles for debug data
 concptr ANGBAND_DIR_USER; //!< User "preference" files (ascii) These files are rarely portable between platforms
 concptr ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rarely portable between platforms
 
@@ -42,6 +43,7 @@ concptr ANGBAND_DIR_XTRA; //!< Various extra files (binary) These files are rare
  */
 char savefile[1024];
 char savefile_base[40];
+char debug_savefile[1024];
 
 /*!
  * @brief プレイヤーステータスをファイルダンプ出力する
index 6060aba..7b4b9ee 100644 (file)
@@ -4,6 +4,7 @@
 
 extern char savefile[1024];
 extern char savefile_base[40];
+extern char debug_savefile[1024];
 
 extern concptr ANGBAND_DIR;
 extern concptr ANGBAND_DIR_APEX;
@@ -16,6 +17,7 @@ extern concptr ANGBAND_DIR_HELP;
 extern concptr ANGBAND_DIR_INFO;
 extern concptr ANGBAND_DIR_PREF;
 extern concptr ANGBAND_DIR_SAVE;
+extern concptr ANGBAND_DIR_DEBUG_SAVE;
 extern concptr ANGBAND_DIR_USER;
 extern concptr ANGBAND_DIR_XTRA;
 
index 162bda6..c2cc572 100644 (file)
@@ -3459,6 +3459,7 @@ static void init_stuff(void)
     validate_dir(ANGBAND_DIR_INFO, FALSE);
     validate_dir(ANGBAND_DIR_PREF, TRUE);
     validate_dir(ANGBAND_DIR_SAVE, FALSE);
+    validate_dir(ANGBAND_DIR_DEBUG_SAVE, FALSE);
     validate_dir(ANGBAND_DIR_USER, TRUE);
     validate_dir(ANGBAND_DIR_XTRA, TRUE);
     path_build(path, sizeof(path), ANGBAND_DIR_FILE, _("news_j.txt", "news.txt"));
index 0d5b230..e7ec060 100644 (file)
@@ -27,6 +27,7 @@
 #include "system/system-variables.h"
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
+#include "time.h"
 #include "util/angband-files.h"
 #include "world/world.h"
 
@@ -57,6 +58,7 @@ void init_file_paths(char *libpath, char *varpath)
     string_free(ANGBAND_DIR_HELP);
     string_free(ANGBAND_DIR_INFO);
     string_free(ANGBAND_DIR_SAVE);
+    string_free(ANGBAND_DIR_DEBUG_SAVE);
     string_free(ANGBAND_DIR_USER);
     string_free(ANGBAND_DIR_XTRA);
 
@@ -83,6 +85,8 @@ void init_file_paths(char *libpath, char *varpath)
     ANGBAND_DIR_PREF = string_make(libpath);
     strcpy(vartail, "save");
     ANGBAND_DIR_SAVE = string_make(varpath);
+    strcpy(vartail, "save\\log");
+    ANGBAND_DIR_DEBUG_SAVE = string_make(varpath);
 #ifdef PRIVATE_USER_PATH
     path_build(buf, sizeof(buf), PRIVATE_USER_PATH, VERSION_NAME);
     ANGBAND_DIR_USER = string_make(buf);
@@ -92,6 +96,12 @@ void init_file_paths(char *libpath, char *varpath)
 #endif
     strcpy(libtail, "xtra");
     ANGBAND_DIR_XTRA = string_make(libpath);
+
+    time_t now = time(NULL);
+    struct tm *t = localtime(&now);
+    char tmp[128];
+    strftime(tmp, sizeof(tmp), "%Y-%m-%d-%H-%M-%S", t);
+    path_build(debug_savefile, sizeof(debug_savefile), ANGBAND_DIR_DEBUG_SAVE, tmp);
 }
 
 /*!
index 1928dc3..a2ab2b8 100644 (file)
  */
 void process_player_name(player_type *creature_ptr, bool sf)
 {
-       char old_player_base[32] = "";
-       if (current_world_ptr->character_generated)
-               strcpy(old_player_base, creature_ptr->base_name);
+    char old_player_base[32] = "";
+    if (current_world_ptr->character_generated)
+        strcpy(old_player_base, creature_ptr->base_name);
 
-       for (int i = 0; creature_ptr->name[i]; i++)
-       {
+    for (int i = 0; creature_ptr->name[i]; i++) {
 #ifdef JP
-               if (iskanji(creature_ptr->name[i]))
-               {
-                       i++;
-                       continue;
-               }
+        if (iskanji(creature_ptr->name[i])) {
+            i++;
+            continue;
+        }
 
-               if (iscntrl((unsigned char)creature_ptr->name[i]))
+        if (iscntrl((unsigned char)creature_ptr->name[i]))
 #else
-               if (iscntrl(creature_ptr->name[i]))
+        if (iscntrl(creature_ptr->name[i]))
 #endif
-               {
-                       quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), creature_ptr->name);
-               }
-       }
-
-       int k = 0;
-       for (int i = 0; creature_ptr->name[i]; i++)
-       {
+        {
+            quit_fmt(_("'%s' という名前は不正なコントロールコードを含んでいます。", "The name '%s' contains control chars!"), creature_ptr->name);
+        }
+    }
+
+    int k = 0;
+    for (int i = 0; creature_ptr->name[i]; i++) {
 #ifdef JP
-               unsigned char c = creature_ptr->name[i];
+        unsigned char c = creature_ptr->name[i];
 #else
-               char c = creature_ptr->name[i];
+        char c = creature_ptr->name[i];
 #endif
 
 #ifdef JP
-               if (iskanji(c)) {
-                       if (k + 2 >= (int)sizeof(creature_ptr->base_name) || !creature_ptr->name[i + 1])
-                               break;
-
-                       creature_ptr->base_name[k++] = c;
-                       i++;
-                       creature_ptr->base_name[k++] = creature_ptr->name[i];
-               }
+        if (iskanji(c)) {
+            if (k + 2 >= (int)sizeof(creature_ptr->base_name) || !creature_ptr->name[i + 1])
+                break;
+
+            creature_ptr->base_name[k++] = c;
+            i++;
+            creature_ptr->base_name[k++] = creature_ptr->name[i];
+        }
 #ifdef SJIS
-               else if (iskana(c)) creature_ptr->base_name[k++] = c;
+        else if (iskana(c))
+            creature_ptr->base_name[k++] = c;
 #endif
-               else
+        else
 #endif
-                       if (!strncmp(PATH_SEP, creature_ptr->name + i, strlen(PATH_SEP)))
-                       {
-                               creature_ptr->base_name[k++] = '_';
-                               i += strlen(PATH_SEP);
-                       }
+            if (!strncmp(PATH_SEP, creature_ptr->name + i, strlen(PATH_SEP))) {
+            creature_ptr->base_name[k++] = '_';
+            i += strlen(PATH_SEP);
+        }
 #if defined(WINDOWS)
-                       else if (angband_strchr("\"*,/:;<>?\\|", c))
-                               creature_ptr->base_name[k++] = '_';
+        else if (angband_strchr("\"*,/:;<>?\\|", c))
+            creature_ptr->base_name[k++] = '_';
 #endif
-                       else if (isprint(c))
-                               creature_ptr->base_name[k++] = c;
-       }
+        else if (isprint(c))
+            creature_ptr->base_name[k++] = c;
+    }
 
-       creature_ptr->base_name[k] = '\0';
-       if (!creature_ptr->base_name[0])
-               strcpy(creature_ptr->base_name, "PLAYER");
+    creature_ptr->base_name[k] = '\0';
+    if (!creature_ptr->base_name[0])
+        strcpy(creature_ptr->base_name, "PLAYER");
 
 #ifdef SAVEFILE_MUTABLE
-       sf = TRUE;
+    sf = TRUE;
 #endif
-       if (!savefile_base[0] && savefile[0])
-       {
-               concptr s = savefile;
-               while (TRUE)
-               {
-                       concptr t;
-                       t = angband_strstr(s, PATH_SEP);
-                       if (!t)
-                               break;
-                       s = t + 1;
-               }
-
-               strcpy(savefile_base, s);
-       }
-
-       if (!savefile_base[0] || !savefile[0])
-               sf = TRUE;
-
-       if (sf)
-       {
-               char temp[128];
-               strcpy(savefile_base, creature_ptr->base_name);
+    if (!savefile_base[0] && savefile[0]) {
+        concptr s = savefile;
+        while (TRUE) {
+            concptr t;
+            t = angband_strstr(s, PATH_SEP);
+            if (!t)
+                break;
+            s = t + 1;
+        }
+
+        strcpy(savefile_base, s);
+    }
+
+    if (!savefile_base[0] || !savefile[0])
+        sf = TRUE;
+
+    if (sf) {
+        char temp[128];
+        strcpy(savefile_base, creature_ptr->base_name);
 
 #ifdef SAVEFILE_USE_UID
-               /* Rename the savefile, using the creature_ptr->player_uid and creature_ptr->base_name */
-               (void)sprintf(temp, "%d.%s", creature_ptr->player_uid, creature_ptr->base_name);
+        /* Rename the savefile, using the creature_ptr->player_uid and creature_ptr->base_name */
+        (void)sprintf(temp, "%d.%s", creature_ptr->player_uid, creature_ptr->base_name);
 #else
-               /* Rename the savefile, using the creature_ptr->base_name */
-               (void)sprintf(temp, "%s", creature_ptr->base_name);
+        /* Rename the savefile, using the creature_ptr->base_name */
+        (void)sprintf(temp, "%s", creature_ptr->base_name);
 #endif
-               path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
-       }
+        path_build(savefile, sizeof(savefile), ANGBAND_DIR_SAVE, temp);
+    }
 
-       if (current_world_ptr->character_generated && !streq(old_player_base, creature_ptr->base_name))
-       {
-               autopick_load_pref(creature_ptr, FALSE);
-       }
+    if (current_world_ptr->character_generated && !streq(old_player_base, creature_ptr->base_name)) {
+        autopick_load_pref(creature_ptr, FALSE);
+    }
 }
 
-
 /*!
  * @brief プレイヤーの名前を変更するコマンドのメインルーチン
  * Gets a name for the character, reacting to name changes.
@@ -141,29 +133,27 @@ void process_player_name(player_type *creature_ptr, bool sf)
  */
 void get_name(player_type *creature_ptr)
 {
-       char tmp[64];
-       strcpy(tmp, creature_ptr->name);
+    char tmp[64];
+    strcpy(tmp, creature_ptr->name);
 
-       if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15))
-       {
-               strcpy(creature_ptr->name, tmp);
-       }
+    if (get_string(_("キャラクターの名前を入力して下さい: ", "Enter a name for your character: "), tmp, 15)) {
+        strcpy(creature_ptr->name, tmp);
+    }
 
-       if (strlen(creature_ptr->name) == 0)
-       {
-               strcpy(creature_ptr->name, "PLAYER");
-       }
+    if (strlen(creature_ptr->name) == 0) {
+        strcpy(creature_ptr->name, "PLAYER");
+    }
 
-       strcpy(tmp, ap_ptr->title);
+    strcpy(tmp, ap_ptr->title);
 #ifdef JP
-       if (ap_ptr->no == 1)
-               strcat(tmp, "の");
+    if (ap_ptr->no == 1)
+        strcat(tmp, "の");
 #else
-       strcat(tmp, " ");
+    strcat(tmp, " ");
 #endif
-       strcat(tmp, creature_ptr->name);
+    strcat(tmp, creature_ptr->name);
 
-       term_erase(34, 1, 255);
-       c_put_str(TERM_L_BLUE, tmp, 1, 34);
-       clear_from(22);
-}
+    term_erase(34, 1, 255);
+    c_put_str(TERM_L_BLUE, tmp, 1, 34);
+    clear_from(22);
+}
\ No newline at end of file
index 9b2bb95..617c0b7 100644 (file)
@@ -282,9 +282,12 @@ bool save_player(player_type *player_ptr, save_type type)
         strcat(temp, ".old");
         safe_setuid_grab(player_ptr);
         fd_kill(temp);
-        strcpy(filename, savefile);
+
         if (type == SAVE_TYPE_DEBUG)
-            strcat(filename, ".debug");
+            strcpy(filename, debug_savefile);
+        if (type == SAVE_TYPE_NORMAL)
+            strcpy(filename, savefile);
+
         fd_move(filename, temp);
         fd_move(safe, filename);
         fd_kill(temp);