Skip to content

Commit 8392c79

Browse files
committed
Add examples
- Added example script for Linux and Windows to download all games using Gogg
1 parent d21edad commit 8392c79

File tree

8 files changed

+132
-84
lines changed

8 files changed

+132
-84
lines changed

.github/workflows/publish_snap.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ bin/
8181
download/
8282
catalogue.csv
8383
*.snap
84+
gogg/
85+
games/
86+
gogg_catalogue*

cmd/catalogue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func refreshCatalogue(cmd *cobra.Command, numThreads int) {
251251

252252
wg.Wait()
253253
bar.Finish()
254-
cmd.Printf("Refreshing completed successfully. There are %d games in the catalogue.\n", len(games))
254+
cmd.Printf("Refreshing completed successfully.")
255255
}
256256

257257
// searchCmd searches for games in the catalogue by ID or title

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
var (
88
// Gogg version
9-
version = "1.0.0"
9+
version = "0.2.0"
1010
)
1111

1212
// versionCmd shows the version of Gogg

docs/examples/.gitkeep

Whitespace-only changes.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# To run the script, open PowerShell and execute the following command:
2+
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass; .\download_all_games.ps1
3+
4+
# Colors
5+
$RED = "`e[31m"
6+
$GREEN = "`e[32m"
7+
$YELLOW = "`e[33m"
8+
$NC = "`e[0m" # No Color
9+
10+
Write-Host "${GREEN}===================== Download All Games (Windows Powershell Version) ======================${NC}"
11+
Write-Host "${GREEN}The code in this script downloads all games owned by the user on GOG.com with given options.${NC}"
12+
Write-Host "${GREEN}============================================================================================${NC}"
13+
14+
$DEBUG_MODE = 1 # Debug mode enabled
15+
$GOGG = (Get-Command "bin\gogg" -ErrorAction SilentlyContinue) -or (Get-Command "gogg" -ErrorAction SilentlyContinue)
16+
17+
$LANG = "en" # Language English
18+
$PLATFORM = "windows" # Platform Windows
19+
$INCLUDE_DLC = 1 # Include DLCs
20+
$INCLUDE_EXTRA_CONTENT = 1 # Include extra content
21+
$RESUME_DOWNLOAD = 1 # Resume download
22+
$NUM_THREADS = 4 # Number of worker threads for downloading
23+
24+
# Function to clean up the CSV file
25+
function Cleanup {
26+
if ($latest_csv) {
27+
Remove-Item -Force $latest_csv
28+
if ($?) {
29+
Write-Host "${RED}Cleanup: removed $latest_csv${NC}"
30+
}
31+
}
32+
}
33+
34+
# Trap Ctrl+C and call Cleanup
35+
$global:latest_csv = $null
36+
Register-ObjectEvent -InputObject $Host -EventName "CancelKeyPress" -Action { Cleanup }
37+
38+
# Update game catalogue and export it to a CSV file
39+
& $GOGG catalogue refresh
40+
& $GOGG catalogue export --format csv --dir ./
41+
42+
# Find the newest catalogue file
43+
$latest_csv = Get-ChildItem -Path . -Filter "gogg_catalogue_*.csv" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
44+
45+
# Check if the catalogue file exists
46+
if (-not $latest_csv) {
47+
Write-Host "${RED}No CSV file found.${NC}"
48+
exit 1
49+
}
50+
51+
Write-Host "${GREEN}Using catalogue file: $($latest_csv.Name)${NC}"
52+
53+
# Download each game listed in catalogue file, skipping the first line
54+
Get-Content $latest_csv.FullName | Select-Object -Skip 1 | ForEach-Object {
55+
$fields = $_ -split ","
56+
$game_id = $fields[0]
57+
$game_title = $fields[1]
58+
Write-Host "${YELLOW}Game ID: $game_id, Title: $game_title${NC}"
59+
& $GOGG download --id $game_id --dir "./games" --platform $PLATFORM --lang $LANG `
60+
--dlcs $INCLUDE_DLC --extras $INCLUDE_EXTRA_CONTENT --resume $RESUME_DOWNLOAD --threads $NUM_THREADS
61+
Start-Sleep -Seconds 1
62+
# Remove the break to download all games
63+
}
64+
65+
# Clean up
66+
Cleanup
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# Colors
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[1;33m'
7+
NC='\033[0m' # No Color
8+
9+
echo -e "${GREEN}=========================== Download All Games (Linux Version) =============================${NC}"
10+
echo -e "${GREEN}The code in this script downloads all games owned by the user on GOG.com with given options.${NC}"
11+
echo -e "${GREEN}============================================================================================${NC}"
12+
13+
DEBUG_MODE=1 # Debug mode enabled
14+
GOGG=$(command -v bin/gogg || command -v gogg)
15+
16+
LANG=en # Language English
17+
PLATFORM=windows # Platform Windows
18+
INCLUDE_DLC=1 # Include DLCs
19+
INCLUDE_EXTRA_CONTENT=1 # Include extra content
20+
RESUME_DOWNLOAD=1 # Resume download
21+
NUM_THREADS=4 # Number of worker threads for downloading
22+
23+
# Function to clean up the CSV file
24+
cleanup() {
25+
if [ -n "$latest_csv" ]; then
26+
rm -f "$latest_csv"
27+
if [ $? -eq 0 ]; then
28+
echo -e "${RED}Cleanup: removed $latest_csv${NC}"
29+
fi
30+
fi
31+
}
32+
33+
# Trap SIGINT (Ctrl+C) and call cleanup
34+
trap cleanup SIGINT
35+
36+
# Update game catalogue and export it to a CSV file
37+
$GOGG catalogue refresh
38+
$GOGG catalogue export --format csv --dir ./
39+
40+
# Find the newest catalogue file
41+
latest_csv=$(ls -t gogg_catalogue_*.csv 2>/dev/null | head -n 1)
42+
43+
# Check if the catalogue file exists
44+
if [ -z "$latest_csv" ]; then
45+
echo -e "${RED}No CSV file found.${NC}"
46+
exit 1
47+
fi
48+
49+
echo -e "${GREEN}Using catalogue file: $latest_csv${NC}"
50+
51+
# Download each game listed in catalogue file, skipping the first line
52+
tail -n +2 "$latest_csv" | while IFS=, read -r game_id game_title; do
53+
echo -e "${YELLOW}Game ID: $game_id, Title: $game_title${NC}"
54+
DEBUG_GOGG=$DEBUG_MODE $GOGG download --id $game_id --dir ./games --platform $PLATFORM --lang $LANG \
55+
--dlcs $INCLUDE_DLC --extras $INCLUDE_EXTRA_CONTENT --resume $RESUME_DOWNLOAD --threads $NUM_THREADS
56+
sleep 1
57+
#break # Comment out this line to download all games
58+
done
59+
60+
# Clean up
61+
cleanup

snap/snapcraft.yaml

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)