Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / Plugins / Prefs / FileTypes / DefIconsPrefs.c
blob9bb5d62c1dd73d7b437848c4e831614f1d79ed7f
1 // DefIconsPrefs.c
2 // $Date$
3 // $Revision$
6 #include <ctype.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <exec/types.h>
11 #include <exec/execbase.h>
12 #include <exec/memory.h>
13 #include <dos/filehandler.h>
14 #include <libraries/iffparse.h>
15 #include <libraries/locale.h>
16 #include <libraries/mui.h>
17 #include <libraries/asl.h>
18 #include <utility/tagitem.h>
19 #include <datatypes/iconobject.h>
21 #define __USE_SYSBASE
23 #include <proto/exec.h>
24 #include <proto/dos.h>
25 #include <proto/utility.h>
26 #include <proto/iconobject.h>
27 #include <proto/intuition.h>
28 #include <proto/wb.h>
29 #define NO_INLINE_STDARG
30 #include <proto/muimaster.h>
32 #include <clib/alib_protos.h>
34 #include <mui/NListview_mcc.h>
35 #include <mui/NListtree_mcc.h>
36 #include <defs.h>
38 #define ScalosFileTypes_NUMBERS
39 #include STR(SCALOSLOCALE)
41 #include <stdlib.h>
42 #include <stdio.h>
43 #include <string.h>
45 #include <DefIcons.h>
47 #include "debug.h"
48 #include "FileTypesPrefs.h"
49 #include "FileTypesPrefs_proto.h"
50 #include "IconobjectMCC.h"
52 //----------------------------------------------------------------------------
54 // local data structures
56 #define IOBUFFERLEN 480
58 #define DEFICON_THEME_PREFIX "THEME:DefIcons/def_"
59 #define DEFICON_PATH_PREFIX "ENV:Sys/def_"
61 #define IS_CASE_SENSITIVE(magic) ((magic)->arg2 >= 0)
63 enum ProtectionMode
65 PROT_Set,
66 PROT_Unset,
67 PROT_Ignore,
70 //----------------------------------------------------------------------------
72 // defined in FileTypesPrefs.c
73 extern STRPTR AddFileTypeActionStrings[];
74 extern STRPTR AddFileTypeActionStringsProject[];
75 extern STRPTR AddFileTypeActionStringsDisk[];
77 //----------------------------------------------------------------------------
79 static void FillFileTypesActions(struct FileTypesPrefsInst *inst,
80 struct FileTypesEntry *fte, BOOL IsRootEntry);
81 static void TranslateMatchStringToPrintable(STRPTR Dest, size_t DestLength,
82 CONST_STRPTR Src, size_t SrcLength);
83 static void GetProtectionString(STRPTR Buffer, size_t BuffSize,
84 ULONG AndMask, ULONG CmpMask);
85 static STRPTR GetProtectionBitString(ULONG BitMask, ULONG AndMask, ULONG CmpMask,
86 ULONG MsgIdSet, ULONG MsgIdCleared,
87 STRPTR Buffer, size_t *BuffSize);
88 static void SetProtectionCycle(Object *o, ULONG BitMask,
89 ULONG AndMask, ULONG CmpMask);
90 static void SetMagicString(struct FileTypesActionEntry *fae, CONST_STRPTR String, size_t Length);
91 static size_t TranslateFromPrintable(STRPTR Buffer, size_t BuffLength,
92 CONST_STRPTR InputString);
93 static UBYTE HexValue(char ch);
94 static void SetProtectionBits(struct FileTypesActionEntry *fae,
95 enum ProtectionMode Protect, ULONG Mask);
96 static struct FileTypesActionListEntry *AddFileTypesAction(struct FileTypesEntry *fte,
97 const struct Magic *curr, struct Node *PrevNode);
98 static void CleanupFileTypesActions(struct FileTypesEntry *fte);
99 static ULONG GetActionFromString(CONST_STRPTR ActionString);
100 static void DefIconFullName(struct FileTypesPrefsInst *inst,
101 STRPTR Path, size_t MaxLen, CONST_STRPTR FileTypeName);
102 static void InvokeWBInfo(struct FileTypesPrefsInst *inst,
103 BPTR DirLock, STRPTR DefIconName);
104 static void SelectFileType(struct FileTypesPrefsInst *inst, const struct TypeNode *tn);
105 static struct MUI_NListtree_TreeNode *GetRootEntry(struct FileTypesPrefsInst *inst,
106 struct MUI_NListtree_TreeNode *ln);
108 //----------------------------------------------------------------------------
110 static void FillFileTypesActions(struct FileTypesPrefsInst *inst,
111 struct FileTypesEntry *fte, BOOL IsRootEntry)
113 d1(KPrintF(__FILE__ "/%s/%ld: fte=%08lx <%s> IsRootEntry=%ld\n", __FUNC__, __LINE__, fte, fte->fte_TypeNode.tn_Name, IsRootEntry));
115 if (fte)
117 struct FileTypesActionListEntry *ftale;
119 // OBJNDX_String_FileTypes_Name is read-only for root entries
120 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Name],
121 MUIA_Disabled, IsRootEntry);
123 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Name], MUIA_String_Contents,
124 fte->fte_TypeNode.tn_Name);
126 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
127 MUIM_NList_Clear);
128 set(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
129 MUIA_NList_Quiet, MUIV_NList_Quiet_Full);
132 for (ftale = (struct FileTypesActionListEntry *) fte->fte_MagicList.lh_Head;
133 ftale != (struct FileTypesActionListEntry *) &fte->fte_MagicList.lh_Tail;
134 ftale = (struct FileTypesActionListEntry *) ftale->ftale_Node.ln_Succ)
136 d1(KPrintF(__FILE__ "/%s/%ld: ftale=%08lx action=%ld\n", \
137 __FUNC__, __LINE__, ftale, ftale->ftale_Magic.action));
139 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
140 MUIM_NList_InsertSingle,
141 ftale,
142 MUIV_NList_Insert_Bottom);
145 set(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
146 MUIA_NList_Quiet, MUIV_NList_Quiet_None);
150 //----------------------------------------------------------------------------
152 SAVEDS(APTR) INTERRUPT FileTypesActionConstructFunc(struct Hook *hook, APTR obj, struct NList_ConstructMessage *ltcm)
154 struct FileTypesActionListEntry *ftale = ltcm->entry;
155 struct FileTypesActionEntry *fae = (struct FileTypesActionEntry *) AllocPooled(ltcm->pool, sizeof(struct FileTypesActionEntry));
157 d1(KPrintF(__FILE__ "/%s/%ld: obj=%08lx ltcm=%08lx memPool=%08lx UserData=%08lx\n", \
158 __FUNC__, __LINE__, obj, ltcm, ltcm->pool, ltcm->entry));
159 d1(KPrintF(__FILE__ "/%s/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
161 if (fae)
163 fae->fae_ftale = ftale;
166 return fae;
169 SAVEDS(void) INTERRUPT FileTypesActionDestructFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
171 struct FileTypesActionEntry *fae = ltdm->entry;
173 d1(KPrintF(__FILE__ "/%s/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
174 if (fae)
176 FreePooled(ltdm->pool, fae, sizeof(struct FileTypesActionEntry));
177 ltdm->entry = NULL;
181 SAVEDS(ULONG) INTERRUPT FileTypesActionDisplayFunc(struct Hook *hook, APTR obj, struct NList_DisplayMessage *ltdm)
183 struct FileTypesActionEntry *fae = ltdm->entry;
185 d1(KPrintF(__FILE__ "/%s/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
187 if (fae)
189 char TempString[80];
191 d1(KPrintF(__FILE__ "/%s/%ld: action=%d\n", __FUNC__, __LINE__, fae->fae_ftale->ftale_Magic.action));
193 ltdm->preparses[0] = "";
195 strcpy(fae->fae_ActionAttrs, "");
197 switch (fae->fae_ftale->ftale_Magic.action)
199 case ACT_MATCH:
200 ltdm->strings[0] = AddFileTypeActionStrings[0];
201 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
202 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
203 sprintf(fae->fae_ActionAttrs, "%lu \"%s\"%s",
204 (unsigned long) fae->fae_ftale->ftale_Magic.arg1,
205 TempString,
206 IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic) ? GetLocString(MSGID_FILETYPESACTION_CASE_SENSITIVE) : (STRPTR) "");
207 break;
208 case ACT_SEARCH:
209 ltdm->strings[0] = AddFileTypeActionStrings[1];
210 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
211 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
212 sprintf(fae->fae_ActionAttrs, "\"%s\"%s",
213 TempString,
214 IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic) ? GetLocString(MSGID_FILETYPESACTION_CASE_SENSITIVE) : (STRPTR) "");
215 break;
216 case ACT_SEARCHSKIPSPACES:
217 ltdm->strings[0] = AddFileTypeActionStrings[1];
218 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
219 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
220 sprintf(fae->fae_ActionAttrs, "\"%s\"%s%s",
221 TempString,
222 GetLocString(MSGID_FILETYPESACTION_SKIP_SPACES),
223 IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic) ? GetLocString(MSGID_FILETYPESACTION_CASE_SENSITIVE) : (STRPTR) "");
224 break;
225 case ACT_DOSDEVICE:
226 ltdm->strings[0] = AddFileTypeActionStrings[7];
227 sprintf(fae->fae_ActionAttrs, "\"%s\"", fae->fae_ftale->ftale_Magic.str);
228 break;
229 case ACT_DEVICENAME:
230 ltdm->strings[0] = AddFileTypeActionStrings[8];
231 sprintf(fae->fae_ActionAttrs, "\"%s\"", fae->fae_ftale->ftale_Magic.str);
232 break;
233 case ACT_CONTENTS:
234 ltdm->strings[0] = AddFileTypeActionStrings[9];
235 sprintf(fae->fae_ActionAttrs, "\"%s\"", fae->fae_ftale->ftale_Magic.str);
236 break;
237 case ACT_DOSTYPE:
238 ltdm->strings[0] = AddFileTypeActionStrings[10];
239 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
240 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
241 sprintf(fae->fae_ActionAttrs, "\"%s\"", TempString);
242 break;
243 case ACT_MINSIZEMB:
244 ltdm->strings[0] = AddFileTypeActionStrings[11];
245 sprintf(fae->fae_ActionAttrs,
246 GetLocString(MSGID_FILETYPESACTION_MINSIZEMB),
247 fae->fae_ftale->ftale_Magic.arg2);
248 break;
249 case ACT_FILESIZE:
250 ltdm->strings[0] = AddFileTypeActionStrings[2];
251 sprintf(fae->fae_ActionAttrs,
252 GetLocString(MSGID_FILETYPESACTION_FILESIZE),
253 fae->fae_ftale->ftale_Magic.arg2);
254 break;
255 case ACT_NAMEPATTERN:
256 ltdm->strings[0] = AddFileTypeActionStrings[3];
257 sprintf(fae->fae_ActionAttrs, "\"%s\"", fae->fae_ftale->ftale_Magic.str);
258 break;
259 case ACT_PROTECTION:
260 ltdm->strings[0] = AddFileTypeActionStrings[4];
261 GetProtectionString(fae->fae_ActionAttrs, sizeof(fae->fae_ActionAttrs),
262 fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
263 break;
264 case ACT_OR:
265 strcpy(fae->fae_ActionAttrs, "\033C");
266 ltdm->strings[0] = AddFileTypeActionStrings[5];
267 break;
268 case ACT_ISASCII:
269 ltdm->strings[0] = AddFileTypeActionStrings[6];
270 break;
271 case ACT_MACROCLASS:
272 ltdm->strings[0] = AddFileTypeActionStrings[12];
273 break;
274 case ACT_END:
275 default:
276 ltdm->strings[0] = "???";
277 break;
280 ltdm->strings[1] = fae->fae_ActionAttrs;
282 else
284 // display titles
285 ltdm->preparses[0] = "";
287 ltdm->strings[0] = "";
290 return 0;
293 //----------------------------------------------------------------------------
295 static void TranslateMatchStringToPrintable(STRPTR Dest, size_t DestLength,
296 CONST_STRPTR Src, size_t SrcLength)
298 while (SrcLength && DestLength > 1)
300 if (isprint(*Src) && isascii(*Src))
302 *Dest++ = *Src++;
303 SrcLength--;
304 DestLength--;
306 else
308 if (DestLength < 4 + 1)
309 break;
310 sprintf(Dest, "\\x%02x", *Src);
311 Src++;
312 SrcLength--;
313 DestLength -= strlen(Dest);
314 Dest += strlen(Dest);
317 *Dest = '\0';
320 //----------------------------------------------------------------------------
322 static void GetProtectionString(STRPTR Buffer, size_t BuffSize,
323 ULONG AndMask, ULONG CmpMask)
325 Buffer = GetProtectionBitString(FIBF_HIDDEN, AndMask, CmpMask,
326 MSGID_FILETYPESACTION_PROTECTION_H_SET,
327 MSGID_FILETYPESACTION_PROTECTION_H_CLEARED,
328 Buffer, &BuffSize);
329 Buffer = GetProtectionBitString(FIBF_SCRIPT, AndMask, CmpMask,
330 MSGID_FILETYPESACTION_PROTECTION_S_SET,
331 MSGID_FILETYPESACTION_PROTECTION_S_CLEARED,
332 Buffer, &BuffSize);
333 Buffer = GetProtectionBitString(FIBF_PURE, AndMask, CmpMask,
334 MSGID_FILETYPESACTION_PROTECTION_P_SET,
335 MSGID_FILETYPESACTION_PROTECTION_P_CLEARED,
336 Buffer, &BuffSize);
337 Buffer = GetProtectionBitString(FIBF_ARCHIVE, AndMask, CmpMask,
338 MSGID_FILETYPESACTION_PROTECTION_A_SET,
339 MSGID_FILETYPESACTION_PROTECTION_A_CLEARED,
340 Buffer, &BuffSize);
342 Buffer = GetProtectionBitString(FIBF_READ, AndMask, CmpMask,
343 MSGID_FILETYPESACTION_PROTECTION_R_SET,
344 MSGID_FILETYPESACTION_PROTECTION_R_CLEARED,
345 Buffer, &BuffSize);
346 Buffer = GetProtectionBitString(FIBF_WRITE, AndMask, CmpMask,
347 MSGID_FILETYPESACTION_PROTECTION_W_SET,
348 MSGID_FILETYPESACTION_PROTECTION_W_CLEARED,
349 Buffer, &BuffSize);
350 Buffer = GetProtectionBitString(FIBF_EXECUTE, AndMask, CmpMask,
351 MSGID_FILETYPESACTION_PROTECTION_E_SET,
352 MSGID_FILETYPESACTION_PROTECTION_E_CLEARED,
353 Buffer, &BuffSize);
354 /* Buffer = */ GetProtectionBitString(FIBF_DELETE, AndMask, CmpMask,
355 MSGID_FILETYPESACTION_PROTECTION_D_SET,
356 MSGID_FILETYPESACTION_PROTECTION_D_CLEARED,
357 Buffer, &BuffSize);
361 //----------------------------------------------------------------------------
363 static STRPTR GetProtectionBitString(ULONG BitMask, ULONG AndMask, ULONG CmpMask,
364 ULONG MsgIdSet, ULONG MsgIdCleared,
365 STRPTR Buffer, size_t *BuffSize)
367 if (BitMask & AndMask)
369 if (BitMask & CmpMask)
370 stccpy(Buffer, GetLocString(MsgIdSet), *BuffSize);
371 else
372 stccpy(Buffer, GetLocString(MsgIdCleared), *BuffSize);
374 else
375 stccpy(Buffer, GetLocString(MSGID_FILETYPESACTION_PROTECTION_IGNORE), *BuffSize);
377 *BuffSize -= strlen(Buffer);
379 return Buffer + strlen(Buffer);
382 //----------------------------------------------------------------------------
384 static void SetProtectionCycle(Object *o, ULONG BitMask,
385 ULONG AndMask, ULONG CmpMask)
387 if (BitMask & AndMask)
389 if (BitMask & CmpMask)
390 set(o, MUIA_Cycle_Active, 0); // set
391 else
392 set(o, MUIA_Cycle_Active, 1); // unset
394 else
396 set(o, MUIA_Cycle_Active, 2); // ignore
400 //----------------------------------------------------------------------------
402 void SetFileTypesIcon(struct FileTypesPrefsInst *inst, struct MUI_NListtree_TreeNode *ln)
404 BOOL FoundNative = TRUE;
406 while (ln)
408 struct FileTypesEntry *fte = (struct FileTypesEntry *) ln->tn_User;
410 d1(KPrintF(__FILE__ "/%s/%ld: fte=%08lx\n", __FUNC__, __LINE__, fte));
411 if (fte)
413 d1(KPrintF(__FILE__ "/%s/%ld: fte=%08lx <%s>\n", __FUNC__, __LINE__, fte, fte->fte_TypeNode.tn_Name));
415 if (DisplayFileTypesIcon(inst, fte->fte_TypeNode.tn_Name))
416 break;
419 FoundNative = FALSE;
421 ln = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
422 MUIM_NListtree_GetEntry,
424 MUIV_NListtree_GetEntry_Position_Parent, 0);
427 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_CreateIcon],
428 MUIA_Disabled, FoundNative);
429 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_EditIcon],
430 MUIA_Disabled, !FoundNative);
433 //----------------------------------------------------------------------------
435 SAVEDS(ULONG) INTERRUPT SelectFileTypesEntryHookFunc(struct Hook *hook, Object *o, Msg msg)
437 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
438 struct MUI_NListtree_TreeNode *ln = NULL;
440 // Make sure Popobject is closed
441 DoMethod(inst->fpb_Objects[OBJNDX_Popobject_FileTypes_Methods_Add],
442 MUIM_Popstring_Close, FALSE);
444 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
446 d1(KPrintF("%s/%s/%ld: inst=%08lx ln=%08lx\n", __FILE__, __FUNC__, __LINE__, inst, ln));
448 if (ln)
450 struct FileTypesEntry *fte = (struct FileTypesEntry *) ln->tn_User;
451 struct MUI_NListtree_TreeNode *lnRoot;
452 struct MUI_NListtree_TreeNode *pln;
453 ULONG Level;
455 for (pln = ln, Level = 0; pln && Level < 5; Level++)
457 pln = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
458 MUIM_NListtree_GetEntry, pln,
459 MUIV_NListtree_GetEntry_Position_Parent, 0);
460 d1(KPrintF("%s/%s/%ld: pln=%08lx <%s> Level=%lu\n", __FILE__, __FUNC__, __LINE__, \
461 pln, pln ? pln->tn_Name : (STRPTR) "", Level));
464 d1(KPrintF("%s/%s/%ld: pln=%08lx pln=%08lx\n", __FILE__, __FUNC__, __LINE__, pln + 0, pln + 1));
465 d1(KPrintF("%s/%s/%ld: Level=%lu\n", __FILE__, __FUNC__, __LINE__, Level));
467 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Name], MUIA_Disabled, FALSE);
468 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Remove], MUIA_Disabled, FALSE);
470 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Actions_Learn], MUIA_Disabled, FALSE);
471 set(inst->fpb_Objects[OBJNDX_Popobject_FileTypes_Methods_Add], MUIA_Disabled, FALSE);
473 lnRoot = GetRootEntry(inst, ln);
475 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods_Add],
476 MUIM_NList_Clear);
477 if (0 == Stricmp(lnRoot->tn_Name, "Project"))
479 d1(KPrintF("%s/%s/%ld: Add Project\n", __FILE__, __FUNC__, __LINE__));
481 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods_Add],
482 MUIM_NList_Insert, AddFileTypeActionStringsProject,
483 -1, MUIV_NList_Insert_Sorted, 0);
485 else if (0 == Stricmp(lnRoot->tn_Name, "Disk"))
487 d1(KPrintF("%s/%s/%ld: Add Disk\n", __FILE__, __FUNC__, __LINE__));
489 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods_Add],
490 MUIM_NList_Insert, AddFileTypeActionStringsDisk,
491 -1, MUIV_NList_Insert_Sorted, 0);
493 set(inst->fpb_Objects[OBJNDX_Menu_ExpandFileTypes], MUIA_Menuitem_Enabled, TRUE);
494 set(inst->fpb_Objects[OBJNDX_Menu_CollapseFileTypes], MUIA_Menuitem_Enabled, TRUE);
496 set(inst->fpb_Objects[OBJNDX_Text_FileTypes_FileTypesName],
497 MUIA_Text_Contents, fte->fte_TypeNode.tn_Name);
499 FillFileTypesActions(inst, fte, Level <= 2);
501 SetFileTypesIcon(inst, ln);
503 // Select corresponding entry in OBJNDX_MainListTree
504 SelectFileType(inst, &fte->fte_TypeNode);
506 else
508 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
509 MUIM_NList_Clear);
511 set(inst->fpb_Objects[OBJNDX_Text_FileTypes_FileTypesName],
512 MUIA_Text_Contents, "");
514 set(inst->fpb_Objects[OBJNDX_Menu_ExpandFileTypes], MUIA_Menuitem_Enabled, TRUE);
515 set(inst->fpb_Objects[OBJNDX_Menu_CollapseFileTypes], MUIA_Menuitem_Enabled, TRUE);
517 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Actions_Remove], MUIA_Disabled, TRUE);
518 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Actions_Learn], MUIA_Disabled, TRUE);
519 set(inst->fpb_Objects[OBJNDX_Popobject_FileTypes_Methods_Add], MUIA_Disabled, TRUE);
521 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Name], MUIA_Disabled, TRUE);
522 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Remove], MUIA_Disabled, TRUE);
524 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods_Add],
525 MUIM_NList_Clear);
528 return 0;
531 //----------------------------------------------------------------------------
533 SAVEDS(ULONG) INTERRUPT SelectFileTypesActionEntryHookFunc(struct Hook *hook, Object *o, Msg msg)
535 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
536 struct FileTypesActionEntry *fae;
537 ULONG n;
538 ULONG visibleNdx = 0;
540 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
542 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
543 MUIM_NList_GetEntry,
544 MUIV_NList_GetEntry_Active, &fae);
546 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
548 if (fae)
550 char TempString[80];
552 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx action=%ld\n", __FUNC__, __LINE__, fae, fae->fae_ftale->ftale_Magic.action));
554 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Actions_Remove], MUIA_Disabled, FALSE);
556 switch (fae->fae_ftale->ftale_Magic.action)
558 case ACT_MATCH:
559 set(inst->fpb_Objects[OBJNDX_String_Filetypes_Actions_Match_Offset], MUIA_String_Integer, fae->fae_ftale->ftale_Magic.arg1);
560 set(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Match_Case], MUIA_Selected, IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic));
561 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
562 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
563 set(inst->fpb_Objects[OBJNDX_String_Filetypes_Actions_Match_Match], MUIA_String_Contents, TempString);
565 visibleNdx = OBJNDX_Group_Filetypes_Actions_Match;
566 break;
568 case ACT_SEARCH:
569 set(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Search_SkipSpaces], MUIA_Selected, FALSE);
570 set(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Search_Case], MUIA_Selected, IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic));
571 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
572 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
573 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Search_Search], MUIA_String_Contents, TempString);
575 visibleNdx =OBJNDX_Group_Filetypes_Actions_Search;
576 break;
578 case ACT_SEARCHSKIPSPACES:
579 set(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Search_SkipSpaces], MUIA_Selected, TRUE);
580 set(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Search_Case], MUIA_Selected, IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic));
581 TranslateMatchStringToPrintable(TempString, sizeof(TempString),
582 fae->fae_ftale->ftale_Magic.str, abs(fae->fae_ftale->ftale_Magic.arg2));
583 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Search_Search], MUIA_String_Contents, TempString);
585 visibleNdx = OBJNDX_Group_Filetypes_Actions_Search;
586 break;
588 case ACT_FILESIZE:
589 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Filesize_Filesize], MUIA_String_Integer, fae->fae_ftale->ftale_Magic.arg2);
590 visibleNdx = OBJNDX_Group_Filetypes_Actions_Filesize;
591 break;
593 case ACT_MINSIZEMB:
594 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_MinSizeMB_MinSize], MUIA_String_Integer, fae->fae_ftale->ftale_Magic.arg2);
595 visibleNdx =OBJNDX_Group_FileTypes_Action_MinSizeMB;
596 break;
598 case ACT_NAMEPATTERN:
599 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Pattern_Pattern], MUIA_String_Contents, fae->fae_ftale->ftale_Magic.str);
600 visibleNdx =OBJNDX_Group_Filetypes_Actions_Pattern;
601 break;
603 case ACT_DOSDEVICE:
604 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_DosDevice_Pattern], MUIA_String_Contents, fae->fae_ftale->ftale_Magic.str);
605 visibleNdx = OBJNDX_Group_Filetypes_Actions_DosDevice;
606 break;
608 case ACT_DEVICENAME:
609 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_DeviceName_Pattern], MUIA_String_Contents, fae->fae_ftale->ftale_Magic.str);
610 visibleNdx = OBJNDX_Group_Filetypes_Actions_DeviceName;
611 break;
613 case ACT_CONTENTS:
614 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Contents_Pattern], MUIA_String_Contents, fae->fae_ftale->ftale_Magic.str);
615 visibleNdx = OBJNDX_Group_Filetypes_Actions_Contents;
616 break;
618 case ACT_DOSTYPE:
619 set(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_DosType_Pattern], MUIA_String_Contents, fae->fae_ftale->ftale_Magic.str);
620 visibleNdx = OBJNDX_Group_Filetypes_Actions_DosType;
621 break;
623 case ACT_PROTECTION:
624 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_R],
625 FIBF_READ, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
626 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_W],
627 FIBF_WRITE, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
628 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_E],
629 FIBF_EXECUTE, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
630 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_D],
631 FIBF_DELETE, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
632 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_H],
633 FIBF_HIDDEN, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
634 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_S],
635 FIBF_SCRIPT, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
636 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_P],
637 FIBF_PURE, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
638 SetProtectionCycle(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_A],
639 FIBF_ARCHIVE, fae->fae_ftale->ftale_Magic.arg1, fae->fae_ftale->ftale_Magic.arg2);
641 visibleNdx = OBJNDX_Group_Filetypes_Actions_Protection;
642 break;
644 case ACT_OR:
645 case ACT_ISASCII:
646 case ACT_MACROCLASS:
647 case ACT_END:
648 visibleNdx = OBJNDX_Group_Filetypes_Actions_Empty;
649 break;
652 else
654 set(inst->fpb_Objects[OBJNDX_Button_FileTypes_Actions_Remove], MUIA_Disabled, TRUE);
655 visibleNdx = OBJNDX_Group_Filetypes_Actions_Empty;
658 for (n = OBJNDX_Group_Filetypes_Actions_Protection;
659 n <= OBJNDX_Group_Filetypes_Actions_DosType; n++)
661 set(inst->fpb_Objects[n], MUIA_ShowMe, n == visibleNdx);
664 return 0;
667 //----------------------------------------------------------------------------
669 SAVEDS(void) INTERRUPT ChangedFileTypesActionMatchMatchHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
671 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
672 struct FileTypesActionEntry *fae;
674 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
676 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
677 MUIM_NList_GetEntry,
678 MUIV_NList_GetEntry_Active, &fae);
680 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
682 if (fae && ACT_MATCH == fae->fae_ftale->ftale_Magic.action)
684 char TempString[255];
685 CONST_STRPTR MatchString = NULL;
686 size_t Length;
688 get(inst->fpb_Objects[OBJNDX_String_Filetypes_Actions_Match_Match], MUIA_String_Contents, &MatchString);
690 Length = TranslateFromPrintable(TempString, sizeof(TempString), MatchString);
692 SetMagicString(fae, TempString, Length);
694 if (IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic))
695 fae->fae_ftale->ftale_Magic.arg2 = Length;
696 else
697 fae->fae_ftale->ftale_Magic.arg2 = -Length;
699 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
700 MUIM_NList_RedrawEntry, fae);
704 SAVEDS(void) INTERRUPT ChangedFileTypesActionMatchCaseHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
706 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
707 struct FileTypesActionEntry *fae;
709 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
711 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
712 MUIM_NList_GetEntry,
713 MUIV_NList_GetEntry_Active, &fae);
715 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
717 if (fae && ACT_MATCH == fae->fae_ftale->ftale_Magic.action)
719 size_t Length = abs(fae->fae_ftale->ftale_Magic.arg2);
720 ULONG MatchCase = 0;
722 get(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Match_Case], MUIA_Selected, &MatchCase);
724 if (MatchCase)
725 fae->fae_ftale->ftale_Magic.arg2 = Length;
726 else
727 fae->fae_ftale->ftale_Magic.arg2 = -Length;
729 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
730 MUIM_NList_RedrawEntry, fae);
734 SAVEDS(void) INTERRUPT ChangedFileTypesActionMatchOffsetHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
736 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
737 struct FileTypesActionEntry *fae;
739 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
741 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
742 MUIM_NList_GetEntry,
743 MUIV_NList_GetEntry_Active, &fae);
745 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
747 if (fae && ACT_MATCH == fae->fae_ftale->ftale_Magic.action)
749 ULONG MatchOffset = 0;
751 get(inst->fpb_Objects[OBJNDX_String_Filetypes_Actions_Match_Offset], MUIA_String_Integer, &MatchOffset);
753 fae->fae_ftale->ftale_Magic.arg1 = MatchOffset;
755 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
756 MUIM_NList_RedrawEntry, fae);
760 SAVEDS(void) INTERRUPT ChangedFileTypesActionSearchSearchHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
762 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
763 struct FileTypesActionEntry *fae;
765 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
767 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
768 MUIM_NList_GetEntry,
769 MUIV_NList_GetEntry_Active, &fae);
771 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
773 if (fae && (ACT_SEARCH == fae->fae_ftale->ftale_Magic.action || ACT_SEARCHSKIPSPACES == fae->fae_ftale->ftale_Magic.action))
775 char TempString[255];
776 CONST_STRPTR SearchString = NULL;
777 size_t Length;
779 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Search_Search], MUIA_String_Contents, &SearchString);
781 Length = TranslateFromPrintable(TempString, sizeof(TempString), SearchString);
783 if (IS_CASE_SENSITIVE(&fae->fae_ftale->ftale_Magic))
784 fae->fae_ftale->ftale_Magic.arg2 = Length;
785 else
786 fae->fae_ftale->ftale_Magic.arg2 = -Length;
788 SetMagicString(fae, TempString, Length);
790 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
791 MUIM_NList_RedrawEntry, fae);
795 SAVEDS(void) INTERRUPT ChangedFileTypesActionSearchCaseHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
797 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
798 struct FileTypesActionEntry *fae;
800 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
802 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
803 MUIM_NList_GetEntry,
804 MUIV_NList_GetEntry_Active, &fae);
806 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
808 if (fae && (ACT_SEARCH == fae->fae_ftale->ftale_Magic.action || ACT_SEARCHSKIPSPACES == fae->fae_ftale->ftale_Magic.action))
810 ULONG SearchCaseSensitive = 0;
811 size_t Length = abs(fae->fae_ftale->ftale_Magic.arg2);
813 get(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Search_Case], MUIA_Selected, &SearchCaseSensitive);
815 if (SearchCaseSensitive)
816 fae->fae_ftale->ftale_Magic.arg2 = Length;
817 else
818 fae->fae_ftale->ftale_Magic.arg2 = -Length;
820 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
821 MUIM_NList_RedrawEntry, fae);
825 SAVEDS(void) INTERRUPT ChangedFileTypesActionSearchSkipSpacesHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
827 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
828 struct FileTypesActionEntry *fae;
830 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
832 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
833 MUIM_NList_GetEntry,
834 MUIV_NList_GetEntry_Active, &fae);
836 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
838 if (fae && (ACT_SEARCH == fae->fae_ftale->ftale_Magic.action || ACT_SEARCHSKIPSPACES == fae->fae_ftale->ftale_Magic.action))
840 ULONG SkipSpaces = 0;
842 get(inst->fpb_Objects[OBJNDX_Checkmark_FileTypes_Action_Search_SkipSpaces], MUIA_Selected, &SkipSpaces);
844 if (SkipSpaces)
845 fae->fae_ftale->ftale_Magic.action = ACT_SEARCHSKIPSPACES;
846 else
847 fae->fae_ftale->ftale_Magic.action = ACT_SEARCH;
849 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
850 MUIM_NList_RedrawEntry, fae);
854 SAVEDS(void) INTERRUPT ChangedFileTypesActionFilesizeHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
856 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
857 struct FileTypesActionEntry *fae;
859 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
861 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
862 MUIM_NList_GetEntry,
863 MUIV_NList_GetEntry_Active, &fae);
865 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
867 if (fae && ACT_FILESIZE == fae->fae_ftale->ftale_Magic.action)
869 ULONG FileSize = 0;
871 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Filesize_Filesize], MUIA_String_Integer, &FileSize);
873 fae->fae_ftale->ftale_Magic.arg2 = FileSize;
875 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
876 MUIM_NList_RedrawEntry, fae);
880 SAVEDS(void) INTERRUPT ChangedFileTypesActionMinSizeHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
882 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
883 struct FileTypesActionEntry *fae;
885 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
887 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
888 MUIM_NList_GetEntry,
889 MUIV_NList_GetEntry_Active, &fae);
891 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
893 if (fae && ACT_MINSIZEMB == fae->fae_ftale->ftale_Magic.action)
895 ULONG FileSize = 0;
897 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_MinSizeMB_MinSize], MUIA_String_Integer, &FileSize);
899 fae->fae_ftale->ftale_Magic.arg2 = FileSize;
901 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
902 MUIM_NList_RedrawEntry, fae);
905 SAVEDS(void) INTERRUPT ChangedFileTypesActionPatternHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
907 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
908 struct FileTypesActionEntry *fae;
910 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
912 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
913 MUIM_NList_GetEntry,
914 MUIV_NList_GetEntry_Active, &fae);
916 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
918 if (fae && ACT_NAMEPATTERN == fae->fae_ftale->ftale_Magic.action)
920 CONST_STRPTR Pattern = NULL;
922 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Pattern_Pattern], MUIA_String_Contents, &Pattern);
924 SetMagicString(fae, Pattern, 1 + strlen(Pattern));
926 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
927 MUIM_NList_RedrawEntry, fae);
932 SAVEDS(void) INTERRUPT ChangedFileTypesActionDosDeviceHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
934 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
935 struct FileTypesActionEntry *fae;
937 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
939 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
940 MUIM_NList_GetEntry,
941 MUIV_NList_GetEntry_Active, &fae);
943 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
945 if (fae && ACT_DOSDEVICE == fae->fae_ftale->ftale_Magic.action)
947 CONST_STRPTR Pattern = NULL;
949 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_DosDevice_Pattern], MUIA_String_Contents, &Pattern);
951 SetMagicString(fae, Pattern, 1 + strlen(Pattern));
953 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
954 MUIM_NList_RedrawEntry, fae);
959 SAVEDS(void) INTERRUPT ChangedFileTypesActionDeviceNameHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
961 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
962 struct FileTypesActionEntry *fae;
964 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
966 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
967 MUIM_NList_GetEntry,
968 MUIV_NList_GetEntry_Active, &fae);
970 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
972 if (fae && ACT_DEVICENAME == fae->fae_ftale->ftale_Magic.action)
974 CONST_STRPTR Pattern = NULL;
976 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_DeviceName_Pattern], MUIA_String_Contents, &Pattern);
978 SetMagicString(fae, Pattern, 1 + strlen(Pattern));
980 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
981 MUIM_NList_RedrawEntry, fae);
986 SAVEDS(void) INTERRUPT ChangedFileTypesActionContentsHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
988 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
989 struct FileTypesActionEntry *fae;
991 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
993 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
994 MUIM_NList_GetEntry,
995 MUIV_NList_GetEntry_Active, &fae);
997 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
999 if (fae && ACT_CONTENTS == fae->fae_ftale->ftale_Magic.action)
1001 CONST_STRPTR Pattern = NULL;
1003 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_Contents_Pattern], MUIA_String_Contents, &Pattern);
1005 SetMagicString(fae, Pattern, 1 + strlen(Pattern));
1007 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1008 MUIM_NList_RedrawEntry, fae);
1013 SAVEDS(void) INTERRUPT ChangedFileTypesActionDosTypeHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
1015 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1016 struct FileTypesActionEntry *fae;
1018 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
1020 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1021 MUIM_NList_GetEntry,
1022 MUIV_NList_GetEntry_Active, &fae);
1024 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
1026 if (fae && ACT_DOSTYPE == fae->fae_ftale->ftale_Magic.action)
1028 char TempString[255];
1029 size_t Length;
1030 CONST_STRPTR MatchString = NULL;
1032 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Action_DosType_Pattern], MUIA_String_Contents, &MatchString);
1034 Length = TranslateFromPrintable(TempString, sizeof(TempString), MatchString);
1036 SetMagicString(fae, TempString, Length);
1037 fae->fae_ftale->ftale_Magic.arg2 = Length;
1039 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1040 MUIM_NList_RedrawEntry, fae);
1045 SAVEDS(void) INTERRUPT ChangedFileTypesActionProtectionHookFunc(struct Hook *hook, APTR obj, struct NList_DestructMessage *ltdm)
1047 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1048 struct FileTypesActionEntry *fae;
1050 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
1052 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1053 MUIM_NList_GetEntry,
1054 MUIV_NList_GetEntry_Active, &fae);
1056 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
1058 if (fae && ACT_PROTECTION == fae->fae_ftale->ftale_Magic.action)
1060 ULONG Protect = 0;
1062 if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_R] == obj)
1064 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_R], MUIA_Cycle_Active, &Protect);
1065 SetProtectionBits(fae, Protect, FIBF_READ);
1067 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_W] == obj)
1069 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_W], MUIA_Cycle_Active, &Protect);
1070 SetProtectionBits(fae, Protect, FIBF_WRITE);
1072 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_E] == obj)
1074 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_E], MUIA_Cycle_Active, &Protect);
1075 SetProtectionBits(fae, Protect, FIBF_EXECUTE);
1077 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_D] == obj)
1079 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_D], MUIA_Cycle_Active, &Protect);
1080 SetProtectionBits(fae, Protect, FIBF_DELETE);
1082 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_S] == obj)
1084 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_S], MUIA_Cycle_Active, &Protect);
1085 SetProtectionBits(fae, Protect, FIBF_SCRIPT);
1087 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_P] == obj)
1089 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_P], MUIA_Cycle_Active, &Protect);
1090 SetProtectionBits(fae, Protect, FIBF_PURE);
1092 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_A] == obj)
1094 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_A], MUIA_Cycle_Active, &Protect);
1095 SetProtectionBits(fae, Protect, FIBF_ARCHIVE);
1097 else if (inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_H] == obj)
1099 get(inst->fpb_Objects[OBJNDX_Cycle_Filetypes_Protection_H], MUIA_Cycle_Active, &Protect);
1100 SetProtectionBits(fae, Protect, FIBF_HIDDEN);
1103 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1104 MUIM_NList_RedrawEntry, fae);
1108 //----------------------------------------------------------------------------
1110 static void SetMagicString(struct FileTypesActionEntry *fae, CONST_STRPTR String, size_t Length)
1112 if (fae->fae_ftale->ftale_AllocatedString)
1113 free(fae->fae_ftale->ftale_AllocatedString);
1115 fae->fae_ftale->ftale_AllocatedString = fae->fae_ftale->ftale_Magic.str = malloc(Length);
1116 if (fae->fae_ftale->ftale_Magic.str)
1117 memcpy(fae->fae_ftale->ftale_Magic.str, String, Length);
1120 //----------------------------------------------------------------------------
1122 static size_t TranslateFromPrintable(STRPTR Buffer, size_t BuffLength,
1123 CONST_STRPTR InputString)
1125 size_t DestLength = 0;
1127 d1(KPrintF(__FUNC__ "/%ld: InputString=<%s>\n", __FUNC__, __LINE__, InputString));
1129 while (BuffLength && *InputString)
1131 if ('\\' == InputString[0]
1132 && strlen(InputString) >= 4
1133 && 'x' == tolower(InputString[1])
1134 && isxdigit(InputString[2])
1135 && isxdigit(InputString[3]))
1137 *Buffer++ = (HexValue(InputString[2]) << 4)
1138 + HexValue(InputString[3]);
1139 InputString += 4; // skip "0x99"
1141 else
1143 *Buffer++ = *InputString++;
1146 DestLength++;
1147 BuffLength--;
1150 d1(KPrintF(__FUNC__ "/%ld: DestLength=%d\n", __FUNC__, __LINE__, DestLength));
1152 return DestLength;
1155 //----------------------------------------------------------------------------
1157 static UBYTE HexValue(char ch)
1159 if (isdigit(ch))
1160 return (UBYTE) (ch - '0');
1161 else
1162 return (UBYTE) (tolower(ch) + 10 - 'a');
1165 //----------------------------------------------------------------------------
1167 static void SetProtectionBits(struct FileTypesActionEntry *fae,
1168 enum ProtectionMode Protect, ULONG Mask)
1170 switch (Protect)
1172 case PROT_Set:
1173 fae->fae_ftale->ftale_Magic.arg1 |= Mask;
1174 fae->fae_ftale->ftale_Magic.arg2 |= Mask;
1175 break;
1176 case PROT_Unset:
1177 fae->fae_ftale->ftale_Magic.arg1 |= Mask;
1178 fae->fae_ftale->ftale_Magic.arg2 &= ~Mask;
1179 break;
1180 case PROT_Ignore:
1181 default:
1182 fae->fae_ftale->ftale_Magic.arg1 &= ~Mask;
1183 fae->fae_ftale->ftale_Magic.arg2 &= ~Mask;
1187 //----------------------------------------------------------------------------
1189 SAVEDS(void) INTERRUPT RenameFileTypeHookFunc(struct Hook *hook, APTR obj, Msg *msg)
1191 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1192 struct MUI_NListtree_TreeNode *ln = NULL;
1194 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
1196 if (ln)
1198 struct FileTypesEntry *fte = (struct FileTypesEntry *) ln->tn_User;
1199 CONST_STRPTR NewName = NULL;
1201 CleanupFoundNodes(inst);
1203 get(inst->fpb_Objects[OBJNDX_String_FileTypes_Name], MUIA_String_Contents, &NewName);
1205 if (fte->fte_AllocatedName)
1206 free(fte->fte_AllocatedName);
1207 fte->fte_AllocatedName = fte->fte_TypeNode.tn_Name = strdup(NewName);
1209 DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1210 MUIM_NListtree_Redraw,
1211 ln);
1213 set(inst->fpb_Objects[OBJNDX_Text_FileTypes_FileTypesName],
1214 MUIA_Text_Contents, fte->fte_TypeNode.tn_Name);
1216 SetFileTypesIcon(inst, ln);
1221 SAVEDS(void) INTERRUPT AddFileTypeHookFunc(struct Hook *hook, APTR obj, Msg *msg)
1223 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1224 struct TypeNode NewTn;
1225 struct MUI_NListtree_TreeNode *ln;
1227 memset(&NewTn, 0, sizeof(NewTn));
1229 CleanupFoundNodes(inst);
1231 NewTn.tn_Name = GetLocString(MSGID_NEW_FILETYPE);
1232 NewTn.tn_Description[0].action = ACT_END;
1234 ln = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1235 MUIM_NListtree_Insert,
1236 NewTn.tn_Name,
1237 &NewTn,
1238 MUIV_NListtree_Insert_ListNode_Active,
1239 MUIV_NListtree_Insert_PrevNode_Active,
1240 TNF_LIST);
1242 if (ln)
1244 // Make the new filetype the active one
1245 set(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, ln);
1247 // try to activate filetype name string gadget
1248 set(inst->fpb_Objects[OBJNDX_WIN_Main], MUIA_Window_ActiveObject, inst->fpb_Objects[OBJNDX_String_FileTypes_Name]);
1253 SAVEDS(void) INTERRUPT RemoveFileTypeHookFunc(struct Hook *hook, APTR obj, Msg *msg)
1255 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1256 struct MUI_NListtree_TreeNode *ln = NULL;
1258 CleanupFoundNodes(inst);
1259 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
1261 if (ln)
1263 DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1264 MUIM_NListtree_Remove,
1265 MUIV_NListtree_Remove_ListNode_Active,
1266 ln);
1271 // Close "Add method" popup
1272 SAVEDS(void) INTERRUPT AddFileTypesMethodHookFunc(struct Hook *hook, APTR obj, Msg msg)
1274 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1275 struct FileTypesActionEntry *fae;
1276 struct MUI_NListtree_TreeNode *ln = NULL;
1278 d1(KPrintF("%s/%s//%ld: inst=%08lx\n", __FILE__, __FUNC__, __LINE__, inst));
1280 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
1281 d1(KPrintF("%s/%s//%ld: ln=%08lx\n", __FILE__, __FUNC__, __LINE__, ln));
1282 if (ln)
1284 struct FileTypesEntry *fte = (struct FileTypesEntry *) ln->tn_User;
1285 CONST_STRPTR NewActionString;
1287 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1288 MUIM_NList_GetEntry,
1289 MUIV_NList_GetEntry_Active, &fae);
1291 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods_Add],
1292 MUIM_NList_GetEntry,
1293 MUIV_NList_GetEntry_Active,
1294 &NewActionString);
1295 d1(KPrintF("%s/%s//%ld: NewAction=<%s>\n", __FILE__, __FUNC__, __LINE__, NewActionString));
1297 if (NewActionString && strlen(NewActionString))
1299 struct Magic Newmg;
1300 struct FileTypesActionListEntry *ftaleNew;
1302 memset(&Newmg, 0, sizeof(Newmg));
1303 Newmg.action = GetActionFromString(NewActionString);
1304 Newmg.str = (STRPTR) "";
1305 d1(KPrintF("%s/%s//%ld: NewAction=<%s> %ld\n", __FILE__, __FUNC__, __LINE__, NewActionString, Newmg.action));
1307 ftaleNew = AddFileTypesAction(fte, &Newmg, fae ? &fae->fae_ftale->ftale_Node : NULL);
1309 if (ftaleNew)
1311 ULONG InsertPos;
1313 if (fae)
1315 InsertPos = MUIV_NList_GetPos_Start;
1317 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1318 MUIM_NList_GetPos, fae, &InsertPos);
1320 d1(KPrintF("%s/%s/%ld: InsertPos=%ld\n", __FILE__, __FUNC__, __LINE__, InsertPos));
1322 InsertPos++;
1324 else
1325 InsertPos = MUIV_NList_Insert_Bottom;
1327 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1328 MUIM_NList_InsertSingle,
1329 ftaleNew,
1330 InsertPos);
1332 // Make the new action the active one
1333 get(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods], MUIA_NList_InsertPosition, &InsertPos);
1334 set(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods], MUIA_NList_Active, InsertPos);
1339 DoMethod(inst->fpb_Objects[OBJNDX_Popobject_FileTypes_Methods_Add], MUIM_Popstring_Close, TRUE);
1343 SAVEDS(void) INTERRUPT RemoveFileTypesActionHookFunc(struct Hook *hook, APTR obj, Msg *msg)
1345 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1346 struct FileTypesActionEntry *fae;
1348 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
1350 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1351 MUIM_NList_GetEntry,
1352 MUIV_NList_GetEntry_Active, &fae);
1354 d1(KPrintF(__FUNC__ "/%ld: fae=%08lx\n", __FUNC__, __LINE__, fae));
1356 if (fae)
1358 Remove(&fae->fae_ftale->ftale_Node);
1360 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1361 MUIM_NList_Remove,
1362 MUIV_NList_Remove_Active);
1366 //----------------------------------------------------------------------------
1368 SAVEDS(APTR) INTERRUPT FileTypesConstructFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_ConstructMessage *ltcm)
1370 struct FileTypesEntry *fte;
1371 BOOL Success = FALSE;
1373 d1(kprintf(__FILE__ "/%s/%ld: obj=%08lx ltcm=%08lx memPool=%08lx UserData=%08lx\n", \
1374 __FUNC__, __LINE__, obj, ltcm, ltcm->MemPool, ltcm->UserData));
1376 do {
1377 const struct TypeNode *TnOrig = ltcm->UserData;
1378 const struct Magic *curr;
1380 fte = AllocPooled(ltcm->MemPool, sizeof(struct FileTypesEntry));
1381 d1(KPrintF(__FILE__ "/%s/%ld: fte=%08lx\n", __FUNC__, __LINE__, fte));
1382 if (NULL == fte)
1383 break;
1385 NewList(&fte->fte_MagicList);
1386 fte->fte_TypeNode = *TnOrig;
1388 fte->fte_FindStart = 0;
1389 fte->fte_FindLength = 0;
1391 fte->fte_AllocatedName2 = NULL;
1393 fte->fte_AllocatedName = fte->fte_TypeNode.tn_Name = strdup(TnOrig->tn_Name);
1394 if (NULL == fte->fte_AllocatedName)
1395 break;
1397 // add all ACT_*** entries to fte_MagicList
1398 for (curr = TnOrig->tn_Description; ACT_END != curr->action; curr++)
1400 d1(KPrintF(__FILE__ "/%s/%ld: curr=%08lx action=%ld\n", __FUNC__, __LINE__, curr, curr->action));
1402 if (!AddFileTypesAction(fte, curr, NULL))
1403 break;
1406 Success = TRUE;
1407 } while (0);
1409 if (!Success && fte)
1411 CleanupFileTypesActions(fte);
1412 if (fte->fte_AllocatedName)
1414 free(fte->fte_AllocatedName);
1415 fte->fte_AllocatedName = NULL;
1417 FreePooled(ltcm->MemPool, fte, sizeof(struct FileTypesEntry));
1418 fte = NULL;
1421 return fte;
1424 SAVEDS(void) INTERRUPT FileTypesDestructFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_DestructMessage *ltdm)
1426 struct FileTypesEntry *fte = (struct FileTypesEntry *) ltdm->UserData;
1428 d1(KPrintF(__FILE__ "/%s/%ld: fte=%08lx\n", __FUNC__, __LINE__, fte));
1430 CleanupFileTypesActions(fte);
1432 if (fte->fte_AllocatedName)
1433 free(fte->fte_AllocatedName);
1434 if (fte->fte_AllocatedName2)
1435 free(fte->fte_AllocatedName2);
1437 FreePooled(ltdm->MemPool, fte, sizeof(struct FileTypesEntry));
1438 ltdm->UserData = NULL;
1441 SAVEDS(ULONG) INTERRUPT FileTypesDisplayFunc(struct Hook *hook, APTR obj, struct MUIP_NListtree_DisplayMessage *ltdm)
1443 struct FileTypesEntry *fte = (struct FileTypesEntry *) ltdm->TreeNode->tn_User;
1445 d1(KPrintF(__FILE__ "/%s/%ld: fte=%08lx\n", __FUNC__, __LINE__, fte));
1447 if (fte)
1449 if (fte->fte_FindLength > 0)
1451 if (fte->fte_AllocatedName2)
1452 free(fte->fte_AllocatedName2);
1454 fte->fte_AllocatedName2 = malloc(1 + strlen(fte->fte_TypeNode.tn_Name) + 2 * 6);
1455 if (fte->fte_AllocatedName2)
1457 if (fte->fte_FindStart)
1458 stccpy(fte->fte_AllocatedName2, fte->fte_TypeNode.tn_Name, fte->fte_FindStart);
1459 else
1460 strcpy(fte->fte_AllocatedName2, "");
1462 strcat(fte->fte_AllocatedName2, "\0335" ); // FILLPEN
1463 strncat(fte->fte_AllocatedName2, fte->fte_TypeNode.tn_Name + fte->fte_FindStart, fte->fte_FindLength);
1464 strcat(fte->fte_AllocatedName2, MUIX_PT);
1465 strcat(fte->fte_AllocatedName2, fte->fte_TypeNode.tn_Name + fte->fte_FindStart + fte->fte_FindLength);
1467 ltdm->Array[0] = fte->fte_AllocatedName2;
1469 else
1471 ltdm->Array[0] = fte->fte_TypeNode.tn_Name;
1474 else
1476 ltdm->Array[0] = fte->fte_TypeNode.tn_Name;
1480 return 0;
1483 //----------------------------------------------------------------------------
1485 static struct FileTypesActionListEntry *AddFileTypesAction(struct FileTypesEntry *fte,
1486 const struct Magic *curr, struct Node *PrevNode)
1488 struct FileTypesActionListEntry *ftale;
1489 BOOL Success = FALSE;
1491 ftale = calloc(1, sizeof(struct FileTypesActionListEntry));
1492 if (ftale)
1494 ftale->ftale_AllocatedString = NULL;
1495 ftale->ftale_Magic = *curr;
1497 switch (curr->action)
1499 case ACT_SEARCHSKIPSPACES:
1500 case ACT_MATCH:
1501 ftale->ftale_AllocatedString = ftale->ftale_Magic.str = malloc(1 + abs(ftale->ftale_Magic.arg2));
1502 if (ftale->ftale_Magic.str)
1504 memcpy(ftale->ftale_Magic.str, curr->str, abs(ftale->ftale_Magic.arg2));
1505 Success = TRUE;
1507 break;
1508 case ACT_NAMEPATTERN:
1509 ftale->ftale_AllocatedString = ftale->ftale_Magic.str = malloc(1 + strlen(ftale->ftale_Magic.str));
1510 if (ftale->ftale_Magic.str)
1512 strcpy(ftale->ftale_Magic.str, curr->str);
1513 Success = TRUE;
1515 break;
1516 default:
1517 Success = TRUE;
1518 break;
1522 if (Success)
1524 if (PrevNode)
1525 Insert(&fte->fte_MagicList, &ftale->ftale_Node, PrevNode->ln_Pred);
1526 else
1527 AddTail(&fte->fte_MagicList, &ftale->ftale_Node);
1529 else
1531 if (ftale)
1532 free(ftale);
1533 ftale = NULL;
1536 return ftale;
1539 //----------------------------------------------------------------------------
1541 static void CleanupFileTypesActions(struct FileTypesEntry *fte)
1543 struct FileTypesActionListEntry *ftale;
1545 while ((ftale = (struct FileTypesActionListEntry *) RemTail(&fte->fte_MagicList)))
1547 if (ftale->ftale_AllocatedString)
1548 free(ftale->ftale_AllocatedString);
1549 free(ftale);
1553 //----------------------------------------------------------------------------
1555 static ULONG GetActionFromString(CONST_STRPTR ActionString)
1557 static const ULONG Actions[] =
1559 ACT_MATCH,
1560 ACT_SEARCH,
1561 ACT_FILESIZE,
1562 ACT_NAMEPATTERN,
1563 ACT_PROTECTION,
1564 ACT_OR,
1565 ACT_ISASCII,
1566 ACT_DOSDEVICE,
1567 ACT_DEVICENAME,
1568 ACT_CONTENTS,
1569 ACT_DOSTYPE,
1570 ACT_MINSIZEMB,
1571 ACT_MACROCLASS,
1573 ULONG n;
1575 for (n = 0; AddFileTypeActionStrings[n]; n++)
1577 if (n < Sizeof(Actions) &&
1578 0 == strcmp(AddFileTypeActionStrings[n], ActionString))
1580 return Actions[n];
1584 // not found -- this should never happen
1585 return ACT_END;
1588 //----------------------------------------------------------------------------
1590 SAVEDS(void) INTERRUPT FileTypesActionDragDropSortHookFunc(struct Hook *hook, APTR obj, Msg msg)
1592 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1593 struct FileTypesActionEntry *fae;
1594 struct MUI_NListtree_TreeNode *ln = NULL;
1595 ULONG InsertPosition = 0;
1597 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst));
1599 get(obj, MUIA_NList_DragSortInsert, &InsertPosition);
1600 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1601 MUIM_NList_GetEntry,
1602 InsertPosition, &fae);
1604 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
1606 if (ln && fae)
1608 struct FileTypesEntry *fte = (struct FileTypesEntry *) ln->tn_User;
1609 struct FileTypesActionEntry *faeParent = NULL;
1611 d1(KPrintF(__FUNC__ "/%ld: InsertPosition=%lu fae=%08lx\n", __FUNC__, __LINE__, InsertPosition, fae));
1613 // Remove from parent list at former position
1614 Remove(&fae->fae_ftale->ftale_Node);
1616 if (InsertPosition > 0)
1618 // Get new parent
1619 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1620 MUIM_NList_GetEntry,
1621 InsertPosition - 1, &faeParent);
1624 d1(KPrintF(__FUNC__ "/%ld: faeParent=%08lx\n", __FUNC__, __LINE__));
1626 // insert into parent list at new position
1627 if (faeParent)
1628 Insert(&fte->fte_MagicList, &fae->fae_ftale->ftale_Node, &faeParent->fae_ftale->ftale_Node);
1629 else
1630 AddHead(&fte->fte_MagicList, &fae->fae_ftale->ftale_Node);
1634 //----------------------------------------------------------------------------
1636 SAVEDS(void) INTERRUPT LearnFileTypeHookFunc(struct Hook *hook, APTR obj, Msg msg)
1638 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1639 BPTR OldDir = (BPTR)NULL;
1640 BPTR fh = (BPTR)NULL;
1641 STRPTR MergedDataBuffer = NULL;
1642 STRPTR ReadDataBuffer = NULL;
1643 UBYTE *CompareFlags = NULL;
1644 size_t BuffLength = 488;
1646 struct MUI_NListtree_TreeNode *ln = NULL;
1648 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
1650 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst, ln));
1652 do {
1653 BOOL Result;
1654 struct Window *win = NULL;
1655 ULONG n;
1656 ULONG StartOffset, Count;
1657 size_t MergedLength = BuffLength;
1658 struct MUI_NListtree_TreeNode *ln = NULL;
1659 struct FileTypesEntry *fte;
1661 get(inst->fpb_Objects[OBJNDX_NListtree_FileTypes], MUIA_NListtree_Active, &ln);
1663 d1(KPrintF(__FUNC__ "/%ld: inst=%08lx\n", __FUNC__, __LINE__, inst, ln));
1665 if (NULL == ln)
1666 break;
1668 fte = (struct FileTypesEntry *) ln->tn_User;
1670 get(inst->fpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Window, &win);
1671 if (NULL == win)
1672 break;
1674 CompareFlags = malloc(BuffLength);
1675 if (NULL == CompareFlags)
1676 break;
1678 ReadDataBuffer = malloc(BuffLength);
1679 if (NULL == ReadDataBuffer)
1680 break;
1682 MergedDataBuffer = malloc(BuffLength);
1683 if (NULL == MergedDataBuffer)
1684 break;
1686 if (NULL == inst->fpb_LearnReq)
1688 inst->fpb_LearnReq = MUI_AllocAslRequestTags(ASL_FileRequest,
1689 ASLFR_Flags1, FRF_DOPATTERNS,
1690 ASLFR_UserData, inst,
1691 ASLFR_DoMultiSelect, TRUE,
1692 ASLFR_IntuiMsgFunc, &inst->fpb_Hooks[HOOKNDX_AslIntuiMsg],
1693 TAG_END);
1696 if (NULL == inst->fpb_LearnReq)
1697 break;
1699 //AslRequest(
1700 Result = MUI_AslRequestTags(inst->fpb_LearnReq,
1701 ASLFR_Window, win,
1702 ASLFR_SleepWindow, TRUE,
1703 ASLFR_TitleText, GetLocString(MSGID_LEARN_OPEN),
1704 TAG_END);
1706 if (!Result)
1707 break;
1709 if (inst->fpb_LearnReq->fr_NumArgs < 2)
1711 MUI_Request(inst->fpb_Objects[OBJNDX_APP_Main], inst->fpb_Objects[OBJNDX_WIN_Main], 0, NULL,
1712 GetLocString(MSGID_SELECT_TWO_REQ_OK),
1713 GetLocString(MSGID_SELECT_TWO_REQ_CONTENTS));
1714 break;
1717 // read all specified sample files,
1718 // and collect equal areas
1719 for (n = 0; n < inst->fpb_LearnReq->fr_NumArgs; n++)
1721 OldDir = CurrentDir(inst->fpb_LearnReq->fr_ArgList[n].wa_Lock);
1723 // open next file
1724 fh = Open(inst->fpb_LearnReq->fr_ArgList[n].wa_Name, MODE_OLDFILE);
1725 if ((BPTR)NULL == fh)
1726 break;
1728 // Read one block
1729 MergedLength = FRead(fh, ReadDataBuffer, 1, MergedLength);
1730 if (MergedLength < 1)
1731 break;
1733 if (0 == n)
1735 // if first file, then initialize MergedDataBuffer and CompareFlags
1736 memcpy(MergedDataBuffer, ReadDataBuffer, MergedLength);
1737 memset(CompareFlags, 1, MergedLength);
1739 else
1741 // mask out all different bytes
1742 ULONG k;
1744 for (k = 0; k < MergedLength; k++)
1746 if (MergedDataBuffer[k] != ReadDataBuffer[k])
1747 CompareFlags[k] = 0;
1751 Close(fh);
1752 fh = (BPTR)NULL;
1754 CurrentDir(OldDir);
1755 OldDir = (BPTR)NULL;
1758 // now we have the common data in MergedDataBuffer,
1759 // and a 1 in CompareFlags for each byte that was
1760 // equal for all sample files
1761 for (n = Count = StartOffset= 0; n < MergedLength; n++)
1763 if (CompareFlags[n])
1765 if (0 == Count++)
1766 StartOffset = n;
1768 else
1770 // ignore all equal sections of less than 2 bytes
1771 if (Count >= 2)
1773 struct Magic Newmg;
1774 struct FileTypesActionListEntry *ftaleNew;
1776 memset(&Newmg, 0, sizeof(Newmg));
1777 Newmg.action = ACT_MATCH;
1778 Newmg.arg1 = StartOffset;
1779 Newmg.arg2 = Count;
1780 Newmg.str = MergedDataBuffer + StartOffset;
1782 ftaleNew = AddFileTypesAction(fte, &Newmg, NULL);
1784 if (ftaleNew)
1786 DoMethod(inst->fpb_Objects[OBJNDX_NListview_FileTypes_Methods],
1787 MUIM_NList_InsertSingle,
1788 ftaleNew,
1789 MUIV_NList_Insert_Bottom);
1792 Count = 0;
1795 } while (0);
1797 if (fh)
1798 Close(fh);
1799 if (OldDir)
1800 CurrentDir(OldDir);
1801 if (MergedDataBuffer)
1802 free(MergedDataBuffer);
1803 if (ReadDataBuffer)
1804 free(ReadDataBuffer);
1805 if (CompareFlags)
1806 free(CompareFlags);
1809 //----------------------------------------------------------------------------
1811 SAVEDS(void) INTERRUPT CreateNewFileTypesIconHookFunc(struct Hook *hook, APTR obj, Msg msg)
1813 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1815 if (inst->fpb_IconObject)
1817 struct MUI_NListtree_TreeNode *ln;
1819 ln = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1820 MUIM_NListtree_GetEntry,
1821 MUIV_NListtree_GetEntry_ListNode_Active,
1822 MUIV_NListtree_GetEntry_Position_Active, 0);
1823 if (ln)
1825 struct FileTypesEntry *fte = (struct FileTypesEntry *) ln->tn_User;
1826 char IconPath[MAX_FILENAME];
1827 struct TagItem ti[] = {
1828 {ICONA_NoPosition, TRUE},
1829 {TAG_END}};
1831 DefIconFullName(inst, IconPath, sizeof(IconPath),
1832 fte->fte_TypeNode.tn_Name);
1834 DoMethod(inst->fpb_IconObject,
1835 IDTM_Write,
1836 IconPath,
1837 NULL,
1838 ti);
1840 // Toggle selection of current entry to enforce re-evaluation of icon via HOOKNDX_SelectFileTypesEntry
1841 set(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1842 MUIA_NListtree_Active, MUIV_NListtree_Active_Off);
1843 set(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1844 MUIA_NListtree_Active, ln);
1849 //----------------------------------------------------------------------------
1851 SAVEDS(void) INTERRUPT EditFileTypesIconHookFunc(struct Hook *hook, APTR obj, Msg msg)
1853 struct FileTypesPrefsInst *inst = (struct FileTypesPrefsInst *) hook->h_Data;
1854 BPTR DirLock = (BPTR)NULL;
1856 do {
1857 struct MUI_NListtree_TreeNode *ln;
1858 char IconPath[MAX_FILENAME];
1859 STRPTR DefIconName = "";
1861 if (NULL == inst->fpb_IconObject)
1862 break;
1864 ln = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1865 MUIM_NListtree_GetEntry,
1866 MUIV_NListtree_GetEntry_ListNode_Active,
1867 MUIV_NListtree_GetEntry_Position_Active, 0);
1868 if (NULL == ln)
1869 break;
1871 get(inst->fpb_Objects[OBJNDX_Text_FileTypes_DefIconName], MUIA_Text_Contents, &DefIconName);
1873 stccpy(IconPath, inst->fpb_DefIconPath, sizeof(IconPath));
1874 AddPart(IconPath, DefIconName, sizeof(IconPath));
1876 DirLock = Lock(inst->fpb_DefIconPath, ACCESS_READ);
1877 if ((BPTR)NULL == DirLock)
1878 break;
1880 DefIconName = FilePart(IconPath);
1881 if (NULL == DefIconName)
1882 break;
1884 set(inst->fpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Sleep, TRUE);
1885 InvokeWBInfo(inst, DirLock, DefIconName);
1886 SetFileTypesIcon(inst, ln);
1887 set(inst->fpb_Objects[OBJNDX_WIN_Main], MUIA_Window_Sleep, FALSE);
1888 } while (0);
1890 if (DirLock)
1891 UnLock(DirLock);
1894 //----------------------------------------------------------------------------
1896 BOOL DisplayFileTypesIcon(struct FileTypesPrefsInst *inst, CONST_STRPTR FileTypesName)
1898 char IconPath[MAX_FILENAME];
1899 BOOL Success = FALSE;
1901 if (inst->fpb_IconObject)
1903 DisposeIconObject(inst->fpb_IconObject);
1904 inst->fpb_IconObject = NULL;
1907 DefIconFullName(inst, IconPath, sizeof(IconPath), FileTypesName);
1909 inst->fpb_IconObject = NewIconObject(IconPath, NULL);
1910 if (inst->fpb_IconObject)
1912 // display name of filetype
1913 set(inst->fpb_Objects[OBJNDX_Text_FileTypes_DefIconName],
1914 MUIA_Text_Contents, FilePart(IconPath));
1916 // display icon for filetype
1917 set(inst->fpb_Objects[OBJNDX_IconObjectMCC_FileTypes_Icon],
1918 MUIA_Iconobj_Object, inst->fpb_IconObject);
1920 Success = TRUE;
1923 return Success;
1926 //----------------------------------------------------------------------------
1928 static void DefIconFullName(struct FileTypesPrefsInst *inst,
1929 STRPTR Path, size_t MaxLen, CONST_STRPTR FileTypesName)
1931 stccpy(Path, inst->fpb_DefIconPath, MaxLen);
1932 AddPart(Path, "def_", MaxLen);
1933 strcat(Path, FileTypesName);
1936 //----------------------------------------------------------------------------
1938 static void InvokeWBInfo(struct FileTypesPrefsInst *inst,
1939 BPTR DirLock, STRPTR DefIconName)
1941 d1(KPrintF(__FILE__ "/%s/%ld: START DefIconName=<%s>\n", __FUNC__, __LINE__, DefIconName));
1943 WBInfo(DirLock, DefIconName, inst->fpb_WBScreen);
1945 d1(KPrintF(__FILE__ "/%s/%ld: END\n", __FUNC__, __LINE__));
1948 //----------------------------------------------------------------------------
1950 static void SelectFileType(struct FileTypesPrefsInst *inst, const struct TypeNode *tn)
1952 d1(KPrintF(__FILE__ "/%s/%ld: START tn=%08lx <%s>\n", __FUNC__, __LINE__, tn, tn->tn_Name));
1954 // first, deselect current entry
1955 set(inst->fpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Active, MUIV_NListtree_Active_Off);
1957 while (tn)
1959 struct MUI_NListtree_TreeNode *lttn;
1961 d1(KPrintF(__FILE__ "/%s/%ld: tn=%08lx <%s>\n", __FUNC__, __LINE__, tn, tn->tn_Name));
1963 lttn = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_MainListTree],
1964 MUIM_NListtree_FindName,
1965 MUIV_NListtree_FindName_ListNode_Root,
1966 tn->tn_Name,
1967 MUIV_NListtree_FindName_Flag_SameLevel);
1968 d1(KPrintF(__FILE__ "/%s/%ld: lttn=%08lx <%s>\n", __FUNC__, __LINE__, lttn, lttn ? lttn->tn_Name : ""));
1969 if (lttn)
1971 // Select correcponding entry in OBJNDX_MainListTree
1972 set(inst->fpb_Objects[OBJNDX_MainListTree], MUIA_NListtree_Active, lttn);
1973 break;
1976 tn = tn->tn_Parent;
1979 d1(KPrintF(__FILE__ "/%s/%ld: END\n", __FUNC__, __LINE__));
1982 //----------------------------------------------------------------------------
1984 static struct MUI_NListtree_TreeNode *GetRootEntry(struct FileTypesPrefsInst *inst,
1985 struct MUI_NListtree_TreeNode *ln)
1987 struct MUI_NListtree_TreeNode *lnp;
1988 struct MUI_NListtree_TreeNode *lnRoot = ln;
1990 do {
1991 lnp = (struct MUI_NListtree_TreeNode *) DoMethod(inst->fpb_Objects[OBJNDX_NListtree_FileTypes],
1992 MUIM_NListtree_GetEntry,
1994 MUIV_NListtree_GetEntry_Position_Parent,
1996 if (lnp)
1998 lnRoot = ln;
1999 ln = lnp;
2001 } while (lnp);
2003 d1(KPrintF(__FILE__ "/%s/%ld: lnRoot=%08lx <%s>\n", __FUNC__, __LINE__, lnRoot, lnRoot ? lnRoot->tn_Name : (STRPTR) ""));
2005 return lnRoot;
2008 //----------------------------------------------------------------------------