-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
72 lines (62 loc) · 2.12 KB
/
Utils.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
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
namespace SupSubtitleParser
{
public class Utils
{
public static string FormatDatetime(UInt32 times)
{
var ms = times / 90;
var MS = ms % 1000;
var sec = ms / 1000;
return $"{(sec / 3600).ToString("00")}:{((sec % 3600) / 60).ToString("00")}:{(sec % 60).ToString("00")},{MS}";
}
public static string GetAppName()
{
return AppDomain.CurrentDomain.FriendlyName.Replace(".exe", "");
}
public static Version GetAppVer()
{
return Assembly.GetEntryAssembly().GetName().Version;
}
public static Color? TryParseColor(string stringColor)
{
if (stringColor.StartsWith("#") && stringColor.Length == 7) //#ffffff
{
if (int.TryParse(stringColor.Substring(1, 2), NumberStyles.HexNumber, null, out var r) &&
int.TryParse(stringColor.Substring(3, 2), NumberStyles.HexNumber, null, out int g) &&
int.TryParse(stringColor.Substring(5, 2), NumberStyles.HexNumber, null, out int b))
{
return Color.FromArgb(r, g, b);
}
else
{
return null;
}
}
ColorConverter colorConv = new ColorConverter(); //named color
try
{
return Color.FromName(stringColor);
}
catch (Exception)
{
return null;
}
}
public static string GetOutputFolder(string inputFile)
{
FileInfo fi = new FileInfo(inputFile);
string path = $"{fi.DirectoryName.TrimEnd('\\')}\\subtitle";
while (Directory.Exists(path))
{
path = $"{fi.DirectoryName.TrimEnd('\\')}\\subtitle_{Path.GetRandomFileName().Substring(0, 4)}";
}
Directory.CreateDirectory(path);
return path;
}
}
}