forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppFolder.cs
56 lines (49 loc) · 1.45 KB
/
AppFolder.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
using System.IO;
namespace System.Application
{
/// <summary>
/// 指定用于检索应用程序所使用的文件夹目录路径的枚举常数
/// </summary>
public enum AppFolder
{
/// <summary>
/// 图片
/// </summary>
Images,
/// <summary>
/// 数据库
/// </summary>
Database,
/// <summary>
/// 缓存、临时文件夹(注意清理!)
/// </summary>
Cache,
}
/// <summary>
/// Enum 扩展 <see cref="AppFolder"/>
/// </summary>
public static class AppFolderEnumExtensions
{
/// <summary>
/// 获取文件夹路径,返回的路径必定存在
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
public static string GetPath(this AppFolder folder)
{
var path1 = folder switch
{
AppFolder.Images or AppFolder.Cache => IOPath.CacheDirectory,
AppFolder.Database => IOPath.AppDataDirectory,
_ => throw new ArgumentOutOfRangeException(nameof(folder), folder, null),
};
var path = Path.Combine(path1, folder.ToString());
IOPath.DirCreateByNotExists(path);
return path;
}
#if DEBUG
[Obsolete("use GetPath", true)]
public static string GetFolderPath(this AppFolder folder) => folder.GetPath();
#endif
}
}