2 #include "autopick/autopick-reader-writer.h"
3 #include "autopick/autopick-initializer.h"
4 #include "autopick/autopick-pref-processor.h"
6 #include "io/read-pref-file.h"
9 * Load an autopick preference file
11 void autopick_load_pref(player_type *player_ptr, bool disp_mes)
15 my_strcpy(buf, pickpref_filename(player_ptr, PT_WITH_PNAME), sizeof(buf));
16 errr err = process_autopick_file(player_ptr, buf, process_autopick_file_command);
17 if (err == 0 && disp_mes)
19 msg_format(_("%s
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\82Ü
\82µ
\82½
\81B", "Loaded '%s'."), buf);
24 my_strcpy(buf, pickpref_filename(player_ptr, PT_DEFAULT), sizeof(buf));
25 err = process_autopick_file(player_ptr, buf, process_autopick_file_command);
26 if (err == 0 && disp_mes)
28 msg_format(_("%s
\82ð
\93Ç
\82Ý
\8d\9e\82Ý
\82Ü
\82µ
\82½
\81B", "Loaded '%s'."), buf);
34 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."));
40 * Get file name for autopick preference
42 concptr pickpref_filename(player_type *player_ptr, int filename_mode)
44 static const char namebase[] = _("picktype", "pickpref");
46 switch (filename_mode)
49 return format("%s.prf", namebase);
52 return format("%s-%s.prf", namebase, player_ptr->base_name);
61 * Read whole lines of a file to memory
63 static concptr *read_text_lines(concptr filename)
65 concptr *lines_list = NULL;
71 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
72 fff = my_fopen(buf, "r");
73 if (!fff) return NULL;
75 C_MAKE(lines_list, MAX_LINES, concptr);
76 while (my_fgets(fff, buf, sizeof(buf)) == 0)
78 lines_list[lines++] = string_make(buf);
79 if (lines >= MAX_LINES - 1) break;
83 lines_list[0] = string_make("");
91 * Copy the default autopick file to the user directory
93 static void prepare_default_pickpref(player_type *player_ptr)
95 const concptr messages[] = {
96 _("
\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."),
97 _("
\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,"),
98 _("
\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 ."),
102 concptr filename = pickpref_filename(player_ptr, PT_DEFAULT);
103 for (int i = 0; messages[i]; i++)
105 msg_print(messages[i]);
110 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
112 user_fp = my_fopen(buf, "w");
113 if (!user_fp) return;
115 fprintf(user_fp, "#***\n");
116 for (int i = 0; messages[i]; i++)
118 fprintf(user_fp, "#*** %s\n", messages[i]);
121 fprintf(user_fp, "#***\n\n\n");
122 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
124 pref_fp = my_fopen(buf, "r");
132 while (!my_fgets(pref_fp, buf, sizeof(buf)))
134 fprintf(user_fp, "%s\n", buf);
142 * Read an autopick prefence file to memory
143 * Prepare default if no user file is found
145 concptr *read_pickpref_text_lines(player_type *player_ptr, int *filename_mode_p)
147 /* Try a filename with player name */
148 *filename_mode_p = PT_WITH_PNAME;
150 strcpy(buf, pickpref_filename(player_ptr, *filename_mode_p));
152 lines_list = read_text_lines(buf);
156 *filename_mode_p = PT_DEFAULT;
157 strcpy(buf, pickpref_filename(player_ptr, *filename_mode_p));
158 lines_list = read_text_lines(buf);
163 prepare_default_pickpref(player_ptr);
164 lines_list = read_text_lines(buf);
169 C_MAKE(lines_list, MAX_LINES, concptr);
170 lines_list[0] = string_make("");
178 * Write whole lines of memory to a file.
180 bool write_text_lines(concptr filename, concptr *lines_list)
183 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
185 fff = my_fopen(buf, "w");
186 if (!fff) return FALSE;
188 for (int lines = 0; lines_list[lines]; lines++)
190 my_fputs(fff, lines_list[lines], 1024);