forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / scalos / Prefs / FileTypes / FileTypes.c
blob155715659469a8ddb68891cc2011b9949ad3bb5f
1 // FileTypes.c
2 // $Date$
3 // $Revision$
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <ctype.h>
9 #include <dos/dos.h>
10 #include <exec/types.h>
11 #include <exec/memory.h>
12 #include <exec/ports.h>
13 #include <exec/io.h>
14 #include <exec/execbase.h>
15 #include <dos/dos.h>
16 #include <libraries/dos.h>
17 #include <libraries/dosextens.h>
18 #include <libraries/gadtools.h>
19 #include <libraries/asl.h>
20 #include <libraries/mui.h>
21 #include <devices/clipboard.h>
22 #include <workbench/workbench.h>
23 #include <workbench/icon.h>
24 #include <intuition/intuition.h>
25 #include <intuition/classusr.h>
26 #include <prefs/prefhdr.h>
28 #include <clib/alib_protos.h>
30 #define __USE_SYSBASE
32 #include <proto/exec.h>
33 #include <proto/dos.h>
34 #include <proto/icon.h>
35 #include <proto/intuition.h>
36 #include <proto/gadtools.h>
37 #include <proto/utility.h>
38 #include <proto/asl.h>
39 #include <proto/muimaster.h>
40 #include <proto/locale.h>
41 #include <proto/scalosprefsplugin.h>
43 #include <defs.h>
44 #include <Year.h> // +jmc+
45 #include <scalosdebug.h>
47 #include <scalos/scalosprefsplugin.h>
49 struct ScalosFileTypes_LocaleInfo
51 APTR li_LocaleBase;
52 APTR li_Catalog;
53 struct LocaleIFace *li_ILocale;
56 #define ScalosFileTypes_NUMBERS
57 #define ScalosFileTypes_ARRAY
58 #define ScalosFileTypes_CODE
59 #include STR(SCALOSLOCALE)
61 //----------------------------------------------------------------------------
63 #define Sizeof(array) (sizeof(array) / sizeof((array)[0]))
65 //----------------------------------------------------------------------------
67 #if !defined(__amigaos4__) && !defined(__AROS__)
68 #include <dos.h>
70 long _stack = 16384; // minimum stack size, used by SAS/C startup code
71 #endif
73 //----------------------------------------------------------------------------
75 // local data structures
77 #define KeyButtonHelp(name,key,HelpText)\
78 TextObject,\
79 ButtonFrame,\
80 MUIA_Font, MUIV_Font_Button,\
81 MUIA_Text_Contents, name,\
82 MUIA_Text_PreParse, "\33c",\
83 MUIA_Text_HiChar , key,\
84 MUIA_ControlChar , key,\
85 MUIA_CycleChain , TRUE, \
86 MUIA_InputMode , MUIV_InputMode_RelVerify,\
87 MUIA_Background , MUII_ButtonBack,\
88 MUIA_ShortHelp, HelpText,\
89 End
92 #define Application_Return_EDIT 0
93 #define Application_Return_USE 1001
94 #define Application_Return_SAVE 1002
96 //----------------------------------------------------------------------------
98 // local functions
100 static void init(void);
101 static void fail(APTR APP_Main, CONST_STRPTR str);
102 static BOOL OpenLibraries(void);
103 static void CloseLibraries(void);
104 static SAVEDS(APTR) INTERRUPT OpenAboutMUIFunc(struct Hook *hook, Object *o, Msg msg);
105 static STRPTR GetLocString(ULONG MsgId);
106 //static void TranslateStringArray(STRPTR *stringArray);
107 static struct MUI_CustomClass *OpenPrefsModule(CONST_STRPTR FileName);
108 static struct TagItem *CreatePluginSubWindowArray(void);
109 static void DisposePrefsPlugin(void);
110 static BOOL CheckMCCforPlugin(STRPTR *UsedClasses, size_t MaxUsedClasses);
111 static BOOL CheckMCCVersion(CONST_STRPTR name, ULONG minver, ULONG minrev);
112 #if !defined(__SASC) &&!defined(__MORPHOS__)
113 size_t stccpy(char *dest, const char *src, size_t MaxLen);
114 #endif /* !defined(__SASC) &&!defined(__MORPHOS__) */
116 //----------------------------------------------------------------------------
118 // local data items
120 struct Library *MUIMasterBase;
121 T_LOCALEBASE LocaleBase;
122 struct Library *IconBase;
123 struct IntuitionBase *IntuitionBase;
124 struct Library *ScalosPrefsPluginBase;
126 #ifdef __amigaos4__
127 extern struct Library *SysBase;
128 struct MUIMasterIFace *IMUIMaster;
129 struct LocaleIFace *ILocale;
130 struct IconIFace *IIcon;
131 struct IntuitionIFace *IIntuition;
132 struct ScalosPrefsPluginIFace *IScalosPrefsPlugin;
133 #endif
135 static struct Catalog *FileTypesCatalog;
137 static struct Hook AboutMUIHook = { { NULL, NULL }, HOOKFUNC_DEF(OpenAboutMUIFunc), NULL };
139 static struct MUI_CustomClass *FileTypesPluginClass;
141 static struct TagItem *SubWindowTagList;
143 static APTR Group_Plugin;
144 static APTR Group_Buttons2;
145 static Object **PluginSubWindows;
146 static APTR APP_Main;
147 static APTR WIN_Main;
148 static APTR WIN_AboutMUI;
149 static APTR WIN_Splash; // +jmc+
150 static APTR TEXT_Splash; // +jmc+
151 static APTR SaveButton, UseButton, CancelButton;
152 static APTR MenuOpen, MenuSaveAs;
153 static APTR MenuAbout, MenuAboutMUI, MenuQuit;
154 static APTR MenuResetToDefaults, MenuLastSaved, MenuRestore;
155 static APTR MenuCreateIcons;
157 //----------------------------------------------------------------------------
159 int main(int argc, char *argv[])
161 LONG Action = Application_Return_EDIT;
162 LONG win_opened = 0;
163 struct RDArgs *rdArgs = NULL;
164 CONST_STRPTR GivenFileName = NULL;
165 BPTR oldDir = (BPTR)NULL;
166 ULONG fCreateIcons = TRUE;
167 struct DiskObject *FileTypesDiskObject = NULL;
168 struct DiskObject *icon = NULL;
169 STRPTR ProgramName;
170 STRPTR UsedClasses[32];
171 struct WBStartup *WBenchMsg =
172 (argc == 0) ? (struct WBStartup *)argv : NULL;
174 init();
176 if (WBenchMsg && WBenchMsg->sm_ArgList)
178 static char PrgNamePath[512];
179 struct WBArg *arg;
181 if (WBenchMsg->sm_NumArgs > 1)
183 arg = &WBenchMsg->sm_ArgList[1];
184 GivenFileName = arg->wa_Name;
186 else
188 arg = &WBenchMsg->sm_ArgList[0];
191 ProgramName = PrgNamePath;
193 NameFromLock(WBenchMsg->sm_ArgList[0].wa_Lock, PrgNamePath, sizeof(PrgNamePath));
194 AddPart(PrgNamePath, WBenchMsg->sm_ArgList[0].wa_Name, sizeof(PrgNamePath));
196 oldDir = CurrentDir(arg->wa_Lock);
197 icon = GetDiskObject(arg->wa_Name);
198 if (icon)
200 STRPTR tt;
202 tt = FindToolType(icon->do_ToolTypes, "CREATEICONS");
203 if (tt)
205 if (MatchToolValue(tt, "NO"))
206 fCreateIcons = FALSE;
209 tt = FindToolType(icon->do_ToolTypes, "ACTION");
210 if (tt)
212 if (MatchToolValue(tt, "EDIT"))
213 Action = Application_Return_EDIT;
214 if (MatchToolValue(tt, "USE"))
215 Action = Application_Return_USE;
216 if (MatchToolValue(tt, "SAVE"))
217 Action = Application_Return_SAVE;
221 else
223 SIPTR ArgArray[4];
225 ProgramName = argv[0];
227 memset(ArgArray, 0, sizeof(ArgArray));
229 rdArgs = ReadArgs("FROM,EDIT/S,USE/S,SAVE/S", ArgArray, NULL);
231 if (ArgArray[0])
232 GivenFileName = (CONST_STRPTR) ArgArray[0];
233 if (ArgArray[1])
234 Action = Application_Return_EDIT;
235 if (ArgArray[2])
236 Action = Application_Return_USE;
237 if (ArgArray[3])
238 Action = Application_Return_SAVE;
241 if (NULL == FileTypesPluginClass)
242 fail(APP_Main, "Failed to open FileTypes Plugin.");
244 Group_Plugin = NewObject(FileTypesPluginClass->mcc_Class, 0,
245 MUIA_ScalosPrefs_CreateIcons, fCreateIcons,
246 MUIA_ScalosPrefs_ProgramName, (IPTR) ProgramName,
247 TAG_END);
248 if (NULL == Group_Plugin)
249 fail(APP_Main, "Failed to create Group_Plugin.");
251 if (!CheckMCCforPlugin(UsedClasses, Sizeof(UsedClasses)))
252 fail(APP_Main, "Required MCC missing.");
254 FileTypesDiskObject = GetDiskObject(ProgramName);
256 SubWindowTagList = CreatePluginSubWindowArray();
258 APP_Main = ApplicationObject,
259 MUIA_Application_Title, (IPTR)GetLocString(MSGID_TITLENAME),
260 MUIA_Application_Version, (IPTR)"$VER: Scalos FileTypes Prefs V40.24 (" __DATE__ ")" COMPILER_STRING,
261 MUIA_Application_Copyright, (IPTR)"The Scalos Team, 2000" CURRENTYEAR,
262 MUIA_Application_Author, (IPTR)"The Scalos Team",
263 MUIA_Application_Description, (IPTR)"Scalos FileTypes preferences editor",
264 MUIA_Application_Base, (IPTR)"SCALOS_FILETYPES",
265 FileTypesDiskObject ? MUIA_Application_DiskObject : TAG_IGNORE, (IPTR)FileTypesDiskObject,
266 #if defined(MUIA_Application_UsedClasses)
267 MUIA_Application_UsedClasses, UsedClasses,
268 #endif /* MUIA_Application_UsedClasses */
270 SubWindow, (IPTR)(WIN_Main = WindowObject,
271 MUIA_Window_Title, (IPTR)GetLocString(MSGID_TITLENAME),
272 MUIA_Window_ID, MAKE_ID('M','A','I','N'),
273 MUIA_Window_AppWindow, TRUE,
274 WindowContents, (IPTR)(VGroup,
275 Child, (IPTR)Group_Plugin,
277 Child, (IPTR)(Group_Buttons2 = HGroup,
278 MUIA_Group_SameWidth, TRUE,
279 Child, (IPTR)(SaveButton = KeyButtonHelp(GetLocString(MSGID_SAVENAME),
280 's', GetLocString(MSGID_SHORTHELP_SAVEBUTTON))),
281 Child, (IPTR)(UseButton = KeyButtonHelp(GetLocString(MSGID_USENAME),
282 'u', GetLocString(MSGID_SHORTHELP_USEBUTTON))),
283 Child, (IPTR)(CancelButton = KeyButtonHelp(GetLocString(MSGID_CANCELNAME),
284 'c', GetLocString(MSGID_SHORTHELP_CANCELBUTTON))),
285 End), //HGroup
286 End), //VGroup
287 End), //WindowObject
289 // -----------------------------------------------------------------------------------------------
291 SubWindow, (IPTR)(WIN_Splash = WindowObject,
292 MUIA_Window_AppWindow, FALSE,
293 MUIA_Window_CloseGadget, FALSE,
294 MUIA_Window_DepthGadget, FALSE,
295 MUIA_Window_DragBar, FALSE,
296 MUIA_Window_NoMenus, TRUE,
297 MUIA_Window_LeftEdge, MUIV_Window_LeftEdge_Centered,
298 MUIA_Window_TopEdge, MUIV_Window_TopEdge_Centered,
300 WindowContents, (IPTR)(VGroup,
301 Child, (IPTR)(TEXT_Splash = TextObject,
302 MUIA_Weight, 0,
303 MUIA_Text_Contents, (IPTR) GetLocString(MSGID_SPLASHWINDOW_LOADING_FILETYPES_PREFS),
304 End), //TextObject
305 End), //VGroup
307 End), //SubWindow
309 // -----------------------------------------------------------------------------------------------
311 MUIA_Application_Menustrip, (IPTR)(MenustripObject,
312 Child, (IPTR)(MenuObjectT(GetLocString(MSGID_MENU_PROJECT)),
313 Child, (IPTR)(MenuOpen = MenuitemObject,
314 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_PROJECT_OPEN),
315 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_PROJECT_OPEN_SHORT),
316 End),
317 Child, (IPTR)(MenuSaveAs = MenuitemObject,
318 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_PROJECT_SAVEAS),
319 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_PROJECT_SAVEAS_SHORT),
320 End),
321 Child, (IPTR)(MenuitemObject,
322 MUIA_Menuitem_Title, -1,
323 End),
324 Child, (IPTR)(MenuAbout = MenuitemObject,
325 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_PROJECT_ABOUT),
326 End),
327 Child, (IPTR)(MenuAboutMUI = MenuitemObject,
328 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_PROJECT_ABOUTMUI),
329 End),
330 Child, (IPTR)(MenuitemObject,
331 MUIA_Menuitem_Title, -1,
332 End),
333 Child, (IPTR)(MenuQuit = MenuitemObject,
334 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_PROJECT_QUIT),
335 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_PROJECT_QUIT_SHORT),
336 End),
338 End), //MenuObjectT
339 Child, (IPTR)(MenuObjectT(GetLocString(MSGID_MENU_EDIT)),
340 Child, (IPTR)(MenuResetToDefaults = MenuitemObject,
341 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_EDIT_RESETTODEFAULTS),
342 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_EDIT_RESETTODEFAULTS_SHORT),
343 End),
344 Child, (IPTR)(MenuLastSaved = MenuitemObject,
345 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_EDIT_LASTSAVED),
346 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_EDIT_LASTSAVED_SHORT),
347 End),
348 Child, (IPTR)(MenuRestore = MenuitemObject,
349 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_EDIT_RESTORE),
350 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_EDIT_RESTORE_SHORT),
351 End),
352 End), //MenuObjectT
353 Child, (IPTR)(MenuObjectT(GetLocString(MSGID_MENU_SETTINGS)),
354 Child, (IPTR)(MenuCreateIcons = MenuitemObject,
355 MUIA_Menuitem_Title, (IPTR)GetLocString(MSGID_MENU_SETTINGS_CREATEICONS),
356 MUIA_Menuitem_Shortcut, (IPTR)GetLocString(MSGID_MENU_SETTINGS_CREATEICONS_SHORT),
357 MUIA_Menuitem_Checkit, TRUE,
358 MUIA_Menuitem_Checked, fCreateIcons,
359 End),
360 End), //MenuObjectT
361 End), //MenuStripObject
363 SubWindowTagList ? TAG_MORE : TAG_IGNORE, (IPTR)SubWindowTagList,
364 End; //ApplicationObject
366 if (NULL == APP_Main)
368 MUI_DisposeObject(Group_Plugin);
369 Group_Plugin = NULL;
370 fail(APP_Main, "Failed to create Application.");
373 // +jmc+ open Splash window
374 set(WIN_Splash, MUIA_Window_Open, TRUE);
376 set(Group_Plugin, MUIA_ScalosPrefs_MainWindow, (IPTR) WIN_Main);
377 set(Group_Plugin, MUIA_ScalosPrefs_Application, (IPTR) APP_Main);
379 DoMethod(Group_Plugin, MUIM_ScalosPrefs_PageActive, TRUE);
381 DoMethod(WIN_Main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
382 WIN_Main, 3, MUIM_Set, MUIA_Window_Open, FALSE);
383 DoMethod(WIN_Main, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
384 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
385 DoMethod(CancelButton, MUIM_Notify, MUIA_Pressed, FALSE,
386 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
388 DoMethod(MenuQuit, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
389 APP_Main, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
391 DoMethod(SaveButton, MUIM_Notify, MUIA_Pressed, FALSE,
392 APP_Main, 2, MUIM_Application_ReturnID, Application_Return_SAVE);
394 DoMethod(UseButton, MUIM_Notify,MUIA_Pressed, FALSE,
395 APP_Main, 2, MUIM_Application_ReturnID, Application_Return_USE);
397 DoMethod(MenuOpen, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
398 Group_Plugin, 1, MUIM_ScalosPrefs_OpenConfig);
400 DoMethod(MenuSaveAs, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
401 Group_Plugin, 1, MUIM_ScalosPrefs_SaveConfigAs);
403 DoMethod(MenuResetToDefaults, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
404 Group_Plugin, 1, MUIM_ScalosPrefs_ResetToDefaults);
406 DoMethod(MenuLastSaved, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
407 Group_Plugin, 1, MUIM_ScalosPrefs_LastSavedConfig);
409 DoMethod(MenuRestore, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
410 Group_Plugin, 1, MUIM_ScalosPrefs_RestoreConfig);
412 DoMethod(MenuAbout, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
413 Group_Plugin, 1, MUIM_ScalosPrefs_About);
415 DoMethod(MenuAboutMUI, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime,
416 APP_Main, 2, MUIM_CallHook, &AboutMUIHook);
418 DoMethod(MenuCreateIcons, MUIM_Notify, MUIA_Menuitem_Checked, MUIV_EveryTime,
419 Group_Plugin, 3, MUIM_Set, MUIA_ScalosPrefs_CreateIcons, MUIV_TriggerValue);
421 d1(kprintf(__FUNC__ "/%ld: \n", __LINE__));
423 if (icon)
425 DoMethod(Group_Plugin, MUIM_ScalosPrefs_ParseToolTypes, icon->do_ToolTypes);
428 if (GivenFileName)
430 DoMethod(Group_Plugin, MUIM_ScalosPrefs_LoadNamedConfig, GivenFileName);
432 else
434 DoMethod(Group_Plugin, MUIM_ScalosPrefs_LoadConfig);
437 if (Application_Return_EDIT == Action)
439 set(WIN_Main, MUIA_Window_Open, TRUE);
441 get(WIN_Main, MUIA_Window_Open, &win_opened);
443 // +jmc+ close Splash window
444 set(WIN_Splash, MUIA_Window_Open, FALSE);
446 if (win_opened)
448 ULONG sigs = 0;
449 BOOL Run = TRUE;
451 while (Run)
453 Action = DoMethod(APP_Main, MUIM_Application_NewInput, &sigs);
455 switch (Action)
457 case MUIV_Application_ReturnID_Quit:
458 case Application_Return_SAVE:
459 case Application_Return_USE:
460 Run = FALSE;
461 break;
464 if (Run && sigs)
466 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
468 if (sigs & SIGBREAKF_CTRL_C)
470 Run = FALSE;
471 break;
476 else
478 printf("failed to open main window !\n");
482 switch (Action)
484 case Application_Return_SAVE:
485 set(TEXT_Splash, MUIA_Text_Contents, (IPTR) GetLocString(MSGID_SPLASHWINDOW_SAVING_FILETYPES_PREFS)); // +jmc+
486 set(WIN_Splash, MUIA_Window_Open, TRUE); // +jmc+
487 DoMethod(Group_Plugin, MUIM_ScalosPrefs_SaveConfig);
488 break;
489 case Application_Return_USE:
490 set(TEXT_Splash, MUIA_Text_Contents, (IPTR) GetLocString(MSGID_SPLASHWINDOW_APPLYING_FILETYPES_PREFS)); // +jmc+
491 set(WIN_Splash, MUIA_Window_Open, TRUE); // +jmc+
492 DoMethod(Group_Plugin, MUIM_ScalosPrefs_UseConfig);
493 break;
496 set(WIN_Main, MUIA_Window_Open, FALSE);
497 set(WIN_Splash, MUIA_Window_Open, FALSE); // +jmc+
499 if (FileTypesDiskObject)
500 FreeDiskObject(FileTypesDiskObject);
501 if (icon)
502 FreeDiskObject(icon);
503 if (oldDir)
504 CurrentDir(oldDir);
505 if (rdArgs)
506 FreeArgs(rdArgs);
508 fail(APP_Main, NULL);
510 return 0;
514 static VOID fail(APTR APP_Main, CONST_STRPTR str)
516 if (APP_Main)
517 MUI_DisposeObject(APP_Main);
519 DisposePrefsPlugin();
521 if (FileTypesCatalog)
523 CloseCatalog(FileTypesCatalog);
524 FileTypesCatalog = NULL;
527 CloseLibraries();
529 if (str)
531 puts(str);
532 exit(20);
535 exit(0);
539 static void init(void)
541 if (!OpenLibraries())
542 fail(NULL, "Failed to open "MUIMASTER_NAME".");
544 if (LocaleBase)
545 FileTypesCatalog = OpenCatalogA(NULL, "Scalos/ScalosFileTypes.catalog", NULL);
547 FileTypesPluginClass = OpenPrefsModule("FileTypes.prefsplugin");
551 static BOOL OpenLibraries(void)
553 IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 39);
554 if (NULL == IntuitionBase)
555 return FALSE;
556 #ifdef __amigaos4__
557 IIntuition = (struct IntuitionIFace *) GetInterface((struct Library *)IntuitionBase, "main", 1, NULL);
558 if (NULL == IIntuition)
559 return FALSE;
560 #endif
562 MUIMasterBase = OpenLibrary("zune.library", 0);
563 if (NULL == MUIMasterBase)
564 MUIMasterBase = OpenLibrary(MUIMASTER_NAME, MUIMASTER_VMIN-1);
565 if (NULL == MUIMasterBase)
566 return FALSE;
567 #ifdef __amigaos4__
568 IMUIMaster = (struct MUIMasterIFace *) GetInterface((struct Library *)MUIMasterBase, "main", 1, NULL);
569 if (NULL == IMUIMaster)
570 return FALSE;
571 #endif
573 IconBase = OpenLibrary("icon.library", 0);
574 if (NULL == IconBase)
575 return FALSE;
576 #ifdef __amigaos4__
577 IIcon = (struct IconIFace *) GetInterface((struct Library *)IconBase, "main", 1, NULL);
578 if (NULL == IIcon)
579 return FALSE;
580 #endif
582 LocaleBase = (T_LOCALEBASE) OpenLibrary("locale.library", 39);
583 #ifdef __amigaos4__
584 if (LocaleBase)
585 ILocale = (struct LocaleIFace *) GetInterface((struct Library *)LocaleBase, "main", 1, NULL);
586 #endif
588 return TRUE;
592 static void CloseLibraries(void)
594 #ifdef __amigaos4__
595 if (ILocale)
597 DropInterface((struct Interface *)ILocale);
598 ILocale = NULL;
600 #endif
601 if (LocaleBase)
603 CloseLibrary((struct Library *) LocaleBase);
604 LocaleBase = NULL;
606 #ifdef __amigaos4__
607 if (IIcon)
609 DropInterface((struct Interface *)IIcon);
610 IIcon = NULL;
612 #endif
613 if (IconBase)
615 CloseLibrary(IconBase);
616 IconBase = NULL;
618 #ifdef __amigaos4__
619 if (IMUIMaster)
621 DropInterface((struct Interface *)IMUIMaster);
622 IMUIMaster = NULL;
624 #endif
625 if (MUIMasterBase)
627 CloseLibrary(MUIMasterBase);
628 MUIMasterBase = NULL;
630 #ifdef __amigaos4__
631 if (IIntuition)
633 DropInterface((struct Interface *)IIntuition);
634 IIntuition = NULL;
636 #endif
637 if (IntuitionBase)
639 CloseLibrary((struct Library *) IntuitionBase);
640 IntuitionBase = NULL;
644 //----------------------------------------------------------------------------
646 static STRPTR GetLocString(ULONG MsgId)
648 struct ScalosFileTypes_LocaleInfo li;
650 li.li_Catalog = FileTypesCatalog;
651 #ifndef __amigaos4__
652 li.li_LocaleBase = LocaleBase;
653 #else
654 li.li_ILocale = ILocale;
655 #endif
657 return (STRPTR) GetScalosFileTypesString(&li, MsgId);
660 static void TranslateStringArray(STRPTR *stringArray)
662 while (*stringArray)
664 *stringArray = GetLocString((IPTR) *stringArray);
665 stringArray++;
669 //----------------------------------------------------------------------------
671 static SAVEDS(APTR) INTERRUPT OpenAboutMUIFunc(struct Hook *hook, Object *o, Msg msg)
673 if (NULL == WIN_AboutMUI)
675 WIN_AboutMUI = MUI_NewObject(MUIC_Aboutmui,
676 MUIA_Window_RefWindow, WIN_Main,
677 MUIA_Aboutmui_Application, APP_Main,
678 End;
681 if (WIN_AboutMUI)
682 set(WIN_AboutMUI, MUIA_Window_Open, TRUE);
684 return 0;
687 //----------------------------------------------------------------------------
689 static struct MUI_CustomClass *OpenPrefsModule(CONST_STRPTR FileName)
691 struct MUI_CustomClass *pclass = NULL;
693 d1(kprintf(__FUNC__ "/%ld: FileName=<%s>\n", __LINE__, FileName));
695 do {
696 ScalosPrefsPluginBase = OpenLibrary(FileName, 0);
697 d1(kprintf(__FUNC__ "/%ld: ScalosPrefsPluginBase=%08lx\n", __LINE__, ScalosPrefsPluginBase));
698 if (NULL == ScalosPrefsPluginBase)
699 break;
700 #ifdef __amigaos4__
701 IScalosPrefsPlugin = (struct ScalosPrefsPluginIFace *)GetInterface(
702 ScalosPrefsPluginBase, "main", 1, NULL
704 #endif
706 pclass = (struct MUI_CustomClass *) SCAGetPrefsInfo(SCAPREFSINFO_GetClass);
707 d1(kprintf(__FUNC__ "/%ld: PluginClass=%08lx\n", __LINE__, ppl->ppl_PluginClass));
708 if (NULL == pclass)
709 break;
710 } while (0);
712 if (NULL == pclass)
713 DisposePrefsPlugin();
715 return pclass;
719 static struct TagItem *CreatePluginSubWindowArray(void)
721 struct TagItem *SubWindowTagList;
722 struct TagItem *ti;
723 ULONG SubWindowCount = 0;
724 ULONG n;
726 PluginSubWindows = (Object **) DoMethod(Group_Plugin, MUIM_ScalosPrefs_CreateSubWindows);
728 for (n=0; PluginSubWindows && PluginSubWindows[n]; n++)
729 SubWindowCount++;
731 SubWindowTagList = ti = calloc(1 + SubWindowCount, sizeof(struct TagItem));
732 if (NULL == SubWindowTagList)
733 return NULL;
735 for (n=0; PluginSubWindows && PluginSubWindows[n]; n++)
737 ti->ti_Tag = MUIA_Application_Window;
738 ti->ti_Data = (IPTR) PluginSubWindows[n];
739 ti++;
742 ti->ti_Tag = TAG_END;
744 return SubWindowTagList;
748 static void DisposePrefsPlugin(void)
750 #ifdef __amigaos4__
751 if (IScalosPrefsPlugin)
753 DropInterface((struct Interface *)IScalosPrefsPlugin);
754 IScalosPrefsPlugin = NULL;
756 #endif
757 if (ScalosPrefsPluginBase)
759 d1(kprintf(__FUNC__ "/%ld: Plugin=<%s> OpenCount=%ld\n", \
760 __LINE__, ScalosPrefsPluginBase->lib_Node.ln_Name, ScalosPrefsPluginBase->lib_OpenCnt));
762 if (NULL == Group_Plugin)
763 CloseLibrary(ScalosPrefsPluginBase);
764 ScalosPrefsPluginBase = NULL;
768 //----------------------------------------------------------------------------
770 static BOOL CheckMCCforPlugin(STRPTR *UsedClasses, size_t MaxUsedClasses)
772 const struct MUIP_ScalosPrefs_MCCList *RequiredMccList = NULL;
774 RequiredMccList = (const struct MUIP_ScalosPrefs_MCCList *) DoMethod(Group_Plugin, MUIM_ScalosPrefs_GetListOfMCCs);
776 while (RequiredMccList && RequiredMccList->MccName)
778 if (!CheckMCCVersion(RequiredMccList->MccName,
779 RequiredMccList->MccMinVersion,
780 RequiredMccList->MccMinRevision))
781 return FALSE;
783 if (MaxUsedClasses > 1)
785 *UsedClasses++ = (STRPTR) RequiredMccList->MccName;
786 MaxUsedClasses--;
789 RequiredMccList++;
792 *UsedClasses = NULL;
794 return TRUE;
797 //----------------------------------------------------------------------------
799 // Checks if a certain version of a MCC is available
800 static BOOL CheckMCCVersion(CONST_STRPTR name, ULONG minver, ULONG minrev)
802 BOOL flush = TRUE;
804 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: %s ", name, __LINE__);)
806 while (1)
808 ULONG ver = 0;
809 ULONG rev = 0;
810 struct Library *base;
811 char libname[256];
813 // First we attempt to acquire the version and revision through MUI
814 Object *obj = MUI_NewObject((STRPTR) name, TAG_DONE);
815 if (obj)
817 get(obj, MUIA_Version, &ver);
818 get(obj, MUIA_Revision, &rev);
820 MUI_DisposeObject(obj);
822 if(ver > minver || (ver == minver && rev >= minrev))
824 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: v%ld.%ld found through MUIA_Version/Revision\n", __LINE__, ver, rev);)
825 return TRUE;
829 // If we did't get the version we wanted, let's try to open the
830 // libraries ourselves and see what happens...
831 stccpy(libname, "PROGDIR:mui", sizeof(libname));
832 AddPart(libname, name, sizeof(libname));
834 if ((base = OpenLibrary(&libname[8], 0)) || (base = OpenLibrary(&libname[0], 0)))
836 UWORD OpenCnt = base->lib_OpenCnt;
838 ver = base->lib_Version;
839 rev = base->lib_Revision;
841 CloseLibrary(base);
843 // we add some additional check here so that eventual broken .mcc also have
844 // a chance to pass this test (i.e. Toolbar.mcc is broken)
845 if (ver > minver || (ver == minver && rev >= minrev))
847 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: v%ld.%ld found through OpenLibrary()\n", __LINE__, ver, rev);)
848 return TRUE;
851 if (OpenCnt > 1)
853 if (MUI_Request(NULL, NULL, 0L, GetLocString(MSGID_STARTUP_FAILURE),
854 GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD), GetLocString(MSGID_STARTUP_MCC_IN_USE),
855 (IPTR) name, minver, minrev, ver, rev))
857 flush = TRUE;
859 else
860 break;
863 // Attempt to flush the library if open count is 0 or because the
864 // user wants to retry (meaning there's a chance that it's 0 now)
866 if (flush)
868 struct Library *result;
870 Forbid();
871 if ((result = (struct Library *) FindName(&((struct ExecBase *)SysBase)->LibList, name)))
872 RemLibrary(result);
873 Permit();
874 flush = FALSE;
876 else
878 d1(kprintf(__FILE__ "/" __FUNC__ "/%ld: couldn`t find minimum required version.\n", __LINE__);)
880 // We're out of luck - open count is 0, we've tried to flush
881 // and still haven't got the version we want
882 if (MUI_Request(NULL, NULL, 0L, GetLocString(MSGID_STARTUP_FAILURE),
883 GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD), GetLocString(MSGID_STARTUP_OLD_MCC),
884 (IPTR) name, minver, minrev, ver, rev))
886 flush = TRUE;
888 else
889 break;
892 else
894 // No MCC at all - no need to attempt flush
895 flush = FALSE;
896 if (!MUI_Request(NULL, NULL, 0L, GetLocString(MSGID_STARTUP_FAILURE),
897 GetLocString(MSGID_STARTUP_RETRY_QUIT_GAD), GetLocString(MSGID_STARTUP_MCC_NOT_FOUND),
898 (IPTR) name, minver, minrev))
900 break;
905 return FALSE;
908 //----------------------------------------------------------------------------
910 #if !defined(__SASC) && !defined(__amigaos4__)
911 // Replacement for SAS/C library functions
913 #if !defined(__MORPHOS__)
914 // Replacement for SAS/C library functions
916 size_t stccpy(char *dest, const char *src, size_t MaxLen)
918 size_t Count = 0;
920 while (*src && MaxLen > 1)
922 *dest++ = *src++;
923 MaxLen--;
924 Count++;
926 *dest = '\0';
927 Count++;
929 return Count;
931 #endif /*__MORPHOS__*/
933 #endif /* !defined(__SASC) && !defined(__amigaos4__) */
934 //-----------------------------------------------------------------------------