search for steam userdata dir automaticly
This commit is contained in:
		
							parent
							
								
									bc862a41ad
								
							
						
					
					
						commit
						c0eae078fa
					
				@ -1,7 +1,10 @@
 | 
				
			|||||||
package main
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"runtime"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	steamimmich "git.kapelle.org/niklas/steam-immich/internal"
 | 
						steamimmich "git.kapelle.org/niklas/steam-immich/internal"
 | 
				
			||||||
	"github.com/alexflint/go-arg"
 | 
						"github.com/alexflint/go-arg"
 | 
				
			||||||
@ -19,11 +22,70 @@ func main() {
 | 
				
			|||||||
	var args args
 | 
						var args args
 | 
				
			||||||
	arg.MustParse(&args)
 | 
						arg.MustParse(&args)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var steamUserdataDir = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if args.UserdataDir != "" {
 | 
				
			||||||
 | 
							steamUserdataDir = os.ExpandEnv(args.UserdataDir)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							steamUserdataDir = findUserdataDir()
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if steamUserdataDir == "" {
 | 
				
			||||||
 | 
							log.Fatal("Can not find steam userdata dir. Please set with --steam-userdata-dir")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	steamimmich.Run(steamimmich.Config{
 | 
						steamimmich.Run(steamimmich.Config{
 | 
				
			||||||
		APIKey:      args.APIKey,
 | 
							APIKey:      args.APIKey,
 | 
				
			||||||
		BaseURL:     args.BaseURL,
 | 
							BaseURL:     args.BaseURL,
 | 
				
			||||||
		UserdataDir: os.ExpandEnv(args.UserdataDir),
 | 
							UserdataDir: steamUserdataDir,
 | 
				
			||||||
		DeiveID:     args.DeviceID,
 | 
							DeiveID:     args.DeviceID,
 | 
				
			||||||
		Album:       args.Album,
 | 
							Album:       args.Album,
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func findUserdataDir() string {
 | 
				
			||||||
 | 
						var candidates []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						switch runtime.GOOS {
 | 
				
			||||||
 | 
						case "windows":
 | 
				
			||||||
 | 
							// Common Steam install paths on Windows
 | 
				
			||||||
 | 
							localAppData := os.Getenv("LOCALAPPDATA")
 | 
				
			||||||
 | 
							programFiles := os.Getenv("ProgramFiles(x86)")
 | 
				
			||||||
 | 
							if programFiles == "" {
 | 
				
			||||||
 | 
								programFiles = os.Getenv("ProgramFiles")
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							candidates = []string{
 | 
				
			||||||
 | 
								filepath.Join(programFiles, "Steam"),
 | 
				
			||||||
 | 
								filepath.Join(localAppData, "Steam"),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						case "linux":
 | 
				
			||||||
 | 
							home := os.Getenv("HOME")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							candidates = []string{
 | 
				
			||||||
 | 
								filepath.Join(home, ".steam", "steam"),                                         // standard
 | 
				
			||||||
 | 
								filepath.Join(home, ".local", "share", "Steam"),                                // alternate
 | 
				
			||||||
 | 
								filepath.Join(home, ".var", "app", "com.valvesoftware.Steam", "data", "Steam"), // Flatpak
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						case "darwin":
 | 
				
			||||||
 | 
							// Common Steam install path on macOS
 | 
				
			||||||
 | 
							home := os.Getenv("HOME")
 | 
				
			||||||
 | 
							candidates = []string{
 | 
				
			||||||
 | 
								filepath.Join(home, "Library", "Application Support", "Steam"),
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return ""
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, base := range candidates {
 | 
				
			||||||
 | 
							userdata := filepath.Join(base, "userdata")
 | 
				
			||||||
 | 
							info, err := os.Stat(userdata)
 | 
				
			||||||
 | 
							if err == nil && info.IsDir() {
 | 
				
			||||||
 | 
								return userdata
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user