-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
profiles.go
77 lines (65 loc) · 1.94 KB
/
profiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package craw
import (
"errors"
"io/fs"
"path/filepath"
"strings"
"github.com/ncruces/rethinkraw/pkg/dng"
)
// GetCameraProfiles gets all the profiles that apply to a given camera.
// Returns the DCP file paths for the profiles.
// It looks for profiles under the GlobalSettings and UserSettings directories.
func GetCameraProfiles(make, model string) ([]string, error) {
once.Do(initPaths)
glb, err := LoadIndex(filepath.Join(GlobalSettings, filepath.FromSlash("CameraProfiles/Index.dat")))
if err != nil {
return nil, err
}
usr, err := LoadIndex(filepath.Join(UserSettings, filepath.FromSlash("CameraProfiles/Index.dat")))
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return nil, err
}
make = strings.ToUpper(make)
model = strings.ToUpper(model)
makeModel := make + " " + model
var profiles []string
for _, rec := range append(glb, usr...) {
test := strings.ToUpper(rec.Prop["model_restriction"])
var matches bool
if test == "" || test == model || test == makeModel {
matches = true
} else if testMake, testModel, ok := strings.Cut(test, " "); ok {
matches = testModel == model && strings.Contains(make, testMake)
}
if matches {
profiles = append(profiles, rec.Path)
}
}
return profiles, nil
}
// GetCameraProfileNames gets the names of all profiles that apply to a given camera.
// It looks for profiles under the GlobalSettings and UserSettings directories,
// and in the EmbedProfiles file, if set.
func GetCameraProfileNames(make, model string) ([]string, error) {
once.Do(initPaths)
profiles, err := GetCameraProfiles(make, model)
if err != nil {
return nil, err
}
var names []string
for _, profile := range profiles {
name, err := dng.GetDCPProfileName(profile)
if err != nil {
return nil, err
}
names = append(names, name)
}
if make == "FUJIFILM" {
embed, err := fujiCameraProfiles(model)
if err != nil {
return nil, err
}
names = append(names, embed...)
}
return names, nil
}