2 #include "autopick/autopick-reader-writer.h"
3 #include "autopick/autopick-initializer.h"
5 #include "io/read-pref-file.h"
8 * Load an autopick preference file
10 void autopick_load_pref(player_type *player_ptr, bool disp_mes)
14 my_strcpy(buf, pickpref_filename(player_ptr, PT_WITH_PNAME), sizeof(buf));
15 errr err = process_autopick_file(player_ptr, buf);
16 if (err == 0 && disp_mes)
18 msg_format(_("%s
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\82Ü
\82µ
\82½
\81B", "Loaded '%s'."), buf);
23 my_strcpy(buf, pickpref_filename(player_ptr, PT_DEFAULT), sizeof(buf));
24 err = process_autopick_file(player_ptr, buf);
25 if (err == 0 && disp_mes)
27 msg_format(_("%s
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\82Ü
\82µ
\82½
\81B", "Loaded '%s'."), buf);
33 msg_print(_("
\8e©
\93®
\8fE
\82¢
\90Ý
\92è
\83t
\83@
\83C
\83\8b\82Ì
\93Ç
\82Ý
\8d\9e\82Ý
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B", "Failed to reload autopick preference."));
39 * Get file name for autopick preference
41 concptr pickpref_filename(player_type *player_ptr, int filename_mode)
43 static const char namebase[] = _("picktype", "pickpref");
45 switch (filename_mode)
48 return format("%s.prf", namebase);
51 return format("%s-%s.prf", namebase, player_ptr->base_name);
60 * Read whole lines of a file to memory
62 static concptr *read_text_lines(concptr filename)
64 concptr *lines_list = NULL;
70 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
71 fff = my_fopen(buf, "r");
72 if (!fff) return NULL;
74 C_MAKE(lines_list, MAX_LINES, concptr);
75 while (my_fgets(fff, buf, sizeof(buf)) == 0)
77 lines_list[lines++] = string_make(buf);
78 if (lines >= MAX_LINES - 1) break;
82 lines_list[0] = string_make("");
90 * Copy the default autopick file to the user directory
92 static void prepare_default_pickpref(player_type *player_ptr)
94 const concptr messages[] = {
95 _("
\82 \82È
\82½
\82Í
\81u
\8e©
\93®
\8fE
\82¢
\83G
\83f
\83B
\83^
\81v
\82ð
\8f\89\82ß
\82Ä
\8bN
\93®
\82µ
\82Ü
\82µ
\82½
\81B", "You have activated the Auto-Picker Editor for the first time."),
96 _("
\8e©
\93®
\8fE
\82¢
\82Ì
\83\86\81[
\83U
\81[
\90Ý
\92è
\83t
\83@
\83C
\83\8b\82ª
\82Ü
\82¾
\8f\91\82©
\82ê
\82Ä
\82¢
\82È
\82¢
\82Ì
\82Å
\81A", "Since user pref file for autopick is not yet created,"),
97 _("
\8aî
\96{
\93I
\82È
\8e©
\93®
\8fE
\82¢
\90Ý
\92è
\83t
\83@
\83C
\83\8b\82ðlib/pref/picktype.prf
\82©
\82ç
\83R
\83s
\81[
\82µ
\82Ü
\82·
\81B", "the default setting is loaded from lib/pref/pickpref.prf ."),
101 concptr filename = pickpref_filename(player_ptr, PT_DEFAULT);
102 for (int i = 0; messages[i]; i++)
104 msg_print(messages[i]);
109 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
111 user_fp = my_fopen(buf, "w");
112 if (!user_fp) return;
114 fprintf(user_fp, "#***\n");
115 for (int i = 0; messages[i]; i++)
117 fprintf(user_fp, "#*** %s\n", messages[i]);
120 fprintf(user_fp, "#***\n\n\n");
121 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
123 pref_fp = my_fopen(buf, "r");
131 while (!my_fgets(pref_fp, buf, sizeof(buf)))
133 fprintf(user_fp, "%s\n", buf);
141 * Read an autopick prefence file to memory
142 * Prepare default if no user file is found
144 concptr *read_pickpref_text_lines(player_type *player_ptr, int *filename_mode_p)
146 /* Try a filename with player name */
147 *filename_mode_p = PT_WITH_PNAME;
149 strcpy(buf, pickpref_filename(player_ptr, *filename_mode_p));
151 lines_list = read_text_lines(buf);
155 *filename_mode_p = PT_DEFAULT;
156 strcpy(buf, pickpref_filename(player_ptr, *filename_mode_p));
157 lines_list = read_text_lines(buf);
162 prepare_default_pickpref(player_ptr);
163 lines_list = read_text_lines(buf);
168 C_MAKE(lines_list, MAX_LINES, concptr);
169 lines_list[0] = string_make("");
177 * Write whole lines of memory to a file.
179 bool write_text_lines(concptr filename, concptr *lines_list)
182 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
184 fff = my_fopen(buf, "w");
185 if (!fff) return FALSE;
187 for (int lines = 0; lines_list[lines]; lines++)
189 my_fputs(fff, lines_list[lines], 1024);