diff --git a/.editorconfig b/.editorconfig index dca51d9..1086346 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ insert_final_newline = true # Make sure files end with a newline trim_trailing_whitespace = true # Remove trailing whitespace # Go files -[*.Go] +[*.go] max_line_length = 100 # Markdown files @@ -25,8 +25,10 @@ trim_trailing_whitespace = false # Don't remove trailing whitespace in Markdown [*.sh] indent_size = 2 -# YAML files -[*.yaml] +# PowerShell scripts +[*.ps1] indent_size = 2 - +# YAML files +[*.{yaml,yml}] +indent_size = 2 \ No newline at end of file diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 42ce7db..a4bbcf8 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -1,44 +1,38 @@ name: Linux Build on: - workflow_dispatch: # Enable manual execution + workflow_dispatch: # Allow manual execution jobs: - build: - runs-on: ubuntu-latest - - steps: - # Checkout the repository - - name: Checkout Repository - uses: actions/checkout@v4 - - # Set up Go - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.23 - - # Install dependencies and run the tests - - name: Install Dependencies - run: | - sudo apt-get install -y make - make format - make test - continue-on-error: false - - # Build the application - - name: Build for Linux - run: | - make build - continue-on-error: false - - # Debug: List Build Directory - - name: List Build Directory - run: ls -R bin - - # Upload Build Artifact - - name: Upload Build Artifact - uses: actions/upload-artifact@v4 - with: - name: gogg-linux-amd64 - path: 'bin/gogg' + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y make + make test + continue-on-error: false + + - name: Build for Linux + run: | + make build + continue-on-error: false + + - name: List Build Directory (for Debugging) + run: ls -R bin + + - name: Upload Build Artifact + uses: actions/upload-artifact@v4 + with: + name: gogg-linux-amd64 + path: 'bin/gogg' diff --git a/.github/workflows/build_macos.yml b/.github/workflows/build_macos.yml index fb23f61..904c25c 100644 --- a/.github/workflows/build_macos.yml +++ b/.github/workflows/build_macos.yml @@ -1,44 +1,37 @@ name: MacOS Build on: - workflow_dispatch: # Enable manual execution + workflow_dispatch: # Allow manual execution jobs: - build: - runs-on: macos-latest - - steps: - # Checkout the repository - - name: Checkout Repository - uses: actions/checkout@v4 - - # Set up Go - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.23 - - # Install dependencies and run the tests - - name: Install Dependencies - run: | - brew install make - make format - make test - continue-on-error: false - - # Build the application - - name: Build for MacOS - run: | - make build-macos - continue-on-error: false - - # Debug: List Build Directory - - name: List Build Directory - run: ls -R bin - - # Upload Build Artifact - - name: Upload Build Artifact - uses: actions/upload-artifact@v4 - with: - name: gogg-macos-universal - path: 'bin/gogg' + build: + runs-on: macos-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install Dependencies + run: | + brew install make + make test + continue-on-error: false + + - name: Build for MacOS + run: | + make build-macos + continue-on-error: false + + - name: List Build Directory (for Debugging) + run: ls -R bin + + - name: Upload Build Artifact + uses: actions/upload-artifact@v4 + with: + name: gogg-macos-universal + path: 'bin/gogg' diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index 4731b9c..2626bc8 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -1,44 +1,37 @@ name: Windows Build on: - workflow_dispatch: # Enable manual execution + workflow_dispatch: # Allow manual execution jobs: - build: - runs-on: windows-latest - - steps: - # Checkout the repository - - name: Checkout Repository - uses: actions/checkout@v4 - - # Set up Go - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.23 - - # Install dependencies and run the tests - - name: Install Dependencies - run: | - choco install make -y - make format - make test - continue-on-error: false - - # Build the application - - name: Build for Windows - run: | - make build GOGG_BINARY=gogg.exe - continue-on-error: false - - # Debug: List Build Directory - - name: List Build Directory - run: ls -R bin - - # Upload Build Artifact - - name: Upload Build Artifact - uses: actions/upload-artifact@v4 - with: - name: gogg-windows-amd64 - path: 'bin/gogg.exe' + build: + runs-on: windows-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install Dependencies + run: | + choco install make -y + make test + continue-on-error: false + + - name: Build for Windows + run: | + make build GOGG_BINARY=gogg.exe + continue-on-error: false + + - name: List Build Directory (for Debugging) + run: ls -R bin + + - name: Upload Build Artifact + uses: actions/upload-artifact@v4 + with: + name: gogg-windows-amd64 + path: 'bin/gogg.exe' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 31a0448..79fd7dc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,28 +1,31 @@ name: Run Linters on: - workflow_dispatch: # Allow manual execution - push: - tags: - - 'v*' # Trigger on version tags + workflow_dispatch: # Allow manual execution + push: + tags: + - 'v*' # Trigger on version tags jobs: - lint: - runs-on: ubuntu-latest + lint: + runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 + steps: + - name: Checkout Repository + uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.23' + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 - - name: Install golangci-lint - run: | - make install-deps + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y make + make install-deps - - name: Run golangci-lint - run: | - make lint + - name: Run Linters + run: | + make lint + continue-on-error: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4959351..ee5e78e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,137 +1,134 @@ name: Build and Release on: - workflow_dispatch: # Allow manual execution - push: - tags: - - 'v*' # Trigger on version tags + workflow_dispatch: # Allow manual execution + push: + tags: + - 'v*' # Trigger on version tags jobs: - build-windows: - runs-on: windows-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.23 - - - name: Install Dependencies - run: | - choco install make -y - make format - make test - - - name: Build Windows Binary - run: | - make build GOGG_BINARY=gogg.exe - - - name: Upload Windows Artifact - uses: actions/upload-artifact@v4 - with: - name: gogg-windows - path: bin/gogg.exe - - build-linux: - runs-on: ubuntu-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.23 - - - name: Install Dependencies - run: | - sudo apt-get update - sudo apt-get install -y make - make format - make test - - - name: Build Linux Binary - run: | - make build - - - name: Upload Linux Artifact - uses: actions/upload-artifact@v4 - with: - name: gogg-linux - path: bin/gogg - - build-macos: - runs-on: macos-latest - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.23 - - - name: Install Dependencies - run: | - brew install make - make format - make test - - - name: Build macOS Binary - run: | - make build-macos - - - name: Upload macOS Artifact - uses: actions/upload-artifact@v4 - with: - name: gogg-macos - path: bin/gogg - - release: - runs-on: ubuntu-latest - needs: [ build-windows, build-linux, build-macos ] - steps: - - name: Download Windows Artifact - uses: actions/download-artifact@v4 - with: - name: gogg-windows - path: ./windows - - - name: Download Linux Artifact - uses: actions/download-artifact@v4 - with: - name: gogg-linux - path: ./linux - - - name: Download macOS Artifact - uses: actions/download-artifact@v4 - with: - name: gogg-macos - path: ./macos - - - name: List Downloaded Files (for debugging) - run: ls -R . - - - name: Rename Extracted Binaries - run: | - cd windows && zip -r9 ../gogg-windows-amd64.zip gogg.exe && cd .. - cd linux && zip -r9 ../gogg-linux-amd64.zip gogg && cd .. - cd macos && zip -r9 ../gogg-macos-universal.zip gogg && cd .. - - - name: Create GitHub Release - uses: ncipollo/release-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - name: ${{ github.ref_name }} - tag: ${{ github.ref_name }} - body: | - Release version ${{ github.ref_name }} - - Binary builds for Windows, Linux, and macOS - artifacts: | - gogg-windows-amd64.zip - gogg-linux-amd64.zip - gogg-macos-universal.zip - draft: false - prerelease: false + build-windows: + runs-on: windows-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install Dependencies + run: | + choco install make -y + make test + + - name: Build Windows Binary + run: | + make build GOGG_BINARY=gogg.exe + + - name: Upload Windows Artifact + uses: actions/upload-artifact@v4 + with: + name: gogg-windows + path: bin/gogg.exe + + build-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y make + make test + + - name: Build Linux Binary + run: | + make build + + - name: Upload Linux Artifact + uses: actions/upload-artifact@v4 + with: + name: gogg-linux + path: bin/gogg + + build-macos: + runs-on: macos-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23 + + - name: Install Dependencies + run: | + brew install make + make test + + - name: Build macOS Binary + run: | + make build-macos + + - name: Upload macOS Artifact + uses: actions/upload-artifact@v4 + with: + name: gogg-macos + path: bin/gogg + + release: + runs-on: ubuntu-latest + needs: [ build-windows, build-linux, build-macos ] + steps: + - name: Download Windows Artifact + uses: actions/download-artifact@v4 + with: + name: gogg-windows + path: ./windows + + - name: Download Linux Artifact + uses: actions/download-artifact@v4 + with: + name: gogg-linux + path: ./linux + + - name: Download macOS Artifact + uses: actions/download-artifact@v4 + with: + name: gogg-macos + path: ./macos + + - name: List Downloaded Files (for debugging) + run: ls -R . + + - name: Rename Extracted Binaries + run: | + cd windows && zip -r9 ../gogg-windows-amd64.zip gogg.exe && cd .. + cd linux && zip -r9 ../gogg-linux-amd64.zip gogg && cd .. + cd macos && zip -r9 ../gogg-macos-universal.zip gogg && cd .. + + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + name: ${{ github.ref_name }} + tag: ${{ github.ref_name }} + body: | + Release version ${{ github.ref_name }} + - Binary builds for Windows, Linux, and macOS + artifacts: | + gogg-windows-amd64.zip + gogg-linux-amd64.zip + gogg-macos-universal.zip + draft: false + prerelease: false diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fb1ca88..bd72420 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,41 +1,43 @@ name: Tests on: - workflow_dispatch: # Only enable manual runs for now + workflow_dispatch: # Allow manual execution + push: + tags: + - 'v*' # Trigger on version tags jobs: - build: - runs-on: ubuntu-latest - - strategy: - matrix: - # Define the Go versions to test against - go-version: [ "1.21", "1.22", "1.23" ] - - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Set up Go ${{ matrix.go-version }} - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go-version }} - - # Install dependencies and run the tests - - name: Install Dependencies - run: | - sudo apt-get install -y make - make format - continue-on-error: false - - - name: Run Tests and Generate Coverage Report - run: | - make test - make codecov - continue-on-error: false - - # Upload the coverage report to Codecov - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v5 - with: - token: ${{ secrets.CODECOV_TOKEN }} + build: + runs-on: ubuntu-latest + + strategy: + matrix: + # Go versions to test against + go-version: [ "1.21", "1.22", "1.23" ] + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y make + make install-deps + continue-on-error: false + + - name: Run Tests and Generate Coverage Report + run: | + make test # Generates a coverage.txt file for Codecov + continue-on-error: false + + - name: Upload Coverage Reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + continue-on-error: false # Set to true to prevent failing the build if Codecov fails diff --git a/.golangci.yml b/.golangci.yml index 91b2cd8..642bd1e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,16 +1,16 @@ run: - timeout: 5m + timeout: 5m linters: - enable: - - errcheck - - gosimple - - govet - - staticcheck - - unused + enable: + - errcheck + - gosimple + - govet + - staticcheck + - unused issues: - exclude-rules: - - path: _test\.go - linters: - - errcheck + exclude-rules: + - path: _test\.go + linters: + - errcheck diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 05a693f..f395a1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,20 +17,29 @@ Contributions are always welcome and appreciated. ## Submitting Pull Requests -- Make sure all tests pass before submitting a pull request. -- Write a clear description of the changes you made and why you made them for the pull request. +- Ensure all tests pass before submitting a pull request. +- Write a clear description of the changes you made and the reasons behind them. -## Code Style +> [!IMPORTANT] +> It's assumed that by submitting a pull request, you agree to license your contributions under the project's license. + +## Development Workflow + +### Code Style - Use the `make format` command to format the code. -## Running Tests +### Running Tests + +- Use the `make test` command to run the tests. + +### Running Linters -- Use the `make test` command to run the unit tests. +- Use the `make lint` command to run the linters. -## Miscellaneous +### See Available Commands -- Run `make help` to see all available commands to manage different tasks. +- Run `make help` to see all available commands for managing different tasks. ## Code of Conduct diff --git a/Makefile b/Makefile index e51eafe..22e337d 100644 --- a/Makefile +++ b/Makefile @@ -1,79 +1,66 @@ -# Declare PHONY targets -.PHONY: build format test test-cover clean run build-macos help snap-deps snap install-deps - # Variables PKG = github.com/habedi/gogg BINARY_NAME = $(or $(GOGG_BINARY), $(notdir $(PKG))) BINARY = bin/$(BINARY_NAME) -COVER_PROFILE = cover.out +COVER_PROFILE = coverage.txt GO_FILES = $(shell find . -type f -name '*.go') COVER_FLAGS = --cover --coverprofile=$(COVER_PROFILE) CUSTOM_SNAPCRAFT_BUILD_ENVIRONMENT = $(or $(SNAP_BACKEND), multipass) +PATH := /snap/bin:$(PATH) + +# Default target +.DEFAULT_GOAL := help -# Help target -help: - @echo "Available targets:" - @echo "" - @echo " build Build the Go project" - @echo " format Format Go files" - @echo " test Run tests" - @echo " test-cover Run tests with coverage report" - @echo " clean Clean generated and temporary files" - @echo " run Build and run the project" - @echo " build-macos Build a universal binary for macOS" - @echo " snap-deps Install Snapcraft dependencies" - @echo " snap Build the Snap package" - @echo " install-deps Install development dependencies on Debian-based systems" - @echo " lint Lint Go files to check for potential errors" - @echo " codecov Create test coverage report for Codecov" - @echo " help Show this help message" +.PHONY: help +help: ## Show this help message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -# Building the project -build: format +.PHONY: build +build: format ## Build the binary for the current platform @echo "Tidying dependencies..." go mod tidy @echo "Building the project..." go build -o $(BINARY) -# Formatting Go files -format: +.PHONY: format +format: ## Format Go files @echo "Formatting Go files..." go fmt ./... -# Running tests -test: format +.PHONY: test +test: format ## Run tests @echo "Running tests..." - go test -v ./... --race + go test -v ./... $(COVER_FLAGS) --race -test-cover: format - @echo "Running tests with coverage..." - go test -v ./... --race $(COVER_FLAGS) - @echo "Generating HTML coverage report..." - go tool cover -html=$(COVER_PROFILE) +.PHONY: showcov +showcov: test ## Display test coverage report + @echo "Displaying test coverage report..." + go tool cover -func=$(COVER_PROFILE) -# Cleaning generated and temporary files -clean: +.PHONY: clean +clean: ## Remove generated and temporary files @echo "Cleaning up..." find . -type f -name '*.got.*' -delete find . -type f -name '*.out' -delete find . -type f -name '*.snap' -delete + rm -f $(COVER_PROFILE) rm -rf bin/ -# Running the built executable -run: build - @echo "Running the project..." +.PHONY: run +run: build ## Build and run the binary + @echo "Running the $(BINARY) binary..." ./$(BINARY) -# Custom build for macOS -build-macos: format +.PHONY: build-macos +build-macos: format ## Build a universal binary for macOS (x86_64 and arm64) @echo "Building universal binary for macOS..." mkdir -p bin GOARCH=amd64 go build -o bin/$(BINARY_NAME)-x86_64 ./main.go GOARCH=arm64 go build -o bin/$(BINARY_NAME)-arm64 ./main.go lipo -create -output $(BINARY) bin/$(BINARY_NAME)-x86_64 bin/$(BINARY_NAME)-arm64 -# Install Snapcraft Dependencies -snap-deps: +.PHONY: snap-deps +snap-deps: ## Install Snapcraft dependencies @echo "Installing Snapcraft dependencies..." sudo apt-get update sudo apt-get install -y snapd @@ -81,26 +68,17 @@ snap-deps: sudo snap install snapcraft --classic sudo snap install multipass --classic -# Build Snap package -snap: build # snap-deps - @echo "Building Snap package..." - SNAPCRAFT_BUILD_ENVIRONMENT=$(CUSTOM_SNAPCRAFT_BUILD_ENVIRONMENT) snapcraft - -# Install Dependencies on Debian-based systems like Ubuntu -install-deps: +.PHONY: install-deps +install-deps: ## Install development dependencies on Debian-based systems @echo "Installing dependencies..." make snap-deps - sudo apt-get install -y chromium-browser build-essential + sudo apt-get install -y chromium-browser build-essential chromium || true # ignore errors sudo snap install chromium sudo snap install go --classic sudo snap install golangci-lint --classic + go mod download -# Linting Go files -lint: +.PHONY: lint +lint: format ## Run linters on Go files @echo "Linting Go files..." golangci-lint run ./... - -# Create Test Coverage Report for Codecov -codecov: format - @echo "Uploading coverage report to Codecov..." - go test -coverprofile=coverage.txt ./... diff --git a/README.md b/README.md index 1f56b3d..b4a616d 100644 --- a/README.md +++ b/README.md @@ -9,32 +9,35 @@

- Tests + Tests - Linux Build + Linux Build - Windows Build + Windows Build - MacOS Build + MacOS Build
- - Go Report Card + + Docs + + + License - Code Coverage + Code Coverage - CodeFactor + CodeFactor - Release + Release - Total Downloads + Total Downloads

diff --git a/client/download.go b/client/download.go index 6b75dd1..3cef1fd 100644 --- a/client/download.go +++ b/client/download.go @@ -157,26 +157,36 @@ func DownloadGameFiles(accessToken string, game Game, downloadPath string, return err } + // Check if resuming is enabled; and if file already exists and is fully downloaded var file *os.File var startOffset int64 - // Check if resuming is enabled and the file already exists if resume { fileInfo, err := os.Stat(filePath) if err == nil { startOffset = fileInfo.Size() log.Info().Msgf("Resuming download for %s from offset %d", fileName, startOffset) file, err = os.OpenFile(filePath, os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + log.Error().Err(err).Msgf("Failed to open file %s for appending", filePath) + return err + } } else if os.IsNotExist(err) { file, err = os.Create(filePath) + if err != nil { + log.Error().Err(err).Msgf("Failed to create file %s", filePath) + return err + } + } else { + log.Error().Err(err).Msgf("Failed to stat file %s", filePath) + return err } } else { file, err = os.Create(filePath) - } - - if err != nil { - log.Error().Err(err).Msgf("Failed to create or open file %s", filePath) - return err + if err != nil { + log.Error().Err(err).Msgf("Failed to create file %s", filePath) + return err + } } defer file.Close() @@ -245,7 +255,9 @@ func DownloadGameFiles(accessToken string, game Game, downloadPath string, }), ) // Set progress bar to the starting point (resume offset) - progressBar.Set64(startOffset) + if err := progressBar.Set64(startOffset); err != nil { + return fmt.Errorf("failed to set progress bar start offset: %w", err) + } // Wrap response body with progress bar progressReader := io.TeeReader(resp.Body, progressBar) @@ -277,7 +289,9 @@ func DownloadGameFiles(accessToken string, game Game, downloadPath string, // Enqueue download tasks for _, download := range game.Downloads { - if strings.ToLower(download.Language) != strings.ToLower(gameLanguage) { + + // Check if the language of the download matches the selected language + if !strings.EqualFold(download.Language, gameLanguage) { log.Info().Msgf("Skipping download for language %s because it doesn't match selected language %s", download.Language, gameLanguage) fmt.Printf("Skipping downloading game files for %s\n", download.Language) continue @@ -328,9 +342,11 @@ func DownloadGameFiles(accessToken string, game Game, downloadPath string, log.Info().Msgf("Processing DLC: %s", dlc.Title) for _, download := range dlc.ParsedDownloads { - if strings.ToLower(download.Language) != strings.ToLower(gameLanguage) { - log.Info().Msgf("Skipping DLC download for language %s because it doesn't match selected language %s", download.Language, gameLanguage) - fmt.Printf("Skipping downloading DLC files for %s\n", download.Language) + + // Check if the language of the download matches the selected language + if !strings.EqualFold(download.Language, gameLanguage) { + log.Info().Msgf("Skipping download for language %s because it doesn't match selected language %s", download.Language, gameLanguage) + fmt.Printf("Skipping downloading game files for %s\n", download.Language) continue } diff --git a/cmd/catalogue.go b/cmd/catalogue.go index 5cd0477..7facbb8 100644 --- a/cmd/catalogue.go +++ b/cmd/catalogue.go @@ -271,8 +271,14 @@ func refreshCatalogue(cmd *cobra.Command, numThreads int) { close(taskChan) }() + // Wait for all workers to finish wg.Wait() - bar.Finish() + + // Finish the progress bar and check for any errors + if err := bar.Finish(); err != nil { + log.Error().Err(err).Msg("Failed to finish progress bar") + } + cmd.Println("Refreshed the game catalogue successfully.") } diff --git a/cmd/file.go b/cmd/file.go index d179913..3e6b95a 100644 --- a/cmd/file.go +++ b/cmd/file.go @@ -142,7 +142,7 @@ func generateHashFiles(dir string, algo string, recursive bool, saveToFile bool, // Walk through the directory go func() { - filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil { log.Error().Msgf("Error accessing path %q: %v", path, err) return err @@ -168,6 +168,9 @@ func generateHashFiles(dir string, algo string, recursive bool, saveToFile bool, fileChan <- path return nil }) + if err != nil { + log.Error().Msgf("Error walking the path %q: %v", dir, err) + } close(fileChan) }() @@ -344,7 +347,9 @@ func estimateStorageSize(gameID string, language string, platformName string, ex // Calculate the size of downloads for _, download := range nestedData.Downloads { - if strings.ToLower(download.Language) != strings.ToLower(language) { + + // Skip downloads with different language than specified + if !strings.EqualFold(download.Language, language) { log.Info().Msgf("Skipping language %s", download.Language) continue } @@ -395,7 +400,9 @@ func estimateStorageSize(gameID string, language string, platformName string, ex if dlcFlag { for _, dlc := range nestedData.DLCs { for _, download := range dlc.ParsedDownloads { - if strings.ToLower(download.Language) != strings.ToLower(language) { + + // Skip downloads with different language than specified + if !strings.EqualFold(download.Language, language) { log.Info().Msgf("DLC %s: Skipping language %s", dlc.Title, download.Language) continue } diff --git a/db/token.go b/db/token.go index 79935ee..43e47e7 100644 --- a/db/token.go +++ b/db/token.go @@ -30,10 +30,6 @@ func GetTokenRecord() (*Token, error) { return nil, err } - if &token == nil { - return nil, fmt.Errorf("no token data found. Please try logging in first") - } - return &token, nil } diff --git a/docs/examples/calculate_storage_for_all_games.ps1 b/docs/examples/calculate_storage_for_all_games.ps1 index 87d4255..2b53972 100644 --- a/docs/examples/calculate_storage_for_all_games.ps1 +++ b/docs/examples/calculate_storage_for_all_games.ps1 @@ -31,14 +31,14 @@ $STORAGE_UNIT = "GB" # Storage unit (MB or GB) # Function to clean up the CSV file function Cleanup { - if ($latest_csv) + if ($latest_csv) + { + Remove-Item -Force $latest_csv + if ($?) { - Remove-Item -Force $latest_csv - if ($?) - { - Write-Host "${RED}Cleanup: removed $latest_csv${NC}" - } + Write-Host "${RED}Cleanup: removed $latest_csv${NC}" } + } } # Update game catalogue and export it to a CSV file @@ -51,8 +51,8 @@ $latest_csv = Get-ChildItem -Path . -Filter "gogg_catalogue_*.csv" | Sort-Object # Check if the catalogue file exists if (-not $latest_csv) { - Write-Host "${RED}No CSV file found.${NC}" - exit 1 + Write-Host "${RED}No CSV file found.${NC}" + exit 1 } Write-Host "${GREEN}Using catalogue file: $( $latest_csv.Name )${NC}" @@ -63,17 +63,17 @@ $totalSize = 0.0 # Download each game listed in catalogue file, skipping the first line Get-Content $latest_csv.FullName | Select-Object -Skip 1 | ForEach-Object { - $fields = $_ -split "," - $game_id = $fields[0] - $game_title = $fields[1] - $counter++ - Write-Host "${YELLOW}${counter}: Game ID: $game_id, Title: $game_title${NC}" - $sizeOutput = & $GOGG file size $game_id --platform=$PLATFORM --lang=$LANG --dlcs=$INCLUDE_DLC ` + $fields = $_ -split "," + $game_id = $fields[0] + $game_title = $fields[1] + $counter++ + Write-Host "${YELLOW}${counter}: Game ID: $game_id, Title: $game_title${NC}" + $sizeOutput = & $GOGG file size $game_id --platform=$PLATFORM --lang=$LANG --dlcs=$INCLUDE_DLC ` --extras=$INCLUDE_EXTRA_CONTENT --unit=$STORAGE_UNIT - $size = [double]($sizeOutput -replace '[^\d.]', '') - $totalSize += $size - Write-Host "${YELLOW}Total download size: $size $STORAGE_UNIT${NC}" - Start-Sleep -Seconds 0.0 + $size = [double]($sizeOutput -replace '[^\d.]', '') + $totalSize += $size + Write-Host "${YELLOW}Total download size: $size $STORAGE_UNIT${NC}" + Start-Sleep -Seconds 0.0 } # Print total download size diff --git a/docs/examples/download_all_games.ps1 b/docs/examples/download_all_games.ps1 index 4541095..9db6827 100644 --- a/docs/examples/download_all_games.ps1 +++ b/docs/examples/download_all_games.ps1 @@ -27,14 +27,14 @@ $OUTPUT_DIR = "./games" # Output directory # Function to clean up the CSV file function Cleanup { - if ($latest_csv) + if ($latest_csv) + { + Remove-Item -Force $latest_csv + if ($?) { - Remove-Item -Force $latest_csv - if ($?) - { - Write-Host "${RED}Cleanup: removed $latest_csv${NC}" - } + Write-Host "${RED}Cleanup: removed $latest_csv${NC}" } + } } # Update game catalogue and export it to a CSV file @@ -47,22 +47,22 @@ $latest_csv = Get-ChildItem -Path . -Filter "gogg_catalogue_*.csv" | Sort-Object # Check if the catalogue file exists if (-not $latest_csv) { - Write-Host "${RED}No CSV file found.${NC}" - exit 1 + Write-Host "${RED}No CSV file found.${NC}" + exit 1 } Write-Host "${GREEN}Using catalogue file: $( $latest_csv.Name )${NC}" # Download each game listed in catalogue file, skipping the first line Get-Content $latest_csv.FullName | Select-Object -Skip 1 | ForEach-Object { - $fields = $_ -split "," - $game_id = $fields[0] - $game_title = $fields[1] - Write-Host "${YELLOW}Game ID: $game_id, Title: $game_title${NC}" - & $GOGG download $game_id $OUTPUT_DIR --platform=$PLATFORM --lang=$LANG ` + $fields = $_ -split "," + $game_id = $fields[0] + $game_title = $fields[1] + Write-Host "${YELLOW}Game ID: $game_id, Title: $game_title${NC}" + & $GOGG download $game_id $OUTPUT_DIR --platform=$PLATFORM --lang=$LANG ` --dlcs=$INCLUDE_DLC --extras=$INCLUDE_EXTRA_CONTENT --resume=$RESUME_DOWNLOAD --threads=$NUM_THREADS ` --flatten=$FLATTEN - Start-Sleep -Seconds 1 + Start-Sleep -Seconds 1 } # Clean up