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