forked from GenieClient/Genie4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalDirectory.cs
54 lines (49 loc) · 1.66 KB
/
LocalDirectory.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
using System;
using System.Windows.Forms;
using System.IO;
namespace GenieClient
{
static class LocalDirectory
{
public static string Path = AppDomain.CurrentDomain.BaseDirectory;
public static bool IsLocal = true;
public static void CheckUserDirectory()
{
string dir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config");
if (!System.IO.Directory.Exists(dir))
{
// No local settings, change to user data directory
SetUserDataDirectory();
}
}
public static void SetUserDataDirectory()
{
string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
dir = System.IO.Path.Combine(dir, Application.ProductName);
if (!System.IO.Directory.Exists(dir))
{
System.IO.Directory.CreateDirectory(dir);
}
Path = dir;
IsLocal = false;
}
public static string ValidateDirectory(string path)
{
try
{
if (!System.IO.Path.IsPathRooted(path)) path = Path + "\\" + path;
DirectoryInfo directory = new DirectoryInfo(path);
if (!directory.Exists)
{
directory.Create();
return $"Directory Created: {directory.FullName}";
}
return $"Diretory Found: {directory.FullName}";
}
catch (Exception ex)
{
throw new Exception($"Error Setting Directory: {ex.Message}");
}
}
}
}