summarylogtreecommitdiffstats
path: root/uTorrent
blob: 651c8a2ec15faa0d049ca3b10154a7bc5aa8eae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash -e

ClearDumps="yes"  # Clean up "[build]-utorrent.XXXX.dmp" dumps in ~/.uTorrent/
Debug="no"        # Supress _all_ output (even that outside of Wine)

# Set Wine home
if [[ ! $WINEPREFIX ]]; then
    WINEPREFIX=~/.wine
fi

# Symlink uTorrent.exe
if [[ ! -L ~/.uTorrent/uTorrent.exe ]]; then
    install -d ~/.uTorrent/
    ln -s /usr/share/utorrent/uTorrent.exe ~/.uTorrent/uTorrent.exe
fi

# Store settings in ~/.uTorrent/
if [[ ! -f ~/.uTorrent/settings.dat ]]; then
    touch ~/.uTorrent/settings.dat
fi

# Symlink AppData directory to ~/.uTorrent/
appdata="$WINEPREFIX/drive_c/users/$USER/Application Data/uTorrent"
if [[ ! -L $appdata ]]; then
    # Move any settings first
    if [[ -e $appdata ]]; then
        if [[ -f $appdata/settings.dat ]]; then
            cp -r "$appdata/"* ~/.uTorrent/
        fi
        rm -r "$appdata/"
    fi
    ln -sf ~/.uTorrent/ "$appdata"
fi

# Clear piling up memory dumps
if [[ $ClearDumps = yes ]]; then
    rm -f ~/.uTorrent/*.dmp
fi

# Add torrent(s)/magnet link(s)
for i; do # for i = for i in "$@"
    # Add path in Wine form (e.g. "z:/home/user/Desktop/lol.torrent")
    if [[ -f /${i#?:} ]]; then 
        torrents+=("z:${i#?:}")   # When opened through .desktop or Wine path (e.g. z:/*)
    elif [[ $i != 'magnet:'* ]]; then
        torrents+=("z:$(pwd)/$i") # When path only partial or in current directory
    else    # Magnet links
        torrents+=("$i")
    fi
done

# Launch app
if [[ $Debug = no ]]; then
    env WINEPREFIX="$WINEPREFIX" wine ~/.uTorrent/uTorrent.exe "${torrents[@]}" &>/dev/null
else
    env WINEPREFIX="$WINEPREFIX" wine ~/.uTorrent/uTorrent.exe "${torrents[@]}"
fi