source: AE/Setup/Mac/AE Setup/AE Setup/AppDelegate.applescript@ 1096

Last change on this file since 1096 was 1091, checked in by iritscen, 7 years ago

Updating Mac AE Setup to v1.3 (no code changes, only the new AEIU .jar file).

File size: 19.6 KB
Line 
1-- Anniversary Edition Setup
2-- for Anniversary Edition Seven
3-- by Iritscen
4-- For installing the Anniversary Edition Seven's AEI Updater. This script looks for an existing Oni
5-- installation, places the AEInstaller2Updater into a new AE/ folder, and runs it. It also makes sure
6-- that the user has Java installed so he can run the Updater and Installer. It does not check for Mono
7-- because that would be redundant of the Installer itself.
8-- History:
9-- 1.3.0 - No code changes. Re-built in order to include AEInstaller2Updater 1.3.
10-- 1.2.0 - No code changes. Re-built in order to include Run AE Installer 1.1.0, which had a change
11-- made to ensure Mono compatibility in 10.13.
12-- 1.1.9 - No code changes. Re-built in order to include Run AE Installer 1.0.9, which also had no
13-- code changes but needed to be re-built in 10.12 in order to run in 10.12.
14-- 1.1.8 - Updated "Run AE Installer" script for Mono in 10.11.
15-- 1.1.7 - Now an AppleScriptObjC application to ensure signing integrity and OS compatibility.
16-- 1.1.6 - Now testing for Java's existence before talking to it, because it seems that simply calling
17-- "java -version" now causes the script to fail with an error dialog instead of invoking
18-- OS X's Java installation prompt. Setup app now uses the standard icon name "applet" so
19-- that Info.plist does not have to be edited, since that invalidates the code signature
20-- applied by OS X 10.6's Script Editor. Some dialog text has been made clearer. Fixed a
21-- weird bug that cropped up for the first time while testing this script, which was
22-- breaking GDF validation.
23-- 1.1.5 - Now using fixed paths for Java for 10.6 and for 10.7+ because "which java" is not reliable.
24-- 1.1.4 - Now attempting to call Java through "java" again before falling back to looking in Internet
25-- Plug-Ins, because 10.6 has Java installed differently.
26-- 1.1.3 - No longer supplying link to MacUpdate page for Apple Java because it is out of date; only
27-- supplying link to java.com.
28-- 1.1.2 - Calling Java at Internet plug-in location instead of using basic command-line "java", as
29-- only the JDK installs command-line Java.
30-- 1.1.1 - Changed the "Run AE Installer" script to set environment to UTF-8 in order to avoid 'ƒ'
31-- problem in Java 7.
32-- 1.1 - Updated bundled AEI Updater to 1.1, which supports proxies.
33-- 1.0 - Initial release.
34
35script AppDelegate
36 property parent : class "NSObject"
37 global pathToMe
38 global sosumi
39 global gNeedsJavaVersionMajor
40 global gNeedsJavaVersionMinor
41
42 -- IBOutlets
43 property theWindow : missing value
44 property aesIcon : missing value
45
46 on applicationWillFinishLaunching_(aNotification)
47 -- Set globals
48 set gNeedsJavaVersionMajor to 1
49 set gNeedsJavaVersionMinor to 6
50
51 -- Set "pathToMe" for various future uses; its value will be "/path/to/Anniversary Edition Setup.app/Contents/Resources"
52 tell current application's class "NSBundle"
53 tell its mainBundle()
54 set pathToMe to resourcePath() as string
55 end tell
56 end tell
57
58 -- Draw the AE Setup icon in the window
59 set iconPath to POSIX path of ((pathToMe & "/AppIcon.png") as string)
60 set aesIconImg to current application's NSImage's alloc's initWithContentsOfFile_(iconPath)
61 aesIcon's setImage_(aesIconImg)
62
63 -- Set up "sosumi" with the Sosumi sound
64 tell current application's NSSound to set thisSound to soundNamed_("Sosumi")
65
66 -- Bring self to front in case something else stole focus
67 tell me
68 activate
69 end tell
70 end applicationWillFinishLaunching_
71
72 on applicationShouldTerminateAfterLastWindowClosed_(sender)
73 return true
74 end applicationShouldTerminateAfterLastWindowClosed_
75
76 on applicationShouldTerminate_(sender)
77 -- Insert code here to do any housekeeping before your application quits
78 return current application's NSTerminateNow
79 end applicationShouldTerminate_
80
81 -- IBActions
82 on clickStart_(sender)
83 set installPath to my find_Oni_folder()
84 tell me
85 activate
86 end tell
87 if (installPath is "Gave up") then
88 display dialog "Sorry, the AE currently requires a retail Oni installation." buttons {"OK"} default button 1 with title "AE Setup"
89 else if (installPath is "AE exists") then
90 display dialog "If you are sure you want to start over with a new AE installation in this location, then you should delete the existing AE/ folder and then run this Setup app again." buttons {"OK"} default button 1 with title "AE Setup"
91 else if (installPath is "") then
92 display dialog "Unknown error encountered while choosing Oni installation. Please ask for help in the Anniversary Edition sub-forum of the Oni Central Forum." buttons {"Go to forum", "OK"} default button 2 with title "AE Setup"
93 set quitOrForum to button returned of the result
94 if (quitOrForum is "Go to forum") then
95 open location "http://oni.bungie.org/community/forum/index.php"
96 end if
97 else
98 set installResult to my install_AEI_Updater(installPath)
99 tell me
100 activate
101 end tell
102 if (installResult is 0) then
103 display dialog "Updater installed. AE Setup will now continue the installation by running the Updater." buttons {"OK"} default button 1 with title "AE Setup"
104 set runResult to my run_AEIU(installPath)
105 tell me
106 activate
107 end tell
108 -- Quit if running Run AE Installer seems to have been successful
109 if (runResult is 0) then
110 tell me
111 quit
112 end tell
113 else if (runResult is 1) then
114 display dialog "Script copy error. Please ask for help in the Anniversary Edition sub-forum of the Oni Central Forum." buttons {"Go to forum", "OK"} default button 2 with title "AE Setup"
115 set quitOrForum to button returned of the result
116 if (quitOrForum is "Go to forum") then
117 open location "http://oni.bungie.org/community/forum/index.php"
118 end if
119 else if (runResult is 2) then
120 display dialog "Could not run AEI Updater. Please ask for help in the Anniversary Edition sub-forum of the Oni Central Forum." buttons {"Go to forum", "OK"} default button 2 with title "AE Setup"
121 set quitOrForum to button returned of the result
122 if (quitOrForum is "Go to forum") then
123 open location "http://oni.bungie.org/community/forum/index.php"
124 end if
125 end if
126 else if (installResult is 1) then
127 display dialog "Could not install the AEI Updater because Java was not installed or new enough. Please obtain a Java installer from Java.com." buttons {"Go to Java.com", "OK"} default button 2 with title "AE Setup"
128 set quitOrJava to button returned of the result
129 if (quitOrJava is "Go to Java.com") then
130 open location "http://www.java.com/"
131 end if
132 else if (installResult is 2) then -- file operation failure
133 display dialog "Could not install the AEI Updater. Please ask for help in the Anniversary Edition sub-forum of the Oni Central Forum." buttons {"Go to forum", "OK"} default button 2 with title "AE Setup"
134 set quitOrForum to button returned of the result
135 if (quitOrForum is "Go to forum") then
136 open location "http://oni.bungie.org/community/forum/index.php"
137 end if
138 else
139 display dialog "Unknown error returned from install_AEI_Updater()! Please ask for help in the Anniversary Edition sub-forum of the Oni Central Forum." buttons {"Go to forum", "OK"} default button 2 with title "AE Setup"
140 set quitOrForum to button returned of the result
141 if (quitOrForum is "Go to forum") then
142 open location "http://oni.bungie.org/community/forum/index.php"
143 end if
144 end if
145 end if
146 end clickStart_
147
148 -- The user must pick an acceptable folder to install the AE in, or die trying (or give up)
149 -- Returns "Gave up" if user clicked Quit after being told his choice was not the Oni folder,
150 -- "AE exists" if user clicked Quit after being told that the AE folder was already present, and
151 -- returns the user's chosen path if validation was successful
152 -- Called by clickStart_()
153 on find_Oni_folder()
154 tell me
155 tell me
156 activate
157 end tell
158 set tryAgain to true
159 set isOniRetail to false
160 set pathProblem to ""
161 set folderTest to 0
162 repeat while (tryAgain is true)
163 set chosenPath to (choose folder with prompt "Please locate your Oni installation.")
164 if (chosenPath is "") then
165 display dialog "There was an error in choosing the Oni folder." buttons {"OK"} default button 1 with title "AE Setup"
166 return chosenPath
167 end if
168 set folderTest to my validate_Oni_folder(chosenPath)
169 tell me
170 activate
171 end tell
172 if (folderTest is 1) then
173 display dialog "This doesn't seem to be your Oni installation. Click \"Try again\" to locate another folder." buttons {"Cancel", "Try again"} default button 2 with title "AE Setup"
174 set cancelOrTryAgain to the button returned of the result
175 if (cancelOrTryAgain is "Cancel") then
176 set tryAgain to false
177 set pathProblem to "Gave up"
178 end if
179 else if (folderTest is 2) then
180 display dialog "This Oni installation already has an AE/ folder! This means that you've probably already run this Setup app, and now you should be opening the \"Run AE Installer\" script in the AE/ folder. You can also click \"Try again\" to find another Oni installation in which to install the AE." buttons {"Cancel", "Try again"} default button 2 with title "AE Setup"
181 set cancelOrTryAgain to the button returned of the result
182 if (cancelOrTryAgain is "Cancel") then
183 set tryAgain to false
184 set pathProblem to "AE exists"
185 end if
186 else
187 set tryAgain to false -- we got it, let's get out of this loop
188 end if
189 end repeat
190 if (folderTest is 0) then
191 return chosenPath
192 else
193 return pathProblem
194 end if
195 end tell
196 end find_Oni_folder
197
198 -- Returns 0 if this is a valid target for the AE installation,
199 -- 1 if this is not a valid target, and
200 -- 2 if the AE is already here
201 -- Called by find_Oni_folder()
202 on validate_Oni_folder(folderPath)
203 tell application "Finder"
204 tell me
205 activate
206 end tell
207 -- Is the GDF here?
208 if not (exists folder "GameDataFolder" in folder folderPath) then
209 display dialog "GameDataFolder not detected here." buttons {"OK"} default button 1 with title "AE Setup"
210 return 1
211 end if
212 -- Is the AE folder here? Because we won't install over it.
213 if (exists folder "AE" in folder folderPath) then
214 return 2
215 end if
216
217 -- Now see if this is the full installation or demo
218 set retailLevelList to {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}
219 set demoLevelList to {0, 1, 4} -- there's also a separate demo release of just level 2 to be dropped into the demo's GDF, but 1 and 4 were the only core demo levels
220 set isRetail to true
221 set isDemo to true
222 -- Look for levels until one is missing and we know this isn't a complete retail release
223 repeat with thisLevel in retailLevelList
224 if not (exists file ((folderPath & "GameDataFolder:level" & (thisLevel as string) & "_Final.dat") as string)) then
225 set isRetail to false
226 exit repeat
227 end if
228 end repeat
229 if (isRetail) then
230 -- Don't return here if we add demo support below
231 return 0
232 end if
233 -- Look for levels until one is missing and we know this isn't a complete demo release
234 repeat with thisLevel in demoLevelList
235 if not (exists file ((folderPath & "GameDataFolder:level" & (thisLevel as string) & "_Final.dat") as string)) then
236 set isDemo to false
237 exit repeat
238 end if
239 end repeat
240 if (isDemo) then
241 -- Insert handling of demo status here if we ever support a demo AE
242 return 1
243 else
244 return 1
245 end if
246 end tell
247 end validate_Oni_folder
248
249 -- If Java is found, creates the AE/ folder with the Updater
250 -- Returns 0 if the Updater was installed (which will install the Installer itself afterward),
251 -- 1 if Java fails verification, and
252 -- 2 if a file operation or other error occurs
253 -- Called by clickStart_()
254 on install_AEI_Updater(pathToOni)
255 tell me
256 set javaResult to my verify_Java()
257 if (javaResult is 1) then
258 return 1
259 end if
260 end tell
261 -- Make "Oni/AE" folder
262 tell application "Finder"
263 if ((pathToOni & "AE") exists) then -- shouldn't happen because we already looked for it in validate_Oni_folder()
264 display alert "AE folder already present!"
265 return 2
266 end if
267 try
268 make new folder at pathToOni with properties {name:"AE"}
269 delay 0.5
270 make new folder at ((pathToOni as string) & "AE") with properties {name:"AEInstaller"}
271 on error
272 display alert "Couldn't make AE or AEI folder!"
273 return 2
274 end try
275
276 -- Copy AEI Updater into "AE/"
277 set AEIU to POSIX file (pathToMe & "/AEInstaller2Updater.jar") as alias
278 if (AEIU exists) then
279 set AEIfolder to (pathToOni & "AE:AEInstaller" as string)
280 try
281 duplicate file AEIU to folder AEIfolder
282 on error copyError
283 return 2
284 end try
285 else
286 display dialog "AE Installer Updater is not present in the Setup app!"
287 return 2
288 end if
289 end tell
290 return 0
291 end install_AEI_Updater
292
293 -- Checks for an acceptable Java installation
294 -- This function was going to support a bundled JRE for those without Java,
295 -- but it adds too many complications, so just make the user install it himself
296 -- Returns 1 if Java is not found or too old, and
297 -- 0 if Java is found and the version is acceptable
298 -- Called by install_AEI_Updater()
299 on verify_Java()
300 tell me
301 set origDelimiters to AppleScript's text item delimiters
302 set OSversion to (system version of (system info) as string)
303 set AppleScript's text item delimiters to "."
304
305 -- Java's location is different in 10.6 than in 10.7+
306 if ((second text item of OSversion) as number > 6) then
307 set javaPath to "/Library/Internet\\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
308 else
309 set javaPath to "/usr/bin/java"
310 end if
311
312 -- Test for Java before talking to it
313 set javaExistsTest to ("if [ -f " & javaPath & " ]; then echo okay; fi") as string
314 set javaExists to do shell script javaExistsTest without altering line endings
315 if (javaExists is "") then
316 return 1
317 end if
318
319 -- Get Java's version
320 set javaVersionCmd to ((javaPath & " -version 2>&1") as string) -- Java's version output is sometimes on stderr, not stdout :-/
321 set javaVersionText to do shell script javaVersionCmd without altering line endings
322 if (javaVersionText is "") then
323 return 1
324 end if
325
326 -- Isolate version number from output with format:
327 (* java version "1.7.0_17"
328 Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
329 Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode) *)
330 -- Get first line
331 set AppleScript's text item delimiters to "
332"
333 set javaVersionText to first text item of javaVersionText
334 -- Get text after first quote mark
335 set AppleScript's text item delimiters to "\""
336 set javaVersionText to second text item of javaVersionText
337 -- Get first and second version numbers, third doesn't matter
338 set AppleScript's text item delimiters to "."
339 set versionMajor to first text item of javaVersionText
340 set versionMinor to second text item of javaVersionText
341 set AppleScript's text item delimiters to origDelimiters
342 -- Inform user if Java is too old
343 if (versionMajor ≥ gNeedsJavaVersionMajor) then
344 if (versionMinor < gNeedsJavaVersionMinor) then
345 display dialog (("Sorry, Java v" & gNeedsJavaVersionMajor & "." & gNeedsJavaVersionMinor & " is required; found v" & versionMajor & "." & versionMinor & " instead.") as string) buttons {"OK"} default button 1 with title "AE Setup"
346 return 1
347 end if
348 else
349 display dialog (("Sorry, Java v" & gNeedsJavaVersionMajor & "." & gNeedsJavaVersionMinor & " is required; found v" & versionMajor & "." & versionMinor & " instead.") as string) buttons {"OK"} default button 1 with title "AE Setup"
350 return 1
351 end if
352 end tell
353 return 0
354 end verify_Java
355
356 -- Drops an applet into the new "AE/" folder and runs it;
357 -- the applet will try to run the AEI, but if it's not found,
358 -- it runs the AEI Updater, which is what we want to happen
359 -- so that the AEI can be installed.
360 -- Returns 0 if this is a valid target for the AE installation,
361 -- 1 if the applet cannot be dropped, and
362 -- 2 if the applet cannot be run
363 -- Called by clickStart_()
364 on run_AEIU(pathToOni)
365 tell application "Finder"
366 -- Copy applet to AE/ that opens AEI or AEIU if AEI is not around
367 set RAEI to POSIX file (pathToMe & "/Run AE Installer.app") as alias
368 set pathToAE to alias ((pathToOni & "AE") as string)
369 try
370 duplicate RAEI to pathToAE
371 on error copyError
372 return 1
373 end try
374 set RAEI to ((pathToAE as string) & "Run AE Installer.app")
375 try
376 open RAEI
377 on error runError
378 return 2
379 end try
380 end tell
381 return 0
382 end run_AEIU
383
384 on play_error_sound()
385 tell sosumi
386 play()
387 end tell
388 end play_error_sound
389end script
Note: See TracBrowser for help on using the repository browser.