-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject.cs
More file actions
322 lines (290 loc) · 12.9 KB
/
Project.cs
File metadata and controls
322 lines (290 loc) · 12.9 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Xml;
using System.Diagnostics;
namespace Love_Design
{
class Project
{
public static string path_to_love = "";
public static string current_build;
public static string project_path;
public static string project_name;
public static string current_file_path;
public static Dictionary<string, string> edited_files = new Dictionary<string, string>();
public static Dictionary<string, string> edited_files_path = new Dictionary<string, string>();
public static Dictionary<string, bool> edited_saved = new Dictionary<string, bool>();
public static void buildLove(string path)
{
var mainForm = Form.ActiveForm as Form1;
if (project_path != null)
{
//current_build = project_name + "_" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".love";
mainForm.toolStripStatusLabel1.Text = "Zipping...";
ZipFile.CreateFromDirectory(project_path, path);
mainForm.toolStripStatusLabel1.Text = "Zipped!";
}
}
public static void buildGame(string path)
{
var mainForm = Form.ActiveForm as Form1;
if (project_path != null)
{
current_build = project_name + "_" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".love";
mainForm.toolStripStatusLabel1.Text = "Zipping...";
ZipFile.CreateFromDirectory(project_path, @"build\" + current_build);
mainForm.toolStripStatusLabel1.Text = "Zipped!";
//string b = @"/b" + " " + '"' + path_to_love + @"\love.exe" + '"' + "+" + '"' + Directory.GetCurrentDirectory() + @"\build\" + current_build + '"' + " " + '"' + path + '"';
string b = String.Format(@"/C copy /b ""{0}\love.exe""+""{1}\build\{2}"" ""{3}""", path_to_love, Directory.GetCurrentDirectory(), current_build, path);
Process.Start("cmd.exe", b);
mainForm.toolStripStatusLabel1.Text = "Builded! (" + path + ")";
}
}
public static void run()
{
var mainForm = Form.ActiveForm as Form1;
if (project_path != null)
{
Process.Start(path_to_love + "\\love.exe", '"' + project_path + '"');
mainForm.toolStripStatusLabel1.Text = "Runing";
}
}
public static void create(string path)
{
var mainForm = Form.ActiveForm as Form1;
mainForm.treeView1.Nodes.Clear();
project_path = path;
string[] array = path.Split('\\');
project_name = array.Last();
File.Copy(@"project\main.lua", project_path + @"\main.lua", true);
File.Copy(@"project\conf.lua", project_path + @"\conf.lua", true);
if (array.Last() != "")
Item.add(0, array.Last(), "");
CreatePath(mainForm.treeView1.Nodes, project_name + @"\main.lua", 4);
CreatePath(mainForm.treeView1.Nodes, project_name + @"\conf.lua", 4);
}
private static void buildTree(string path)
{
Item.add(5, "", path.Substring(path.IndexOf(project_name)));
string[] files = Directory.GetFiles(path);
foreach (string f in files)
{
Item.add(4, f.Split('\\').Last(), path.Substring(path.IndexOf(project_name)));
}
string[] directories = Directory.GetDirectories(path);
foreach (string d in directories)
{
buildTree(d);
}
}
public static void open(string path)
{
var mainForm = Form.ActiveForm as Form1;
mainForm.treeView1.Nodes.Clear();
project_path = path;
string[] array = path.Split('\\');
project_name = array.Last();
if (array.Last() != "")
Item.add(0, array.Last(), "");
buildTree(path);
}
public static void save()
{
var mainForm = Form.ActiveForm as Form1;
if (Project.current_file_path != null && !Project.edited_saved[Project.current_file_path])
{
StreamWriter writer = new StreamWriter(Project.project_path.Replace(Project.project_name, "") + current_file_path);
writer.Write(edited_files[current_file_path]);
edited_saved[Project.current_file_path] = true;
mainForm.toolStripStatusLabel1.Text = "Saved (" + current_file_path.Split('\\').Last() +")";
mainForm.toolStripStatusLabel2.Text = Project.countEdited();
writer.Close();
}
}
public static void saveAll()
{
var mainForm = Form.ActiveForm as Form1;
int countEdFiles = 0;
foreach (KeyValuePair<string, bool> cf in edited_saved.ToList())
{
if (cf.Key != null && !cf.Value)
{
countEdFiles++;
StreamWriter writer = new StreamWriter(Project.project_path.Replace(Project.project_name, "") + cf.Key);
writer.Write(edited_files[cf.Key]);
edited_saved[cf.Key] = true;
mainForm.toolStripStatusLabel1.Text = "Saved All (" + countEdFiles + ")";
mainForm.toolStripStatusLabel2.Text = Project.countEdited();
writer.Close();
}
}
}
public static string countEdited()
{
int fp = 0;
foreach (KeyValuePair<string, bool> cf in edited_saved.ToList())
{
if (cf.Key != null && !cf.Value)
{
fp++;
}
}
return fp + " edited";
}
public static void loadSettings()
{
var mainForm = Form.ActiveForm as Form1;
XmlReader reader = XmlReader.Create("data\\config.xml");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element
&& reader.Name == "lovedesign")
{
mainForm.Width = Convert.ToInt32(reader.GetAttribute(0));
mainForm.Height = Convert.ToInt32(reader.GetAttribute(1));
FormWindowState fws = (FormWindowState)Enum.Parse(typeof(FormWindowState), reader.GetAttribute(2));
mainForm.WindowState = fws;
mainForm.Left = Convert.ToInt32(reader.GetAttribute(3));
mainForm.Top = Convert.ToInt32(reader.GetAttribute(4));
while (reader.NodeType != XmlNodeType.EndElement)
{
reader.Read();
if (reader.Name == "pathToLove")
{
while (reader.NodeType != XmlNodeType.EndElement)
{
reader.Read();
if (reader.NodeType == XmlNodeType.Text)
{
path_to_love = reader.Value;
}
}
reader.Read();
}
}
}
}
}
public static void uptadeSettings()
{
var mainForm = Form.ActiveForm as Form1;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create("data\\config.xml", settings);
writer.WriteStartDocument();
writer.WriteStartElement("lovedesign");
writer.WriteAttributeString("windowWidth", mainForm.Width.ToString());
writer.WriteAttributeString("windowHeight", mainForm.Height.ToString());
writer.WriteAttributeString("windowState", mainForm.WindowState.ToString());
writer.WriteAttributeString("positionX", mainForm.Left.ToString());
writer.WriteAttributeString("positionY", mainForm.Top.ToString());
writer.WriteElementString("pathToLove", path_to_love);
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
public static void loadEditorSettings()
{
var mainForm = Form.ActiveForm as Form1;
XmlReader reader = XmlReader.Create("data\\editor.xml");
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element
&& reader.Name == "editor")
{
mainForm.fastColoredTextBox1.Font = new Font(reader.GetAttribute(0), Convert.ToSingle(reader.GetAttribute(1)), FontStyle.Regular);
mainForm.fastColoredTextBox1.ForeColor = Color.FromArgb(Convert.ToInt32(reader.GetAttribute(2)));
mainForm.fastColoredTextBox1.BackColor = Color.FromArgb(Convert.ToInt32(reader.GetAttribute(3)));
mainForm.fastColoredTextBox1.LineNumberColor = Color.FromArgb(Convert.ToInt32(reader.GetAttribute(4)));
mainForm.fastColoredTextBox1.CaretColor = Color.FromArgb(Convert.ToInt32(reader.GetAttribute(5)));
}
}
}
public static void updateEditorSettings()
{
var mainForm = Form.ActiveForm as Form1;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create("data\\editor.xml", settings);
writer.WriteStartDocument();
writer.WriteStartElement("editor");
writer.WriteAttributeString("fontFamily", mainForm.fastColoredTextBox1.Font.FontFamily.Name);
writer.WriteAttributeString("fontSize", mainForm.fastColoredTextBox1.Font.Size.ToString());
writer.WriteAttributeString("fontColor", mainForm.fastColoredTextBox1.ForeColor.ToArgb().ToString());
writer.WriteAttributeString("backGroundColor", mainForm.fastColoredTextBox1.BackColor.ToArgb().ToString());
writer.WriteAttributeString("lineNumberColor", mainForm.fastColoredTextBox1.LineNumberColor.ToArgb().ToString());
writer.WriteAttributeString("caretColor", mainForm.fastColoredTextBox1.CaretColor.ToArgb().ToString());
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
public static void CreatePath(TreeNodeCollection nodeList, string path,int imgIdx)
{
TreeNode node = null;
string folder = string.Empty;
int p = path.IndexOf('\\');
if (p == -1)
{
folder = path;
path = "";
}
else
{
folder = path.Substring(0, p);
path = path.Substring(p + 1, path.Length - (p + 1));
}
node = null;
foreach (TreeNode item in nodeList)
{
if (item.Text == folder)
{
node = item;
}
}
if (node == null)
{
node = new TreeNode(folder);
nodeList.Add(node);
node.ImageIndex = imgIdx;
node.SelectedImageIndex = imgIdx;
}
if (path != "")
{
CreatePath(node.Nodes, path, imgIdx);
}
}
public static DialogResult InputBox(string title, ref string value)
{
Form form = new Form();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
form.Text = title;
textBox.Text = value;
buttonOk.Text = "OK";
buttonOk.DialogResult = DialogResult.OK;
textBox.SetBounds(12, 12, 342, 20);
buttonOk.SetBounds(271, 38, 83, 23);
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(366, 72);
form.Controls.AddRange(new Control[] { textBox, buttonOk });
form.ClientSize = new System.Drawing.Size(366, 72);
form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
}
}
}