This guide will cover the use of BitTorrent as a source for apps. To learn about the feature, first visit Features.

Get the magnet link

In denget, downloading apps via BitTorrent is available using magnet links. This link will be used as a source in the app manifest.

Create an app manifest

Create an app manifest as described in Creating an app manifest.

You should put the magnet link in $source in Data Setup section.

Here is an example of a manifest that uses BitTorrent. It installs GIMP 2.8.20. You can use it to quickly start creating similar manifests.

### ARIA2 PORTABLE MANIFEST ###
param (
    [string]$cmd,
    [string]$trgversion,
    [string]$path,
    [switch]$force,
    [switch]$quiet
)

### PATH RESOLVER ###

$dgpath = getdgpath

if($path -eq '')
{
    $path = "$dgpath\apps"
}
else
{
    if(!(Test-Path $path))
    {
        Write-Host "Error: " -f r -n
        Write-Host "path isn't accessible."
        exit -1
    }
}

### DATA SETUP ###

$name = "gimp"
$portable = $true
$version = "2.8.20"
$source = "magnet:?xt=urn:btih:825000684BC3FE6F619705D99B3B2EBDB9214A28&dn=GIMP%20v2.8.20%20(Image%20Editor)%20-%20SeuPirate&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce"
$sourcetype = "hardlink"
$executable = "$path\$name\$version\bin\gimp-2.8.exe"
$uninstaller = "$path\$name\$version\uninst\unins000.exe"
$dependencies = @()

### INSTALL ###

if($cmd -eq "install")
{

    ### NON-PORTABLE WARNING ###

    if($portable -eq $false -and !($quiet))
    {
        Write-Host "Warning: " -f y -n
        Write-Host "$name " -f gre -n; Write-Host "is not a portable application. It won't be installed in " -n; Write-Host "'denget/apps'" -f gre -n; Write-Host ". Do you want to continue? (y/n): " -n
        $answer = Read-Host

        if($answer -eq "n" -or $answer -eq "N")
        {
            exit -1
        }
    }

    ### ARIA2 RESOLVER ###

    $aria2 = getinstalled "aria2" executable

    if ($null -eq $aria2)
    {
        Write-Host "Error: " -f r -n
        Write-Host "aria2 is not installed. To download via BitTorrent first run '" -n; Write-Host "denget install aria2" -f m -n; Write-Host "'."
        exit -1
    }

    if (!($quiet)) {
        Write-Host "BitTorrent downloads could take a while. Do you want to launch aria2 in a new window to see the progress? (y/n): " -n
        $answer = Read-Host
        if ($answer -eq "y" -or $answer -eq "Y") { $qarg = ""; $nnwarg = $false }
        else { $qarg = "-q"; $nnwarg = $true }
    }
    else { $qarg = "-q"; $nnwarg = $true }

    ### PRE-INSTALLATION STEPS ###

    ### INSTALLER/FILES DOWNLOAD VIA ARIA2 ###

    Write-Quiet "Downloading " -n; Write-Quiet "$name" -f gre -n; Write-Quiet " from " -n; Write-Quiet "$source" -f gre -n; Write-Quiet "..."
    $aria2params = @{
        FilePath     = $aria2
        ArgumentList = "--seed-time=0 $source --dir $dgpath\temp\$name -x 16 -k 1M $qarg"
        Wait         = $true
        NoNewWindow  = $nnwarg
    }
    Start-Process @aria2params

    ### INSTALLER EXECUTION / FILE COPY ###

    Write-Quiet "Extracting..."
    $installerparams = @{
        FilePath     = "$dgpath\temp\$name\gimp-2.8.20-setup.exe"
        ArgumentList = "/DIR=$path\$name\$version", '/VERYSILENT', '/NOICONS'
        Wait         = $true
        WindowStyle = 'Hidden'
    }
    Start-Process @installerparams

    ### CREATE DESKTOP SHORTCUT ###

    if (!$quiet) {
    Write-Host "Do you want to create a desktop shortcut? (y/n): " -NoNewline
    $answer = Read-Host

    if($answer -eq "y" -or $answer -eq "Y")
    {
        Write-Host "Creating desktop shortcut..."
        $shortcut = (New-Object -ComObject Wscript.Shell).CreateShortcut("$env:USERPROFILE\Desktop\$name.lnk")
        $shortcut.TargetPath = $executable
        #$shortcut.Arguments = ''
        #$shortcut.IconLocation = ''
        $shortcut.Save()
    }
    }

    ### POST-INSTALLATION STEPS ###

    ### REMOVING INSTALLER / CLEANING TEMP ###

    Write-Quiet "Cleaning up..."
    Remove-Item "$dgpath\temp\$name" -Recurse -Force

    ### CHECKING IF EXECUTABLE EXISTS ###

    if(!(Test-Path $executable))
    {
        Write-Host "Error: " -f r -n
        Write-Host "executable not found. Installation failed or aborted by user."
        exit -1
    }

    ### DEPENDENCIES CHECK ###

    if($dependencies.Length -ne 0)
    {
        Write-Quiet "Note: " -f blu -n
        Write-Quiet "this app has the following dependencies:"
        foreach($dependency in $dependencies)
        {
            Write-Quiet "$dependency" -f gre
        }

        $bucketoforigin = $PSScriptRoot.Split("\")[-1]
        Write-Quiet "You can see this list again by running '" -n; Write-Quiet "denget dependencies $name $bucketoforigin" -f m -n; Write-Quiet "'."
    }

    ### RETURNING DATA TO DENGET ###

    $global:appversion = $version
    $global:portable = $portable
    $global:executable = $executable

    exit 0
}

### UNINSTALL ###

if($cmd -eq "uninstall")
{
    ### CHECK IF VERSIONS ARE MISMATCHED FOR PORTABLE ###

    if ($version -ne $trgversion -and $portable -and !($force))
    {
        Write-Host "Warning: " -f y -n
        Write-Host "version installed ($trgversion) doesn't match the version in the manifest ($version)."
        Write-Host "Possibly, the manifest was updated. Uninstalling may result in an error if the uninstalling process has changed."
        Write-Host "Do you want to proceed anyway? (y/n): " -NoNewline
        $answer = Read-Host

        if($answer -eq "n" -or $answer -eq "N")
        {
            exit -1
        }
    }

    ### WARNINGS / PRE-UNINSTALLATION STEPS ###

    if(!($quiet)) {
        Write-Host "Are you sure you want to uninstall " -n; Write-Host "$name" -f gre -n; Write-Host "? (y/n): " -n
        $answer = Read-Host

        if($answer -eq "n" -or $answer -eq "N")
        {
            exit -1
        }
    }

    ### UNINSTALLER EXECUTION / FILE DELETION ###

    Write-Quiet "Deleting app..."

    $uninstallerparams = @{
        FilePath     = $uninstaller
        Wait         = $true
        WindowStyle = 'Hidden'
    }
    Start-Process @uninstallerparams

    ### CHECKING IF EXECUTABLE EXISTS ###

    if(Test-Path $executable)
    {
        Write-Host "Error: " -f r -n
        Write-Host "executable still exists. Uninstallation failed or aborted by user."
        exit -1
    }

    ### POST-UNINSTALLATION STEPS ###

    ### DEPENDENCIES CHECK ###

    if($dependencies.Length -ne 0)
    {
        Write-Quiet "Note: " -f blu -n
        Write-Quiet "this app has the following dependencies you might want to uninstall too:"
        foreach($dependency in $dependencies)
        {
            Write-Quiet "$dependency" -f gre
        }

        $bucketoforigin = $PSScriptRoot.Split("\")[-1]
        Write-Quiet "You can see this list again by running '" -n; Write-Quiet "denget dependencies $name $bucketoforigin" -f m -n; Write-Quiet "'."
    }

    ### REMOVE DESKTOP SHORTCUT ###

    if(Test-Path "$env:USERPROFILE\Desktop\$name.lnk")
    {
        Write-Quiet "Removing desktop shortcut..."
        Remove-Item "$env:USERPROFILE\Desktop\$name.lnk"
    }

    ### REMOVE START MENU SHORTCUT ###

    if(Test-Path "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\denget\$name.lnk")
    {
        Write-Quiet "Removing start menu shortcut..."
        Remove-Item "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\denget\$name.lnk"
    }

    exit 0
}