-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
125 lines (114 loc) · 3.62 KB
/
Copy pathutils.go
File metadata and controls
125 lines (114 loc) · 3.62 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"os"
"path/filepath"
"runtime"
"strings"
)
type Profile struct {
PlatformSystem string `json:"platformSystem"`
ExcludedPaths []string `json:"excludedPaths"`
SkipHidden bool `json:"skipHidden"`
MinFileSize int64 `json:"minFileSize"`
FollowSymlinks bool `json:"followSymlinks"`
SkipNetworkFS bool `json:"skipNetworkFS"`
UseCache bool `json:"useCache"`
ShowTooltips bool `json:"showTooltips"`
TooltipDelayMS int `json:"tooltipDelayMs"`
AllowDelete bool `json:"allowDelete"`
AllowPermanentDelete bool `json:"allowPermanentDelete"`
RescanOnDelete bool `json:"rescanOnDelete"`
Appearance AppearanceSettings `json:"appearance"`
Controls ControlSettings `json:"controls"`
}
type AppearanceSettings struct {
Palette string `json:"palette"`
CustomThemes []ColorTheme `json:"customThemes,omitempty"`
ZoomFactor float64 `json:"zoomFactor"`
CornerRadius int `json:"cornerRadius"`
ReliefStrength float64 `json:"reliefStrength"`
HoverBrightness float64 `json:"hoverBrightness"`
RollOverBoxes bool `json:"rollOverBoxes"`
}
type ColorTheme struct {
Name string `json:"name"`
Colors []string `json:"colors"`
}
type ControlSettings struct {
Back string `json:"back"`
Forward string `json:"forward"`
Parent string `json:"parent"`
Root string `json:"root"`
Open string `json:"open"`
OpenWith string `json:"openWith"`
VisitSelected string `json:"visitSelected"`
Refresh string `json:"refresh"`
Delete string `json:"delete"`
}
func defaultControlSettings() ControlSettings {
return ControlSettings{
Open: "Ctrl+O",
OpenWith: "Ctrl+Shift+O",
VisitSelected: "Enter",
Refresh: "Ctrl+R",
Delete: "Delete",
}
}
func defaultAppearanceSettings() AppearanceSettings {
return AppearanceSettings{
Palette: "default",
ZoomFactor: 1,
CornerRadius: 0,
ReliefStrength: 0.30,
HoverBrightness: 0.12,
RollOverBoxes: false,
}
}
func shouldExclude(p *Profile, absPath string) bool {
candidate := filepath.Clean(absPath)
caseInsensitive := p.PlatformSystem == "windows"
for _, ex := range p.ExcludedPaths {
if strings.TrimSpace(ex) == "" {
continue
}
excluded := filepath.Clean(ex)
if pathsEqual(candidate, excluded, caseInsensitive) {
return true
}
prefix := strings.TrimRight(excluded, `/\`) + string(os.PathSeparator)
if pathHasPrefix(candidate, prefix, caseInsensitive) {
return true
}
}
return false
}
func pathsEqual(left, right string, caseInsensitive bool) bool {
if caseInsensitive {
return strings.EqualFold(left, right)
}
return left == right
}
func pathHasPrefix(path, prefix string, caseInsensitive bool) bool {
if len(path) < len(prefix) {
return false
}
return pathsEqual(path[:len(prefix)], prefix, caseInsensitive)
}
func defaultProfile() *Profile {
p := &Profile{
PlatformSystem: runtime.GOOS, // "windows" | "darwin" | "linux"
SkipHidden: false,
MinFileSize: 1024,
FollowSymlinks: false,
SkipNetworkFS: true,
UseCache: true,
ShowTooltips: true,
TooltipDelayMS: 0,
AllowDelete: false,
AllowPermanentDelete: false,
RescanOnDelete: true,
Appearance: defaultAppearanceSettings(),
Controls: defaultControlSettings(),
}
return p
}