Skip to content

Commit

Permalink
Merge pull request #130 from nonepork/main
Browse files Browse the repository at this point in the history
Added support for windows.
  • Loading branch information
yorukot authored May 12, 2024
2 parents d263a55 + 4b66e8e commit cb803c8
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ Or wget:
bash -c "$(wget -qO- https://raw.githubusercontent.com/MHNightCat/superfile/main/install.sh)"
```

### 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'))
```

### NixOS

<details><summary>Click to expand</summary>
Expand Down
102 changes: 102 additions & 0 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -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
'@
2 changes: 2 additions & 0 deletions runfromwindows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REM God have mercy on what I'm about to do
chcp 65001 & spf-executable.exe
69 changes: 69 additions & 0 deletions uninstall.ps1
Original file line number Diff line number Diff line change
@@ -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!
'@

0 comments on commit cb803c8

Please sign in to comment.