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