forked from Oonej/ChaosHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
143 lines (130 loc) · 4.47 KB
/
Util.cs
File metadata and controls
143 lines (130 loc) · 4.47 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.IO;
using System.Reflection;
namespace ChaosHelper
{
public static class Util
{
public static void LogError(Exception ex)
{
try
{
using (StreamWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Asheron's Call\" + Globals.PluginName + " errors.txt", true))
{
writer.WriteLine("============================================================================");
writer.WriteLine(DateTime.Now.ToString());
writer.WriteLine("Error: " + ex.Message);
writer.WriteLine("Source: " + ex.Source);
writer.WriteLine("Stack: " + ex.StackTrace);
if (ex.InnerException != null)
{
writer.WriteLine("Inner: " + ex.InnerException.Message);
writer.WriteLine("Inner Stack: " + ex.InnerException.StackTrace);
}
writer.WriteLine("============================================================================");
writer.WriteLine("");
writer.Close();
}
}
catch
{
}
}
public static string[] GetIni()
{
try
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(assemblyFolder, "chaoshelper.ini");
return File.ReadAllLines(filePath);
}
catch (Exception ex)
{
WriteToChat(ex.Message);
}
return null;
}
public static string[] GetConfig(string configname)
{
try
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(assemblyFolder, configname);
return File.ReadAllLines(filePath);
}
catch (Exception ex)
{
WriteToChat(ex.Message);
}
return null;
}
public static string[] GetListofConfigs()
{
try
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string[] temp = Directory.GetFiles(assemblyFolder, "*.txt");
for(int i = 0; i < temp.Length; i++)
{
temp[i] = temp[i].Remove(0, assemblyFolder.Length + 1);
}
return temp;
}
catch (Exception ex)
{
WriteToChat(ex.Message);
}
return null;
}
public static void WriteToChat(string message)
{
try
{
Globals.Host.Actions.AddChatText("<{" + Globals.PluginName + "}>: " + message, 5);
}
catch (Exception ex) { LogError(ex); }
}
public static void SaveIni(string command, string config)
{
try
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(assemblyFolder, "chaoshelper.ini");
string[] lines = File.ReadAllLines(filePath);
using (StreamWriter writer = new StreamWriter(filePath, false))
{
foreach (string line in lines)
{
if (line.Contains("sendchatcommand"))
{
writer.WriteLine("sendchatcommand:" + command);
}
else if(line.Contains("default config"))
{
writer.WriteLine("default config:" + config);
}
}
}
WriteToChat("Chat Command Saved to :" + command);
}
catch (Exception ex)
{
WriteToChat(ex.Message);
}
}
public static string[] LoadLayout(string layout)
{
try
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(assemblyFolder, layout);
return File.ReadAllLines(filePath);
}
catch (Exception ex)
{
WriteToChat(ex.Message);
}
return null;
}
}
}