Skip to content

Commit

Permalink
Added PowerShell script for installing TgDownloaderDesktop
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianMorozov committed Dec 8, 2024
1 parent d059c57 commit 8807faf
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions Clients/TgDownloaderDesktop/TgDownloaderDesktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
<None Include="..\..\Docs\SCREENSHOTS.md" Link="Docs\SCREENSHOTS.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\Docs\TgDownloaderDesktop-Installing.ps1" Link="Docs\TgDownloaderDesktop-Installing.ps1" />
<None Include="..\..\LICENSE.md" Link="Docs\LICENSE.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
85 changes: 85 additions & 0 deletions Docs/TgDownloaderDesktop-Installing.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Clear-Host
Write-Host "TgDownloaderDesktop PowerShell script: installing latest release"

$releasePath = "C:\TgDownloader-Releases"
$archivePath = "$releasePath\Archives"
$destinationPath = "$releasePath\TgDownloaderDesktop-AppPackages"

Write-Host "Directory creation"
New-Item -ItemType Directory -Force -Path $archivePath
New-Item -ItemType Directory -Force -Path $destinationPath

Write-Host "Searching for the latest release on GitHub via API"
$repoOwner = "DamianMorozov"
$repoName = "TgDownloader"
$apiUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases/latest"

Write-Host "Getting information about the latest release"
$releaseInfo = Invoke-RestMethod -Uri $apiUrl -Headers @{ "User-Agent" = "PowerShell" }

if ($releaseInfo -and $releaseInfo.assets.Count -gt 0) {
Write-Host "Creating a catalog for an archive with a tag"
$tagName = $releaseInfo.tag_name -replace '[\/:*?"<>|]', '_'
$tagFolderPath = "$archivePath\$tagName"
New-Item -ItemType Directory -Force -Path $tagFolderPath

Write-Host "Downloading assets for release: $($releaseInfo.tag_name)"
foreach ($asset in $releaseInfo.assets) {
if ($asset.name -like "*AppPackages.zip*") {
Write-Host "Getting URL and file name: $apiUrl"
$assetUrl = $asset.browser_download_url
$fileName = $asset.name
$filePath = "$tagFolderPath\$fileName"
# Checking the existence of a file before downloading
if (-not (Test-Path $filePath)) {
try {
Write-Host "Checking the existence of a ${fileName}: downloading"
Invoke-WebRequest -Uri $assetUrl -OutFile $filePath
Write-Host "Unzipping the archive: $fileName"
Expand-Archive -Path $filePath -DestinationPath $destinationPath -Force
} catch {
Write-Host "Error downloading or unzipping the file: $_"
}
} else {
Write-Host "Checking the existence of a ${fileName}: already exists, skipping download"
}
}
}

# Checking Windows Developer Mode
try {
$devModeKeyPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
$devModeValue = (Get-ItemProperty -Path $devModeKeyPath -Name AllowDevelopmentWithoutDevLicense -ErrorAction SilentlyContinue).AllowDevelopmentWithoutDevLicense
if ($devModeValue -ne 1) {
Write-Host "Checking Windows Developer Mode: is not enabled, please enable it to continue"
exit
} else {
Write-Host "Checking Windows Developer Mode: is enabled"
}
} catch {
Write-Host "Error checking Developer Mode: $_"
}

Write-Host "Searching for the last release"
try {
$latestFolder = Get-ChildItem -Path $destinationPath | Sort-Object Name | Select-Object -Last 1

if ($latestFolder) {
$installScript = "$($latestFolder.FullName)\Install.ps1"
if (Test-Path $installScript) {
Write-Host "Starting the software installation: Install.ps1 is found"
& $installScript
} else {
Write-Host "Starting the software installation: Install.ps1 is not found in the catalog $($latestFolder.FullName)"
}
} else {
Write-Host "No folders found in the destination path."
}
} catch {
Write-Host "Error searching for the last release folder: $_"
}

Write-Host "Installation of the release has been completed: $($releaseInfo.tag_name)"
} else {
Write-Host "Couldn't find the latest release or no assets available."
}

0 comments on commit 8807faf

Please sign in to comment.