forked from harliq/AceCreator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtil.cs
140 lines (127 loc) · 5.62 KB
/
Util.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Decal.Adapter;
using AceCreator.Lib;
namespace AceCreator
{
public static class Util
{
public static void LogError(Exception ex)
{
try
{
using (StreamWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Decal Plugins\AceContentCreator\" + 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 void LogLocation(string location)
{
try
{
using (StreamWriter writer = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\Decal Plugins\AceContentCreator\" + Globals.PluginName + " Locations.txt", true))
{
writer.WriteLine(location);
writer.Close();
}
}
catch (Exception ex) { LogError(ex); }
}
public static void WriteToChat(string message)
{
try
{
Globals.Host.Actions.AddChatText("<{" + Globals.PluginName + "}>: " + message, 5);
}
catch (Exception ex) { LogError(ex); }
}
/// <summary>
/// This will first attempt to send the messages to all plugins. If no plugins set e.Eat to true on the message, it will then simply call InvokeChatParser.
/// </summary>
/// <param name="chatcommand"></param>
public static void SendChatCommand(string chatcommand)
{
try
{
DecalProxy.DispatchChatToBoxWithPluginIntercept(chatcommand);
}
catch (Exception ex) { LogError(ex); }
}
public static void SaveIni(string weenie_jsonpath, string weenie_sqlpath, string landblock_jsonpath, string landblock_sqlpath,
string quest_jsonpath, string quest_sqlpath, string recipe_jsonpath, string recipe_sqlpath)
{
try
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(assemblyFolder, "acecreator.ini");
if (!File.Exists(filePath))
{
File.Create(filePath).Close();
using (StreamWriter writer = new StreamWriter(filePath, false))
{
writer.WriteLine("weenie_jsonpath=");
writer.WriteLine("weenie_sqlpath=");
writer.WriteLine("landblock_jsonpath=");
writer.WriteLine("landblock_sqlpath=");
writer.WriteLine("quest_jsonpath=");
writer.WriteLine("quest_sqlpath=");
writer.WriteLine("recipe_jsonpath=");
writer.WriteLine("recipe_sqlpath=");
writer.Close();
}
}
string[] lines = File.ReadAllLines(filePath);
using (StreamWriter writer = new StreamWriter(filePath, false))
{
writer.WriteLine("weenie_jsonpath=" + weenie_jsonpath);
writer.WriteLine("weenie_sqlpath=" + weenie_sqlpath);
writer.WriteLine("landblock_jsonpath=" + landblock_jsonpath);
writer.WriteLine("landblock_sqlpath=" + landblock_sqlpath);
writer.WriteLine("quest_jsonpath=" + quest_jsonpath);
writer.WriteLine("quest_sqlpath=" + quest_sqlpath);
writer.WriteLine("recipe_jsonpath=" + recipe_jsonpath);
writer.WriteLine("recipe_sqlpath=" + recipe_sqlpath);
writer.Close();
WriteToChat("Path Settings Saved to acecreator.ini");
}
}
catch (Exception ex)
{
WriteToChat(ex.Message);
}
}
internal static Dictionary<string, string> LoadSetttings()
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string filePath = Path.Combine(assemblyFolder, "acecreator.ini");
Dictionary<string, string> temp = new Dictionary<string, string>();
if (!File.Exists(filePath))
SaveIni("", "", "", "", "", "", "", "");
foreach (string line in File.ReadAllLines(filePath))
{
WriteToChat(line);
string[] templineinfo = line.Split('=');
temp.Add(templineinfo[0], templineinfo[1]);
}
return temp;
}
}
}