From 02c88ebf49ed82b7de68a4579d781fb40eb3e28f Mon Sep 17 00:00:00 2001 From: nonepork <59335048+nonepork@users.noreply.github.com> Date: Sun, 12 May 2024 20:35:53 +0800 Subject: [PATCH 1/2] Added support (install only) for windows --- README.md | 9 ++++ install.ps1 | 102 +++++++++++++++++++++++++++++++++++++++++++++ runfromwindows.bat | 2 + uninstall.ps1 | 69 ++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 install.ps1 create mode 100644 runfromwindows.bat create mode 100644 uninstall.ps1 diff --git a/README.md b/README.md index e4f32de7..cf8b02e8 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,15 @@ Or wget: bash -c "$(wget -qO- https://raw.githubusercontent.com/MHNightCat/superfile/main/install.sh)" ``` +### Windows + +It actually supports windows! Sort of. + +```powershell +Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://github.com/MHNightCat/superfile/blob/main/install.ps1')) + +``` + ### NixOS
Click to expand diff --git a/install.ps1 b/install.ps1 new file mode 100644 index 00000000..5bb7a8ba --- /dev/null +++ b/install.ps1 @@ -0,0 +1,102 @@ +param( + [switch] + $AllUsers +) + +function FolderIsInPATH($Path_to_directory) { + return ([Environment]::GetEnvironmentVariable("PATH", "User") -split ';').TrimEnd('\') -contains $Path_to_directory.TrimEnd('\') +} + +Write-Host -ForegroundColor DarkRed " ______ __ __ " +Write-Host -ForegroundColor Red " / \ / |/ | " +Write-Host -ForegroundColor DarkYellow " _______ __ __ ______ ______ ______ /`$`$`$`$`$`$ |`$`$/ `$`$ | ______ " +Write-Host -ForegroundColor Yellow " / |/ | / | / \ / \ / \ `$`$ |_ `$`$/ / |`$`$ | / \ " +Write-Host -ForegroundColor DarkGreen "/`$`$`$`$`$`$`$/ `$`$ | `$`$ |/`$`$`$`$`$`$ |/`$`$`$`$`$`$ |/`$`$`$`$`$`$ |`$`$ | `$`$ |`$`$ |/`$`$`$`$`$`$ |" +Write-Host -ForegroundColor Green "`$`$ \ `$`$ | `$`$ |`$`$ | `$`$ |`$`$ `$`$ |`$`$ | `$`$/ `$`$`$`$/ `$`$ |`$`$ |`$`$ `$`$ |" +Write-Host -ForegroundColor DarkBlue " `$`$`$`$`$`$ |`$`$ \__`$`$ |`$`$ |__`$`$ |`$`$`$`$`$`$`$`$/ `$`$ | `$`$ | `$`$ |`$`$ |`$`$`$`$`$`$`$`$/ " +Write-Host -ForegroundColor Blue " `$`$/ `$`$ `$`$/ `$`$ `$`$/ `$`$ |`$`$ | `$`$ | `$`$ |`$`$ |`$`$ |" +Write-Host -ForegroundColor DarkMagenta "`$`$`$`$`$`$`$/ `$`$`$`$`$`$/ `$`$`$`$`$`$`$/ `$`$`$`$`$`$`$/ `$`$/ `$`$/ `$`$/ `$`$/ `$`$`$`$`$`$`$/ " +Write-Host -ForegroundColor Magenta " `$`$ | " +Write-Host -ForegroundColor DarkRed " `$`$ | " +Write-Host -ForegroundColor Red " `$`$/ " +Write-Host "" + +$package = "superfile" +$version = "1.1.2" + +$installInstructions = @' +This installer is only available for Windows. +If you're looking for installation instructions for your operating system, +please visit the following link: +'@ +if ($IsMacOS) { + Write-Host @" +$installInstructions + +https://github.com/MHNightCat/superfile?tab=readme-ov-file#installation +"@ + exit +} +if ($IsLinux) { + Write-Host @" +$installInstructions + +https://github.com/MHNightCat/superfile?tab=readme-ov-file#installation +"@ + exit +} + +$arch = (Get-CimInstance -Class Win32_Processor -Property Architecture).Architecture | Select-Object -First 1 +switch ($arch) { + 5 { $arch = "arm64" } # ARM + 9 { + if ([Environment]::Is64BitOperatingSystem) { + $arch = "amd64" + } + } + 12 { $arch = "arm64" } # Surface Pro X +} +if ([string]::IsNullOrEmpty($arch)) { + Write-Host @" +The installer for system arch ($arch) is not available. +"@ + exit +} +$filename = "$package-windows-v$version-$arch.zip" + +Write-Host "Downloading superfile..." + +$superfileProgramPath = [Environment]::GetFolderPath("LocalApplicationData") + "\Programs\superfile" +if (-not (Test-Path $superfileProgramPath)) { + New-Item -Path $superfileProgramPath -ItemType Directory -Verbose:$false | Out-Null +} else { + Write-Host "Folder $superfileProgramPath already exists. :/" + exit +} +$url = "https://github.com/MHNightCat/superfile/releases/download/$version/$filename" +Invoke-WebRequest -OutFile "$superfileProgramPath\$filename" $url + +Write-Host "Extracting compressed file..." + +try { + Expand-Archive -Path "$superfileProgramPath\$filename" -DestinationPath $superfileProgramPath + Remove-Item -Path "$superfileProgramPath\$filename" +} catch { + Write-Host "An error occurred: $_" + exit +} +if (-not (FolderIsInPATH "$superfileProgramPath\spf.bat")) { + $envPath = [Environment]::GetEnvironmentVariable("PATH", "User") + $newPath = "$superfileProgramPath\spf.bat" + $updatedPath = $envPath + ";" + $newPath + [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "User") +} + +Write-Host @' +Done! + +Restart you terminal, and for the love of Get-Command +Take a look at tutorial :) + +https://github.com/MHNightCat/superfile/wiki/Tutorial +'@ diff --git a/runfromwindows.bat b/runfromwindows.bat new file mode 100644 index 00000000..e04fe34c --- /dev/null +++ b/runfromwindows.bat @@ -0,0 +1,2 @@ +REM God have mercy on what I'm about to do +chcp 65001 & spf-executable.exe diff --git a/uninstall.ps1 b/uninstall.ps1 new file mode 100644 index 00000000..758f7a3f --- /dev/null +++ b/uninstall.ps1 @@ -0,0 +1,69 @@ +param( + [switch] + $AllUsers +) + +function FolderIsInPATH($Path_to_directory) { + return ([Environment]::GetEnvironmentVariable("PATH", "User") -split ';').TrimEnd('\') -contains $Path_to_directory.TrimEnd('\') +} + +Write-Host -ForegroundColor DarkRed " ______ __ __ " +Write-Host -ForegroundColor Red " / \ / |/ | " +Write-Host -ForegroundColor DarkYellow " _______ __ __ ______ ______ ______ /`$`$`$`$`$`$ |`$`$/ `$`$ | ______ " +Write-Host -ForegroundColor Yellow " / |/ | / | / \ / \ / \ `$`$ |_ `$`$/ / |`$`$ | / \ " +Write-Host -ForegroundColor DarkGreen "/`$`$`$`$`$`$`$/ `$`$ | `$`$ |/`$`$`$`$`$`$ |/`$`$`$`$`$`$ |/`$`$`$`$`$`$ |`$`$ | `$`$ |`$`$ |/`$`$`$`$`$`$ |" +Write-Host -ForegroundColor Green "`$`$ \ `$`$ | `$`$ |`$`$ | `$`$ |`$`$ `$`$ |`$`$ | `$`$/ `$`$`$`$/ `$`$ |`$`$ |`$`$ `$`$ |" +Write-Host -ForegroundColor DarkBlue " `$`$`$`$`$`$ |`$`$ \__`$`$ |`$`$ |__`$`$ |`$`$`$`$`$`$`$`$/ `$`$ | `$`$ | `$`$ |`$`$ |`$`$`$`$`$`$`$`$/ " +Write-Host -ForegroundColor Blue " `$`$/ `$`$ `$`$/ `$`$ `$`$/ `$`$ |`$`$ | `$`$ | `$`$ |`$`$ |`$`$ |" +Write-Host -ForegroundColor DarkMagenta "`$`$`$`$`$`$`$/ `$`$`$`$`$`$/ `$`$`$`$`$`$`$/ `$`$`$`$`$`$`$/ `$`$/ `$`$/ `$`$/ `$`$/ `$`$`$`$`$`$`$/ " +Write-Host -ForegroundColor Magenta " `$`$ | " +Write-Host -ForegroundColor DarkRed " `$`$ | " +Write-Host -ForegroundColor Red " `$`$/ " +Write-Host "" + +$package = "superfile" +$version = "1.1.2" + +$installInstructions = @' +This uninstaller is only available for Windows. +'@ +if ($IsMacOS) { + Write-Host "$installInstructions" + exit +} +if ($IsLinux) { + Write-Host "$installInstructions" + exit +} + +Write-Host "Removing folder..." + +$superfileProgramPath = [Environment]::GetFolderPath("LocalApplicationData") + "\Programs\superfile" +try { + if (Test-Path $superfileProgramPath) { + Remove-Item -Path $superfileProgramPath -Recurse -Force + } +} +catch { + Write-Host "An error occurred: $_" + exit +} + +Write-Host "Removing environment path..." + +try { + if (FolderIsInPATH "$superfileProgramPath\spf.bat") { + $envPath = [Environment]::GetEnvironmentVariable("PATH", "User") + $updatedPath =($envPath.Split(';') | Where-Object { $_ -ne "$superfileProgramPath\spf.bat" }) -join ';' + [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "User") + } +} +catch { + Write-Host "An error occurred: $_" + exit +} + +Write-Host @' +Uninstall Done! +'@ + From 6c2faefc98d9d71edb06eacfccc4dbb2dc083593 Mon Sep 17 00:00:00 2001 From: nonepork <59335048+nonepork@users.noreply.github.com> Date: Sun, 12 May 2024 20:38:00 +0800 Subject: [PATCH 2/2] a --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cf8b02e8..c4450bac 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ bash -c "$(wget -qO- https://raw.githubusercontent.com/MHNightCat/superfile/main ### Windows It actually supports windows! Sort of. +For uninstall do the same but uninstall.ps1 ```powershell Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://github.com/MHNightCat/superfile/blob/main/install.ps1'))