53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package steamimmich
 | 
						|
 | 
						|
import (
 | 
						|
	"os"
 | 
						|
	"path/filepath"
 | 
						|
	"regexp"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
func listScreenshots(steamUserdataDir string) (map[string][]string, error) {
 | 
						|
	if _, err := os.Stat(steamUserdataDir); os.IsNotExist(err) {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
 | 
						|
	// Pattern: userdata/<steamid>/760/remote/<appid>/screenshots
 | 
						|
	reAppDir := regexp.MustCompile(`.*/760/remote/([0-9]+)/screenshots$`)
 | 
						|
 | 
						|
	screenshotFiles := make(map[string][]string)
 | 
						|
 | 
						|
	err := filepath.WalkDir(steamUserdataDir, func(path string, d os.DirEntry, err error) error {
 | 
						|
		if err != nil {
 | 
						|
			return nil
 | 
						|
		}
 | 
						|
		if !d.IsDir() {
 | 
						|
			return nil
 | 
						|
		}
 | 
						|
 | 
						|
		if reAppDir.MatchString(path) {
 | 
						|
			appid := reAppDir.FindStringSubmatch(path)[1]
 | 
						|
			files, _ := os.ReadDir(path)
 | 
						|
			for _, f := range files {
 | 
						|
				if f.IsDir() {
 | 
						|
					continue
 | 
						|
				}
 | 
						|
				name := strings.ToLower(f.Name())
 | 
						|
				if strings.HasSuffix(name, ".jpg") ||
 | 
						|
					strings.HasSuffix(name, ".jpeg") ||
 | 
						|
					strings.HasSuffix(name, ".png") {
 | 
						|
					fullPath := filepath.Join(path, f.Name())
 | 
						|
					screenshotFiles[appid] = append(screenshotFiles[appid], fullPath)
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
		return nil
 | 
						|
	})
 | 
						|
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
 | 
						|
	return screenshotFiles, nil
 | 
						|
}
 |