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