1 #include "MultiArc.hpp"
5 BOOL
PluginClass::GetFormatName(char *FormatName
, char *DefExt
)
11 return ArcPlugin
->GetFormatName(ArcPluginNumber
, ArcPluginType
, FormatName
, DefExt
? DefExt
: TempDefExt
);
14 void PluginClass::GetCommandFormat(int Command
, char *Format
, int FormatSize
)
17 char ArcFormat
[100] /*,DefExt[NM]*/;
18 /*if (!ArcPlugin->GetFormatName(ArcPluginNumber,ArcPluginType,ArcFormat,DefExt))
20 if (!GetFormatName(ArcFormat
))
22 ArcPlugin
->GetDefaultCommands(ArcPluginNumber
, ArcPluginType
, Command
, Format
);
23 KeyFileReadSection(INI_LOCATION
, ArcFormat
).GetChars(Format
, FormatSize
, CmdNames
[Command
], Format
);
26 int PluginClass::DeleteFiles(struct PluginPanelItem
*PanelItem
, int ItemsNumber
, int OpMode
)
28 char Command
[MA_MAX_SIZE_COMMAND_NAME
], AllFilesMask
[MA_MAX_SIZE_COMMAND_NAME
];
31 if ((OpMode
& OPM_SILENT
) == 0) {
32 const char *MsgItems
[] = {GetMsg(MDeleteTitle
), GetMsg(MDeleteFiles
), GetMsg(MDeleteDelete
),
33 GetMsg(MDeleteCancel
)};
35 if (ItemsNumber
== 1) {
37 FSF
.TruncPathStr(strncpy(NameMsg
, PanelItem
[0].FindData
.cFileName
, sizeof(NameMsg
) - 1),
39 FSF
.sprintf(Msg
, GetMsg(MDeleteFile
), NameMsg
);
42 if (Info
.Message(Info
.ModuleNumber
, 0, NULL
, MsgItems
, ARRAYSIZE(MsgItems
), 2) != 0)
44 if (ItemsNumber
> 1) {
46 FSF
.sprintf(Msg
, GetMsg(MDeleteNumberOfFiles
), ItemsNumber
);
48 if (Info
.Message(Info
.ModuleNumber
, FMSG_WARNING
, NULL
, MsgItems
, ARRAYSIZE(MsgItems
), 2) != 0)
52 GetCommandFormat(CMD_DELETE
, Command
, sizeof(Command
));
53 GetCommandFormat(CMD_ALLFILESMASK
, AllFilesMask
, sizeof(AllFilesMask
));
54 int IgnoreErrors
= (CurArcInfo
.Flags
& AF_IGNOREERRORS
);
55 ArcCommand
ArcCmd(PanelItem
, ItemsNumber
, Command
, ArcName
, CurDir
, "", AllFilesMask
, IgnoreErrors
, CMD_DELETE
, 0,
56 CurDir
, ItemsInfo
.Codepage
);
57 if (!IgnoreErrors
&& ArcCmd
.GetExecCode() != 0)
59 if (Opt
.UpdateDescriptions
)
60 for (int I
= 0; I
< ItemsNumber
; I
++)
61 PanelItem
[I
].Flags
|= PPIF_PROCESSDESCR
;
65 int PluginClass::ProcessHostFile(struct PluginPanelItem
*PanelItem
, int ItemsNumber
, int OpMode
)
71 static const ArcCmdMenuData MenuData
[] = {
72 {MArcCmdTest
, CMD_TEST
},
73 {MArcCmdComment
, CMD_COMMENT
},
74 {MArcCmdCommentFiles
, CMD_COMMENTFILES
},
75 {MArcCmdSFX
, CMD_SFX
},
76 {MArcCmdRecover
, CMD_RECOVER
},
77 {MArcCmdProtect
, CMD_PROTECT
},
78 {MArcCmdLock
, CMD_LOCK
},
81 char Command
[MA_MAX_SIZE_COMMAND_NAME
], AllFilesMask
[MA_MAX_SIZE_COMMAND_NAME
];
86 struct FarMenuItemEx MenuItems
[ARRAYSIZE(MenuData
)];
89 MenuItems
[ExitCode
].Flags
= MIF_SELECTED
;
92 for (size_t i
= 0; i
< ARRAYSIZE(MenuData
); i
++) {
93 GetCommandFormat(MenuData
[i
].Cmd
, Command
, sizeof(Command
));
95 MenuItems
[Count
].Text
.TextPtr
= GetMsg(MenuData
[i
].Msg
);
96 MenuItems
[Count
].Flags
|= MIF_USETEXTPTR
;
97 MenuItems
[Count
++].UserData
= MenuData
[i
].Cmd
;
103 MenuItems
[0].UserData
= 0xFFFFFFFF;
107 int BreakKeys
[2] = {VK_F4
, 0};
108 ExitCode
= Info
.Menu(Info
.ModuleNumber
, -1, -1, 0, FMENU_USEEXT
| FMENU_WRAPMODE
,
109 GetMsg(MArcCmdTitle
), GetMsg(MSelectF4
), "ArcCmd", BreakKeys
, &BreakCode
,
110 (FarMenuItem
*)MenuItems
, Count
);
112 if (BreakCode
== 0) // F4 pressed
114 MenuItems
[0].Flags
&= ~MIF_USETEXTPTR
;
115 GetFormatName(MenuItems
[0].Text
.Text
);
116 ConfigCommands(MenuItems
[0].Text
.Text
, 2 + MenuData
[ExitCode
].Cmd
* 2);
119 CommandType
= (int)MenuItems
[ExitCode
].UserData
;
120 if (MenuItems
[ExitCode
].UserData
== 0xFFFFFFFF)
127 WINPORT(FlushConsoleInputBuffer
)(NULL
); // GetStdHandle(STD_INPUT_HANDLE));
129 GetCommandFormat(CommandType
, Command
, sizeof(Command
));
130 GetCommandFormat(CMD_ALLFILESMASK
, AllFilesMask
, sizeof(AllFilesMask
));
131 int IgnoreErrors
= (CurArcInfo
.Flags
& AF_IGNOREERRORS
);
135 int AskVolume
= (OpMode
& (OPM_FIND
| OPM_VIEW
| OPM_EDIT
| OPM_QUICKVIEW
)) == 0 && CurArcInfo
.Volume
136 && *CurDir
== 0 && ExitCode
== 0;
137 struct PluginPanelItem MaskPanelItem
;
142 FSF
.TruncPathStr(strncpy(NameMsg
, FSF
.PointToName(ArcName
), sizeof(NameMsg
) - 1), MAX_WIDTH_MESSAGE
);
143 FSF
.sprintf(VolMsg
, GetMsg(MExtrVolume
), NameMsg
);
144 const char *MsgItems
[] = {"", VolMsg
, GetMsg(MExtrVolumeAsk1
), GetMsg(MExtrVolumeAsk2
),
145 GetMsg(MExtrVolumeSelFiles
), GetMsg(MExtrAllVolumes
)};
146 int MsgCode
= Info
.Message(Info
.ModuleNumber
, 0, NULL
, MsgItems
, ARRAYSIZE(MsgItems
), 2);
150 ZeroFill(MaskPanelItem
);
151 strncpy(MaskPanelItem
.FindData
.cFileName
, AllFilesMask
,
152 ARRAYSIZE(MaskPanelItem
.FindData
.cFileName
) - 1);
153 if (ItemsInfo
.Encrypted
)
154 MaskPanelItem
.Flags
= F_ENCRYPTED
;
155 PanelItem
= &MaskPanelItem
;
160 if (strstr(Command
, "%%P") != NULL
)
161 for (int I
= 0; I
< ItemsNumber
; I
++)
162 if ((PanelItem
[I
].Flags
& F_ENCRYPTED
)
163 || (ItemsInfo
.Encrypted
164 && (PanelItem
[I
].FindData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))) {
165 if (!GetPassword(Password
, FSF
.PointToName(ArcName
)))
170 ArcCommand
ArcCmd(PanelItem
, ItemsNumber
, Command
, ArcName
, CurDir
, Password
, AllFilesMask
, IgnoreErrors
,
171 CommandType
, 0, CurDir
,
173 return IgnoreErrors
|| ArcCmd
.GetExecCode() == 0;
176 int __cdecl
FormatSort(struct FarMenuItemEx
*Item1
, struct FarMenuItemEx
*Item2
)
178 #ifdef _NEW_ARC_SORT_
179 int Temp
= (int)Item2
->UserData
- (int)Item1
->UserData
;
180 return Temp
? Temp
: (int)Item1
->UserData
== -1 ? 0 : FSF
.LStricmp(Item1
->Text
.Text
, Item2
->Text
.Text
);
182 return strcasecmp(Item1
->Text
.Text
, Item2
->Text
.Text
);
186 int PluginClass::SelectFormat(char *ArcFormat
, int AddOnly
)
188 typedef int(__cdecl
* FCmp
)(const void *, const void *);
189 struct FarMenuItemEx
*MenuItems
= NULL
, *NewMenuItems
;
190 int MenuItemsNumber
= 0;
191 char Format
[100], DefExt
[NM
];
193 int BreakKeys
[] = {VK_F4
, VK_RETURN
, 0};
196 #ifdef _NEW_ARC_SORT_
197 int SortModeIndex
= GetPrivateProfileInt("MultiArc", "SortMode", 1, IniFile
);
199 if (SortModeIndex
<= 1 || SortModeIndex
>= ARRAYSIZE(SortModes
))
202 SortMode
= SortModes
[SortModeIndex
];
205 BreakKeys
[1] = (AddOnly
) ? 0 : VK_RETURN
;
208 for (int i
= 0; i
< ArcPlugin
->FmtCount(); i
++) {
209 for (int j
= 0;; j
++) {
210 if (!ArcPlugin
->GetFormatName(i
, j
, Format
, DefExt
))
213 if (AddOnly
) // Only add to archive?
215 char Buffer
[MA_MAX_SIZE_COMMAND_NAME
];
216 ArcPlugin
->GetDefaultCommands(i
, j
, CMD_ADD
, Buffer
);
217 KeyFileReadSection(INI_LOCATION
, Format
)
218 .GetChars(Buffer
, sizeof(Buffer
), CmdNames
[CMD_ADD
], Buffer
);
223 NewMenuItems
= (struct FarMenuItemEx
*)realloc(MenuItems
,
224 (MenuItemsNumber
+ 1) * sizeof(struct FarMenuItemEx
));
225 if (NewMenuItems
== NULL
) {
229 MenuItems
= NewMenuItems
;
230 ZeroFill(MenuItems
[MenuItemsNumber
]);
231 MenuItems
[MenuItemsNumber
].UserData
= MAKEWPARAM((WORD
)i
, (WORD
)j
);
232 strncpy(MenuItems
[MenuItemsNumber
].Text
.Text
, Format
,
233 sizeof(MenuItems
[MenuItemsNumber
].Text
.Text
) - 1);
234 MenuItems
[MenuItemsNumber
].Flags
=
235 ((MenuItemsNumber
== 0 && *ArcFormat
== 0) || !strcasecmp(ArcFormat
, Format
))
238 #ifdef _NEW_ARC_SORT_
240 MenuItems
[MenuItemsNumber
].UserData
= GetPrivateProfileInt(SortMode
, Format
, 0, IniFile
);
242 MenuItems
[MenuItemsNumber
].UserData
= SortModeIndex
? 0 : -1;
248 if (MenuItemsNumber
== 0)
251 FSF
.qsort(MenuItems
, MenuItemsNumber
, sizeof(struct FarMenuItemEx
), (FCmp
)FormatSort
);
253 DWORD Flags
= FMENU_AUTOHIGHLIGHT
| FMENU_USEEXT
;
254 if (!Opt
.AdvFlags
.MenuWrapMode
)
255 Flags
|= FMENU_WRAPMODE
;
256 else if (Opt
.AdvFlags
.MenuWrapMode
== 2) {
257 CONSOLE_SCREEN_BUFFER_INFO csbi
;
258 WINPORT(GetConsoleScreenBufferInfo
)(NULL
, &csbi
); // GetStdHandle(STD_OUTPUT_HANDLE)
259 if (csbi
.dwSize
.Y
- 6 >= MenuItemsNumber
)
260 Flags
|= FMENU_WRAPMODE
;
262 ExitCode
= Info
.Menu(Info
.ModuleNumber
, -1, -1, 0, Flags
, GetMsg(MSelectArchiver
), GetMsg(MSelectF4
),
263 NULL
, BreakKeys
, &BreakCode
, (struct FarMenuItem
*)MenuItems
, MenuItemsNumber
);
265 strcpy(ArcFormat
, MenuItems
[ExitCode
].Text
.Text
);
266 if ((BreakCode
>= 0 && BreakCode
<= 1) || !AddOnly
) // F4 or Enter pressed
267 ConfigCommands(ArcFormat
, 2, TRUE
, LOWORD(MenuItems
[ExitCode
].UserData
),
268 HIWORD(MenuItems
[ExitCode
].UserData
));
279 return ExitCode
>= 0;
282 int PluginClass::FormatToPlugin(char *Format
, int &PluginNumber
, int &PluginType
)
284 char PluginFormat
[100], DefExt
[NM
];
285 for (int i
= 0; i
< ArcPlugin
->FmtCount(); i
++) {
286 for (int j
= 0;; j
++) {
287 if (!ArcPlugin
->GetFormatName(i
, j
, PluginFormat
, DefExt
))
289 if (!strcasecmp(PluginFormat
, Format
)) {
299 SHAREDSYMBOL
int WINAPI _export
Configure(int ItemNumber
);
301 int PluginClass::ProcessKey(int Key
, unsigned int ControlState
)
303 if ((ControlState
& PKF_ALT
) && Key
== VK_F6
) {
304 // HANDLE hScreen=Info.SaveScreen(0,0,-1,-1);
305 if (strstr(ArcName
, /*"FarTmp"*/ "FTMP") == NULL
) //$AA какая-то бяка баловалась
308 ArrayCpyZ(CurDir
, ArcName
);
309 char *Slash
= strrchr(CurDir
, GOOD_SLASH
);
313 // if (Slash!=CurDir && *(Slash-1)==':')
317 if (sdc_chdir(CurDir
))
318 fprintf(stderr
, "sdc_chdir('%s') - %u\n", CurDir
, errno
);
321 struct PanelInfo PInfo
;
322 Info
.Control(this, FCTL_GETPANELINFO
, &PInfo
);
323 GetFiles(PInfo
.SelectedItems
, PInfo
.SelectedItemsNumber
, FALSE
, PInfo
.CurDir
, OPM_SILENT
);
324 // Info.RestoreScreen(hScreen);
325 Info
.Control(this, FCTL_UPDATEPANEL
, (void *)1);
326 Info
.Control(this, FCTL_REDRAWPANEL
, NULL
);
327 Info
.Control(this, FCTL_UPDATEANOTHERPANEL
, (void *)1);
328 Info
.Control(this, FCTL_REDRAWANOTHERPANEL
, NULL
);
330 } else if (ControlState
== (PKF_ALT
| PKF_SHIFT
) && Key
== VK_F9
) {