mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Moved everything out of internal
This commit is contained in:
64
manager/paths/paths.go
Normal file
64
manager/paths/paths.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package paths
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/manager/jsonschema"
|
||||
"github.com/stashapp/stash/utils"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Paths struct {
|
||||
FixedPaths *fixedPaths
|
||||
Config *jsonschema.Config
|
||||
Generated *generatedPaths
|
||||
JSON *jsonPaths
|
||||
|
||||
Gallery *galleryPaths
|
||||
Scene *scenePaths
|
||||
SceneMarkers *sceneMarkerPaths
|
||||
}
|
||||
|
||||
func RefreshPaths() *Paths {
|
||||
fp := newFixedPaths()
|
||||
ensureConfigFile(fp)
|
||||
return newPaths(fp)
|
||||
}
|
||||
|
||||
func newPaths(fp *fixedPaths) *Paths {
|
||||
p := Paths{}
|
||||
p.FixedPaths = fp
|
||||
p.Config = jsonschema.LoadConfigFile(p.FixedPaths.ConfigFile)
|
||||
p.Generated = newGeneratedPaths(p)
|
||||
p.JSON = newJSONPaths(p)
|
||||
|
||||
p.Gallery = newGalleryPaths(p.Config)
|
||||
p.Scene = newScenePaths(p)
|
||||
p.SceneMarkers = newSceneMarkerPaths(p)
|
||||
return &p
|
||||
}
|
||||
|
||||
func getExecutionDirectory() string {
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return filepath.Dir(ex)
|
||||
}
|
||||
|
||||
func getHomeDirectory() string {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return currentUser.HomeDir
|
||||
}
|
||||
|
||||
func ensureConfigFile(fp *fixedPaths) {
|
||||
configFileExists, _ := utils.FileExists(fp.ConfigFile) // TODO: Verify JSON is correct. Pass verified
|
||||
if configFileExists {
|
||||
return
|
||||
}
|
||||
|
||||
panic("No config file found")
|
||||
}
|
||||
Reference in New Issue
Block a user