2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
8 /******************************************************************************
25 Initialises preferences files on startup.
32 This is a command executed on startup by the s:startup-sequence script file.
33 So no actual need of the command afterwards.
47 ******************************************************************************/
50 #include "trackdiskprefs.h"
52 #include <dos/dostags.h>
55 #include <aros/debug.h>
57 #include <aros/detach.h>
62 /*********************************************************************************************/
69 BOOL nocloseafterpatch
;
73 {&IntuitionBase
, "intuition.library" , 39, FALSE
},
74 {&GfxBase
, "graphics.library" , 39, FALSE
},
75 {&UtilityBase
, "utility.library" , 39, TRUE
},
76 {&IFFParseBase
, "iffparse.library" , 39, FALSE
},
77 {&LocaleBase
, "locale.library" , 39, TRUE
},
78 {&KeymapBase
, "keymap.library" , 39, FALSE
},
79 {&KMSBase
, "kms.library" , 3, FALSE
},
80 {&LayersBase
, "layers.library" , 39, FALSE
},
81 {&DataTypesBase
, "datatypes.library" , 39, FALSE
},
82 {&DiskfontBase
, "diskfont.library" , 39, FALSE
},
86 /*********************************************************************************************/
88 static struct prefinfo
91 STRPTR filenamebuffer
;
93 struct NotifyRequest nr
;
98 {"input" , inputprefsname
, InputPrefs_Handler
},
99 {"locale" , localeprefsname
, LocalePrefs_Handler
}, /* Keep before font */
100 {"font" , fontprefsname
, FontPrefs_Handler
},
101 {"palette" , paletteprefsname
, NULL
},
102 {"wbpattern" , patternprefsname
, WBPatternPrefs_Handler
},
103 {"icontrol" , icontrolprefsname
, IControlPrefs_Handler
},
104 {"screenmode" , screenmodeprefsname
, ScreenModePrefs_Handler
},
105 {"serial" , serialprefsname
, SerialPrefs_Handler
},
106 {"printer" , printerprefsname
, PrinterPrefs_Handler
},
107 {"pointer" , pointerprefsname
, PointerPrefs_Handler
},
108 {"overscan" , overscanprefsname
, NULL
},
113 /*********************************************************************************************/
115 static ULONG notifysig
;
117 /*********************************************************************************************/
119 static void CloseLibs(void);
120 static void KillNotifications(void);
122 /*********************************************************************************************/
124 WORD
ShowMessage(STRPTR title
, STRPTR text
, STRPTR gadtext
)
126 struct EasyStruct es
;
128 es
.es_StructSize
= sizeof(es
);
131 es
.es_TextFormat
= text
;
132 es
.es_GadgetFormat
= gadtext
;
134 return EasyRequestArgs(NULL
, &es
, NULL
, NULL
);
136 /*********************************************************************************************/
138 void Cleanup(STRPTR msg
)
142 if (IntuitionBase
/* && !((struct Process *)FindTask(NULL))->pr_CLI */)
144 ShowMessage("IPrefs", msg
, "Ok");
150 RootPatternCleanup();
158 /*********************************************************************************************/
160 static void OpenLibs(void)
164 for (li
= libtable
; li
->var
; li
++)
166 if (!((*(struct Library
**)li
->var
) = OpenLibrary(li
->name
,
169 sprintf(s
, "Can't open %s V%d!", li
->name
, li
->version
);
175 /*********************************************************************************************/
177 static void CloseLibs(void)
181 for(li
= libtable
; li
->var
; li
++)
183 if (!patches_installed
|| !li
->nocloseafterpatch
)
185 if (*(struct Library
**)li
->var
) CloseLibrary((*(struct Library
**)li
->var
));
190 /*********************************************************************************************/
192 static void GetENVName(void)
197 lock
= Lock("ENV:", SHARED_LOCK
);
200 if (NameFromLock(lock
, envname
, 256)) ok
= TRUE
;
204 if (!ok
) Cleanup("Error expanding \"ENV:\" to full name!");
207 /*********************************************************************************************/
209 static void StartNotifications(void)
213 notifyport
= CreateMsgPort();
214 if (!notifyport
) Cleanup("Can't create notification msg port!\n");
216 notifysig
= 1L << notifyport
->mp_SigBit
;
218 for(i
= 0; preftable
[i
].filename
; i
++)
220 strncpy(preftable
[i
].filenamebuffer
, envname
, 256);
221 AddPart(preftable
[i
].filenamebuffer
, "Sys", 256);
222 AddPart(preftable
[i
].filenamebuffer
, preftable
[i
].filename
, 256);
223 if (strlen(preftable
[i
].filenamebuffer
) < 250)
224 strcat(preftable
[i
].filenamebuffer
, ".prefs");
227 D(bug("Filename too long for %s prefs\n", preftable
[i
].filename
));
228 Cleanup("Prefs filename too long!\n");
231 preftable
[i
].nr
.nr_Name
= preftable
[i
].filenamebuffer
;
232 preftable
[i
].nr
.nr_UserData
= i
;
233 preftable
[i
].nr
.nr_Flags
= NRF_SEND_MESSAGE
| NRF_NOTIFY_INITIAL
;
234 preftable
[i
].nr
.nr_stuff
.nr_Msg
.nr_Port
= notifyport
;
236 D(bug("\nTrying to start notification for file \"%s\".\n", preftable
[i
].filenamebuffer
));
238 if (StartNotify(&preftable
[i
].nr
))
240 D(bug("Notification successfully started.\n"));
242 preftable
[i
].notifystarted
= TRUE
;
246 D(bug("Notification start failed!! Continuing anyway!\n"));
249 } /* for(i = 0; preftable[i].filename; i++) */
252 /*********************************************************************************************/
254 static void KillNotifications(void)
258 for(i
= 0; preftable
[i
].filename
; i
++)
260 if (preftable
[i
].notifystarted
)
262 EndNotify(&preftable
[i
].nr
);
263 preftable
[i
].notifystarted
= FALSE
;
269 DeleteMsgPort(notifyport
);
275 /*********************************************************************************************/
277 static void PreparePatches(void)
279 struct IPrefsSem
*sem
;
280 BOOL created_sem
= FALSE
;
282 sem
= AllocVec(sizeof(struct IPrefsSem
), MEMF_PUBLIC
| MEMF_CLEAR
);
283 if (!sem
) Cleanup("Out of memory!");
285 InitSemaphore(&sem
->sem
);
286 sem
->sem
.ss_Link
.ln_Name
= sem
->semname
;
287 strcpy(sem
->semname
, IPREFS_SEM_NAME
);
290 if(!(iprefssem
= (struct IPrefsSem
*)FindSemaphore(IPREFS_SEM_NAME
)))
293 AddSemaphore(&iprefssem
->sem
);
310 /*********************************************************************************************/
312 static void HandleNotify(void)
314 struct NotifyMessage
*msg
;
316 while((msg
= (struct NotifyMessage
*)GetMsg(notifyport
)))
318 WORD id
= msg
->nm_NReq
->nr_UserData
;
320 D(bug("Received notify message. UserData = %d --> File = \"%s\"\n", id
,
321 preftable
[id
].filenamebuffer
));
323 if (preftable
[id
].func
)
325 preftable
[id
].func(preftable
[id
].filenamebuffer
);
328 ReplyMsg(&msg
->nm_ExecMessage
);
330 } /* while((msg = (struct NotifyMessage *)GetMsg(notifyport))) */
333 /*********************************************************************************************/
335 static void HandleAll(void)
341 sigs
= Wait(notifysig
| SIGBREAKF_CTRL_C
);
343 if (sigs
& SIGBREAKF_CTRL_C
) break;
345 if (sigs
& notifysig
) HandleNotify();
351 /*********************************************************************************************/
354 int __nocommandline
= 1;
355 STRPTR __detached_name
= IPREFS_SEM_NAME
;
362 StartNotifications();
372 /*********************************************************************************************/