forked from schmaldeo/DS4Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathds4w.bat
More file actions
81 lines (65 loc) · 2.76 KB
/
ds4w.bat
File metadata and controls
81 lines (65 loc) · 2.76 KB
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
@echo off
setlocal enabledelayedexpansion
:: Define the installation path in AppData local folder
set INSTALL_PATH=%LOCALAPPDATA%\DS4Windows
:: Prompt for version choice
set /p VERSION_CHOICE="Do you want to install the latest version? (y/n): "
if /i "%VERSION_CHOICE%"=="y" (
:: Get the latest version using GitHub API
for /f "delims=" %%A in ('powershell -Command "(Invoke-WebRequest -Uri 'https://api.github.com/repos/schmaldeo/DS4Windows/releases/latest' -Headers @{ 'User-Agent' = 'Mozilla/5.0' }).Content | ConvertFrom-Json | Select-Object -ExpandProperty tag_name"') do (
set LATEST_VERSION=%%A
)
:: Ensure the version starts with 'v' and remove only the leading 'v'
if "!LATEST_VERSION:~0,1!"=="v" (
set LATEST_VERSION=!LATEST_VERSION:~1!
)
echo Latest version is !LATEST_VERSION!.
set VERSION=!LATEST_VERSION!
) else (
:: Prompt for specific version
:prompt_version
set /p VERSION="Enter the version (e.g., x.x.x): "
if "!VERSION!"=="" (
echo Version cannot be empty. Please try again.
goto prompt_version
)
)
:: Prompt for architecture
:prompt_arch
set /p ARCH="Enter the architecture (x64 or x86, default is x64): "
if "%ARCH%"=="" (
set ARCH=x64
)
set BASE_URL=https://github.com/schmaldeo/DS4Windows/releases/download
set DOWNLOAD_URL=%BASE_URL%/v!VERSION!/DS4Windows_!VERSION!_!ARCH!.zip
:: Download the file
echo Downloading !DOWNLOAD_URL! ...
powershell -Command "Invoke-WebRequest -Uri '!DOWNLOAD_URL!' -OutFile 'DS4Windows_!VERSION!_!ARCH!.zip'"
if %errorLevel% neq 0 (
echo Download failed. Please check the version and architecture.
exit /b
)
echo Download completed.
:: Remove the previous version if it exists
if exist "%INSTALL_PATH%" (
echo Removing previous version from %INSTALL_PATH%...
rmdir /S /Q "%INSTALL_PATH%"
)
:: Unpack the ZIP file
echo Unpacking the ZIP file...
powershell -Command "Expand-Archive -Path 'DS4Windows_!VERSION!_!ARCH!.zip' -DestinationPath 'DS4Windows'"
:: Move the folder to AppData local
echo Moving DS4Windows folder to %INSTALL_PATH%...
move /Y "DS4Windows\DS4Windows" "%INSTALL_PATH%"
:: Create a shortcut on the desktop
set SHORTCUT_PATH="%USERPROFILE%\Desktop\DS4Windows.lnk"
powershell -Command "$s = New-Object -COMObject WScript.Shell; $shortcut = $s.CreateShortcut('%SHORTCUT_PATH%'); $shortcut.TargetPath = '%INSTALL_PATH%\DS4Windows.exe'; $shortcut.IconLocation = '%INSTALL_PATH%\DS4Windows.exe'; $shortcut.Save()"
:: Clean up downloaded and unpacked files
echo Cleaning up...
del /Q "DS4Windows_!VERSION!_!ARCH!.zip"
rmdir /S /Q "DS4Windows"
echo Installation completed.
:: Wait for user input before closing
echo Press any key to exit...
pause >nul
endlocal