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

Last change on this file since 1072 was 1065, checked in by iritscen, 8 years ago

Updated AE Setup to v1.2.0 to ensure Mono and macOS 10.13 compatibility.

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