-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayoutFileHelper.cs
More file actions
35 lines (31 loc) · 1.29 KB
/
LayoutFileHelper.cs
File metadata and controls
35 lines (31 loc) · 1.29 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
namespace DesktopICO
{
public class LayoutFileHelper
{
public record LayoutFileInfo(string Prefix, string Resolution, string UserName, DateTime Timestamp);
public static string CreateFileName(string prefix, bool autoBackup = false)
{
string resolution = $"{Screen.PrimaryScreen?.Bounds.Width}x{Screen.PrimaryScreen?.Bounds.Height}";
string userName = Environment.UserName;
string timestamp = DateTime.Now.ToString("yyyy_MMdd_HHmmss");
return $"{(autoBackup ? "自动备份" : prefix)}_{resolution}_{userName}_{timestamp}";
}
public static string CreateDisplayName(string prefix, string resolution)
{
return $"{prefix}[{resolution}]";
}
public static LayoutFileInfo ParseFileName(string fileName)
{
var parts = Path.GetFileNameWithoutExtension(fileName).Split('_');
if (parts.Length < 6)
throw new ArgumentException("Invalid file name format");
string dateString = $"{parts[3]}{parts[4]}{parts[5]}";
return new LayoutFileInfo(
parts[0],
parts[1],
parts[2],
DateTime.ParseExact(dateString, "yyyyMMddHHmmss", null)
);
}
}
}