-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathUtils.cs
118 lines (108 loc) · 2.56 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
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
using PingLogger.Models;
using PingLogger.Workers;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace PingLogger
{
public static partial class Utils
{
public static void CreateShortcut()
{
#if Windows
Win.CreateShortcut();
#elif Linux
Linux.CreateShortcut();
#elif OSX
PingLogger.Views.MessageBox.ShowAsError("Error", "This option is not avaiable on MacOS");
#endif
}
public static void DeleteShortcut()
{
#if Windows
Win.DeleteShortcut();
#elif Linux
Linux.DeleteShortcut();
#elif OSX
PingLogger.Views.MessageBox.ShowAsError("Error", "This option is not avaiable on MacOS");
#endif
}
public static Dictionary<string, string> GetOSInfo()
{
var values = new Dictionary<string, string>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
values.Add("OperatingSystem", "Windows");
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
values.Add("OperatingSystem", "Linux");
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
values.Add("OperatingSystem", "Linux");
}
values.Add("OSVersion", Environment.OSVersion.VersionString);
values.Add("CountryCode", RegionInfo.CurrentRegion.TwoLetterISORegionName);
return values;
}
public static string FileBasePath
{
get
{
#if Windows
if (Win.AppIsClickOnce)
{
var appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "PingLogger";
if (!Directory.Exists(appDataDir))
{
Directory.CreateDirectory(appDataDir);
}
return appDataDir;
}
else
{
return Environment.CurrentDirectory;
}
#elif Linux
return Linux.GetFileSavePath();
#else
return Environment.CurrentDirectory;
#endif
}
}
/// <summary>
/// Generates a random string with the specified length.
/// </summary>
/// <param name="length">Number of characters in the string</param>
/// <returns>Random string of letters and numbers</returns>
public static string RandomString(int length)
{
Random random = new();
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public static bool IsLightTheme
{
get
{
if (Config.Theme == Theme.Auto)
{
#if Windows
return Win.GetLightMode();
#else
return true;
#endif
}
else
{
return Config.Theme == Theme.Light;
}
}
}
}
}