This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathahorn.bat
258 lines (189 loc) · 7.06 KB
/
ahorn.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
@echo off
setlocal EnableDelayedExpansion
set minimum_version="v\"1.6.0\""
set julia_url_64bit=https://julialang-s3.julialang.org/bin/winnt/x64/1.6/julia-1.6.0-win64.exe
set julia_url_32bit=https://julialang-s3.julialang.org/bin/winnt/x86/1.6/julia-1.6.0-win32.exe
set julia_filename=julia-1.6.0-installer.exe
set install_url=https://raw.githubusercontent.com/CelestialCartographers/Ahorn/master/install_ahorn.jl
set install_filename=install_ahorn.jl
rem Set up launch arguments
rem Not the best solution, but it works for simple arguments
set darkMode=0
set developerMode=0
set onlyUpdate=0
set updateFirst=0
set displayHelp=0
for %%A in (%*) do (
if "%%A" equ "--dark" (
set darkMode=1
)
if "%%A" equ "--developer" (
set developerMode=1
)
if "%%A" equ "--update" (
set updateFirst=1
)
if "%%A" equ "--onlyUpdate" (
set onlyUpdate=1
set updateFirst=1
)
if "%%A" equ "--help" (
set displayHelp=1
)
)
:darkmode
if %darkMode% equ 1 (
SET GTK_CSD=1
SET GTK_THEME=Adwaita:dark
)
:displayHelp
if %displayHelp% equ 1 (
echo Program launch flags
echo --help
echo Displays this page.
echo.
echo --dark
echo Sets environmental variables to use the default Gtk.jl dark theme.
echo This is not a native Windows theme, some interface elements might look different.
echo.
echo --developer
echo Puts error messages in the terminal rather than in the error log.
echo.
echo --update
echo Attempts to update Ahorn before starting.
echo.
echo --onlyUpdate
echo Only attempts to update Ahorn. Does not start the program afterwards.
echo.
goto :end
)
:start
rem Check if Julia runs at all when set with PATH
rem For some reason Windows might ship without `where` program
julia -e "exit(0)" >nul 2>nul
if %ERRORLEVEL% equ 0 (
echo Using Julia from PATH environment variable.
echo Making sure this version is meeting the requirements for Ahorn.
julia -e "exit(Int(VERSION < %minimum_version%))"
if !ERRORLEVEL! neq 0 (
echo The PATH Julia version is too old to run Ahorn. Attempting to use auto detected version.
goto :autodetect
)
goto :install
)
:autodetect
rem Default for 1.5
rem Looks for both Julia- and Julia, just to be safe
for /F " tokens=*" %%i in ('dir /b /ad-h /o-d "%LocalAppData%\Programs"') do (
set fn=%%i
if "!fn:~0,6!" == "Julia-" (
set JULIA_PATH="%LocalAppData%\Programs\%%i\bin"
goto :foundJulia
)
if "!fn:~0,6!" == "Julia " (
set JULIA_PATH="%LocalAppData%\Programs\%%i\bin"
goto :foundJulia
)
)
rem Default for 1.4
for /F " tokens=*" %%i in ('dir /b /ad-h /o-d "%LocalAppData%\Programs\Julia"') do (
set fn=%%i
if "!fn:~0,6!" == "Julia-" (
set JULIA_PATH="%LocalAppData%\Programs\Julia\%%i\bin"
goto :foundJulia
)
)
rem Default for 1.3
for /F " tokens=*" %%i in ('dir /b /ad-h /o-d "%LocalAppData%"') do (
set fn=%%i
if "!fn:~0,6!" == "Julia-" (
set JULIA_PATH="%LocalAppData%\%%i\bin"
goto :foundJulia
)
)
echo Julia installation not found in default install directory "%LocalAppData%\Programs\".
echo Please install to the default directory or add Julia manually to the PATH environment variable.
goto :installPrompt
:foundJulia
set PATH=%JULIA_PATH%;%PATH%
echo Using Julia from: %JULIA_PATH%
julia -e "exit(Int(VERSION < %minimum_version%))"
if %ERRORLEVEL% neq 0 (
echo The Julia version is too old to run Ahorn. Please make sure the right version is used. You need at least Julia 1.3.0.
:installPrompt
set /p "confirmJuliaInstall=Do you want to install a compatible version of Julia? [y/N]: "
IF /I "!confirmJuliaInstall!" equ "y" (
echo Downloading compatible Julia version and starting the installer.
echo By default this adds Julia to the PATH environment variable, allowing installation to any directory.
echo If you wish to manually add Julia to PATH you can uncheck the option in the installer.
echo Downloading installer
if "%PROCESSOR_ARCHITECTURE%" equ "AMD64" (
powershell -Command "(New-Object Net.WebClient).DownloadFile('%julia_url_64bit%', '%julia_filename%')"
) else (
powershell -Command "(New-Object Net.WebClient).DownloadFile('%julia_url_32bit%', '%julia_filename%')"
)
if !ERRORLEVEL! neq 0 (
echo Unable to download Julia installer.
echo Might be due to TLS issues or PowerShell version.
echo Please manually download and install Julia from the Julia website.
goto end
)
echo Running installer
start /wait "" "%~dp0%julia_filename%" /TASKS="addtopath"
del "%~dp0%julia_filename%"
goto :start
)
goto :end
)
:install
set AHORN_PATH=%LocalAppData%\Ahorn
set "AHORN_PATH=%AHORN_PATH:\=/%"
set AHORN_ENV=\"%AHORN_PATH%/env/\"
julia -e "using Pkg; Pkg.activate(%AHORN_ENV%); exit(length(Pkg.installed()))" > NUL 2>&1
if %ERRORLEVEL% equ 0 (
echo Installing Ahorn, this might take a while.
echo Please make sure not to put the command line into select mode, that means do not click inside the window.
if not exist "%cd%\%install_filename%" (
powershell -Command "(New-Object Net.WebClient).DownloadFile('%install_url%', '%install_filename%')"
if !ERRORLEVEL! neq 0 (
echo Unable to download Ahorn install script.
echo Might be due to TLS issues or PowerShell version.
echo Please manually download install_ahorn.jl and put it in the same folder as ahorn.bat and then rerun.
echo Optionally install Ahorn manually via cross platform instructions.
goto :end
)
)
julia "%~dp0%install_filename%"
del "%~dp0%install_filename%"
julia -e "using Pkg; Pkg.activate(%AHORN_ENV%); exit(length(Pkg.installed()))" > NUL 2>&1
if !ERRORLEVEL! equ 0 (
goto :end
)
goto :install
)
:update
if %updateFirst% equ 1 (
echo Attempting to update Ahorn.
if !developerMode! equ 1 (
julia -e "using Pkg; Pkg.activate(%AHORN_ENV%); Pkg.update()"
) else (
julia -e "using Pkg; Pkg.activate(%AHORN_ENV%); Pkg.update()" 2> "%AHORN_PATH%/update.log"
)
if !onlyUpdate! equ 1 (
goto :end
)
)
:run
if %developerMode% equ 1 (
echo Warnings and errors will be printed to this window rather than error log.
julia -e "using Pkg; Pkg.activate(%AHORN_ENV%); using Ahorn; Ahorn.displayMainWindow()"
) else (
echo If this is the first time running Ahorn, this might take a while.
echo The window might stay blank for a long time, this is normal as packages are precompiling in the background.
echo Be patient, the program is still running until the terminal says "Press any key to continue" (or equivalent in your language^).
echo The error log is located at "%AHORN_PATH%/error.log", should any problems occur.
julia -e "using Pkg; Pkg.activate(%AHORN_ENV%); using Ahorn; Ahorn.displayMainWindow()" 2> "%AHORN_PATH%/error.log"
)
:end
endlocal
pause