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>
50 #define STARTUPDIR "sys:WBStartup/"
59 const TEXT version_string
[] = "$VER: ExecuteStartup 0.2 (20.10.2007) © AROS Dev Team";
61 static TEXT fileNameBuffer
[MAXFILENAMELENGTH
];
64 static BOOL
checkIcon(STRPTR name
, LONG
*pri
, ULONG
*time
, BOOL
*notwait
);
65 static BOOL
searchInfo(struct List
*infoList
);
66 static void executePrograms(struct List
*infolist
);
67 static BOOL
executeWBStartup(void);
77 checkIcon(STRPTR name
, LONG
*pri
, ULONG
*time
, BOOL
*notwait
)
83 struct DiskObject
*dobj
= GetDiskObject(name
);
86 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
87 "Error", "ExecuteStartup\nGetDiskObject failed for:\n%s", "OK"};
88 EasyRequest(0, &es
, 0, name
);
92 if ((dobj
->do_Type
== WBTOOL
) || (dobj
->do_Type
== WBPROJECT
))
94 const STRPTR
*toolarray
= (const STRPTR
*)dobj
->do_ToolTypes
;
96 if ((s
= FindToolType(toolarray
, "STARTPRI")))
99 if (*pri
< -128) *pri
= -128;
100 if (*pri
> 127) *pri
= 127;
102 if ((s
= FindToolType(toolarray
, "WAIT")))
105 if (*time
> 60) *time
= 60;
107 if ((s
= FindToolType(toolarray
, "DONOTWAIT")))
111 FreeDiskObject(dobj
);
118 searchInfo(struct List
*infoList
)
120 BOOL retvalue
= TRUE
;
122 struct AnchorPath
*ap
= AllocPooled(poolmem
, sizeof(struct AnchorPath
));
125 error
= MatchFirst(STARTUPDIR
"?#?.info", ap
);
128 strcpy(fileNameBuffer
, ap
->ap_Info
.fib_FileName
);
129 BYTE
* pointPos
= strrchr(fileNameBuffer
, '.');
135 if (checkIcon(fileNameBuffer
, &pri
, &time
, ¬wait
))
137 struct InfoNode
*newnode
= AllocPooled(poolmem
, sizeof (*newnode
));
140 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
141 "Error", "ExecuteStartup\nOut of memory for InfoNode", "OK"};
142 EasyRequest(0, &es
, 0);
146 newnode
->node
.ln_Name
= AllocPooled(poolmem
, strlen(fileNameBuffer
) + 1);
147 if (newnode
->node
.ln_Name
== NULL
)
149 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
150 "Error", "ExecuteStartup\nOut of memory for ln_Name", "OK"};
151 EasyRequest(0, &es
, 0);
155 strcpy(newnode
->node
.ln_Name
, fileNameBuffer
);
156 newnode
->node
.ln_Pri
= pri
;
157 newnode
->waittime
= time
;
158 newnode
->donotwait
= notwait
;
159 Enqueue(infoList
, (struct Node
*)newnode
);
161 error
= MatchNext(ap
);
164 if (error
!= ERROR_NO_MORE_ENTRIES
)
166 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
167 "Error", "ExecuteStartup\nError %ld occured while scanning directory", "OK"};
168 EasyRequest(0, &es
, 0, error
);
176 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
177 "Error", "ExecuteStartup\nOut of memory for AnchorPath", "OK"};
178 EasyRequest(0, &es
, 0);
186 executePrograms(struct List
*infolist
)
188 struct InfoNode
*infonode
;
189 ForeachNode(infolist
, infonode
)
191 D(bug("ExecuteStartup Name %s Pri %d Time %d Notwait %d\n",
192 infonode
->node
.ln_Name
, infonode
->node
.ln_Pri
,
193 infonode
->waittime
, infonode
->donotwait
));
194 if (OpenWorkbenchObject(infonode
->node
.ln_Name
, TAG_END
))
196 Delay(infonode
->waittime
* 50);
200 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
201 "Warning", "ExecuteStartup\nOpenWorkbenchObject failed for:\n%s", "OK"};
202 EasyRequest(0, &es
, 0, infonode
->node
.ln_Name
);
208 executeWBStartup(void)
210 struct List infoList
;
212 BOOL retvalue
= FALSE
;
213 BPTR olddir
= (BPTR
)-1;
216 struct FileInfoBlock
*fib
= AllocDosObjectTags(DOS_FIB
, TAG_END
);
217 poolmem
= CreatePool(MEMF_ANY
| MEMF_CLEAR
, sizeof(struct InfoNode
) * 10, sizeof(struct InfoNode
) * 5);
219 while (TRUE
) /*Cicle loop to avoid the use of goto; It uses now break instruction;*/
223 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
224 "Error", "ExecuteStartup\nOut of memory for FileInfoBlock", "OK"};
225 EasyRequest(0, &es
, 0);
231 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
232 "Error", "ExecuteStartup\nCouldn't create pool memory", "OK"};
233 EasyRequest(0, &es
, 0);
237 if ( (startupdir
= Lock(STARTUPDIR
, ACCESS_READ
) ) == 0)
239 D(bug("ExecuteStartup: Couldn't lock " STARTUPDIR
"\n"));
243 if ( ! Examine(startupdir
, fib
))
245 struct EasyStruct es
= {sizeof(struct EasyStruct
), 0,
246 "Error", "ExecuteStartup\nCouldn't examine " STARTUPDIR
, "OK"};
247 EasyRequest(0, &es
, 0);
251 // check if startupdir is a directory
252 if (fib
->fib_DirEntryType
>= 0)
254 olddir
= CurrentDir(startupdir
);
255 if (searchInfo(&infoList
))
257 executePrograms(&infoList
);
263 D(bug("ExecuteStartup: " STARTUPDIR
" isn't a directory\n"));
271 if (startupdir
) UnLock(startupdir
);
272 if (olddir
!= (BPTR
)-1) CurrentDir(olddir
);
273 if (fib
) FreeDosObject(DOS_FIB
, fib
);
274 if (poolmem
) DeletePool(poolmem
);