author | Claus Gittinger <cg@exept.de> |
Thu, 22 Oct 2009 21:07:43 +0200 | |
changeset 12335 | af9a7bc14d6a |
parent 11807 | f9e3c45c53c8 |
child 12523 | df8cb7ffe5eb |
permissions | -rw-r--r-- |
9944 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
14 |
Object subclass:#StandaloneStartup |
|
15 |
instanceVariableNames:'' |
|
10772 | 16 |
classVariableNames:'Verbose CommandLineArguments' |
9944 | 17 |
poolDictionaries:'' |
18 |
category:'System-Support' |
|
19 |
! |
|
20 |
||
11102 | 21 |
StandaloneStartup class instanceVariableNames:'MutexHandle' |
22 |
||
23 |
" |
|
24 |
No other class instance variables are inherited by this class. |
|
25 |
" |
|
26 |
! |
|
27 |
||
9944 | 28 |
!StandaloneStartup class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
a subclassable template class for a standalone GUI-application's startup; |
|
47 |
For your own stand alone programs, define a subclass of this, |
|
12335 | 48 |
and redefine the #main: method there. |
9944 | 49 |
(of course, the other methods can also be redefined.) |
50 |
||
51 |
[author:] |
|
52 |
Claus Gittinger |
|
53 |
||
54 |
[start with:] |
|
55 |
<yourNamehere>Startup start |
|
10886 | 56 |
|
57 |
[see also:] |
|
58 |
Smalltalk |
|
59 |
GetOpt |
|
60 |
ReadEvalPrintLoop |
|
9944 | 61 |
" |
11102 | 62 |
! |
63 |
||
64 |
howToDealWithMultipleApplicationInstances |
|
65 |
" |
|
66 |
please read the comment in the corresponding ApplicationModel class-documentation method. |
|
67 |
" |
|
11352 | 68 |
! |
69 |
||
70 |
whichMethodsToRedefine |
|
71 |
" |
|
72 |
main:argv |
|
73 |
thats the actual program. |
|
74 |
||
75 |
suppressRCFileReading |
|
76 |
false here; redefine to return true, to disable the rc-file reading. |
|
77 |
you loose the chance of configuration, but lock the user out from any access to any smalltalk |
|
78 |
(if you have a user-phobia) |
|
79 |
||
80 |
allowDebugOption |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
81 |
false here; redefine to return true, to enable the --debug startup option. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
82 |
if disabled, you loose the chance of debugging, but lock the user out from any access to any smalltalk |
11352 | 83 |
|
84 |
allowScriptingOption |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
85 |
false here; redefine to return true, to enable the --scripting startup option. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
86 |
if disabled, you loose the chance of remote control, but lock the user out from any access to any smalltalk |
11352 | 87 |
|
88 |
" |
|
9944 | 89 |
! ! |
90 |
||
91 |
!StandaloneStartup class methodsFor:'initialization'! |
|
92 |
||
93 |
initialize |
|
11360 | 94 |
"/ Verbose := true. |
9944 | 95 |
Verbose := false. |
96 |
! ! |
|
97 |
||
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
98 |
!StandaloneStartup class methodsFor:'defaults'! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
99 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
100 |
allowDebugOption |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
101 |
"enable/disable the --debug startup option. |
11363 | 102 |
The default is now false, so standAlone apps are closed by default. |
103 |
Can be redefined in subclasses to enable it" |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
104 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
105 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
106 |
! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
107 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
108 |
allowScriptingOption |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
109 |
"enable/disable the --scripting startup option. |
11363 | 110 |
The default is now false, so standAlone apps are closed by default. |
111 |
Can be redefined in subclasses to enable it" |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
112 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
113 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
114 |
! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
115 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
116 |
suppressRCFileReading |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
117 |
"enable/disable the rc-file reading (and also the --rcFileName option). |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
118 |
If suppressed, there is no chance to interfere with the startup. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
119 |
Can be redefined in subclasses to disable it" |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
120 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
121 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
122 |
! ! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
123 |
|
9944 | 124 |
!StandaloneStartup class methodsFor:'helpers'! |
125 |
||
11423 | 126 |
printInfo:msg |
127 |
Transcript |
|
128 |
show:('%1 [info]: ' bindWith:(self applicationName)); |
|
129 |
showCR:msg |
|
130 |
! |
|
131 |
||
9944 | 132 |
redirectStandardStreams |
133 |
Stdout := Stderr. |
|
134 |
Transcript := Stderr. |
|
135 |
! |
|
136 |
||
137 |
verboseInfo:msg |
|
138 |
Verbose == true ifFalse:[^ self]. |
|
11423 | 139 |
self printInfo:msg |
9944 | 140 |
|
141 |
"Modified: / 19-09-2006 / 16:30:27 / cg" |
|
142 |
! ! |
|
143 |
||
11102 | 144 |
!StandaloneStartup class methodsFor:'multiple applications support'! |
145 |
||
146 |
applicationRegistryPath |
|
147 |
"the key under which this application stores its process ID in the registry |
|
148 |
as a collection of path-components. |
|
149 |
i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored |
|
150 |
in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID. |
|
151 |
(would also be used as a relative path for a temporary lock file under unix). |
|
152 |
Used to detect if another instance of this application is already running." |
|
153 |
||
154 |
self subclassResponsibility |
|
155 |
! |
|
156 |
||
157 |
applicationUUID |
|
158 |
"answer an application-specific unique uuid. |
|
159 |
This is used as the name of some exclusive OS-resource, which is used to find out, |
|
160 |
if another instance of this application is already running. |
|
161 |
Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used." |
|
162 |
||
163 |
self subclassResponsibility |
|
164 |
! |
|
165 |
||
166 |
checkForAndExitIfAnotherApplicationInstanceIsRunning |
|
167 |
"if another instance of this application is running, |
|
168 |
send it an openFile command for my file-argument, and exit. |
|
169 |
(i.e. to let the already running application open up another window)." |
|
170 |
||
171 |
|shouldExit| |
|
172 |
||
173 |
self isAnotherApplicationInstanceRunning ifTrue:[ |
|
174 |
shouldExit := self processStartupOfASecondInstance. |
|
175 |
shouldExit ifTrue:[ |
|
176 |
self releaseApplicationMutex. |
|
177 |
Smalltalk isStandAloneApp ifTrue:[ |
|
178 |
Smalltalk exit. |
|
179 |
] |
|
180 |
]. |
|
181 |
]. |
|
182 |
! ! |
|
183 |
||
184 |
!StandaloneStartup class methodsFor:'multiple applications support-helpers'! |
|
185 |
||
186 |
applicationRegistryEntry |
|
187 |
"retrieve the registry entry in which (if present), any currently running application |
|
188 |
has left its process ID" |
|
189 |
||
190 |
|path relPathName applicationEntry softwareEntry| |
|
191 |
||
192 |
path := self applicationRegistryPath. |
|
193 |
relPathName := path asStringWith:$\. |
|
194 |
applicationEntry := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\',relPathName. |
|
195 |
applicationEntry isNil ifTrue:[ |
|
196 |
softwareEntry := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software'. |
|
197 |
softwareEntry isNil ifTrue:[ |
|
198 |
Transcript showCR: 'Failed to get Software entry in registry'. |
|
199 |
^ nil. |
|
200 |
]. |
|
11103 | 201 |
|
11102 | 202 |
path do:[:subKey | |
203 |
|subEntry| |
|
204 |
||
11103 | 205 |
subEntry := softwareEntry createSubKeyNamed:subKey. |
11102 | 206 |
subEntry isNil ifTrue:[ |
207 |
Transcript showCR: 'Failed to create ',subKey,' entry in registry'. |
|
208 |
^ nil. |
|
209 |
]. |
|
210 |
softwareEntry := subEntry. |
|
211 |
]. |
|
212 |
applicationEntry := softwareEntry. |
|
213 |
]. |
|
214 |
^ applicationEntry |
|
215 |
! |
|
216 |
||
11107 | 217 |
confirmOpenNewApplicationInstance |
218 |
||
219 |
^ Dialog confirm: ('Continue opening a new instance of %1 or exit?' bindWith:self applicationName) |
|
220 |
title: ('%1 is already open!!' bindWith:self applicationName) |
|
221 |
yesLabel: 'Continue' |
|
222 |
noLabel: 'Exit' |
|
223 |
! |
|
224 |
||
11102 | 225 |
currentIDKeyInRegistry |
226 |
^ 'CurrentID' |
|
227 |
! |
|
228 |
||
229 |
getCurrentIDFromRegistry |
|
230 |
||
231 |
|applicationEntry| |
|
232 |
||
233 |
applicationEntry := self applicationRegistryEntry. |
|
234 |
applicationEntry isNil ifTrue:[^ nil.]. |
|
235 |
^ applicationEntry valueNamed: self currentIDKeyInRegistry |
|
236 |
||
237 |
" |
|
238 |
|hWnd externalAddress| |
|
239 |
hWnd := DapasXStartup getCurrentIDFromRegistry. |
|
240 |
hWnd isEmptyOrNil ifTrue:[^ self halt.]. |
|
241 |
hWnd := hWnd asInteger. |
|
242 |
externalAddress := ExternalAddress newAddress: hWnd. |
|
243 |
Display raiseWindow:externalAddress. |
|
244 |
Display setForegroundWindow:externalAddress |
|
245 |
" |
|
246 |
! |
|
247 |
||
248 |
getIDOfRunningApplicationFromRegistryEntry |
|
249 |
|applicationEntry| |
|
250 |
||
251 |
applicationEntry := self applicationRegistryEntry. |
|
252 |
applicationEntry isNil ifTrue:[^ nil.]. |
|
253 |
^ applicationEntry valueNamed: self currentIDKeyInRegistry |
|
254 |
! |
|
255 |
||
256 |
isAnotherApplicationInstanceRunning |
|
257 |
"answer true, if another instance of mzself is currently running. |
|
258 |
For now, it only works under win32, because it uses the underlying mutex mechanism." |
|
259 |
||
11106 | 260 |
| lastErrorCode alreadyExists handleAndLastErrorCode | |
11102 | 261 |
|
262 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
263 |
handleAndLastErrorCode := OperatingSystem createMutexNamed: (self applicationUUID printString). |
|
264 |
MutexHandle := handleAndLastErrorCode first. |
|
265 |
lastErrorCode := handleAndLastErrorCode second. |
|
266 |
"/ self assert: lastErrorCode == 0. |
|
267 |
alreadyExists := |
|
268 |
MutexHandle isNil |
|
269 |
or:[lastErrorCode == 183 "ERROR_ALREADY_EXISTS" |
|
270 |
or:[lastErrorCode == 5 "ERROR_ACCESS_DENIED"]]. |
|
271 |
||
272 |
alreadyExists ifFalse:[OperatingSystem waitForSingleObject: MutexHandle]. |
|
273 |
^ alreadyExists |
|
274 |
]. |
|
275 |
||
276 |
^ false. |
|
277 |
! |
|
278 |
||
279 |
processStartupOfASecondInstance |
|
280 |
"This is executed when I have been started as a second instance of an already running application. |
|
281 |
If I can get the currentID (i.e. windowID) of the first one and there is a command line argument with a file, |
|
282 |
send a message to the main window of the already running application, o ask it for another window. |
|
283 |
If the currentID is unknown, ask if the user wants to open a new instance of the application anyway. |
|
284 |
Return true if the first instance has been notified, and this second instance should exit." |
|
285 |
||
11107 | 286 |
|currentIDStringFromRegistry currentIDFromRegistry fileArg commands aWindowId setForegroundWindowSucceeded| |
11102 | 287 |
|
288 |
commands := Smalltalk commandLineArguments. |
|
289 |
||
290 |
currentIDStringFromRegistry := self getCurrentIDFromRegistry. |
|
291 |
||
292 |
"If the currentID is not found and there are arguments from the command line, |
|
293 |
we should wait in case of starting the first instance of the application |
|
294 |
with a multiple selection of files." |
|
295 |
(currentIDStringFromRegistry isEmptyOrNil and:[commands notEmptyOrNil]) ifTrue:[ |
|
296 |
Delay waitForSeconds: 2. |
|
297 |
]. |
|
298 |
||
299 |
currentIDStringFromRegistry := self getCurrentIDFromRegistry. |
|
300 |
currentIDStringFromRegistry isEmptyOrNil ifTrue:[ |
|
11107 | 301 |
^ self confirmOpenNewApplicationInstance not. |
11102 | 302 |
]. |
303 |
||
11107 | 304 |
currentIDFromRegistry := Integer readFrom:currentIDStringFromRegistry onError: 0. |
11102 | 305 |
|
306 |
"/ bring the other application to the foreground |
|
307 |
aWindowId := ExternalAddress newAddress: currentIDFromRegistry. |
|
11107 | 308 |
setForegroundWindowSucceeded := Display primSetForegroundWindow: aWindowId. |
11379 | 309 |
"/ setForegroundWindowSucceeded ifFalse:[^ self confirmOpenNewApplicationInstance not]. |
11102 | 310 |
|
311 |
"Autostart for associated extension" |
|
312 |
commands notEmpty ifTrue:[ |
|
313 |
fileArg := commands last asFilename. |
|
314 |
fileArg exists ifTrue:[ |
|
315 |
self sendOpenPathCommand:(fileArg pathName) toWindowId: aWindowId. |
|
316 |
]. |
|
317 |
]. |
|
318 |
^ true |
|
319 |
! |
|
320 |
||
321 |
releaseApplicationMutex |
|
322 |
||
323 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
324 |
MutexHandle notNil ifTrue:[ |
|
325 |
OperatingSystem releaseMutex: MutexHandle. |
|
326 |
OperatingSystem primCloseHandle: MutexHandle. |
|
327 |
]. |
|
328 |
]. |
|
329 |
! |
|
330 |
||
331 |
sendCommand:message toWindowId:aWindowId |
|
332 |
"use the event send mechanism to forward a command to the already running application" |
|
333 |
||
334 |
Display |
|
335 |
sendCopyDataString: message |
|
336 |
toWindowId: aWindowId. |
|
337 |
! |
|
338 |
||
339 |
sendOpenPathCommand:pathName toWindowId:aWindowId |
|
340 |
"use the event send mechanism to forward an open-Path command to the already running application" |
|
341 |
||
342 |
self sendCommand:('openPath:', pathName) toWindowId:aWindowId. |
|
343 |
! |
|
344 |
||
345 |
writeCurrentIDIntoRegistry: currentID |
|
346 |
||
11104 | 347 |
|applicationEntry currentIDEntry| |
11102 | 348 |
|
11104 | 349 |
applicationEntry := self applicationRegistryEntry. |
350 |
applicationEntry isNil ifTrue:[^ false.]. |
|
11102 | 351 |
|
11104 | 352 |
currentIDEntry := applicationEntry createSubKeyNamed:(self currentIDKeyInRegistry). |
11102 | 353 |
currentIDEntry isNil ifTrue:[ |
354 |
Transcript showCR: 'Failed to create CurrentID entry in registry'. |
|
355 |
^ false. |
|
356 |
]. |
|
357 |
||
11104 | 358 |
^ applicationEntry valueNamed:(self currentIDKeyInRegistry) put:(currentID printString). |
11102 | 359 |
|
360 |
" |
|
361 |
| currentID returnedCurrentID | |
|
362 |
currentID := 999. |
|
363 |
DapasXStartup writeCurrentIDIntoRegistry: currentID. |
|
364 |
returnedCurrentID := DapasXStartup getCurrentIDFromRegistry. |
|
365 |
self assert: currentID = returnedCurrentID asNumber. |
|
366 |
" |
|
367 |
! ! |
|
368 |
||
9944 | 369 |
!StandaloneStartup class methodsFor:'queries'! |
370 |
||
371 |
applicationName |
|
11352 | 372 |
"used in verbose messages - can/should be redefined in subclasses" |
9944 | 373 |
|
374 |
|nm| |
|
375 |
||
376 |
nm := self nameWithoutPrefix. |
|
377 |
(nm endsWith:'Startup') ifTrue:[ |
|
378 |
^ nm copyWithoutLast:('Startup' size). |
|
379 |
]. |
|
380 |
(nm endsWith:'Start') ifTrue:[ |
|
381 |
^ nm copyWithoutLast:('Start' size). |
|
382 |
]. |
|
383 |
^ nm |
|
384 |
||
385 |
"Created: / 19-09-2006 / 16:26:44 / cg" |
|
386 |
! |
|
387 |
||
10040
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
388 |
isBrowserStartable |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
389 |
"do not allow clicking on me in the browser" |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
390 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
391 |
^ false |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
392 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
393 |
"Created: / 06-10-2006 / 11:33:13 / cg" |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
394 |
! |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
395 |
|
9944 | 396 |
startupFilename |
11352 | 397 |
"used in verbose messages - can/should be redefined in subclasses" |
9944 | 398 |
|
399 |
^ self applicationName asLowercase,'Start.rc' |
|
400 |
||
401 |
" |
|
11352 | 402 |
ExpeccoStartup startupFilename -> 'expecco.rc' |
9944 | 403 |
" |
404 |
||
405 |
"Created: / 19-09-2006 / 16:38:28 / cg" |
|
406 |
! ! |
|
407 |
||
408 |
!StandaloneStartup class methodsFor:'startup'! |
|
409 |
||
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
410 |
loadPatch:fileName |
11056
e2c4a6e948b6
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
11055
diff
changeset
|
411 |
self verboseInfo:('loading patch: ',fileName baseName). |
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
412 |
Smalltalk fileIn:fileName pathName. |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
413 |
! |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
414 |
|
9944 | 415 |
loadPatches |
11764
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
416 |
|patchesDir prevMode| |
9944 | 417 |
|
10934 | 418 |
patchesDir := OperatingSystem pathOfSTXExecutable asFilename directory construct:'patches'. |
419 |
(patchesDir exists and:[patchesDir isDirectory]) ifTrue:[ |
|
11764
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
420 |
prevMode := ClassCategoryReader sourceMode. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
421 |
ClassCategoryReader sourceMode:#discard. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
422 |
[ |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
423 |
patchesDir directoryContents sort do:[:eachFilenameString | |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
424 |
self loadPatch:(patchesDir construct:eachFilenameString). |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
425 |
]. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
426 |
] ensure:[ |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
427 |
ClassCategoryReader sourceMode:prevMode. |
9944 | 428 |
]. |
429 |
]. |
|
430 |
||
431 |
"Modified: / 19-09-2006 / 16:30:58 / cg" |
|
432 |
! |
|
433 |
||
434 |
setupSmalltalkFromArguments:argv |
|
11352 | 435 |
"handle common command line arguments: |
436 |
--help ............... print usage and exit |
|
437 |
--verbose (-V) ....... be verbose during startup |
|
438 |
--debug .............. enable debugger & inspector |
|
439 |
--rcFileName ......... define a startup rc-file |
|
11435 | 440 |
--scripting portNr ... start a scripting server |
441 |
--allowHost host ..... add host to the allowed scripting hosts |
|
11352 | 442 |
" |
443 |
||
11435 | 444 |
|idx rcFilename nextArg debugging scripting allowedScriptingHosts portNr| |
9944 | 445 |
|
446 |
"/ Smalltalk beHeadless:true. |
|
447 |
"/ OperatingSystem disableSignal:(OperatingSystem sigHUP). |
|
448 |
"/ Smalltalk infoPrinting:true. |
|
449 |
||
450 |
(argv includes:'--help') ifTrue:[ |
|
451 |
self usage. |
|
452 |
AbortOperationRequest raise. |
|
453 |
]. |
|
454 |
||
455 |
idx := argv indexOfAny:#('--verbose' '-V'). |
|
456 |
idx ~~ 0 ifTrue:[ |
|
457 |
argv removeAtIndex:idx. |
|
458 |
Verbose := true. |
|
459 |
]. |
|
10773 | 460 |
self verboseInfo:('args: ',argv asArray printString). |
9944 | 461 |
|
11352 | 462 |
debugging := false. |
463 |
(self allowDebugOption) ifTrue:[ |
|
464 |
idx := argv indexOfAny:#('--debug'). |
|
465 |
idx ~~ 0 ifTrue:[ |
|
11357 | 466 |
self verboseInfo:('debug on'). |
11352 | 467 |
argv removeAtIndex:idx. |
468 |
debugging := true |
|
469 |
]. |
|
470 |
]. |
|
471 |
debugging ifTrue:[ |
|
9944 | 472 |
self setupToolsForDebug. |
473 |
] ifFalse:[ |
|
474 |
self setupToolsForNoDebug. |
|
475 |
]. |
|
476 |
||
11352 | 477 |
self suppressRCFileReading ifFalse:[ |
478 |
idx := argv indexOf:'--rcFileName'. |
|
479 |
idx ~~ 0 ifTrue:[ |
|
480 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
481 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
482 |
rcFilename := nextArg. |
|
483 |
argv removeAtIndex:idx+1; removeAtIndex:idx. |
|
484 |
] |
|
485 |
]. |
|
486 |
||
487 |
rcFilename isNil ifTrue:[ |
|
488 |
rcFilename := self startupFilename. |
|
489 |
]. |
|
490 |
rcFilename asFilename exists ifTrue:[ |
|
491 |
self verboseInfo:('reading ',rcFilename,'...'). |
|
492 |
rcFilename isAbsolute ifFalse:[ |
|
493 |
rcFilename := OperatingSystem pathOfSTXExecutable asFilename directory constructString:rcFilename. |
|
494 |
]. |
|
495 |
Smalltalk secureFileIn:rcFilename |
|
496 |
]. |
|
9944 | 497 |
]. |
498 |
||
11352 | 499 |
scripting := false. |
500 |
(self allowScriptingOption) ifTrue:[ |
|
501 |
idx := argv indexOfAny:#('--scripting'). |
|
502 |
idx ~~ 0 ifTrue:[ |
|
503 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
504 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
505 |
portNr := nextArg asInteger. |
|
506 |
argv removeAtIndex:idx+1. |
|
507 |
]. |
|
508 |
argv removeAtIndex:idx. |
|
509 |
||
510 |
scripting := true |
|
511 |
]. |
|
11435 | 512 |
|
513 |
allowedScriptingHosts := OrderedCollection new. |
|
514 |
||
515 |
idx := argv indexOfAny:#('--allowHost'). |
|
516 |
[idx ~~ 0] whileTrue:[ |
|
517 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
518 |
nextArg isNil ifTrue:[ |
|
519 |
self usage. |
|
520 |
AbortOperationRequest raise. |
|
521 |
]. |
|
522 |
allowedScriptingHosts add:nextArg. |
|
523 |
idx := argv indexOfAny:#('--allowHost'). |
|
524 |
]. |
|
9944 | 525 |
]. |
11435 | 526 |
|
11352 | 527 |
scripting ifTrue:[ |
11358 | 528 |
self verboseInfo:('scripting on'). |
11352 | 529 |
STXScriptingServer notNil ifTrue:[ |
11435 | 530 |
allowedScriptingHosts do:[:eachHost | STXScriptingServer allowHost:eachHost ]. |
531 |
||
11353 | 532 |
"/ scripting on port/stdin_out/8008 |
533 |
self verboseInfo:('start scripting'). |
|
534 |
STXScriptingServer startAt:portNr |
|
11359 | 535 |
] ifFalse:[ |
536 |
self verboseInfo:('missing STXScriptingServer class'). |
|
9944 | 537 |
]. |
538 |
]. |
|
11352 | 539 |
|
9944 | 540 |
^ true |
541 |
||
10773 | 542 |
"Modified: / 31-10-2007 / 16:05:59 / cg" |
9944 | 543 |
! |
544 |
||
11355 | 545 |
setupToolsForDebug |
546 |
Debugger := DebugView ? MiniDebugger. |
|
547 |
Inspector := InspectorView ? MiniInspector. |
|
11736 | 548 |
Verbose ifTrue:[ 'debug enabled - CTRL-C brings you into a debugger.' errorPrintCR ]. |
549 |
"/ self verboseInfo:('debug enabled - CTRL-C brings you into a debugger.'). |
|
9944 | 550 |
|
551 |
"Created: / 19-09-2006 / 16:40:32 / cg" |
|
552 |
! |
|
553 |
||
11355 | 554 |
setupToolsForNoDebug |
555 |
Smalltalk isStandAloneApp ifTrue:[ |
|
11600
1d98211fc0b0
also nil private classes of NewLauncher
Claus Gittinger <cg@exept.de>
parents:
11435
diff
changeset
|
556 |
Smalltalk at:#Debugger put:nil. |
1d98211fc0b0
also nil private classes of NewLauncher
Claus Gittinger <cg@exept.de>
parents:
11435
diff
changeset
|
557 |
Smalltalk at:#Inspector put:nil. |
11714
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
558 |
NewLauncher notNil ifTrue:[ |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
559 |
NewLauncher allPrivateClasses do:[:cls | |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
560 |
Smalltalk at:(cls name) put:nil. |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
561 |
]. |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
562 |
Smalltalk at:#NewLauncher put:nil. |
11600
1d98211fc0b0
also nil private classes of NewLauncher
Claus Gittinger <cg@exept.de>
parents:
11435
diff
changeset
|
563 |
]. |
11736 | 564 |
Verbose ifTrue:[ 'debug disabled.' errorPrintCR ]. |
565 |
||
11355 | 566 |
self redirectStandardStreams. |
10773 | 567 |
]. |
9944 | 568 |
|
569 |
"Created: / 19-09-2006 / 16:40:47 / cg" |
|
10773 | 570 |
"Modified: / 31-10-2007 / 16:18:40 / cg" |
9944 | 571 |
! |
572 |
||
11355 | 573 |
start |
574 |
CommandLineArguments := Smalltalk commandLineArguments. |
|
575 |
||
576 |
self verboseInfo:('starting...'). |
|
577 |
self verboseInfo:('args: ', CommandLineArguments asStringCollection asString). |
|
9944 | 578 |
|
579 |
Smalltalk isStandAloneApp ifTrue:[ |
|
580 |
self loadPatches. |
|
581 |
self verboseInfo:('setup Smalltalk'). |
|
582 |
]. |
|
10772 | 583 |
self setupSmalltalkFromArguments:CommandLineArguments. |
9944 | 584 |
self main |
585 |
||
10772 | 586 |
"Modified: / 31-10-2007 / 16:03:44 / cg" |
9944 | 587 |
! |
588 |
||
11807
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
589 |
startStartBlockProcess |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
590 |
Smalltalk startStartBlockProcess |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
591 |
! |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
592 |
|
11355 | 593 |
usage |
594 |
Stderr nextPutLine:'usage:'. |
|
595 |
Stderr nextPutLine:' ',self applicationName,' [options...]'. |
|
596 |
Stderr nextPutLine:' options:'. |
|
597 |
Stderr nextPutLine:' --help .................. output this message'. |
|
9944 | 598 |
Stderr nextPutLine:' --verbose ............... verbose startup'. |
11610 | 599 |
Stderr nextPutLine:' --noBanner .............. no splash screen'. |
11352 | 600 |
self allowScriptingOption ifTrue:[ |
601 |
Stderr nextPutLine:' --scripting portNr ...... enable scripting via port (or stdin/stdOut, if 0)'. |
|
602 |
]. |
|
603 |
self allowDebugOption ifTrue:[ |
|
604 |
Stderr nextPutLine:' --debug ................. enable Debugger'. |
|
605 |
]. |
|
606 |
self suppressRCFileReading ifFalse:[ |
|
607 |
Stderr nextPutLine:' --rcFileName file ....... execute code from file on startup (default: ',self startupFilename,')'. |
|
608 |
]. |
|
9944 | 609 |
|
610 |
"Created: / 19-09-2006 / 16:37:55 / cg" |
|
611 |
! ! |
|
612 |
||
613 |
!StandaloneStartup class methodsFor:'startup-to be redefined'! |
|
614 |
||
11806
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
615 |
isHeadless |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
616 |
"this is invoked early by Smalltalk>>mainStartup, to ask if I like to |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
617 |
have a Display or if I am a non-GUI headless application. |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
618 |
|
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
619 |
Redefine in subclass, if your application is a non-GUI application" |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
620 |
|
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
621 |
^ false |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
622 |
! |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
623 |
|
11355 | 624 |
main |
625 |
self verboseInfo:('entering main'). |
|
626 |
||
627 |
self main:CommandLineArguments. |
|
628 |
||
629 |
" |
|
630 |
self main |
|
631 |
self main:#('--info') |
|
632 |
" |
|
633 |
||
634 |
"Modified: / 31-10-2007 / 16:03:22 / cg" |
|
10636 | 635 |
! |
636 |
||
11355 | 637 |
main:argv |
638 |
self subclassResponsibility. |
|
639 |
||
640 |
"/ a typical main: looks like (in a subclass): |
|
641 |
||
642 |
"/ |app fileArg| |
|
643 |
"/ |
|
644 |
"/ self verboseInfo:('starting application'). |
|
9944 | 645 |
"/ app := <someGUIApplicationModelClass> open. |
646 |
"/ |
|
647 |
"/ self verboseInfo:('looking for args in ',argv). |
|
648 |
"/ argv notEmptyOrNil ifTrue:[ |
|
649 |
"/ fileArg := argv last asFilename. |
|
650 |
"/ self verboseInfo:('fileArg is ',fileArg name). |
|
651 |
"/ fileArg exists ifTrue:[ |
|
652 |
"/ self verboseInfo:('file exists'). |
|
653 |
"/ |
|
654 |
"/ ( #('foo' 'bar' 'baz' ) includes:fileArg suffix) ifTrue:[ |
|
655 |
"/ self verboseInfo:('loading'). |
|
656 |
"/ |
|
657 |
"/ Error handle:[:ex | |
|
658 |
"/ self verboseInfo:'error while loading'. |
|
659 |
"/ ex suspendedContext fullPrintAll. |
|
660 |
"/ ] do:[ |
|
661 |
"/ app menuLoadFromFile:fileArg |
|
662 |
"/ ]. |
|
663 |
"/ ]. |
|
664 |
"/ ]. |
|
665 |
"/ ]. |
|
666 |
||
667 |
"Created: / 19-09-2006 / 16:48:29 / cg" |
|
668 |
! ! |
|
669 |
||
670 |
!StandaloneStartup class methodsFor:'documentation'! |
|
671 |
||
672 |
version |
|
12335 | 673 |
^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.39 2009-10-22 19:07:43 cg Exp $' |
674 |
! |
|
675 |
||
676 |
version_CVS |
|
677 |
^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.39 2009-10-22 19:07:43 cg Exp $' |
|
9944 | 678 |
! ! |
679 |
||
680 |
StandaloneStartup initialize! |