-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathUpdater.bat
142 lines (92 loc) · 2.7 KB
/
Updater.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
@echo off
setlocal enabledelayedexpansion
cd /d %~dp0
set HERE=%~dp0
set HERE_DS=%HERE:\=\\%
set BUSYBOX="%HERE%App\Utils\busybox.exe"
set CURL="%HERE%App\Utils\curl.exe"
set SZIP="%HERE%App\Utils\7za.exe"
:::::: PROXY
set USE_PROXY=false
set PROXY_TYPE=http
set PROXY_ADDRESS=127.0.0.1:3128
if %USE_PROXY% == true (
set PROXY_URL=%PROXY_TYPE%://%PROXY_ADDRESS%
set CURL_PROXY=--proxy !%PROXY_URL!
)
::::::::::::::::::::
:::::: NETWORK CHECK
%CURL% -I -s %CURL_PROXY% https://www.w3.org | %BUSYBOX% grep -q "HTTP"
if "%ERRORLEVEL%" == "1" (
echo Check Your Network Connection
pause
exit
)
::::::::::::::::::::
:::::: ARCH
if "%PROCESSOR_ARCHITECTURE%" == "x86" (
set ARCH=6.7z
) else if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
set ARCH=4.7z
) else exit
:: set ARCH=6.7z
:: set ARCH=4.7z
:: set ARCH=2.7z
:: 6.7z x32
:: 4.7z x64
:: 2.7z arm64
::::::::::::::::::::
:::::: VERSION CHECK
if not exist "%WINDIR%\system32\wbem\wmic.exe" goto LATEST
wmic datafile where name='%HERE_DS%App\\Obsidian\\Obsidian.exe' get version | %BUSYBOX% tail -n2 ^
| %BUSYBOX% rev ^
| %BUSYBOX% cut -c 6- ^
| %BUSYBOX% rev > current.txt
for /f %%V in ('more current.txt') do (set CURRENT=%%V)
echo Current: %CURRENT%
:LATEST
set LATEST_URL="https://github.com/obsidianmd/obsidian-releases/releases/latest"
%CURL% -I -s %CURL_PROXY% %LATEST_URL% | %BUSYBOX% grep -o tag/v[0-9.]\+[0-9] | %BUSYBOX% cut -d "v" -f2 > latest.txt
for /f %%V in ('more latest.txt') do (set LATEST=%%V)
echo Latest: %LATEST%
echo:
if exist "current.txt" del "current.txt" > NUL
if exist "latest.txt" del "latest.txt" > NUL
if "%CURRENT%" == "%LATEST%" (
echo You Have The Latest Version
pause
exit
) else goto PROCESS
::::::::::::::::::::
:PROCESS
:::::: RUNNING PROCESS CHECK
if not exist "%WINDIR%\system32\tasklist.exe" goto GET
for /f %%P in ('tasklist /NH /FI "IMAGENAME eq Obsidian.exe"') do if %%P == Obsidian.exe (
echo Close Obsidian To Update
pause
exit
)
::::::::::::::::::::
:GET
:::::: GET LATEST VERSION
if exist "TMP" rmdir "TMP" /s /q
mkdir "TMP"
set OBSIDIAN="https://github.com/obsidianmd/obsidian-releases/releases/download/v%LATEST%/Obsidian-%LATEST%.exe"
%CURL% -L %CURL_PROXY% %OBSIDIAN% -o TMP\Obsidian-%LATEST%.exe
::::::::::::::::::::
:::::: UNPACKING
echo:
echo Unpacking
if exist "App\Obsidian" rmdir "App\Obsidian" /s /q
%SZIP% x -t# -aoa TMP\Obsidian-%LATEST%.exe -o"TMP" %ARCH% > NUL
%SZIP% x -aoa TMP\%ARCH% -o"App\Obsidian" > NUL
rmdir "TMP" /s /q
:::::: APP INFO
%BUSYBOX% sed -i "/Version/d" "%HERE%App\AppInfo\AppInfo.ini"
echo. >> "App\AppInfo\AppInfo.ini"
echo [Version] >> "App\AppInfo\AppInfo.ini"
echo DisplayVersion=%LATEST% >> "App\AppInfo\AppInfo.ini"
::::::::::::::::::::
echo:
echo Done
pause