diff --git a/disassembly/preferences.go b/disassembly/preferences.go
index 916170ca..6cf522ac 100644
--- a/disassembly/preferences.go
+++ b/disassembly/preferences.go
@@ -19,8 +19,8 @@ import (
"fmt"
"github.com/jetsetilly/gopher2600/hardware/memory/memorymap"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
type Preferences struct {
@@ -50,7 +50,7 @@ func newPreferences(dsm *Disassembly) (*Preferences, error) {
p.mirrorOrigin = memorymap.OriginCartFxxxMirror
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
diff --git a/gopher2600.go b/gopher2600.go
index 5f167ae2..e8ca39a0 100644
--- a/gopher2600.go
+++ b/gopher2600.go
@@ -37,11 +37,11 @@ import (
"github.com/jetsetilly/gopher2600/hiscore"
"github.com/jetsetilly/gopher2600/logger"
"github.com/jetsetilly/gopher2600/modalflag"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/performance"
"github.com/jetsetilly/gopher2600/playmode"
"github.com/jetsetilly/gopher2600/recorder"
"github.com/jetsetilly/gopher2600/regression"
+ "github.com/jetsetilly/gopher2600/resources"
"github.com/jetsetilly/gopher2600/statsview"
"github.com/jetsetilly/gopher2600/wavwriter"
)
@@ -414,7 +414,7 @@ func play(md *modalflag.Modes, sync *mainSync) error {
func debug(md *modalflag.Modes, sync *mainSync) error {
md.NewMode()
- defInitScript, err := paths.ResourcePath(defaultInitScript)
+ defInitScript, err := resources.JoinPath(defaultInitScript)
if err != nil {
return err
}
diff --git a/gui/crt/preferences.go b/gui/crt/preferences.go
index 7d6a9a91..3e252984 100644
--- a/gui/crt/preferences.go
+++ b/gui/crt/preferences.go
@@ -16,8 +16,8 @@
package crt
import (
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
type Preferences struct {
@@ -84,7 +84,7 @@ func NewPreferences() (*Preferences, error) {
p.SetDefaults()
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
diff --git a/gui/sdlaudio/preferences.go b/gui/sdlaudio/preferences.go
index aa4b472b..2abd22b0 100644
--- a/gui/sdlaudio/preferences.go
+++ b/gui/sdlaudio/preferences.go
@@ -16,8 +16,8 @@
package sdlaudio
import (
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
type Preferences struct {
@@ -36,7 +36,7 @@ func NewPreferences() (*Preferences, error) {
p.SetDefaults()
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
diff --git a/gui/sdlimgui/glsl_screenshot.go b/gui/sdlimgui/glsl_screenshot.go
index 1b0afcee..8f4e5051 100644
--- a/gui/sdlimgui/glsl_screenshot.go
+++ b/gui/sdlimgui/glsl_screenshot.go
@@ -20,7 +20,7 @@ import (
"github.com/jetsetilly/gopher2600/gui/sdlimgui/framebuffer"
"github.com/jetsetilly/gopher2600/hardware/television/specification"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources/unique"
)
type screenshotMode int
@@ -95,9 +95,9 @@ func (sh *screenshotSequencer) startProcess(mode screenshotMode) {
sh.crtProcessing = sh.img.crtPrefs.Enabled.Get().(bool)
if sh.crtProcessing {
- sh.baseFilename = paths.UniqueFilename("crt", sh.img.vcs.Mem.Cart.ShortName)
+ sh.baseFilename = unique.Filename("crt", sh.img.vcs.Mem.Cart.ShortName)
} else {
- sh.baseFilename = paths.UniqueFilename("pix", sh.img.vcs.Mem.Cart.ShortName)
+ sh.baseFilename = unique.Filename("pix", sh.img.vcs.Mem.Cart.ShortName)
}
}
diff --git a/gui/sdlimgui/preferences.go b/gui/sdlimgui/preferences.go
index 1878159a..d290a14a 100644
--- a/gui/sdlimgui/preferences.go
+++ b/gui/sdlimgui/preferences.go
@@ -17,8 +17,8 @@ package sdlimgui
import (
"fmt"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
// unified preferences for both modes (debugger and playmode). preferences
@@ -67,7 +67,7 @@ func newPreferences(img *SdlImgui) (*preferences, error) {
p.superchargerNotifications.Set(true)
// setup preferences
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
@@ -139,7 +139,7 @@ func (p *preferences) setWindowPreferences(isPlayMode bool) error {
}
// setup preferences
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return err
}
diff --git a/gui/sdlimgui/sdlimgui.go b/gui/sdlimgui/sdlimgui.go
index 4cf27530..7f80d53e 100644
--- a/gui/sdlimgui/sdlimgui.go
+++ b/gui/sdlimgui/sdlimgui.go
@@ -29,8 +29,8 @@ import (
"github.com/jetsetilly/gopher2600/hardware"
"github.com/jetsetilly/gopher2600/hardware/television"
"github.com/jetsetilly/gopher2600/logger"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/reflection"
+ "github.com/jetsetilly/gopher2600/resources"
"github.com/jetsetilly/gopher2600/userinput"
"github.com/veandco/go-sdl2/sdl"
@@ -137,7 +137,7 @@ func NewSdlImgui(tv *television.Television) (*SdlImgui, error) {
return nil, curated.Errorf("sdlimgui: %v", err)
}
- iniPath, err := paths.ResourcePath(imguiIniFile)
+ iniPath, err := resources.JoinPath(imguiIniFile)
if err != nil {
return nil, curated.Errorf("sdlimgui: %v", err)
}
diff --git a/gui/sdlimgui/win_coproc_lastexecution.go b/gui/sdlimgui/win_coproc_lastexecution.go
index 39742b17..18235bd3 100644
--- a/gui/sdlimgui/win_coproc_lastexecution.go
+++ b/gui/sdlimgui/win_coproc_lastexecution.go
@@ -23,7 +23,7 @@ import (
"github.com/jetsetilly/gopher2600/disassembly/coprocessor"
"github.com/jetsetilly/gopher2600/hardware/memory/cartridge/harmony/arm7tdmi"
"github.com/jetsetilly/gopher2600/logger"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources/unique"
)
const winCoProcLastExecutionID = "Last Execution"
@@ -270,10 +270,10 @@ func (win *winCoProcLastExecution) save() {
var fn string
if win.showLastExecution {
itr = win.img.dbg.Disasm.Coprocessor.NewIteration(coprocessor.LastExecution)
- fn = paths.UniqueFilename("coproc_lastexecution", "")
+ fn = unique.Filename("coproc_lastexecution", "")
} else {
itr = win.img.dbg.Disasm.Coprocessor.NewIteration(coprocessor.Disassembly)
- fn = paths.UniqueFilename("coproc_disasm", "")
+ fn = unique.Filename("coproc_disasm", "")
}
f, err := os.Create(fmt.Sprintf("%s.csv", fn))
diff --git a/gui/sdlimgui/win_terminal.go b/gui/sdlimgui/win_terminal.go
index f031d42c..f6037c6e 100644
--- a/gui/sdlimgui/win_terminal.go
+++ b/gui/sdlimgui/win_terminal.go
@@ -24,7 +24,7 @@ import (
"github.com/jetsetilly/gopher2600/emulation"
"github.com/jetsetilly/gopher2600/gui/fonts"
"github.com/jetsetilly/gopher2600/logger"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources/unique"
"github.com/inkyblackness/imgui-go/v4"
)
@@ -237,7 +237,7 @@ func (win *winTerm) draw() {
}
func (win *winTerm) saveOutput() {
- fn := paths.UniqueFilename("terminal", "")
+ fn := unique.Filename("terminal", "")
f, err := os.Create(fn)
if err != nil {
win.output = append(win.output, terminalOutput{
diff --git a/hardware/memory/cartridge/plusrom/preferences.go b/hardware/memory/cartridge/plusrom/preferences.go
index 484d758f..42a6a733 100644
--- a/hardware/memory/cartridge/plusrom/preferences.go
+++ b/hardware/memory/cartridge/plusrom/preferences.go
@@ -19,8 +19,8 @@ import (
"fmt"
"math/rand"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
const (
@@ -45,7 +45,7 @@ func newPreferences() (*Preferences, error) {
p.ID.SetMaxLen(MaxIDLength)
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
diff --git a/hardware/memory/cartridge/supercharger/bios.go b/hardware/memory/cartridge/supercharger/bios.go
index 8e160f37..7158b3ea 100644
--- a/hardware/memory/cartridge/supercharger/bios.go
+++ b/hardware/memory/cartridge/supercharger/bios.go
@@ -21,7 +21,7 @@ import (
"github.com/jetsetilly/gopher2600/curated"
"github.com/jetsetilly/gopher2600/logger"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
)
// list of allowed filenames for the supercharger BIOS.
@@ -75,7 +75,7 @@ func loadBIOS(path string) ([]uint8, error) {
// the emulator's resource path
for _, b := range biosFile {
- p, err := paths.ResourcePath(b)
+ p, err := resources.JoinPath(b)
if err != nil {
return nil, err
}
diff --git a/hardware/preferences/preferences.go b/hardware/preferences/preferences.go
index 57a1f805..e647bd38 100644
--- a/hardware/preferences/preferences.go
+++ b/hardware/preferences/preferences.go
@@ -19,8 +19,8 @@ import (
"math/rand"
"time"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
// Preferences defines and collates all the preference values used by the debugger.
@@ -83,7 +83,7 @@ func NewPreferences() (*Preferences, error) {
p.SetDefaults()
// setup preferences and load from disk
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
diff --git a/hardware/riot/ports/savekey/eeprom.go b/hardware/riot/ports/savekey/eeprom.go
index 0fe349a1..acb1806d 100644
--- a/hardware/riot/ports/savekey/eeprom.go
+++ b/hardware/riot/ports/savekey/eeprom.go
@@ -19,7 +19,7 @@ import (
"os"
"github.com/jetsetilly/gopher2600/logger"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
)
const saveKeyPath = "savekey"
@@ -60,7 +60,7 @@ func newEeprom() *EEPROM {
// Read EEPROM data from disk.
func (ee *EEPROM) Read() {
- fn, err := paths.ResourcePath(saveKeyPath)
+ fn, err := resources.JoinPath(saveKeyPath)
if err != nil {
logger.Logf("savekey", "could not load eeprom file (%s)", err)
return
@@ -98,7 +98,7 @@ func (ee *EEPROM) Read() {
// Write EEPROM data to disk.
func (ee *EEPROM) Write() {
- fn, err := paths.ResourcePath(saveKeyPath)
+ fn, err := resources.JoinPath(saveKeyPath)
if err != nil {
logger.Logf("savekey", "could not write eeprom file (%s)", err)
return
diff --git a/hardware/tia/revision/preferences.go b/hardware/tia/revision/preferences.go
index 6e2f9f26..47104318 100644
--- a/hardware/tia/revision/preferences.go
+++ b/hardware/tia/revision/preferences.go
@@ -17,8 +17,8 @@ package revision
import (
"github.com/jetsetilly/gopher2600/curated"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
// Preferences for TIA revisins. Use the "live" values inside the emulation
@@ -57,7 +57,7 @@ func newPreferences() (*Preferences, error) {
p := &Preferences{}
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, curated.Errorf("revision: %v", err)
}
diff --git a/hiscore/preferences.go b/hiscore/preferences.go
index d8f2bf79..d97b9520 100644
--- a/hiscore/preferences.go
+++ b/hiscore/preferences.go
@@ -17,8 +17,8 @@ package hiscore
import (
"github.com/jetsetilly/gopher2600/curated"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
type Preferences struct {
@@ -37,7 +37,7 @@ func newPreferences() (*Preferences, error) {
p := &Preferences{}
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, curated.Errorf("hiscore: %v", err)
}
diff --git a/patch/patch.go b/patch/patch.go
index 48b8882b..f0e64f60 100644
--- a/patch/patch.go
+++ b/patch/patch.go
@@ -25,7 +25,7 @@ import (
"github.com/jetsetilly/gopher2600/curated"
"github.com/jetsetilly/gopher2600/hardware/memory/cartridge"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
)
const patchPath = "patches"
@@ -39,7 +39,7 @@ const neoSeparator = ":"
func CartridgeMemory(mem *cartridge.Cartridge, patchFile string) (bool, error) {
var err error
- p, err := paths.ResourcePath(patchPath, patchFile)
+ p, err := resources.JoinPath(patchPath, patchFile)
if err != nil {
return false, curated.Errorf("patch: %v", err)
}
diff --git a/paths/doc.go b/paths/doc.go
deleted file mode 100644
index 4e6c7909..00000000
--- a/paths/doc.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// This file is part of Gopher2600.
-//
-// Gopher2600 is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Gopher2600 is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Gopher2600. If not, see .
-
-// Package paths contains functions to prepare paths for gopher2600 resources.
-//
-// The ResourcePath() function returns the correct path to the resource
-// directory/file specified in the arguments. The result of ResourcePath
-// depends on the build tag used to compile the program.
-//
-// For "release" tagged builds, the correct path is one rooted in the user's
-// configuration directory. On modern Linux systems the full path would be
-// something like:
-//
-// /home/user/.config/gopher2600/
-//
-// For "non-release" tagged builds, the correct path is rooted in the current
-// working directory:
-//
-// .gopher2600
-//
-// The reason for this is simple. During development, it is more convenient to
-// have the config directory close to hand. For release binaries meanwhile, the
-// config directory should be somewhere the user expects.
-package paths
diff --git a/playmode/play.go b/playmode/play.go
index 4d61c820..745c1378 100644
--- a/playmode/play.go
+++ b/playmode/play.go
@@ -36,8 +36,8 @@ import (
"github.com/jetsetilly/gopher2600/hiscore"
"github.com/jetsetilly/gopher2600/logger"
"github.com/jetsetilly/gopher2600/patch"
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/recorder"
+ "github.com/jetsetilly/gopher2600/resources/unique"
"github.com/jetsetilly/gopher2600/setup"
"github.com/jetsetilly/gopher2600/userinput"
)
@@ -202,7 +202,7 @@ func Play(tv *television.Television, scr gui.GUI, newRecording bool, cartload ca
// new recording requested
// create a unique filename
- recording = paths.UniqueFilename("recording", cartload.ShortName())
+ recording = unique.Filename("recording", cartload.ShortName())
// prepare new recording
rec, err := recorder.NewRecorder(recording, vcs)
diff --git a/prefs/disk.go b/prefs/disk.go
index ccdb8309..3ba858fe 100644
--- a/prefs/disk.go
+++ b/prefs/disk.go
@@ -24,7 +24,7 @@ import (
"unicode"
"github.com/jetsetilly/gopher2600/curated"
- "github.com/jetsetilly/gopher2600/paths/fs"
+ "github.com/jetsetilly/gopher2600/resources/fs"
)
// DefaultPrefsFile is the default filename of the global preferences file.
diff --git a/prefs/doc.go b/prefs/doc.go
index 8a434a58..53a28b61 100644
--- a/prefs/doc.go
+++ b/prefs/doc.go
@@ -21,9 +21,9 @@
//
// The Disk type is the key resource in the package. First, create new Disk
// instance with NewDisk(), specifying the location of the preferences file
-// (using paths.ResourcePath() as necessary).
+// (using resources.ResourcePath() as necessary).
//
-// fn, _ := paths.ResourcePath(prefs.DefaultPrefsFile)
+// fn, _ := resources.ResourcePath(prefs.DefaultPrefsFile)
// prf := prefs.NewDisk(fn)
//
// Preference value can then be added with the Add() function, specifying the
diff --git a/regression/playback.go b/regression/playback.go
index a1d31337..8a351ae4 100644
--- a/regression/playback.go
+++ b/regression/playback.go
@@ -190,7 +190,7 @@ func (reg *PlaybackRegression) regress(newRegression bool, output io.Writer, msg
// regressionScripts directory
if newRegression {
// create a unique filename
- newScript, err := uniqueFilename("playback", plb.CartLoad)
+ newScript, err := uniqueFilename("playback", plb.CartLoad.ShortName())
if err != nil {
return false, "", curated.Errorf("playback: %v", err)
}
diff --git a/regression/regression.go b/regression/regression.go
index 2b16932a..62c30a5c 100644
--- a/regression/regression.go
+++ b/regression/regression.go
@@ -25,14 +25,14 @@ import (
"github.com/jetsetilly/gopher2600/curated"
"github.com/jetsetilly/gopher2600/database"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
)
// ansi code for clear line.
const ansiClearLine = "\033[2K"
// the location of the regressionDB file and the location of any regression
-// scripts. these should be wrapped by paths.ResourcePath().
+// scripts. these should be wrapped by resources.ResourcePath().
const regressionPath = "regression"
const regressionDBFile = "db"
const regressionScripts = "scripts"
@@ -76,7 +76,7 @@ func RegressList(output io.Writer) error {
return curated.Errorf("regression: list: io.Writer should not be nil (use a nopWriter)")
}
- dbPth, err := paths.ResourcePath(regressionPath, regressionDBFile)
+ dbPth, err := resources.JoinPath(regressionPath, regressionDBFile)
if err != nil {
return curated.Errorf("regression: list: %v", err)
}
@@ -99,7 +99,7 @@ func RegressAdd(output io.Writer, reg Regressor) error {
return curated.Errorf("regression: add: io.Writer should not be nil (use a nopWriter)")
}
- dbPth, err := paths.ResourcePath(regressionPath, regressionDBFile)
+ dbPth, err := resources.JoinPath(regressionPath, regressionDBFile)
if err != nil {
return curated.Errorf("regression: add: %v", err)
}
@@ -144,7 +144,7 @@ func RegressRedux(output io.Writer, confirmation io.Reader) error {
return nil
}
- dbPth, err := paths.ResourcePath(regressionPath, regressionDBFile)
+ dbPth, err := resources.JoinPath(regressionPath, regressionDBFile)
if err != nil {
return curated.Errorf("regression: redux: %v", err)
}
@@ -219,7 +219,7 @@ func RegressCleanup(output io.Writer, confirmation io.Reader) error {
return nil
}
- dbPth, err := paths.ResourcePath(regressionPath, regressionDBFile)
+ dbPth, err := resources.JoinPath(regressionPath, regressionDBFile)
if err != nil {
return curated.Errorf("regression: cleanup: %v", err)
}
@@ -257,7 +257,7 @@ func RegressCleanup(output io.Writer, confirmation io.Reader) error {
}
// gather list of files on disk in path
- scriptPth, err := paths.ResourcePath(regressionPath, regressionScripts)
+ scriptPth, err := resources.JoinPath(regressionPath, regressionScripts)
if err != nil {
return curated.Errorf("regression: list: %v", err)
}
@@ -281,7 +281,7 @@ func RegressCleanup(output io.Writer, confirmation io.Reader) error {
for _, e := range filesOnDisk {
found := false
- n, err := paths.ResourcePath(regressionPath, regressionScripts, e.Name())
+ n, err := resources.JoinPath(regressionPath, regressionScripts, e.Name())
if err != nil {
return curated.Errorf("regression: cleanup: %v", err)
}
@@ -333,7 +333,7 @@ func RegressDelete(output io.Writer, confirmation io.Reader, key string) error {
return curated.Errorf("regression: delete: invalid key [%s]", key)
}
- dbPth, err := paths.ResourcePath(regressionPath, regressionDBFile)
+ dbPth, err := resources.JoinPath(regressionPath, regressionDBFile)
if err != nil {
return curated.Errorf("regression: delete: %v", err)
}
@@ -369,7 +369,7 @@ func RegressRun(output io.Writer, verbose bool, filterKeys []string) error {
return curated.Errorf("regression: run: io.Writer should not be nil (use a nopWriter)")
}
- dbPth, err := paths.ResourcePath(regressionPath, regressionDBFile)
+ dbPth, err := resources.JoinPath(regressionPath, regressionDBFile)
if err != nil {
return curated.Errorf("regression: run: %v", err)
}
diff --git a/regression/unique.go b/regression/unique.go
index 45f3dd70..7b93a839 100644
--- a/regression/unique.go
+++ b/regression/unique.go
@@ -16,25 +16,27 @@
package regression
import (
- "github.com/jetsetilly/gopher2600/cartridgeloader"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
+ "github.com/jetsetilly/gopher2600/resources/unique"
)
-// create a unique filename from a CatridgeLoader instance. used when saving
+// uniqueFilename is a shim function for unique.Filename().
+//
+// It create a unique filename from a CatridgeLoader instance. used when saving
// scripts into regressionScripts directory. calls paths.UniqueFilename() to
// maintain common formatting used in the project.
-func uniqueFilename(prepend string, cartload cartridgeloader.Loader) (string, error) {
- f := paths.UniqueFilename(prepend, cartload.ShortName())
+func uniqueFilename(filetype string, cartname string) (string, error) {
+ f := unique.Filename(filetype, cartname)
- scriptsPath, err := paths.ResourcePath(regressionPath, regressionScripts)
+ scriptsPath, err := resources.JoinPath(regressionPath, regressionScripts)
if err != nil {
return "", err
}
- scrPth, err := paths.ResourcePath(scriptsPath, f)
+ p, err := resources.JoinPath(scriptsPath, f)
if err != nil {
return "", err
}
- return scrPth, nil
+ return p, nil
}
diff --git a/regression/video.go b/regression/video.go
index b725d13e..54446511 100644
--- a/regression/video.go
+++ b/regression/video.go
@@ -269,7 +269,7 @@ func (reg *VideoRegression) regress(newRegression bool, output io.Writer, msg st
if reg.State != StateNone {
// create a unique filename
- reg.stateFile, err = uniqueFilename("state", reg.CartLoad)
+ reg.stateFile, err = uniqueFilename("state", reg.CartLoad.ShortName())
if err != nil {
return false, "", curated.Errorf("video: %v", err)
}
diff --git a/paths/dev_path.go b/resources/dev_path.go
similarity index 97%
rename from paths/dev_path.go
rename to resources/dev_path.go
index f69e2a5b..827152ea 100644
--- a/paths/dev_path.go
+++ b/resources/dev_path.go
@@ -16,7 +16,7 @@
//go:build !release
// +build !release
-package paths
+package resources
const gopherConfigDir = ".gopher2600"
diff --git a/resources/doc.go b/resources/doc.go
new file mode 100644
index 00000000..90e28fa7
--- /dev/null
+++ b/resources/doc.go
@@ -0,0 +1,40 @@
+// This file is part of Gopher2600.
+//
+// Gopher2600 is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Gopher2600 is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Gopher2600. If not, see .
+
+// Package resources contains functions to prepare paths for gopher2600
+// resources.
+//
+// The JoinPath() function returns the correct path to the resource
+// directory/file specified in the arguments. It handles the creation of
+// directories as required but does not otherwise touch or create files.
+//
+// JoinPath() handles the inclusion of the correct base path. The base path
+// depends on how the binary was built.
+//
+// For builds with the "releas" build tag, the path returned by JoinPath() is
+// rooted in the user's configuration directory. On modern Linux systems the
+// full path would be something like:
+//
+// /home/user/.config/gopher2600/
+//
+// For non-"release" builds, the correct path is rooted in the current working
+// directory:
+//
+// .gopher2600
+//
+// The package does this because during development it is more convenient to
+// have the config directory close to hand. For release binaries however, the
+// config directory should be somewhere the end-user expects.
+package resources
diff --git a/paths/fs/doc.go b/resources/fs/doc.go
similarity index 100%
rename from paths/fs/doc.go
rename to resources/fs/doc.go
diff --git a/paths/fs/fs.go b/resources/fs/fs.go
similarity index 100%
rename from paths/fs/fs.go
rename to resources/fs/fs.go
diff --git a/paths/fs/wasm.go b/resources/fs/wasm.go
similarity index 100%
rename from paths/fs/wasm.go
rename to resources/fs/wasm.go
diff --git a/paths/paths.go b/resources/join.go
similarity index 85%
rename from paths/paths.go
rename to resources/join.go
index 9d84488b..dd9c8a9a 100644
--- a/paths/paths.go
+++ b/resources/join.go
@@ -13,21 +13,21 @@
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see .
-package paths
+package resources
import (
"os"
"path/filepath"
- "github.com/jetsetilly/gopher2600/paths/fs"
+ "github.com/jetsetilly/gopher2600/resources/fs"
)
-// ResourcePath prepends the supplied path with a with OS/build specific base
+// JoinPath prepends the supplied path with a with OS/build specific base
// paths
//
// The function creates all folders necessary to reach the end of sub-path. It
// does not otherwise touch or create the file.
-func ResourcePath(path ...string) (string, error) {
+func JoinPath(path ...string) (string, error) {
b, err := baseResourcePath()
if err != nil {
return "", err
diff --git a/paths/release_path.go b/resources/release_path.go
similarity index 98%
rename from paths/release_path.go
rename to resources/release_path.go
index a9aab113..777bf414 100644
--- a/paths/release_path.go
+++ b/resources/release_path.go
@@ -16,7 +16,7 @@
//go:build release
// +build release
-package paths
+package resources
import (
"os"
diff --git a/paths/paths_test.go b/resources/resources_test.go
similarity index 57%
rename from paths/paths_test.go
rename to resources/resources_test.go
index 0db36183..9737a19b 100644
--- a/paths/paths_test.go
+++ b/resources/resources_test.go
@@ -13,51 +13,33 @@
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see .
-package paths_test
+package resources_test
import (
"testing"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
"github.com/jetsetilly/gopher2600/test"
)
-func TestResourcePath(t *testing.T) {
- pth, err := paths.ResourcePath("foo/bar", "baz")
+func TestJoinPath(t *testing.T) {
+ pth, err := resources.JoinPath("foo/bar", "baz")
test.Equate(t, err, nil)
test.Equate(t, pth, ".gopher2600/foo/bar/baz")
- pth, err = paths.ResourcePath("foo/bar", "")
+ pth, err = resources.JoinPath("foo", "bar", "baz")
+ test.Equate(t, err, nil)
+ test.Equate(t, pth, ".gopher2600/foo/bar/baz")
+
+ pth, err = resources.JoinPath("foo/bar", "")
test.Equate(t, err, nil)
test.Equate(t, pth, ".gopher2600/foo/bar")
- pth, err = paths.ResourcePath("", "baz")
+ pth, err = resources.JoinPath("", "baz")
test.Equate(t, err, nil)
test.Equate(t, pth, ".gopher2600/baz")
- pth, err = paths.ResourcePath("", "")
- test.Equate(t, err, nil)
- test.Equate(t, pth, ".gopher2600")
-}
-
-func TestResourceFile(t *testing.T) {
- pth, err := paths.ResourcePath("foo/bar", "baz")
- test.Equate(t, err, nil)
- test.Equate(t, pth, ".gopher2600/foo/bar/baz")
-
- pth, err = paths.ResourcePath("foo", "bar", "baz")
- test.Equate(t, err, nil)
- test.Equate(t, pth, ".gopher2600/foo/bar/baz")
-
- pth, err = paths.ResourcePath("foo/bar", "")
- test.Equate(t, err, nil)
- test.Equate(t, pth, ".gopher2600/foo/bar")
-
- pth, err = paths.ResourcePath("", "baz")
- test.Equate(t, err, nil)
- test.Equate(t, pth, ".gopher2600/baz")
-
- pth, err = paths.ResourcePath("", "")
+ pth, err = resources.JoinPath("", "")
test.Equate(t, err, nil)
test.Equate(t, pth, ".gopher2600")
}
diff --git a/resources/unique/doc.go b/resources/unique/doc.go
new file mode 100644
index 00000000..d6d1fde6
--- /dev/null
+++ b/resources/unique/doc.go
@@ -0,0 +1,22 @@
+// This file is part of Gopher2600.
+//
+// Gopher2600 is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Gopher2600 is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Gopher2600. If not, see .
+
+// Package unique contains functions that compose filenames that should be
+// unique on the filesystem.
+//
+// This is useful in other Gopher2600 packages. For example, it used to
+// generate filenames for: playback recordings, regression scripts and many
+// other file types.
+package unique
diff --git a/paths/unique.go b/resources/unique/filename.go
similarity index 64%
rename from paths/unique.go
rename to resources/unique/filename.go
index 2d830e2b..2b15c609 100644
--- a/paths/unique.go
+++ b/resources/unique/filename.go
@@ -13,7 +13,7 @@
// You should have received a copy of the GNU General Public License
// along with Gopher2600. If not, see .
-package paths
+package unique
import (
"fmt"
@@ -21,34 +21,33 @@ import (
"time"
)
-// UniqueFilename creates a filename that (assuming a functioning clock) should
-// not collide with any existing file. Note that the function does not test for
+// Filename creates a filename that (assuming a functioning clock) should not
+// collide with any existing file. Note that the function does not test for
// this.
//
-// Used to generate filenames for:
-// - playback recordings
-// - regression scripts
-// - terminal output (sdlimgui GUI)
-//
// Format of returned string is:
//
-// prepend_cartname_YYYYMMDD_HHMMSS
+// filetype_cartname_YYYYMMDD_HHMMSS
//
// Where cartname is the string returned by cartload.ShortName(). If there is
// no cartridge name the returned string will be of the format:
//
-// prepend_YYYYMMDD_HHMMSS
-func UniqueFilename(prepend string, shortCartName string) string {
+// filetype_YYYYMMDD_HHMMSS
+//
+// The filetype argument is simply another way of identifying the file
+// uniquely. For example, if saving a screenshot the filetype might simply be
+// "screenshot" or "photo".
+func Filename(filetype string, cartName string) string {
n := time.Now()
timestamp := fmt.Sprintf("%04d%02d%02d_%02d%02d%02d", n.Year(), n.Month(), n.Day(), n.Hour(), n.Minute(), n.Second())
var fn string
- c := strings.TrimSpace(shortCartName)
+ c := strings.TrimSpace(cartName)
if len(c) > 0 {
- fn = fmt.Sprintf("%s_%s_%s", prepend, c, timestamp)
+ fn = fmt.Sprintf("%s_%s_%s", filetype, c, timestamp)
} else {
- fn = fmt.Sprintf("%s_%s", prepend, timestamp)
+ fn = fmt.Sprintf("%s_%s", filetype, timestamp)
}
return fn
diff --git a/rewind/preferences.go b/rewind/preferences.go
index 06e5dde0..564d95b2 100644
--- a/rewind/preferences.go
+++ b/rewind/preferences.go
@@ -16,8 +16,8 @@
package rewind
import (
- "github.com/jetsetilly/gopher2600/paths"
"github.com/jetsetilly/gopher2600/prefs"
+ "github.com/jetsetilly/gopher2600/resources"
)
type Preferences struct {
@@ -50,7 +50,7 @@ func newPreferences(r *Rewind) (*Preferences, error) {
p.Freq.Set(snapshotFreq)
// save server using the prefs package
- pth, err := paths.ResourcePath(prefs.DefaultPrefsFile)
+ pth, err := resources.JoinPath(prefs.DefaultPrefsFile)
if err != nil {
return nil, err
}
diff --git a/setup/setup.go b/setup/setup.go
index 032c27a0..cd32bd0a 100644
--- a/setup/setup.go
+++ b/setup/setup.go
@@ -20,7 +20,7 @@ import (
"github.com/jetsetilly/gopher2600/curated"
"github.com/jetsetilly/gopher2600/database"
"github.com/jetsetilly/gopher2600/hardware"
- "github.com/jetsetilly/gopher2600/paths"
+ "github.com/jetsetilly/gopher2600/resources"
)
// the location of the setupDB file.
@@ -65,7 +65,7 @@ func AttachCartridge(vcs *hardware.VCS, cartload cartridgeloader.Loader) error {
return curated.Errorf("setup: %v", err)
}
- dbPth, err := paths.ResourcePath(setupDBFile)
+ dbPth, err := resources.JoinPath(setupDBFile)
if err != nil {
return curated.Errorf("setup: %v", err)
}