From f85934fb0e5d55672acd50b4ecbd4287bc663366 Mon Sep 17 00:00:00 2001 From: mogami Date: Tue, 4 Nov 2003 08:31:34 +0000 Subject: [PATCH] =?utf8?q?picktype.prf=E3=82=92=E3=81=BE=E3=81=A0=E6=9B=B8?= =?utf8?q?=E3=81=84=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E6=99=82=E3=81=AB?= =?utf8?q?=E3=80=81=E8=87=AA=E5=8B=95=E6=8B=BE=E3=81=84=E3=82=A8=E3=83=87?= =?utf8?q?=E3=82=A3=E3=82=BF=E3=82=92=E8=B5=B7=E5=8B=95=E3=81=99=E3=82=8B?= =?utf8?q?=E3=81=A8=E3=83=87=E3=83=95=E3=82=A9=20=E3=83=AB=E3=83=88?= =?utf8?q?=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92=E8=AA=AD=E3=81=BF=E8=BE=BC?= =?utf8?q?=E3=82=80=E3=81=8C=E3=80=81=E3=81=9D=E3=81=AE=E3=81=BE=E3=81=BE^?= =?utf8?q?Q=E3=81=A7=E7=B5=82=E4=BA=86=E3=81=99=E3=82=8B=E3=81=A8=E4=BB=8A?= =?utf8?q?=E8=A6=8B=E3=81=88=E3=81=A6=E3=81=84=E3=81=9F=E8=A8=AD=E5=AE=9A?= =?utf8?q?=E3=81=8C=E9=81=A9=E7=94=A8=E3=82=82=20=E3=82=BB=E3=83=BC?= =?utf8?q?=E3=83=96=E3=82=82=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E3=81=A8?= =?utf8?q?=E3=81=84=E3=81=86=E7=8A=B6=E6=85=8B=E3=81=A0=E3=81=A3=E3=81=9F?= =?utf8?q?=E3=80=82=E3=81=99=E3=81=90=E3=81=AB=E6=9B=B8=E3=81=8D=E8=BE=BC?= =?utf8?q?=E3=82=80=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3=E3=80=82?= =?utf8?q?=20=E3=81=BE=E3=81=9F=E3=80=81=E3=81=9D=E3=81=AE=E6=99=82?= =?utf8?q?=E3=81=AB=E3=83=87=E3=83=95=E3=82=A9=E3=83=AB=E3=83=88=E8=A8=AD?= =?utf8?q?=E5=AE=9A=E3=82=92=E6=9B=B8=E3=81=8D=E8=BE=BC=E3=82=93=E3=81=A0?= =?utf8?q?=E6=97=A8=E3=81=AE=E8=AA=AC=E6=98=8E=E3=81=8C=E5=87=BA=E3=82=8B?= =?utf8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/autopick.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 13 deletions(-) diff --git a/src/autopick.c b/src/autopick.c index aacf6c020..c1ea95563 100644 --- a/src/autopick.c +++ b/src/autopick.c @@ -2828,7 +2828,7 @@ static void describe_autopick(char *buff, autopick_type *entry) /* * Read whole lines of a file to memory */ -static cptr *read_text_lines(cptr filename, bool user) +static cptr *read_text_lines(cptr filename) { cptr *lines_list = NULL; FILE *fff; @@ -2836,14 +2836,7 @@ static cptr *read_text_lines(cptr filename, bool user) int lines = 0; char buf[1024]; - if (user) - { - path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename); - } - else - { - path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename); - } + path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename); /* Open the file */ fff = my_fopen(buf, "r"); @@ -2870,26 +2863,102 @@ static cptr *read_text_lines(cptr filename, bool user) } +/* + * Copy the default autopick file to the user directory + */ +static void prepare_default_pickpref(void) +{ + static char *messages[] = { +#ifdef JP + "¤¢¤Ê¤¿¤Ï¡Ö¼«Æ°½¦¤¤¥¨¥Ç¥£¥¿¡×¤ò½é¤á¤Æµ¯Æ°¤·¤Þ¤·¤¿¡£", + "¼«Æ°½¦¤¤¤Î¥æ¡¼¥¶¡¼ÀßÄê¥Õ¥¡¥¤¥ë¤¬¤Þ¤À½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢", + "´ðËÜŪ¤Ê¼«Æ°½¦¤¤ÀßÄê¥Õ¥¡¥¤¥ë¤òlib/pref/picktype.prf¤«¤é¥³¥Ô¡¼¤·¤Þ¤¹¡£", + NULL +#else + "You have activated the Auto-Picker Editor for the first time.", + "Since no user preference file for autopick is not yet created,", + "the default setting is loaded from lib/pref/pickpref.prf .", + NULL +#endif + }; + + char buf[1024]; + FILE *pref_fp; + FILE *user_fp; + int i; + cptr filename = pickpref_filename(PT_DEFAULT); + + /* Display messages */ + for (i = 0; messages[i]; i++) msg_print(messages[i]); + msg_print(NULL); + + + /* Open new file */ + path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename); + user_fp = my_fopen(buf, "w"); + + /* Failed */ + if (!user_fp) return; + + /* Write header messages for a notification */ + fprintf(user_fp, "#***\n"); + for (i = 0; messages[i]; i++) + { + fprintf(user_fp, "#*** %s\n", messages[i]); + } + fprintf(user_fp, "#***\n\n\n"); + + + /* Open the default file */ + path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename); + pref_fp = my_fopen(buf, "r"); + + /* Failed */ + if (!pref_fp) + { + my_fclose(user_fp); + return; + } + + /* Copy the contents of default file */ + while (!my_fgets(pref_fp, buf, sizeof(buf))) + fprintf(user_fp, "%s\n", buf); + + my_fclose(user_fp); + my_fclose(pref_fp); +} + +/* + * Read an autopick prefence file to memory + * Prepare default if no user file is found + */ static cptr *read_pickpref_text_lines(int *filename_mode_p) { char buf[1024]; cptr *lines_list; + /* Try a filename with player name */ *filename_mode_p = PT_WITH_PNAME; strcpy(buf, pickpref_filename(*filename_mode_p)); - lines_list = read_text_lines(buf, TRUE); + lines_list = read_text_lines(buf); if (!lines_list) { + /* Use default name */ *filename_mode_p = PT_DEFAULT; strcpy(buf, pickpref_filename(*filename_mode_p)); - lines_list = read_text_lines(buf, TRUE); + lines_list = read_text_lines(buf); } if (!lines_list) { - strcpy(buf, pickpref_filename(*filename_mode_p)); - lines_list = read_text_lines(buf, FALSE); + /* There is no preference file in the user directory */ + + /* Copy the default autopick file to the user directory */ + prepare_default_pickpref(); + + /* Use default name again */ + lines_list = read_text_lines(buf); } if (!lines_list) -- 2.11.0