aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormegumin <megumin.bakaretsurie@gmail.com>2022-09-16 19:17:55 +0100
committerGitHub <noreply@github.com>2022-09-16 20:17:55 +0200
commit66098b181ab7aaafb9d7d6fb7f8e568e0568c133 (patch)
tree5b03e4d784733ad381a778ae94309ac1f0cc36ff
parent2fcd075f81e4da367aebdf26baff6c8d3d5519f6 (diff)
downloadVencord-66098b181ab7aaafb9d7d6fb7f8e568e0568c133.tar.gz
Vencord-66098b181ab7aaafb9d7d6fb7f8e568e0568c133.tar.bz2
Vencord-66098b181ab7aaafb9d7d6fb7f8e568e0568c133.zip
feat(installer) Windows powershell installer and uninstaller (#10)
* feat(installer) Windows powershell installer and uninstaller * style(installer): Fix uninstaller file header * feat(installer): Branch selection & Sanity checks
-rw-r--r--install.ps190
-rw-r--r--uninstall.ps173
2 files changed, 163 insertions, 0 deletions
diff --git a/install.ps1 b/install.ps1
new file mode 100644
index 0000000..88a8850
--- /dev/null
+++ b/install.ps1
@@ -0,0 +1,90 @@
+# Vencord Windows Installer
+
+$patcher = "$PWD\dist\patcher.js"
+$patcher_safe = $patcher -replace '\\', '\\'
+
+$APP_PATCH = @"
+require("$patcher_safe");
+require("../app.asar");
+"@
+
+$PACKAGE_JSON = @"
+{
+ "main": "index.js",
+ "name": "discord"
+}
+"@
+
+$branch_paths = Get-ChildItem -Directory -Path $env:LOCALAPPDATA |
+ Select-String -Pattern "Discord\w*" -AllMatches |
+ Select-String -Pattern "DiscordGames" -NotMatch # Ignore DiscordGames folder
+
+$branches = @()
+
+foreach ($branch in $branch_paths) {
+ $branch = $branch.Line.Split("\")[-1]
+
+ if ($branch -eq "Discord") {
+ $branch = "Discord Stable"
+ } else {
+ $branch = $branch.Replace("Discord", "Discord ")
+ }
+
+ $branches = $branches + $branch
+}
+
+$branch_count = $branches.Count
+
+Write-Output "Found $branch_count Branches"
+Write-Output "====================================="
+Write-Output "===== Select a Branch to patch ======"
+
+$i = 0
+foreach ($branch in $branches) {
+ Write-Output "=== $i. $branch"
+ $i++
+}
+
+Write-Output "====================================="
+$pos = Read-Host "Enter a number"
+
+if ($null -eq $branches[$pos]) {
+ Write-Output "Invalid branch selection"
+ exit
+}
+
+$branch = $branches.Get($pos)
+$discord_root = $branch_paths.Get($pos)
+
+Write-Output "`nPatching $branch"
+
+$app_folders = Get-ChildItem -Directory -Path $discord_root |
+ Select-String -Pattern "app-"
+
+foreach ($folder in $app_folders)
+{
+ $version = [regex]::match($folder, 'app-([\d\.]+)').Groups[1].Value
+ Write-Output "Patching Version $version"
+
+ $resources = "$folder\resources"
+ if (-not(Test-Path -Path "$resources")) {
+ Write-Error "Resources folder does not exist. Outdated version?`n"
+ continue
+ }
+ if (-not(Test-Path -Path "$resources\app.asar")) {
+ Write-Error "Failed to find app.asar in $folder`n"
+ continue
+ }
+
+ $app = "$resources\app"
+ if (Test-Path -Path $app) {
+ Write-Error "Are you already patched? App folder already exists at $resources`n"
+ continue
+ }
+
+ $null = New-Item -Path $app -ItemType Directory
+ $null = Tee-Object -InputObject $APP_PATCH -FilePath "$app\index.js"
+ $null = Tee-Object -InputObject $PACKAGE_JSON -FilePath "$app\package.json"
+
+ Write-Output "Patched $branch (version $version) successfully"
+}
diff --git a/uninstall.ps1 b/uninstall.ps1
new file mode 100644
index 0000000..409b20f
--- /dev/null
+++ b/uninstall.ps1
@@ -0,0 +1,73 @@
+# Vencord Uninstaller
+
+$branch_paths = Get-ChildItem -Directory -Path $env:LOCALAPPDATA |
+ Select-String -Pattern "Discord\w*" -AllMatches |
+ Select-String -Pattern "DiscordGames" -NotMatch # Ignore DiscordGames folder
+
+$branches = @()
+
+foreach ($branch in $branch_paths) {
+ $branch = $branch.Line.Split("\")[-1]
+
+ if ($branch -eq "Discord") {
+ $branch = "Discord Stable"
+ } else {
+ $branch = $branch.Replace("Discord", "Discord ")
+ }
+
+ $branches = $branches + $branch
+}
+
+$branch_count = $branches.Count
+
+Write-Output "Found $branch_count Branches"
+Write-Output "====================================="
+Write-Output "===== Select a Branch to unpatch ======"
+
+$i = 0
+foreach ($branch in $branches) {
+ Write-Output "=== $i. $branch"
+ $i++
+}
+
+Write-Output "====================================="
+$pos = Read-Host "Enter a number"
+
+if ($null -eq $branches[$pos]) {
+ Write-Output "Invalid branch selection"
+ exit
+}
+
+$branch = $branches.Get($pos)
+$discord_root = $branch_paths.Get($pos)
+
+Write-Output "`nUnpatch $branch"
+
+$app_folders = Get-ChildItem -Directory -Path $discord_root |
+ Select-String -Pattern "app-"
+
+foreach ($folder in $app_folders)
+{
+ $version = [regex]::match($folder, 'app-([\d\.]+)').Groups[1].Value
+ Write-Output "Unpatching $branch Version $version"
+
+ $resources = "$folder\resources"
+ if (-not(Test-Path -Path "$resources")) {
+ Write-Output "Resources folder doesn't exist... Possibly an outdated copy and can be ignored.`n"
+ continue
+ }
+ if (-not(Test-Path -Path "$resources\app")) {
+ Write-Output "App folder doesn't exist... Already unpatched?`n"
+ continue
+ }
+
+ Remove-Item -Path "$folder\resources\app" -Recurse -Force -Confirm:$false
+
+ if (Test-Path "$folder\resources\app")
+ {
+ Write-Error "Failed to delete $folder\resources\app"
+ } else {
+ Write-Output "Successfully unpatched $branch (version $version)"
+ }
+
+} \ No newline at end of file