source: AE/Setup/Mac/Anniversary Edition Setup.scpt@ 949

Last change on this file since 949 was 788, checked in by iritscen, 12 years ago

Adding code and resources for Mac AE Setup app.

File size: 11.3 KB
Line 
1-- Anniversary Edition Setup v1.0
2-- for Anniversary Edition Seven
3-- by Iritscen
4-- ***NOTE: Save as an application, then place Run AE Installer (built as an application too)
5-- and AEsetuplogo.icns inside Contents/Resources/ folder of the Anniversary Edition Setup app.
6-- Change the CFBundleIcon setting in the Setup app's Info.plist file to "AEsetuplogo" in order to
7-- have the app use the icon.
8-- For installing the Anniversary Edition Seven's AEI Updater. This script looks for an existing Oni
9-- installation, places the AEInstaller2Updater into a new AE/ folder, and runs it. It also makes sure
10-- that the user has Java installed so he can run the Updater and Installer.
11
12global gSetupIcon
13global gNeedsJavaVersionMajor
14global gNeedsJavaVersionMinor
15
16my main()
17
18on main()
19 --tell application "System Events"
20 tell me
21 activate
22 set gSetupIcon to alias ((path to me as string) & "Contents:Resources:AEsetuplogo.icns")
23 set gNeedsJavaVersionMajor to 1
24 set gNeedsJavaVersionMinor to 6
25 set installPath to ""
26 set pathToMe to (path to me as string)
27 display dialog ¬
28 "Thanks for your interest in the fan-made Anniversary Edition (AE) of Oni.
29
30This is the Setup application for the AE. Do not confuse this program with the \"AE Installer\", which will be found in the AE/ folder and which installs mods. This is a preliminary installation program.
31
32Click OK, then locate your Oni installation to install the AE." buttons {"Quit", "OK"} default button 2 ¬
33 with title "Anniversary Edition Setup" with icon gSetupIcon
34 set OKorQuit to the button returned of the result
35 if (OKorQuit is "OK") then
36 set installPath to my find_Oni_folder()
37 activate
38 if (installPath is "") then
39 display dialog "Sorry, the AE requires a retail Oni installation for it to work with." buttons {"Quit"} default button 1 with title "Anniversary Edition Setup" with icon gSetupIcon
40 else
41 set installResult to my install_AEI_Updater(installPath)
42 activate
43 if (installResult is 1) then
44 display dialog "Could not install the AEI Updater because Java was not installed or new enough. The MacUpdate button may take you to the needed page. Otherwise, try the Java.com button." buttons {"MacUpdate", "Java.com", "Quit"} default button 3 with title "Anniversary Edition Setup" with icon gSetupIcon
45 set quitMUOrJava to button returned of the result
46 if (quitMUOrJava is "MacUpdate") then
47 open location "http://www.macupdate.com/app/mac/39490/apple-java"
48 else if (quitMUOrJava is "Java.com") then
49 open location "http://www.java.com/getjava"
50 end if
51 else if (installResult is 2) then -- unknown failure (must be a file operation)
52 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", "Quit"} default button 2 with title "Anniversary Edition Setup" with icon gSetupIcon
53 set quitOrForum to button returned of the result
54 if (quitOrForum is "Go to forum") then
55 open location "http://oni.bungie.org/community/forum/index.php"
56 end if
57 else
58 display dialog "Updater installed. AE Setup will now continue the installation by running the Updater." buttons {"OK"} default button 1 with title "Anniversary Edition Setup" with icon gSetupIcon
59 set runResult to my run_AEIU(installPath)
60 activate
61 if (runResult is 1) then
62 display dialog "Script copy error. Please ask for help in the Anniversary Edition sub-forum of the Oni Central Forum." buttons {"Go to forum", "Quit"} default button 2 with title "Anniversary Edition Setup" with icon gSetupIcon
63 set quitOrForum to button returned of the result
64 if (quitOrForum is "Go to forum") then
65 open location "http://oni.bungie.org/community/forum/index.php"
66 end if
67 else if (runResult is 2) then
68 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", "Quit"} default button 2 with title "Anniversary Edition Setup" with icon gSetupIcon
69 set quitOrForum to button returned of the result
70 if (quitOrForum is "Go to forum") then
71 open location "http://oni.bungie.org/community/forum/index.php"
72 end if
73 end if
74 end if
75 end if
76 end if
77 end tell
78end main
79
80-- The user must pick an acceptable folder to install the AE in, or die trying (or give up)
81on find_Oni_folder()
82 tell me
83 activate
84 set tryAgain to true
85 set isOniRetail to false
86 repeat while (tryAgain is true)
87 set chosenPath to (choose folder with prompt "Please locate your Oni installation.")
88 if (chosenPath is "") then
89 display dialog "There was an error in choosing the Oni folder." buttons {"OK"} default button 1 with title "Anniversary Edition Setup" with icon gSetupIcon
90 return chosenPath
91 end if
92 set folderTest to my validate_Oni_folder(chosenPath)
93 activate
94 if (folderTest is 1) then
95 display dialog "This doesn't seem to be your Oni installation. Click \"Try again\" to locate another folder." buttons {"Quit", "Try again"} default button 2 with title "Anniversary Edition Setup" with icon gSetupIcon
96 set quitOrTryAgain to the button returned of the result
97 if (quitOrTryAgain is "Quit") then
98 set tryAgain to false
99 end if
100 else if (folderTest is 2) then
101 display dialog "This Oni installation already seems to have the AE installed! Click \"Try again\" to locate another folder." buttons {"Quit", "Try again"} default button 2 with title "Anniversary Edition Setup" with icon gSetupIcon
102 set quitOrTryAgain to the button returned of the result
103 if (quitOrTryAgain is "Quit") then
104 set tryAgain to false
105 end if
106 else
107 set tryAgain to false -- we got it, let's get out of this loop
108 end if
109 end repeat
110 if (folderTest is 0) then
111 return chosenPath
112 else
113 return ""
114 end if
115 end tell
116end find_Oni_folder
117
118-- Returns 0 if this is a valid target for the AE installation,
119-- 1 if this is not a valid target, and
120-- 2 if the AE is already here
121on validate_Oni_folder(folderPath)
122 tell application "Finder"
123 activate
124 -- Is the GDF here?
125 if not (exists folder "GameDataFolder" in folder folderPath) then
126 display dialog "GameDataFolder not detected here." buttons {"OK"} default button 1 with title "Anniversary Edition Setup" with icon gSetupIcon
127 return 1
128 end if
129 -- Is the AE folder here? Because we won't install over it.
130 if (exists folder "AE" in folder folderPath) then
131 return 2
132 end if
133
134 -- Now see if this is the full installation or demo
135 set retailLevelList to {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}
136 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
137 set isRetail to true
138 set isDemo to true
139 -- Look for levels until one is missing and we know this isn't a complete retail release
140 repeat with thisLevel in retailLevelList
141 if not (exists file ((folderPath & "GameDataFolder:level" & thisLevel & "_Final.dat") as string)) then
142 set isRetail to false
143 exit repeat
144 end if
145 end repeat
146 if (isRetail) then
147 -- Don't return here if we add demo support below
148 return 0
149 end if
150 -- Look for levels until one is missing and we know this isn't a complete demo release
151 repeat with thisLevel in demoLevelList
152 if not (exists file ((folderPath & "GameDataFolder:level" & thisLevel & "_Final.dat") as string)) then
153 set isDemo to false
154 exit repeat
155 end if
156 end repeat
157 if (isDemo) then
158 -- Insert handling of demo status here if we ever support a demo AE
159 return 1
160 else
161 return 1
162 end if
163 end tell
164end validate_Oni_folder
165
166-- Check for an acceptable Java installation
167-- This function was going to support a bundled JRE for those without Java,
168-- but it adds too many complications, so just make the user install it himself
169-- Returns 0 if the Updater was installed (which will install the Installer itself afterward),
170-- 1 if Java is not found or too old, and
171-- 2 if a file operation or other error occurs
172on install_AEI_Updater(pathToOni)
173 tell me
174 -- See if we have Java
175 set javaPath to ""
176 try
177 set javaPath to do shell script "which java"
178 on error javaError -- "which" returns an error if the command is not found
179 return 1
180 end try
181 if (javaPath is "") then -- safeguard, shouldn't happen
182 return 1
183 end if
184 -- Now see what version it is
185 set javaVersionCmd to ((javaPath & " -version 2>&1") as string) -- for some reason Java's version output is on stderr, not stdout :-/
186 set javaVersionText to do shell script javaVersionCmd without altering line endings
187 -- Isolate version number from output with format:
188 (* java version "1.7.0_17"
189 Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
190 Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode) *)
191 set origDelimiters to text item delimiters
192 -- Get first line
193 set text item delimiters to "
194"
195 set javaVersionText to first text item of javaVersionText
196 -- Get text after first quote mark
197 set text item delimiters to "\""
198 set javaVersionText to second text item of javaVersionText
199 -- Get first and second version numbers, third doesn't matter
200 set text item delimiters to "."
201 set versionMajor to first text item of javaVersionText
202 set versionMinor to second text item of javaVersionText
203 set text item delimiters to origDelimiters
204 -- Inform user if Java is too old
205 if (versionMajor ≥ gNeedsJavaVersionMajor) then
206 if (versionMinor < gNeedsJavaVersionMinor) then
207 display dialog (("Sorry, Java v" & gNeedsJavaVersionMajor & "." & gNeedsJavaVersionMinor & " is required; found v" & versionMajor & "." & versionMinor & " instead.") as string) buttons {"OK"} default button 1 with title "Anniversary Edition Setup" with icon gSetupIcon
208 return 1
209 end if
210 else
211 return 1
212 end if
213 end tell
214 -- Make "Oni/AE" folder
215 tell application "Finder"
216 if ((pathToOni & "AE") exists) then -- shouldn't happen because we already looked for it in validate_Oni_folder()
217 return 2
218 end if
219 try
220 make new folder at pathToOni with properties {name:"AE"}
221 delay 0.5
222 make new folder at ((pathToOni as string) & "AE") with properties {name:"AEInstaller"}
223 on error
224 display alert "Couldn't make AE or AEI folder!"
225 return 2
226 end try
227
228 -- Copy AEI Updater into "AE/"
229 set AEIU to ((path to me as string) & "Contents:Resources:AEInstaller2Updater.jar")
230 set AEIfolder to (pathToOni & "AE:AEInstaller" as string)
231 try
232 duplicate file AEIU to folder AEIfolder
233 on error copyError
234 return 2
235 end try
236 end tell
237 return 0
238end install_AEI_Updater
239
240-- Drops an applet into the new "AE/" folder and runs it;
241-- the applet will try to run the AEI, but if it's not found,
242-- it runs the AEI Updater, which is what we want to happen
243-- so that the AEI can be installed.
244-- Returns 0 if this is a valid target for the AE installation,
245-- 1 if the applet cannot be dropped, and
246-- 2 if the applet cannot be run
247on run_AEIU(pathToOni)
248 tell application "Finder"
249 -- Copy applet to AE/ that opens AEI or AEIU if AEI is not around
250 set RAEI to ((path to me as string) & "Contents:Resources:Run AE Installer.app")
251 set pathToAE to alias ((pathToOni & "AE") as string)
252 try
253 duplicate RAEI to pathToAE
254 on error copyError
255 return 1
256 end try
257 set RAEI to ((pathToAE as string) & "Run AE Installer.app")
258 try
259 open RAEI
260 on error runError
261 return 2
262 end try
263 end tell
264 return 0
265end run_AEIU
Note: See TracBrowser for help on using the repository browser.