@@ -15,119 +15,105 @@ CD app || (
1515
1616SET PATH = C:\Windows\System32;%PATH%
1717
18- :: Set Node.js version and URL base
18+ :: Node.js version and URL base
1919set NODE_VERSION = v18.20.5
2020set BASE_URL = https://nodejs.org/download/release/%NODE_VERSION% /
2121set ARCHIVE_NAME =
2222set ARCHIVE_DIR =
2323set DEST_DIR = node
2424set TEMP_DIR = node
2525
26- IF EXIST " %~dp0 \app\install.js" (GOTO :EXISTING) ELSE GOTO :MISSING
26+ IF NOT EXIST " %~dp0 \app\install.js" (
27+ echo [ERROR] To run the installer, please first unzip the archive
28+ pause
29+ exit /b 1
30+ )
2731
28- :EXISTING
29- :: Create temp directory
30- if not exist " %TEMP_DIR% " mkdir " %TEMP_DIR% "
32+ :: Check if system Node.js exists
33+ WHERE node > nul 2 >& 1
34+ IF %ERRORLEVEL% == 0 (
35+ echo .. Using system Node.js
36+ node install.js " %LocalAPPData% "
3137 if errorlevel 1 (
32- echo Failed to create temp directory
38+ echo Failed to run install.js with system Node.js
3339 pause
3440 exit /b 1
3541 )
42+ GOTO :REGISTRY
43+ )
3644
37- :: Determine architecture and set download file
38- IF " %PROCESSOR_ARCHITECTURE% " == " AMD64" (
39- set ARCHIVE_NAME = node-%NODE_VERSION% -win-x64.zip
40- set ARCHIVE_DIR = node-%NODE_VERSION% -win-x64
41- ) ELSE (
42- set ARCHIVE_NAME = node-%NODE_VERSION% -win-x86.zip
43- set ARCHIVE_DIR = node-%NODE_VERSION% -win-x86
44- )
45+ :: Otherwise, fallback to downloading Node.js
46+ echo .. System Node.js not found, downloading portable version...
4547
46- :: Download Node.js archive
47- ECHO .. Downloading %BASE_URL%%ARCHIVE_NAME%
48- :: Check if curl is available
49- WHERE curl > nul 2 >& 1
50- if %errorlevel% == 0 (
51- ECHO Using curl...
52- curl -k -o " %TEMP_DIR% \%ARCHIVE_NAME% " " %BASE_URL%%ARCHIVE_NAME% "
53- ) else (
54- echo Using PowerShell...
55- powershell -Command ^
56- " [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};" ^
57- " try { Invoke-WebRequest -Uri '%BASE_URL%%ARCHIVE_NAME% ' -OutFile '%TEMP_DIR% \%ARCHIVE_NAME% ' -UseBasicParsing } catch { exit 1 }"
58- )
59- if errorlevel 1 (
60- ECHO Failed to download %ARCHIVE_NAME%
61- pause
62- exit /b 1
63- )
64- ECHO .. Download complete: %TEMP_DIR% \%ARCHIVE_NAME%
48+ :: Create temp directory
49+ if not exist " %TEMP_DIR% " mkdir " %TEMP_DIR% "
6550
66- :: Extract archive
67- ECHO .. Extracting %ARCHIVE_NAME% ...
68- powershell -Command " Expand-Archive -Path ' %TEMP_DIR% \ % ARCHIVE_NAME% ' -DestinationPath ' %DEST_DIR% ' -Force "
69- if errorlevel 1 (
70- ECHO Failed to extract %ARCHIVE_NAME%
71- pause
72- exit /b 1
73- )
51+ :: Determine architecture
52+ IF " %PROCESSOR_ARCHITECTURE% " == " AMD64 " (
53+ set ARCHIVE_NAME = node- %NODE_VERSION% -win-x64.zip
54+ set ARCHIVE_DIR = node- %NODE_VERSION% -win-x64
55+ ) ELSE (
56+ set ARCHIVE_NAME = node- %NODE_VERSION% -win-x86.zip
57+ set ARCHIVE_DIR = node- %NODE_VERSION% -win-x86
58+ )
7459
75- :: Run install.js
76- ECHO .. Running install.js...
77- " %DEST_DIR% \%ARCHIVE_DIR% \node.exe" install.js " %LocalAPPData% "
78- if errorlevel 1 (
79- ECHO Failed to run install.js
80- pause
81- exit /b 1
82- )
60+ :: Download Node.js archive
61+ echo .. Downloading %BASE_URL%%ARCHIVE_NAME%
62+ WHERE curl > nul 2 >& 1
63+ if %errorlevel% == 0 (
64+ curl -k -o " %TEMP_DIR% \%ARCHIVE_NAME% " " %BASE_URL%%ARCHIVE_NAME% "
65+ ) else (
66+ powershell -Command ^
67+ " [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};" ^
68+ " Invoke-WebRequest -Uri '%BASE_URL%%ARCHIVE_NAME% ' -OutFile '%TEMP_DIR% \%ARCHIVE_NAME% ' -UseBasicParsing"
69+ )
70+ if errorlevel 1 (
71+ echo Failed to download %ARCHIVE_NAME%
72+ pause
73+ exit /b 1
74+ )
8375
84- :: Cleanup
85- echo .. Cleaning up...
86- rmdir /s /q " %TEMP_DIR% "
87- if errorlevel 1 (
88- echo Warning: Failed to clean up temp directory
89- )
76+ :: Extract archive
77+ echo .. Extracting %ARCHIVE_NAME% ...
78+ powershell -Command " Expand-Archive -Path '%TEMP_DIR% \%ARCHIVE_NAME% ' -DestinationPath '%DEST_DIR% ' -Force"
79+ if errorlevel 1 (
80+ echo Failed to extract %ARCHIVE_NAME%
81+ pause
82+ exit /b 1
83+ )
9084
91- ECHO .
92- ECHO .. Writing to Chrome Registry
93- ECHO .. Key: HKCU\Software\Google\Chrome\NativeMessagingHosts\com.add0n.node
94- REG ADD " HKCU\Software\Google\Chrome\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %LocalAPPData% \com.add0n.node\manifest-chrome.json" /f
95- if errorlevel 1 echo Warning: Failed to write Chrome registry entry
96-
97- ECHO .. Writing to Chromium Registry
98- ECHO .. Key: HKCU\Software\Chromium\NativeMessagingHosts\com.add0n.node
99- REG ADD " HKCU\Software\Chromium\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %LocalAPPData% \com.add0n.node\manifest-chrome.json" /f
100- if errorlevel 1 echo Warning: Failed to write Chromium registry entry
101-
102- ECHO .. Writing to Edge Registry
103- ECHO .. Key: HKCU\Software\Microsoft\Edge\NativeMessagingHosts\com.add0n.node
104- REG ADD " HKCU\Software\Microsoft\Edge\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %LocalAPPData% \com.add0n.node\manifest-chrome.json" /f
105- if errorlevel 1 echo Warning: Failed to write Edge registry entry
106-
107- ECHO .. Writing to Firefox Registry
108- ECHO .. Key: HKCU\SOFTWARE\Mozilla\NativeMessagingHosts\com.add0n.node
109- FOR %%f in (" %LocalAPPData% " ) do SET SHORT_PATH = %%~sf
110- REG ADD " HKCU\SOFTWARE\Mozilla\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %SHORT_PATH% \com.add0n.node\manifest-firefox.json" /f
111- if errorlevel 1 echo Warning: Failed to write Firefox registry entry
112-
113- ECHO .. Writing to Waterfox Registry
114- ECHO .. Key: HKCU\SOFTWARE\Waterfox\NativeMessagingHosts\com.add0n.node
115- REG ADD " HKCU\SOFTWARE\Waterfox\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %SHORT_PATH% \com.add0n.node\manifest-firefox.json" /f
116- if errorlevel 1 echo Warning: Failed to write Waterfox registry entry
117-
118- ECHO .. Writing to Thunderbird Registry
119- ECHO .. Key: HKCU\SOFTWARE\Thunderbird\NativeMessagingHosts\com.add0n.node
120- REG ADD " HKCU\SOFTWARE\Thunderbird\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %SHORT_PATH% \com.add0n.node\manifest-firefox.json" /f
121- if errorlevel 1 echo Warning: Failed to write Thunderbird registry entry
122-
123- ECHO .
124- ECHO .. Native client is ready!
125- GOTO :COMMON
126-
127- :MISSING
128- ECHO [ERROR] To run the installer, please first unzip the archive
85+ :: Run install.js with portable Node.js
86+ " %DEST_DIR% \%ARCHIVE_DIR% \node.exe" install.js " %LocalAPPData% "
87+ if errorlevel 1 (
88+ echo Failed to run install.js with portable Node.js
12989 pause
13090 exit /b 1
91+ )
92+
93+ :: Cleanup
94+ rmdir /s /q " %TEMP_DIR% " 2 > nul
95+
96+ :REGISTRY
97+ echo .
98+ echo .. Writing to Chrome Registry
99+ REG ADD " HKCU\Software\Google\Chrome\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %LocalAPPData% \com.add0n.node\manifest-chrome.json" /f
100+
101+ echo .. Writing to Chromium Registry
102+ REG ADD " HKCU\Software\Chromium\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %LocalAPPData% \com.add0n.node\manifest-chrome.json" /f
103+
104+ echo .. Writing to Edge Registry
105+ REG ADD " HKCU\Software\Microsoft\Edge\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %LocalAPPData% \com.add0n.node\manifest-chrome.json" /f
106+
107+ echo .. Writing to Firefox Registry
108+ FOR %%f in (" %LocalAPPData% " ) do SET SHORT_PATH = %%~sf
109+ REG ADD " HKCU\SOFTWARE\Mozilla\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %SHORT_PATH% \com.add0n.node\manifest-firefox.json" /f
110+
111+ echo .. Writing to Waterfox Registry
112+ REG ADD " HKCU\SOFTWARE\Waterfox\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %SHORT_PATH% \com.add0n.node\manifest-firefox.json" /f
113+
114+ echo .. Writing to Thunderbird Registry
115+ REG ADD " HKCU\SOFTWARE\Thunderbird\NativeMessagingHosts\com.add0n.node" /ve /t REG_SZ /d " %SHORT_PATH% \com.add0n.node\manifest-firefox.json" /f
131116
132- :COMMON
133- PAUSE
117+ echo .
118+ echo .. Native client is ready!
119+ PAUSE
0 commit comments