Merge pull request #2512 from spnethw/tmppanel_fix_menu_from_file_list_crash
[far2l.git] / multiarc / src / arccfg.cpp
blob75586e4a9235328f10b3a295fad29d3ab41fa6ec
1 #include "MultiArc.hpp"
2 #include "marclng.hpp"
3 #include <farkeys.h>
5 bool ConfigGeneral()
7 struct InitDialogItem InitItems[] = {
8 /* 0 */ {DI_DOUBLEBOX, 3, 1, 72, 17, 0, 0, 0, 0, (char *)MGConfigTitle},
9 /* 1 */ {DI_RADIOBUTTON, 5, 2, 0, 0, 1, 0, DIF_GROUP, 0, (char *)MGConfigHideNone},
10 /* 2 */ {DI_RADIOBUTTON, 5, 3, 0, 0, 0, 0, 0, 0, (char *)MGConfigHideView},
11 /* 3 */ {DI_RADIOBUTTON, 5, 4, 0, 0, 0, 0, 0, 0, (char *)MGConfigHideAlways},
12 /* 4 */ {DI_TEXT, 5, 5, 0, 0, 0, 0, DIF_BOXCOLOR | DIF_SEPARATOR, 0, ""},
13 /* 5 */ {DI_CHECKBOX, 5, 6, 0, 0, 0, 0, 0, 0, (char *)MGConfigProcessShiftF1},
15 /* 5 */ {DI_CHECKBOX, 5, 7, 0, 0, 0, 0, 0, 0, (char *)MGConfigAllowChangeDir},
16 /* 6 */ {DI_CHECKBOX, 5, 8, 0, 0, 0, 0, 0, 0, (char *)MGConfigUseLastHistory},
18 //* 7 */{DI_CHECKBOX,5,8,0,0,0,0,0,0,(char *)MGConfigDeleteExtFile},
19 //* 8 */{DI_CHECKBOX,5,9,0,0,0,0,0,0,(char *)MGConfigAddExtArchive},
20 /* 7 */ {DI_CHECKBOX, 5, 9, 0, 0, 0, 0, 0, 0, (char *)MGConfigAutoResetExactArcName},
21 /* 8 */
22 {DI_CHECKBOX, 5, 10, 0, 0, 0, 1, DIF_DISABLE | DIF_HIDDEN, 0, (char *)MGConfigOldDialogStyle},
24 /* 9 */ {DI_TEXT, 5, 10, 0, 0, 0, 0, DIF_BOXCOLOR | DIF_SEPARATOR, 0, ""},
25 /* 10 */ {DI_TEXT, 5, 11, 0, 0, 0, 0, 0, 0, (char *)MGConfigDizNames},
26 /* 11 */ {DI_EDIT, 5, 12, 70, 10, 0, 0, 0, 0, ""},
27 /* 12 */ {DI_CHECKBOX, 5, 13, 0, 0, 0, 0, 0, 0, (char *)MGConfigReadDiz},
28 /* 13 */ {DI_CHECKBOX, 5, 14, 0, 0, 0, 0, 0, 0, (char *)MGConfigUpdateDiz},
29 /* 14 */ {DI_TEXT, 5, 15, 0, 0, 0, 0, DIF_BOXCOLOR | DIF_SEPARATOR, 0, ""},
30 /* 15 */ {DI_BUTTON, 0, 16, 0, 0, 0, 0, DIF_CENTERGROUP, 1, (char *)MOk},
31 /* 16 */ {DI_BUTTON, 0, 16, 0, 0, 0, 0, DIF_CENTERGROUP, 0, (char *)MCancel},
34 struct FarDialogItem DialogItems[ARRAYSIZE(InitItems)];
35 InitDialogItems(InitItems, DialogItems, ARRAYSIZE(InitItems));
36 DialogItems[1].Selected = (Opt.HideOutput == 0);
37 DialogItems[2].Selected = (Opt.HideOutput == 1);
38 DialogItems[3].Selected = (Opt.HideOutput == 2);
39 DialogItems[5].Selected = Opt.ProcessShiftF1;
40 DialogItems[6].Selected = Opt.AllowChangeDir;
41 DialogItems[7].Selected = Opt.UseLastHistory;
42 // DialogItems[7].Param.Selected=Opt.DeleteExtFile;
43 // DialogItems[8].Param.Selected=Opt.AddExtArchive;
44 DialogItems[8].Selected = Opt.AdvFlags.AutoResetExactArcName;
45 CharArrayCpyZ(DialogItems[12].Data, Opt.DescriptionNames.c_str());
46 DialogItems[13].Selected = Opt.ReadDescriptions;
47 DialogItems[14].Selected = Opt.UpdateDescriptions;
48 int ExitCode = Info.Dialog(Info.ModuleNumber, -1, -1, 76, 19, "ArcSettings1", DialogItems,
49 ARRAYSIZE(DialogItems));
50 if (ExitCode == 17 || ExitCode < 0)
51 return false;
53 if (DialogItems[1].Selected)
54 Opt.HideOutput = 0;
55 else
56 Opt.HideOutput = (DialogItems[2].Selected) ? 1 : 2;
57 Opt.ProcessShiftF1 = DialogItems[5].Selected;
58 Opt.AllowChangeDir = DialogItems[6].Selected;
59 Opt.UseLastHistory = DialogItems[7].Selected;
61 // Opt.DeleteExtFile=DialogItems[7].Param.Selected;
62 // Opt.AddExtArchive=DialogItems[8].Param.Selected;
63 Opt.AdvFlags.AutoResetExactArcName = DialogItems[8].Selected;
65 Opt.DescriptionNames = DialogItems[12].Data;
66 Opt.ReadDescriptions = DialogItems[13].Selected;
67 Opt.UpdateDescriptions = DialogItems[14].Selected;
69 KeyFileHelper kfh(INI_LOCATION);
70 kfh.SetInt(INI_SECTION, "HideOutput", Opt.HideOutput);
71 kfh.SetInt(INI_SECTION, "UseLastHistory", Opt.UseLastHistory);
72 kfh.SetInt(INI_SECTION, "ProcessShiftF1", Opt.ProcessShiftF1);
73 kfh.SetString(INI_SECTION, "DescriptionNames", Opt.DescriptionNames);
74 kfh.SetInt(INI_SECTION, "ReadDescriptions", Opt.ReadDescriptions);
75 kfh.SetInt(INI_SECTION, "UpdateDescriptions", Opt.UpdateDescriptions);
76 kfh.SetInt(INI_SECTION, "AllowChangeDir", Opt.AllowChangeDir);
78 // kfh.SetInt(INI_SECTION,"DeleteExtFile",Opt.DeleteExtFile);
79 // kfh.SetInt(INI_SECTION,"AddExtArchive",Opt.AddExtArchive);
80 // kfh.SetInt(INI_SECTION,"AutoResetExactArcName",Opt.AutoResetExactArcName);
81 kfh.SetInt(INI_SECTION, "AdvFlags", (int)Opt.AdvFlags);
83 return true;
86 #define DM_INITCONFIG DM_USER + 1
87 typedef struct FORMATINFO_
89 std::string ArcFormat;
90 int PluginNumber{}, PluginType{};
91 bool FastAccess{};
92 } FORMATINFO;
94 LONG_PTR WINAPI CfgCmdProc(HANDLE hDlg, int Msg, int Param1, LONG_PTR Param2)
96 switch (Msg) {
97 case DN_INITDIALOG:
98 Info.SendDlgMessage(hDlg, DM_INITCONFIG, 0, 0);
99 break;
101 case DM_INITCONFIG: {
102 int I, J;
103 std::string Command;
104 FORMATINFO *FormatInfo = (FORMATINFO *)Info.SendDlgMessage(hDlg, DM_GETDLGDATA, 0, 0);
105 for (I = 2, J = 0; I <= 32; I+= 2, J++) {
106 Command.clear();
107 int PluginNumber = FormatInfo->PluginNumber, PluginType = FormatInfo->PluginType;
108 if (FormatInfo->FastAccess
109 || PluginClass::FormatToPlugin(FormatInfo->ArcFormat, PluginNumber, PluginType)) {
110 if (I == 32) {
111 std::string PluginFormat;
112 ArcPlugin->GetFormatName(PluginNumber, PluginType, PluginFormat, Command);
113 } else
114 ArcPlugin->GetDefaultCommands(PluginNumber, PluginType, J, Command);
116 if (!Param1) // if not Reset
118 Command = KeyFileReadSection(INI_LOCATION, FormatInfo->ArcFormat).GetString(CmdNames[J], Command.c_str());
120 SetDialogControlText(hDlg, I, Command);
122 return TRUE;
125 case DN_BTNCLICK:
126 if (Param1 == 36) {
127 Info.SendDlgMessage(hDlg, DM_INITCONFIG, 1, 0);
128 return TRUE;
130 break;
133 return Info.DefDlgProc(hDlg, Msg, Param1, Param2);
136 bool ConfigCommands(const std::string &ArcFormat, int IDFocus, bool FastAccess, int PluginNumber, int PluginType)
138 struct InitDialogItem InitItems[] = {
139 /* 00 */ {DI_DOUBLEBOX, 3, 1, 72, 20, 0, 0, 0, 0, ArcFormat.c_str()},
140 /* 01 */ {DI_TEXT, 5, 2, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsExtract},
141 /* 02 */ {DI_EDIT, 25, 2, 70, 3, 0, 0, 0, 0, ""},
142 /* 03 */ {DI_TEXT, 5, 3, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsExtractWithoutPath},
143 /* 04 */ {DI_EDIT, 25, 3, 70, 3, 0, 0, 0, 0, ""},
144 /* 05 */ {DI_TEXT, 5, 4, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsTest},
145 /* 06 */ {DI_EDIT, 25, 4, 70, 3, 0, 0, 0, 0, ""},
146 /* 07 */ {DI_TEXT, 5, 5, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsDelete},
147 /* 08 */ {DI_EDIT, 25, 5, 70, 3, 0, 0, 0, 0, ""},
148 /* 09 */ {DI_TEXT, 5, 6, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsComment},
149 /* 10 */ {DI_EDIT, 25, 6, 70, 3, 0, 0, 0, 0, ""},
150 /* 11 */ {DI_TEXT, 5, 7, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsCommentFiles},
151 /* 12 */ {DI_EDIT, 25, 7, 70, 3, 0, 0, 0, 0, ""},
152 /* 13 */ {DI_TEXT, 5, 8, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsSFX},
153 /* 14 */ {DI_EDIT, 25, 8, 70, 3, 0, 0, 0, 0, ""},
154 /* 15 */ {DI_TEXT, 5, 9, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsLock},
155 /* 16 */ {DI_EDIT, 25, 9, 70, 3, 0, 0, 0, 0, ""},
156 /* 17 */ {DI_TEXT, 5, 10, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsProtect},
157 /* 18 */ {DI_EDIT, 25, 10, 70, 3, 0, 0, 0, 0, ""},
158 /* 19 */ {DI_TEXT, 5, 11, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsRecover},
159 /* 20 */ {DI_EDIT, 25, 11, 70, 3, 0, 0, 0, 0, ""},
160 /* 21 */ {DI_TEXT, 5, 12, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsAdd},
161 /* 22 */ {DI_EDIT, 25, 12, 70, 3, 0, 0, 0, 0, ""},
162 /* 23 */ {DI_TEXT, 5, 13, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsMove},
163 /* 24 */ {DI_EDIT, 25, 13, 70, 3, 0, 0, 0, 0, ""},
164 /* 25 */ {DI_TEXT, 5, 14, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsAddRecurse},
165 /* 26 */ {DI_EDIT, 25, 14, 70, 3, 0, 0, 0, 0, ""},
166 /* 27 */ {DI_TEXT, 5, 15, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsMoveRecurse},
167 /* 28 */ {DI_EDIT, 25, 15, 70, 3, 0, 0, 0, 0, ""},
168 /* 29 */ {DI_TEXT, 5, 16, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsAllFilesMask},
169 /* 30 */ {DI_EDIT, 25, 16, 70, 3, 0, 0, 0, 0, ""},
170 /* 31 */ {DI_TEXT, 5, 17, 0, 0, 0, 0, 0, 0, (char *)MArcSettingsDefaultExt},
171 /* 32 */ {DI_EDIT, 25, 17, 70, 3, 0, 0, 0, 0, ""},
172 /* 33 */ {DI_TEXT, 3, 18, 0, 0, 0, 0, DIF_BOXCOLOR | DIF_SEPARATOR, 0, ""},
173 /* 34 */ {DI_BUTTON, 0, 19, 0, 0, 0, 0, DIF_CENTERGROUP, 1, (char *)MOk},
174 /* 35 */ {DI_BUTTON, 0, 19, 0, 0, 0, 0, DIF_CENTERGROUP, 0, (char *)MCancel},
175 /* 36 */ {DI_BUTTON, 0, 19, 0, 0, 0, 0, DIF_CENTERGROUP, 0, (char *)MReset},
178 struct FarDialogItem DialogItems[ARRAYSIZE(InitItems)];
179 int Length, MaxLength = 0, I, J;
180 InitDialogItems(InitItems, DialogItems, ARRAYSIZE(InitItems));
182 DialogItems[IDFocus].Focus = 1;
184 for (I = 1; I <= 31; I+= 2)
185 if ((Length = strlen(DialogItems[I].Data)) > MaxLength)
186 MaxLength = Length;
188 for (I = 2, J = 0; I <= 32; I+= 2, J++)
189 DialogItems[I].X1 = 6 + MaxLength;
191 FORMATINFO FormatInfo;
192 FormatInfo.ArcFormat = ArcFormat;
193 FormatInfo.FastAccess = FastAccess;
194 FormatInfo.PluginNumber = PluginNumber;
195 FormatInfo.PluginType = PluginType;
197 int ExitCode = Info.DialogEx(Info.ModuleNumber, -1, -1, 76, 22, "ArcSettings2", DialogItems,
198 ARRAYSIZE(DialogItems), 0, 0, CfgCmdProc, (LONG_PTR)&FormatInfo);
200 if (ExitCode == 35 || ExitCode < 0)
201 return false;
203 KeyFileHelper kfh(INI_LOCATION);
204 for (I = 2, J = 0; I <= 32; I+= 2, J++)
205 kfh.SetString(ArcFormat, CmdNames[J], DialogItems[I].Data);
207 return true;