2 Copyright © 2006-2007, The AROS Development Team. All rights reserved.
5 Desc: Executes programs in sys:WBStartup
9 /*****************************************************************************
18 Executes programs in sys:WBStartup.
20 It checks the following tooltypes of the called programs:
21 STARTPRI=n n can be between +127 and -128. The program
22 with the highest priority is started first.
24 WAIT=n Wait n seconds after execution.
25 n can be between 0 and 60.
27 DONOTWAIT don't wait till the program is finished.
32 All programs are treated like DONOTWAIT is set.
36 ******************************************************************************/
43 #include <aros/debug.h>
44 #include <proto/exec.h>
45 #include <proto/dos.h>
46 #include <proto/icon.h>
47 #include <proto/workbench.h>
48 #include <proto/intuition.h>
52 #define STARTUPDIR "sys:WBStartup/"
61 const TEXT version_string
[] = "$VER: ExecuteStartup 0.2 (20.10.2007) © AROS Dev Team";
63 static TEXT fileNameBuffer
[MAXFILENAMELENGTH
];
66 static BOOL
checkIcon(STRPTR name
, LONG
*pri
, ULONG
*time
, BOOL
*notwait
);
67 static BOOL
searchInfo(struct List
*infoList
);
68 static void executePrograms(struct List
*infolist
);
69 static BOOL
executeWBStartup(void);
81 checkIcon(STRPTR name
, LONG
*pri
, ULONG
*time
, BOOL
*notwait
)
87 struct DiskObject
*dobj
= GetDiskObject(name
);
90 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
91 "Error", "ExecuteStartup\nGetDiskObject failed for:\n%s", "OK"};
92 EasyRequest(0, &es
, 0, name
);
96 if ((dobj
->do_Type
== WBTOOL
) || (dobj
->do_Type
== WBPROJECT
))
98 const STRPTR
*toolarray
= (const STRPTR
*)dobj
->do_ToolTypes
;
100 if ((s
= FindToolType(toolarray
, "STARTPRI")))
103 if (*pri
< -128) *pri
= -128;
104 if (*pri
> 127) *pri
= 127;
106 if ((s
= FindToolType(toolarray
, "WAIT")))
109 if (*time
> 60) *time
= 60;
111 if ((s
= FindToolType(toolarray
, "DONOTWAIT")))
115 FreeDiskObject(dobj
);
122 searchInfo(struct List
*infoList
)
124 BOOL retvalue
= TRUE
;
126 struct AnchorPath
*ap
= AllocPooled(poolmem
, sizeof(struct AnchorPath
));
129 error
= MatchFirst(STARTUPDIR
"?#?.info", ap
);
132 strcpy(fileNameBuffer
, ap
->ap_Info
.fib_FileName
);
133 BYTE
* pointPos
= strrchr(fileNameBuffer
, '.');
139 if (checkIcon(fileNameBuffer
, &pri
, &time
, ¬wait
))
141 struct InfoNode
*newnode
= AllocPooled(poolmem
, sizeof (*newnode
));
144 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
145 "Error", "ExecuteStartup\nOut of memory for InfoNode", "OK"};
146 EasyRequest(0, &es
, 0);
150 newnode
->node
.ln_Name
= AllocPooled(poolmem
, strlen(fileNameBuffer
) + 1);
151 if (newnode
->node
.ln_Name
== NULL
)
153 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
154 "Error", "ExecuteStartup\nOut of memory for ln_Name", "OK"};
155 EasyRequest(0, &es
, 0);
159 strcpy(newnode
->node
.ln_Name
, fileNameBuffer
);
160 newnode
->node
.ln_Pri
= pri
;
161 newnode
->waittime
= time
;
162 newnode
->donotwait
= notwait
;
163 Enqueue(infoList
, (struct Node
*)newnode
);
165 error
= MatchNext(ap
);
168 if (error
!= ERROR_NO_MORE_ENTRIES
)
170 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
171 "Error", "ExecuteStartup\nError %ld occured while scanning directory", "OK"};
172 EasyRequest(0, &es
, 0, error
);
180 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
181 "Error", "ExecuteStartup\nOut of memory for AnchorPath", "OK"};
182 EasyRequest(0, &es
, 0);
190 executePrograms(struct List
*infolist
)
192 struct InfoNode
*infonode
;
193 ForeachNode(infolist
, infonode
)
195 D(bug("ExecuteStartup Name %s Pri %d Time %d Notwait %d\n",
196 infonode
->node
.ln_Name
, infonode
->node
.ln_Pri
,
197 infonode
->waittime
, infonode
->donotwait
));
198 if (OpenWorkbenchObject(infonode
->node
.ln_Name
, TAG_END
))
200 Delay(infonode
->waittime
* 50);
204 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
205 "Warning", "ExecuteStartup\nOpenWorkbenchObject failed for:\n%s", "OK"};
206 EasyRequest(0, &es
, 0, infonode
->node
.ln_Name
);
212 executeWBStartup(void)
214 struct List infoList
;
216 BOOL retvalue
= FALSE
;
217 BPTR olddir
= (BPTR
)-1;
220 struct FileInfoBlock
*fib
= AllocDosObjectTags(DOS_FIB
, TAG_END
);
221 poolmem
= CreatePool(MEMF_ANY
| MEMF_CLEAR
, sizeof(struct InfoNode
) * 10, sizeof(struct InfoNode
) * 5);
223 while (TRUE
) /*Cicle loop to avoid the use of goto; It uses now break instruction;*/
227 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
228 "Error", "ExecuteStartup\nOut of memory for FileInfoBlock", "OK"};
229 EasyRequest(0, &es
, 0);
235 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
236 "Error", "ExecuteStartup\nCouldn't create pool memory", "OK"};
237 EasyRequest(0, &es
, 0);
241 if ( (startupdir
= Lock(STARTUPDIR
, ACCESS_READ
) ) == 0)
243 D(bug("ExecuteStartup: Couldn't lock " STARTUPDIR
"\n"));
247 if ( ! Examine(startupdir
, fib
))
249 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
250 "Error", "ExecuteStartup\nCouldn't examine " STARTUPDIR
, "OK"};
251 EasyRequest(0, &es
, 0);
255 // check if startupdir is a directory
256 if (fib
->fib_DirEntryType
>= 0)
258 olddir
= CurrentDir(startupdir
);
259 if (searchInfo(&infoList
))
261 executePrograms(&infoList
);
267 D(bug("ExecuteStartup: " STARTUPDIR
" isn't a directory\n"));
275 if (startupdir
) UnLock(startupdir
);
276 if (olddir
!= (BPTR
)-1) CurrentDir(olddir
);
277 if (fib
) FreeDosObject(DOS_FIB
, fib
);
278 if (poolmem
) DeletePool(poolmem
);