-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTWLoader_Formating.cs
More file actions
191 lines (178 loc) · 6.17 KB
/
Copy pathCTWLoader_Formating.cs
File metadata and controls
191 lines (178 loc) · 6.17 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using Ionic.Zip;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CTW_loader
{
class CTWLoader_Formating
{
[Flags]
public enum TypeData
{
Null = 0,
Bestyary = 1,
Craft = 2,
Skils = 3,
Gnoms = 4,
Worlds = 5,
CharLevel = 6,
Monolog = 7,
GnomsName = 8,
Logo = 9,
Item = 10,
Multy = 11,
World = 12,
}
public static string DialogOpenPath()
{
OpenFileDialog opg = new OpenFileDialog();
opg.SupportMultiDottedExtensions = false;
opg.Multiselect = false;
opg.Title = "Открыть файл CTW сохранения";
if(Directory.Exists(Environment.CurrentDirectory + "\\DownloadingPath"))
opg.InitialDirectory = Environment.CurrentDirectory + "\\DownloadingPath";
opg.Filter = "Файл данных CTWLoader (*.CTWLoader)|*.CTWLoader;";
if (opg.ShowDialog() != DialogResult.OK) return "";
return opg.FileName;
}
public static string DialogSavePath()
{
SaveFileDialog opg = new SaveFileDialog();
opg.SupportMultiDottedExtensions = false;
opg.Title = "Сохранить файл CTW сохранения";
opg.FileName = "CTWLDS_"+DateTime.Now.ToString().Replace(':','_').Replace('.', '_').Replace(' ', '_');
opg.Filter = "Файл данных CTWLoader (*.CTWLoader)|*.CTWLoader;";
if (opg.ShowDialog() != DialogResult.OK) { return ""; };
return opg.FileName;
}
public static SortedList<string, string> Read(string path)
{
if (path == "") return null;
string ty = File.ReadAllText(path).Replace("\r", "");
SortedList<string, string> tmp = new SortedList<string, string>();
tmp.Add("Type", ty.Split(';')[0]);
foreach (var item in ty.Split(';')[1].Split('\n'))
{
if (item.Split('=')[0] != "")
tmp.Add(item.Split('=')[0], item.Split('=')[1]);
}
return tmp;
}
public static void Save(string path, TypeData typedata, SortedList<string, string> data)
{
if (path == "") return;
string tmp = typedata.ToString() + ";";
foreach (var item in data)
{
tmp += item.Key + "=" + item.Value + "\n";
}
File.WriteAllText(path, tmp);
}
public static TypeData GetType(string ReadData)
{
if (ReadData == "") return TypeData.Null;
return (TypeData)Enum.Parse(typeof(TypeData), ReadData);
}
public static TypeData GetType(SortedList<string, string> ReadData)
{
if(ReadData == null) return TypeData.Null;
if (ReadData["Type"] == "") return TypeData.Null;
return (TypeData)Enum.Parse(typeof(TypeData), ReadData["Type"]);
}
public static string GetData(string ReadData, string name)
{
if (ReadData == "") return "";
string tmp = "";
foreach (var item in ReadData.Split(';'))
{
if (item.Split('=')[0] == name)
{
tmp = item.Split('=')[1];
}
}
return tmp;
}
public class CTWLoader_ArrayParam
{
public SortedList<string, string> Param
{
get;
internal set;
}
public CTWLoader_ArrayParam()
{
Param = new SortedList<string, string>();
}
public static CTWLoader_ArrayParam ComboboxParsing(ComboBox ComboBox)
{
CTWLoader_ArrayParam tmp = new CTWLoader_ArrayParam();
for (int i = 0; i < ComboBox.Items.Count; i++)
{
tmp.Param.Add("Param" + i.ToString(), ComboBox.Items[i].ToString());
}
return tmp;
}
}
}
public class CTWLoader_Array
{
private string Name = "";
private SortedList<string, string> sr = new SortedList<string, string>();
public string GetName
{
get { return Name; }
}
public string SetParams(string name, string value)
{
sr.Add(name, value);
return sr[name];
}
public string GetParams(string name)
{
return sr[name];
}
public CTWLoader_Array(string Name)
{
this.Name = Name;
}
public CTWLoader_Array(string Name, string[] array)
{
this.Name = Name;
for (int i = 0; i < array.Length; i++)
{
sr.Add(i.ToString(), array[i]);
}
}
public CTWLoader_Array(string Name, SortedList<string, string> array)
{
this.Name = Name;
for (int i = 0; i < array.Count; i++)
{
sr.Add(array.Keys[i], array.Values[i]);
}
}
public CTWLoader_Array(string Name, string text, char separator, char separator1)
{
this.Name = Name;
foreach (var item in text.Split(separator))
{
if (item.Split(separator1).Length > 1)
sr.Add(item.Split(separator1)[0], item.Split(separator1)[1]);
}
}
public string ToString(char separator, char separator1)
{
string tmp = "";
foreach (var item in sr)
{
tmp += item.Key + separator1.ToString() + item.Value + separator.ToString();
}
return tmp;
}
}
}