Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.24.x'
go-version: '1.26.4'

- name: Build gameid
env:
Expand Down
2 changes: 1 addition & 1 deletion archive/archive.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/archive_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/detect.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/detect_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/path.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/path_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
4 changes: 2 additions & 2 deletions archive/rar.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down Expand Up @@ -60,7 +60,7 @@ func (ra *RARArchive) List() ([]FileInfo, error) {
return nil, fmt.Errorf("create RAR reader: %w", err)
}

var files []FileInfo //nolint:prealloc // RAR file count unknown until full scan
var files []FileInfo
for {
header, err := reader.Next()
if errors.Is(err, io.EOF) {
Expand Down
2 changes: 1 addition & 1 deletion archive/sevenzip.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion archive/zip.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion blockdevice_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion chd/bitstream.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion chd/chd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
6 changes: 4 additions & 2 deletions chd/chd_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down Expand Up @@ -1070,7 +1070,9 @@ func TestNeoGeoCDCHD(t *testing.T) {
codecName := "?"
if int(entry.CompType) < len(header.Compressors) {
tag := header.Compressors[entry.CompType]
codecName = string([]byte{byte(tag >> 24), byte(tag >> 16), byte(tag >> 8), byte(tag)})
codecName = string([]byte{
byte(tag >> 24 & 0xFF), byte(tag >> 16 & 0xFF), byte(tag >> 8 & 0xFF), byte(tag & 0xFF),
})
}
t.Logf("Hunk %d: CompType=%d (%s), CompLength=%d, Offset=%d",
idx, entry.CompType, codecName, entry.CompLength, entry.Offset)
Expand Down
10 changes: 5 additions & 5 deletions chd/codec.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down Expand Up @@ -112,10 +112,10 @@ func codecTagToString(tag uint32) string {
return "none"
}
tagBytes := []byte{
byte(tag >> 24),
byte(tag >> 16),
byte(tag >> 8),
byte(tag),
byte(tag >> 24 & 0xFF),
byte(tag >> 16 & 0xFF),
byte(tag >> 8 & 0xFF),
byte(tag & 0xFF),
}
return string(tagBytes)
}
Expand Down
20 changes: 10 additions & 10 deletions chd/codec_flac.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down Expand Up @@ -76,8 +76,8 @@ func writeFLACFrameSamples(audioFrame *frame.Frame, dst []byte, offset int) int
for ch := range numChannels {
sample := audioFrame.Subframes[ch].Samples[i]
if offset+2 <= len(dst) {
dst[offset] = byte(sample >> 8)
dst[offset+1] = byte(sample)
dst[offset] = byte(sample >> 8 & 0xFF)
dst[offset+1] = byte(sample & 0xFF)
offset += 2
}
}
Expand Down Expand Up @@ -198,18 +198,18 @@ func buildFLACHeader(sampleRate uint32, numChannels uint8, blockSize uint16) []b
copy(header, flacHeaderTemplate)

// Patch block sizes at offsets 0x08 and 0x0A (big-endian 16-bit)
header[0x08] = byte(blockSize >> 8)
header[0x09] = byte(blockSize)
header[0x0A] = byte(blockSize >> 8)
header[0x0B] = byte(blockSize)
header[0x08] = byte(blockSize >> 8 & 0xFF)
header[0x09] = byte(blockSize & 0xFF)
header[0x0A] = byte(blockSize >> 8 & 0xFF)
header[0x0B] = byte(blockSize & 0xFF)

// Patch sample rate, channels, bits at offset 0x12 (big-endian 24-bit)
// Format: (sample_rate << 4) | ((num_channels - 1) << 1) | (bits_per_sample - 1 >> 4)
// For 16-bit audio: bits_per_sample = 16, so (16-1) >> 4 = 0
val := (sampleRate << 4) | (uint32(numChannels-1) << 1)
header[0x12] = byte(val >> 16)
header[0x13] = byte(val >> 8)
header[0x14] = byte(val)
header[0x12] = byte(val >> 16 & 0xFF)
header[0x13] = byte(val >> 8 & 0xFF)
header[0x14] = byte(val & 0xFF)

return header
}
Expand Down
3 changes: 1 addition & 2 deletions chd/codec_lzma.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down Expand Up @@ -142,7 +142,6 @@ func (*cdLZMACodec) DecompressCD(dst, src []byte, destLen, frames int) (int, err
// Extract compressed base length
var compLenBase int
if compLenBytes > 2 {
//nolint:gosec // G602: bounds checked via headerBytes = eccBytes + compLenBytes check above
compLenBase = int(src[eccBytes])<<16 | int(src[eccBytes+1])<<8 | int(src[eccBytes+2])
} else {
compLenBase = int(binary.BigEndian.Uint16(src[eccBytes : eccBytes+2]))
Expand Down
3 changes: 1 addition & 2 deletions chd/codec_zlib.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down Expand Up @@ -87,7 +87,6 @@ func (*cdZlibCodec) DecompressCD(dst, src []byte, destLen, frames int) (int, err
// Extract compressed base length
var compLenBase int
if compLenBytes > 2 {
//nolint:gosec // G602: bounds checked via headerBytes = eccBytes + compLenBytes check above
compLenBase = int(src[eccBytes])<<16 | int(src[eccBytes+1])<<8 | int(src[eccBytes+2])
} else {
compLenBase = int(binary.BigEndian.Uint16(src[eccBytes : eccBytes+2]))
Expand Down
2 changes: 1 addition & 1 deletion chd/codec_zstd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion chd/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion chd/header.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion chd/hunk.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion chd/metadata.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion cmd/dbgen/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion cmd/gameid/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion console.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion console_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
2 changes: 1 addition & 1 deletion database_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand Down
53 changes: 38 additions & 15 deletions gameid.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
// Copyright (c) 2026 Niema Moshiri and The Zaparoo Project.
// SPDX-License-Identifier: GPL-3.0-or-later
//
// This file is part of go-gameid.
Expand All @@ -22,6 +22,7 @@
package gameid

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -137,12 +138,11 @@ func IdentifyWithConsole(path string, console Console, db *GameDatabase) (*Resul
return identifyFromDirectory(path, console, dbInterface)
}

// Check if this identifier needs the file path (disc-based games)
if pid, ok := id.(pathIdentifier); ok {
result, pathErr := pid.IdentifyFromPath(path, dbInterface)
if pathErr != nil {
return nil, fmt.Errorf("identify from path: %w", pathErr)
}
result, handled, pathErr := identifyFromPathIfSupported(id, path, dbInterface)
if pathErr != nil {
return nil, pathErr
}
if handled {
return result, nil
}

Expand All @@ -165,6 +165,28 @@ func IdentifyWithConsole(path string, console Console, db *GameDatabase) (*Resul
return result, nil
}

func identifyFromPathIfSupported(
ident identifier.Identifier,
path string,
database identifier.Database,
) (result *Result, handled bool, err error) {
pid, ok := ident.(pathIdentifier)
if !ok {
return nil, false, nil
}

result, err = pid.IdentifyFromPath(path, database)
if err == nil {
return result, true, nil
}

var notSupported identifier.NotSupportedError
if errors.As(err, &notSupported) {
return nil, false, nil
}
return nil, false, fmt.Errorf("identify from path: %w", err)
}

// identifyFromDirectory identifies a game from a mounted disc directory.
func identifyFromDirectory(path string, console Console, database identifier.Database) (*Result, error) {
id, ok := identifiers[console]
Expand Down Expand Up @@ -281,14 +303,15 @@ func IsCartridgeBased(console Console) bool {
//
//nolint:revive // Line length acceptable for function signature with ignored parameter
func identifyFromBlockDevice(path string, _ Console, ident identifier.Identifier, database identifier.Database) (*Result, error) {
// For disc-based consoles, use IdentifyFromPath which handles block devices
if pid, ok := ident.(pathIdentifier); ok {
result, err := pid.IdentifyFromPath(path, database)
if err != nil {
return nil, fmt.Errorf("identify from path: %w", err)
}
// For disc-based consoles, use IdentifyFromPath which handles block devices.
result, handled, pathErr := identifyFromPathIfSupported(ident, path, database)
if pathErr != nil {
return nil, pathErr
}
if handled {
return result, nil
}
// Fall through to raw block device reading when path identification is unsupported.

// Open block device directly
blockDev, err := os.Open(path) //nolint:gosec // Path from user input is expected for block device
Expand All @@ -302,11 +325,11 @@ func identifyFromBlockDevice(path string, _ Console, ident identifier.Identifier
// Most identifiers only need the first few KB
size := int64(700 * 1024 * 1024) // 700MB typical CD size

result, err := ident.Identify(blockDev, size, database)
identified, err := ident.Identify(blockDev, size, database)
if err != nil {
return nil, fmt.Errorf("identify: %w", err)
}
return result, nil
return identified, nil
}

// identifyFromArchive identifies a game file inside an archive.
Expand Down
Loading
Loading