-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKnownFolders.cs
79 lines (69 loc) · 2.76 KB
/
KnownFolders.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace BackUpDesktop
{
public enum KnownFolder
{
Contacts,
Downloads,
Favorites,
Links,
SavedGames,
SavedSearches,
Desktop,
Document,
Music,
Pictures,
Videos
}
public static class KnownFolders
{
private static readonly Dictionary<KnownFolder, Guid> _guids = new()
{
[KnownFolder.Contacts] = new("56784854-C6CB-462B-8169-88E350ACB882"),
[KnownFolder.Downloads] = new("374DE290-123F-4565-9164-39C4925E467B"),
[KnownFolder.Favorites] = new("1777F761-68AD-4D8A-87BD-30B759FA33DD"),
[KnownFolder.Links] = new("BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968"),
[KnownFolder.SavedGames] = new("4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4"),
[KnownFolder.SavedSearches] = new("7D1D3A04-DEBB-4115-95CF-2F29DA2920DA")
};
private static readonly Dictionary<KnownFolder, string> path = new()
{
[KnownFolder.Desktop] = new(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)),
[KnownFolder.Document] = new(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)),
[KnownFolder.Music] = new(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)),
[KnownFolder.Pictures] = new(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)),
[KnownFolder.Videos] = new(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos))
};
private static List<string> allPath = new();
public static bool check(string s)
{
return (string.IsNullOrEmpty(s) || string.IsNullOrWhiteSpace(s) || s.StartsWith("Path")) ? true : false;
}
public static List<string> GetPath()
{
foreach (var jsonpath in ConfigInit.Config.Path)
{
if (!check(jsonpath)) {
Console.WriteLine($"Custom path: {jsonpath}");
allPath.Add(jsonpath);
}
}
foreach (KeyValuePair<KnownFolder, string> entry in path)
{
allPath.Add(entry.Value);
}
foreach (KeyValuePair<KnownFolder, Guid> entry in _guids)
{
allPath.Add(SHGetKnownFolderPath(_guids[entry.Key], 0));
}
return allPath;
}
[DllImport("shell32",CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
private static extern string SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)] Guid rfid, uint dwFlags, nint hToken = 0);
}
}