-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
paths_windows.go
196 lines (185 loc) · 5.76 KB
/
paths_windows.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package xdg
import (
"path/filepath"
"github.com/adrg/xdg/internal/pathutil"
"github.com/adrg/xdg/internal/userdirs"
"golang.org/x/sys/windows"
)
func initDirs(home string) {
kf := initKnownFolders(home)
initBaseDirs(home, kf)
initUserDirs(home, kf)
}
func initBaseDirs(home string, kf *knownFolders) {
// Initialize standard directories.
baseDirs.dataHome = pathutil.EnvPath(envDataHome, kf.localAppData)
baseDirs.data = pathutil.EnvPathList(envDataDirs, kf.roamingAppData, kf.programData)
baseDirs.configHome = pathutil.EnvPath(envConfigHome, kf.localAppData)
baseDirs.config = pathutil.EnvPathList(envConfigDirs, kf.programData, kf.roamingAppData)
baseDirs.stateHome = pathutil.EnvPath(envStateHome, kf.localAppData)
baseDirs.cacheHome = pathutil.EnvPath(envCacheHome, filepath.Join(kf.localAppData, "cache"))
baseDirs.runtime = pathutil.EnvPath(envRuntimeDir, kf.localAppData)
// Initialize non-standard directories.
baseDirs.binHome = pathutil.EnvPath(envBinHome, kf.userProgramFiles)
baseDirs.applications = []string{
kf.programs,
kf.commonPrograms,
kf.programFiles,
kf.programFilesCommon,
kf.userProgramFiles,
kf.userProgramFilesCommon,
}
baseDirs.fonts = []string{
kf.fonts,
filepath.Join(kf.localAppData, "Microsoft", "Windows", "Fonts"),
}
}
func initUserDirs(home string, kf *knownFolders) {
UserDirs.Desktop = pathutil.EnvPath(userdirs.EnvDesktopDir, kf.desktop)
UserDirs.Download = pathutil.EnvPath(userdirs.EnvDownloadDir, kf.downloads)
UserDirs.Documents = pathutil.EnvPath(userdirs.EnvDocumentsDir, kf.documents)
UserDirs.Music = pathutil.EnvPath(userdirs.EnvMusicDir, kf.music)
UserDirs.Pictures = pathutil.EnvPath(userdirs.EnvPicturesDir, kf.pictures)
UserDirs.Videos = pathutil.EnvPath(userdirs.EnvVideosDir, kf.videos)
UserDirs.Templates = pathutil.EnvPath(userdirs.EnvTemplatesDir, kf.templates)
UserDirs.PublicShare = pathutil.EnvPath(userdirs.EnvPublicShareDir, kf.public)
}
type knownFolders struct {
systemDrive string
systemRoot string
programData string
userProfile string
userProfiles string
roamingAppData string
localAppData string
desktop string
downloads string
documents string
music string
pictures string
videos string
templates string
public string
fonts string
programs string
commonPrograms string
programFiles string
programFilesCommon string
userProgramFiles string
userProgramFilesCommon string
}
func initKnownFolders(home string) *knownFolders {
kf := &knownFolders{
userProfile: home,
}
kf.systemDrive = filepath.VolumeName(pathutil.KnownFolder(
windows.FOLDERID_Windows,
[]string{"SystemDrive", "SystemRoot", "windir"},
[]string{home, `C:`},
)) + string(filepath.Separator)
kf.systemRoot = pathutil.KnownFolder(
windows.FOLDERID_Windows,
[]string{"SystemRoot", "windir"},
[]string{filepath.Join(kf.systemDrive, "Windows")},
)
kf.programData = pathutil.KnownFolder(
windows.FOLDERID_ProgramData,
[]string{"ProgramData", "ALLUSERSPROFILE"},
[]string{filepath.Join(kf.systemDrive, "ProgramData")},
)
kf.userProfiles = pathutil.KnownFolder(
windows.FOLDERID_UserProfiles,
nil,
[]string{filepath.Join(kf.systemDrive, "Users")},
)
kf.roamingAppData = pathutil.KnownFolder(
windows.FOLDERID_RoamingAppData,
[]string{"APPDATA"},
[]string{filepath.Join(home, "AppData", "Roaming")},
)
kf.localAppData = pathutil.KnownFolder(
windows.FOLDERID_LocalAppData,
[]string{"LOCALAPPDATA"},
[]string{filepath.Join(home, "AppData", "Local")},
)
kf.desktop = pathutil.KnownFolder(
windows.FOLDERID_Desktop,
nil,
[]string{filepath.Join(home, "Desktop")},
)
kf.downloads = pathutil.KnownFolder(
windows.FOLDERID_Downloads,
nil,
[]string{filepath.Join(home, "Downloads")},
)
kf.documents = pathutil.KnownFolder(
windows.FOLDERID_Documents,
nil,
[]string{filepath.Join(home, "Documents")},
)
kf.music = pathutil.KnownFolder(
windows.FOLDERID_Music,
nil,
[]string{filepath.Join(home, "Music")},
)
kf.pictures = pathutil.KnownFolder(
windows.FOLDERID_Pictures,
nil,
[]string{filepath.Join(home, "Pictures")},
)
kf.videos = pathutil.KnownFolder(
windows.FOLDERID_Videos,
nil,
[]string{filepath.Join(home, "Videos")},
)
kf.templates = pathutil.KnownFolder(
windows.FOLDERID_Templates,
nil,
[]string{filepath.Join(kf.roamingAppData, "Microsoft", "Windows", "Templates")},
)
kf.public = pathutil.KnownFolder(
windows.FOLDERID_Public,
[]string{"PUBLIC"},
[]string{filepath.Join(kf.userProfiles, "Public")},
)
kf.fonts = pathutil.KnownFolder(
windows.FOLDERID_Fonts,
nil,
[]string{filepath.Join(kf.systemRoot, "Fonts")},
)
kf.programs = pathutil.KnownFolder(
windows.FOLDERID_Programs,
nil,
[]string{filepath.Join(kf.roamingAppData, "Microsoft", "Windows", "Start Menu", "Programs")},
)
kf.commonPrograms = pathutil.KnownFolder(
windows.FOLDERID_CommonPrograms,
nil,
[]string{filepath.Join(kf.programData, "Microsoft", "Windows", "Start Menu", "Programs")},
)
kf.programFiles = pathutil.KnownFolder(
windows.FOLDERID_ProgramFiles,
[]string{"ProgramFiles"},
[]string{filepath.Join(kf.systemDrive, "Program Files")},
)
kf.programFilesCommon = pathutil.KnownFolder(
windows.FOLDERID_ProgramFilesCommon,
nil,
[]string{filepath.Join(kf.programFiles, "Common Files")},
)
kf.userProgramFiles = pathutil.KnownFolder(
windows.FOLDERID_UserProgramFiles,
nil,
[]string{
filepath.Join(kf.localAppData, "Programs"),
},
)
kf.userProgramFilesCommon = pathutil.KnownFolder(
windows.FOLDERID_UserProgramFilesCommon,
nil,
[]string{
filepath.Join(kf.userProgramFiles, "Common"),
},
)
return kf
}