-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFguiToolkitForm.cs
814 lines (737 loc) · 34.8 KB
/
FguiToolkitForm.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows.Forms;
using System.Security;
using System.Xml.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace fgui_toolkit
{
public partial class FguiToolkitForm : Form
{
private string exeLocation = "";
private string FguiLocation = "";
private AutoResetEvent UIEvent = new AutoResetEvent(false);
private string packageDesc = "";
// All Resources id
Dictionary<string, FResource> resourceIDDict = new Dictionary<string, FResource>();
// All export path
public Dictionary<string, ExportInfo> exportInfoDict = new Dictionary<string, ExportInfo>();
public FguiToolkitForm()
{
InitializeComponent();
LoadConfig();
Global.UI = new Global.InvokeUI(UpdateUI);
}
protected void LoadConfig()
{
StringBuilder sb = new StringBuilder(255);
int t = Global.GetPrivateProfileString("FGUI", "Location", "", sb, 255, Application.StartupPath + "\\Config.ini");
FguiLocation = sb.ToString();
txtFguiRoot.Text = FguiLocation;
t = Global.GetPrivateProfileString("FGUI", "Exe", "", sb, 255, Application.StartupPath + "\\Config.ini");
exeLocation = sb.ToString();
exportInfoDict.Clear();
if (FguiLocation.Length > 0)
{
string expinfopath = FguiLocation + "\\settings\\exportinfo.json";
if (File.Exists(expinfopath))
{
exportInfoDict = JsonConvert.DeserializeObject<Dictionary<string, ExportInfo>>(File.ReadAllText(expinfopath));
}
}
updateCombItem();
}
private void btnFguiRoot_Click(object sender, EventArgs e)
{
datagridView1.Rows.Clear();
datagridView1.Refresh();
resourceIDDict.Clear();
OpenFileDialog openFileDialog1 = new OpenFileDialog()
{
FileName = "Select a fairy file",
Filter = "FGUI files (*.fairy)|*.fairy",
Title = "Open fairy file"
};
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
string fproj_loc = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
txtFguiRoot.Text = fproj_loc;
FguiLocation = fproj_loc;
Global.WritePrivateProfileString("FGUI", "Location", fproj_loc, Application.StartupPath + "\\Config.ini");
}
catch (SecurityException ex)
{
MessageBox.Show("不是一個 .fairy 檔案 ");
Console.WriteLine(ex);
}
}
LoadConfig();
}
private void fetchFairyExePath()
{
if (exeLocation.Length > 0)
{
if (File.Exists(exeLocation)) return;
}
var process = Process.GetCurrentProcess(); // Or whatever method you are using
string fullPath = process.MainModule.FileName;
foreach (Process PPath in Process.GetProcesses())
{
if (PPath.ProcessName.ToString() == "FairyGUI-Editor")
{
exeLocation = PPath.MainModule.FileName;
break;
}
}
if (exeLocation.Length > 0)
{
Global.WritePrivateProfileString("FGUI", "Exe", exeLocation, Application.StartupPath + "\\Config.ini");
}
else
{
MessageBox.Show("無法找到FairyGUI.exe,請先開啟專案");
}
}
private bool isFairyRunning()
{
var process = Process.GetCurrentProcess(); // Or whatever method you are using
string fullPath = process.MainModule.FileName;
bool bFound = false;
foreach (Process PPath in Process.GetProcesses())
{
if (PPath.ProcessName.ToString() == "FairyGUI-Editor")
{
bFound = true;
break;
}
}
return bFound;
}
private void btnPurgeProj_Click(object sender, EventArgs e)
{
datagridView1.Rows.Clear();
datagridView1.Refresh();
resourceIDDict.Clear();
if (FguiLocation.Length<1) return;
List<string> dirs = Directory.GetDirectories(FguiLocation, "*", SearchOption.TopDirectoryOnly).ToList();
foreach (string dir in dirs)
{
string lastfolderName = Path.GetFileName(dir);
if (lastfolderName != "assets") continue;
doPurgeProj(dir);
}
fetchFairyExePath();
}
private void doPurgeProj(string assetspath)
{
if (!Directory.Exists(assetspath)) return;
List<string> dirs = Directory.GetDirectories(assetspath, "*", SearchOption.TopDirectoryOnly).ToList();
if (dirs.Count < 1) return;
string[] fileEntries = Directory.GetFiles(dirs[0], "*.xml");
// 特別判斷 font res
Dictionary<string, FResource> fontDict = new Dictionary<string, FResource>();
// 單獨輸出的 comp 收集
Dictionary<string, FResource> exportedComp = new Dictionary<string, FResource>();
// root
string lroot = dirs[0];
#region read package.xml
string packageFileLocation = "";
foreach (string fileName in fileEntries)
{
string curFile = Path.GetFileName(fileName).Split('.')[0];
if (!Global.ContainStr(curFile, "package")) continue;
packageFileLocation = fileName;
XElement rootElement = XElement.Load(fileName);
if (rootElement.Name.ToString() == "packageDescription")
packageDesc = rootElement.Attribute("id").Value;
foreach (XElement childElement in rootElement.Elements())
{
if (childElement.Name.ToString() == "resources")
{
foreach (XElement res in childElement.Elements())
{
string id = res.Attribute("id").Value;
string name = res.Attribute("name").Value;
string path = res.Attribute("path").Value;
if (res.Name.ToString() == "image")
{
FImage img = new FImage();
img.id = id;
img.name = name;
img.path = path;
if (null != res.Attribute("qualityOption"))
img.qualityOption = res.Attribute("qualityOption").Value;
if (null != res.Attribute("quality"))
img.quality = res.Attribute("quality").Value;
if (null != res.Attribute("atlas"))
img.atlas = res.Attribute("atlas").Value;
if (null != res.Attribute("exported"))
img.bUsed = res.Attribute("exported").Value == "true" ? true : false;
resourceIDDict[id] = img;
}
else
{
FResource resource = new FResource();
resource.id = id;
resource.name = name;
resource.path = path;
if ("/" == path)
resource.bUsed = true;
if (res.Name.ToString() == "folder") // 這個不知道要幹嘛用的
resource.bUsed = true;
if (res.Name.ToString() == "sound") //聲音檔先暫時略過,還得搜索 transition 裡面的
resource.bUsed = true;
if (null != res.Attribute("exported"))
{
resource.bUsed = res.Attribute("exported").Value == "true" ? true : false;
exportedComp[lroot + path + name] = resource;
}
resourceIDDict[id] = resource;
if (res.Name.ToString() == "font") // 特別判斷 font,拉到外面再循環檢查一次
fontDict[lroot + path + name] = resource;
}
}
}
}
}
#endregion
#region read main scene xml
// Scan Fonts
foreach (string fonts in fontDict.Keys)
{
checkFont(fonts);
}
// Scan Exported Components
foreach (string xc in exportedComp.Keys)
{
checkResInUseRecursive(xc, lroot);
}
#endregion
#region read package_branch 分支
Dictionary<string, FResource> resdict_branch_unused = new Dictionary<string, FResource>();
DirectoryInfo di = new DirectoryInfo(assetspath);
//Console.WriteLine(di.Parent.FullName);
List<string> assetsdirs = Directory.GetDirectories(di.Parent.FullName, "*", SearchOption.TopDirectoryOnly).ToList();
foreach (string dir in assetsdirs)
{
if (Global.ContainStr(dir, "assets_"))
{
List<string> assSubds = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly).ToList();
if (assSubds.Count < 1) return;
string[] ffs = Directory.GetFiles(assSubds[0], "*.xml");
foreach (string psn in ffs)
{
string curFile = Path.GetFileName(psn).Split('.')[0];
if (!Global.ContainStr(curFile, "package_branch")) continue;
XElement rootElement = XElement.Load(psn);
foreach (XElement childElement in rootElement.Elements())
{
if (childElement.Name.ToString() == "resources")
{
foreach (XElement res in childElement.Elements())
{
string name = res.Attribute("name").Value;
string path = res.Attribute("path").Value;
foreach (string id in resourceIDDict.Keys)
{
if (resourceIDDict[id].path == path &&
resourceIDDict[id].name == name)
{
if (!resourceIDDict[id].bUsed)
{
string rresid = res.Attribute("id").Value;
FResource resource = new FResource();
resource.id = id;
resource.name = name;
resource.path = Path.GetDirectoryName(psn) + path;
resdict_branch_unused[rresid] = resource;
//Console.WriteLine(resourceIDDict[id].name);
}
}
}
}
}
}
}
}
}
#endregion
// final result
foreach (string id in resourceIDDict.Keys)
{
if (!resourceIDDict[id].bUsed)
{
string fullpath = Path.GetDirectoryName(packageFileLocation) + resourceIDDict[id].path.Replace('/', '\\') + resourceIDDict[id].name;
Global.UI(resourceIDDict[id].id, resourceIDDict[id].name, fullpath);
}
}
// 分支
foreach (string id in resdict_branch_unused.Keys)
{
if (!resdict_branch_unused[id].bUsed)
{
string fullpath = resdict_branch_unused[id].path.Replace('/', '\\') + resdict_branch_unused[id].name;
Global.UI(resdict_branch_unused[id].id, resdict_branch_unused[id].name, fullpath);
}
}
}
private void checkResInUseRecursive(string fileName, string root)
{
if (!File.Exists(fileName)) return;
string curext = Path.GetExtension(fileName);
if (curext != ".xml") return;
XElement rootElement = XElement.Load(fileName);
foreach (XElement childElement in rootElement.Elements())
{
if (childElement.Name.ToString() == "displayList")
{
foreach (XElement res in childElement.Elements())
{
if (null != res.Attribute("fileName"))
{
#if DEBUG
if (Path.GetFileName(fileName) == "dialogRoad.xml")
{
Console.WriteLine("2314");
}
//Console.WriteLine(Path.GetFileName(fileName));
#endif
// 發現一個致命的錯誤,直接查找位於xml內 filename 這個屬性有可能是錯的,一定要從src再回去 package 裡面找
string extname = Path.GetExtension(res.Attribute("fileName").Value);
if (extname == ".xml")
{
if (null != res.Attribute("src"))
{
string src = res.Attribute("src").Value;
if (resourceIDDict.ContainsKey(src))
{
resourceIDDict[src].bUsed = true;
}
string path_ = resourceIDDict[src].path;
string name_ = resourceIDDict[src].name;
checkResInUseRecursive(root + path_ + name_, root);
}
}
else if (null != res.Attribute("src"))
{
string src = res.Attribute("src").Value;
if (resourceIDDict.ContainsKey(src))
{
resourceIDDict[src].bUsed = true;
}
}
}
else if ("list" == res.Name)
{
// list content should be recursive
string tgtsid = "";
if (null != res.Attribute("defaultItem"))
{
string strdfitm = res.Attribute("defaultItem").Value.ToString();
string dfitm = strdfitm.Substring(5);
tgtsid = dfitm.Substring(packageDesc.Length);
if (resourceIDDict.ContainsKey(tgtsid))
{
resourceIDDict[tgtsid].bUsed = true;
string path_ = resourceIDDict[tgtsid].path;
string name_ = resourceIDDict[tgtsid].name;
checkResInUseRecursive(root + path_ + name_, root);
}
}
foreach (XElement ls in res.Elements())
{
if (ls.Name.ToString() == "item")
{
if (null != ls.Attribute("url"))
{
string strdfitm = ls.Attribute("url").Value.ToString();
string dfitm = strdfitm.Substring(5);
tgtsid = dfitm.Substring(packageDesc.Length);
if (resourceIDDict.ContainsKey(tgtsid))
{
resourceIDDict[tgtsid].bUsed = true;
string path_ = resourceIDDict[tgtsid].path;
string name_ = resourceIDDict[tgtsid].name;
checkResInUseRecursive(root + path_ + name_, root);
}
}
}
}
}
}
}
else if ("Button" == childElement.Name)
{
if (null != childElement.Attribute("sound"))
{
string strdfitm = childElement.Attribute("sound").Value.ToString();
string dfitm = strdfitm.Substring(5);
string tgtsid = dfitm.Substring(packageDesc.Length);
if (resourceIDDict.ContainsKey(tgtsid))
{
resourceIDDict[tgtsid].bUsed = true;
}
}
}
}
}
private void checkFont(string fileName)
{
if (!File.Exists(fileName)) return;
string curext = Path.GetExtension(fileName);
if (curext != ".fnt") return;
using (var reader = new StreamReader(fileName))
{
string line;
while ((line = reader.ReadLine()) != null)
{
List<string> linespl = line.Split(' ').ToList();
if (Global.ContainStr(linespl[0], "char"))
{
string img = linespl[2].Split('=')[1];
if (resourceIDDict.ContainsKey(img))
resourceIDDict[img].bUsed = true;
}
}
}
}
public void UpdateUI(string wParam, string lParam1, string lParam2)
{
UIEvent.WaitOne(1000);
try
{
if (this.InvokeRequired)
{
Global.InvokeUI Update = new Global.InvokeUI(UpdateUI);
this.BeginInvoke(Update, wParam, lParam1, lParam2);
}
else
{
DebugView(wParam, lParam1, lParam2);
}
}
catch (Exception ex)
{
MessageBox.Show("UpdateUI " + ex.ToString());
}
UIEvent.Set();
}
private void DebugView(string id, string name, string path)
{
ListViewItem NListView = new ListViewItem();
NListView.SubItems.Add(new ListViewItem.ListViewSubItem().Text = id);
NListView.SubItems.Add(new ListViewItem.ListViewSubItem().Text = name);
NListView.SubItems.Add(new ListViewItem.ListViewSubItem().Text = path);
datagridView1.Rows.Add(new string[] { name, path });
}
private void datagridview1_CellMouseDbClick(object sender, System.Windows.Forms.DataGridViewCellMouseEventArgs e)
{
DataGridView view = (DataGridView)sender;
if (e.Button == MouseButtons.Left)
{
if (e.RowIndex < 0) return;
view.Rows[e.RowIndex].Selected = true;
if (null != view.Rows[e.RowIndex].Cells[0].Value)
{
string path = view.Rows[e.RowIndex].Cells[1].Value.ToString();
System.Diagnostics.Process.Start("explorer.exe", string.Format("/select,\"{0}\"", view.Rows[e.RowIndex].Cells[1].Value.ToString()));
}
}
}
private string curRClickPath = "";
private void datagridview1_CellMouseClick(object sender, System.Windows.Forms.DataGridViewCellMouseEventArgs e)
{
DataGridView view = (DataGridView)sender;
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex < 0) return;
view.Rows[e.RowIndex].Selected = true;
if (null != view.Rows[e.RowIndex].Cells[0].Value)
{
string path = view.Rows[e.RowIndex].Cells[1].Value.ToString();
System.Drawing.Rectangle r = view.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
curRClickPath = path;
MenuItem DelMenu = new MenuItem("複製");
DelMenu.Click += new System.EventHandler(this.mi_romenuclick);
List<MenuItem> menuItems = new List<MenuItem>() { DelMenu };
ContextMenu buttonMenu = new ContextMenu(menuItems.ToArray());
buttonMenu.Show((Control)sender, (new System.Drawing.Point(r.Left + e.X, r.Top + e.Y)), LeftRightAlignment.Left);
}
}
}
private void mi_romenuclick(object sender, EventArgs e)
{
Clipboard.Clear();
Clipboard.SetText(curRClickPath);
}
private void btnAddExpPath_Click(object sender, EventArgs e)
{
newPackageForm pf = new newPackageForm(this.exportInfoDict, this);
pf.TopMost = true;
pf.StartPosition = FormStartPosition.Manual;
pf.Location = new Point(this.Location.X, this.Location.Y + 10);
pf.ShowDialog();
}
private void updateCombItem()
{
this.combo_exp.Items.Clear();
this.combo_exp.ResetText();
foreach (string ko in exportInfoDict.Keys)
{
this.combo_exp.Items.Add(ko);
}
this.combo_exp.SelectedIndex = this.combo_exp.Items.Count - 1;
}
private void btnDelExpSet_Click(object sender, EventArgs e)
{
if (combo_exp.Items.Count < 1) return;
//Console.WriteLine(combo_exp.Items[combo_exp.SelectedIndex].ToString());
this.exportInfoDict.Remove(combo_exp.Items[combo_exp.SelectedIndex].ToString());
updateCombItem();
}
public void onAddExpDlgClosing(Dictionary<string, ExportInfo> info)
{
this.exportInfoDict = info;
updateCombItem();
}
private void btnModifyExp_Click(object sender, EventArgs e)
{
if (this.combo_exp.Items.Count < 1) return;
string _iName = this.combo_exp.Items[this.combo_exp.SelectedIndex].ToString();
ExportInfo info = exportInfoDict[_iName];
modifyPackageForm mf = new modifyPackageForm(_iName, info, this);
mf.TopMost = true;
mf.StartPosition = FormStartPosition.Manual;
mf.Location = new Point(this.Location.X, this.Location.Y + 10);
mf.ShowDialog();
}
public void onModifyExpDlgClosing(string _iName, ExportInfo info)
{
if (exportInfoDict.ContainsKey(_iName))
{
exportInfoDict[_iName] = info;
string expinfopath = FguiLocation + "\\settings\\exportinfo.json";
File.WriteAllText(expinfopath, JsonConvert.SerializeObject(exportInfoDict));
}
}
private void modifyExportPath(ExportInfo info)
{
List<string> dirs = Directory.GetDirectories(FguiLocation, "*", SearchOption.TopDirectoryOnly).ToList();
foreach (string dir in dirs)
{
string lastfolderName = Path.GetFileName(dir);
if (Global.ContainStr(lastfolderName, "assets"))
{
List<string> sdirs = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly).ToList();
if (sdirs.Count < 1) return;
string[] fileEntries = Directory.GetFiles(sdirs[0], "*.xml");
foreach (string fileName in fileEntries)
{
string curFile = Path.GetFileName(fileName).Split('.')[0];
if (!Global.ContainStr(curFile, "package")) continue;
//Console.WriteLine(fileName);
XDocument xmlFile = XDocument.Load(fileName);
var query = from c in xmlFile.Elements("packageDescription").Elements("publish") select c;
foreach (XElement book in query)
{
book.Attribute("name").Value = info.PackageName;
}
xmlFile.Save(fileName);
}
}
if (Global.ContainStr(lastfolderName, "settings"))
{
string settingjsonpath = dir + "/Publish.json";
if (!File.Exists(settingjsonpath)) continue;
//Console.WriteLine(settingjsonpath);
JObject publishjson = JObject.Parse(File.ReadAllText(settingjsonpath));
publishjson["path"] = info.ExportPath;
publishjson["branchPath"] = info.ExportPath_Branch;
using (FileStream fs = File.Open(settingjsonpath, FileMode.OpenOrCreate))
using (StreamWriter sw = new StreamWriter(fs))
using (JsonTextWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
//jw.IndentChar = '\t';
//jw.Indentation = 1;
publishjson.WriteTo(jw);
}
}
}
}
private void btnExport_Click(object sender, EventArgs e)
{
if (isFairyRunning())
{
MessageBox.Show("請先關閉 FairyGui Editor 以繼續");
return;
}
foreach (var proc in Process.GetProcessesByName("FairyGUI-Editor"))
{
proc.Kill();
}
if (exeLocation.Length < 1)
{
MessageBox.Show("請先執行場景資源掃描以繼續");
return;
}
if (!File.Exists(exeLocation)) return;
string selstr = combo_exp.Items[combo_exp.SelectedIndex].ToString();
ExportInfo expinfo = new ExportInfo();
if (selstr.Length > 0)
expinfo = exportInfoDict[selstr];
modifyExportPath(expinfo);
// open the export target folder
string tgtdir = retrieveDir(FguiLocation, expinfo.ExportPath_Branch.Replace('\\', '/'));
if (Directory.Exists(tgtdir))
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
Arguments = tgtdir,
FileName = "explorer.exe"
};
Process.Start(startInfo);
}
// Start Export Thread
ParameterizedThreadStart starterp = new ParameterizedThreadStart(startexportThread);
Thread a = new Thread(starterp);
ExportThreadParm parm = new ExportThreadParm();
parm.selstr = selstr;
parm.ExportPath_Branch = expinfo.ExportPath_Branch;
a.Start(parm);
}
private string retrieveDir(string root , string inpath)
{
DirectoryInfo di = new DirectoryInfo(root);
string s_path = inpath;
while (s_path.Substring(0,3)=="../")
{
s_path = s_path.Substring(3);
di = Directory.GetParent(di.FullName);
}
return (di.FullName + '/' + s_path).Replace('/','\\');
}
private void startexportThread(object parm)
{
ExportThreadParm expparm = (ExportThreadParm)parm;
List<string> dirs = Directory.GetDirectories(FguiLocation, "*", SearchOption.TopDirectoryOnly).ToList();
// branch exported first
foreach (string dir in dirs)
{
string lastfolderName = Path.GetFileName(dir);
if (Global.ContainStr(lastfolderName, "assets"))
{
// to check name patter is match ?
bool bNamePatternMatch = true;
int substart = Math.Min(lastfolderName.Length, "assets_".Length);
string gName = lastfolderName.Substring(substart);
// if this guy don't write any expression on group name , don't check just export directly.
if (Global.ContainStr(expparm.selstr, "?") || Global.ContainStr(expparm.selstr, "*"))
{
bNamePatternMatch = false;
List<string> match_spl = expparm.selstr.Split('_').ToList();
List<string> lastfld_spl = gName.Split('_').ToList();
if (match_spl.Count == lastfld_spl.Count)
{
int matchcnt = 0;
for (int i = 0; i < lastfld_spl.Count; i++)
{
if (match_spl[i] == lastfld_spl[i])
matchcnt++;
else if (match_spl[i] == "?")
matchcnt++;
else if (match_spl[i] == "*")
matchcnt++;
}
if (matchcnt == lastfld_spl.Count)
bNamePatternMatch = true;
}
}
if (bNamePatternMatch)
{
string execString = " -p ";
List<String> fileEntries = Directory.GetFiles(FguiLocation, "*.fairy").ToList();
if (fileEntries.Count < 1) continue;
execString += fileEntries[0].Replace('\\', '/');
execString += " -t " + gName;
this.Invoke(new InvokeExpStatus(this.exportThreadMsg), new object[] { lastfolderName + " 導出中..." });
ProcessStartInfo commandInfosub = new ProcessStartInfo();
commandInfosub.WorkingDirectory = FguiLocation;
commandInfosub.UseShellExecute = false;
commandInfosub.RedirectStandardInput = true;
commandInfosub.RedirectStandardOutput = true;
commandInfosub.FileName = exeLocation;
commandInfosub.Arguments = execString;
Process processsub = Process.Start(commandInfosub);
Console.WriteLine(exeLocation + execString);
processsub.WaitForExit();
Thread.Sleep(100);
Console.WriteLine(lastfolderName + " exported ");
}
}
}
// then export main branch
foreach (string dir in dirs)
{
string lastfolderName = Path.GetFileName(dir);
if (lastfolderName == "assets")
{
string execString = " -p ";
List<String> fileEntries = Directory.GetFiles(FguiLocation, "*.fairy").ToList();
if (fileEntries.Count < 1) continue;
execString += fileEntries[0].Replace('\\', '/');
ProcessStartInfo commandInfosub = new ProcessStartInfo();
commandInfosub.WorkingDirectory = FguiLocation;
commandInfosub.UseShellExecute = false;
commandInfosub.RedirectStandardInput = true;
commandInfosub.RedirectStandardOutput = true;
commandInfosub.FileName = exeLocation;
commandInfosub.Arguments = execString;
Process processsub = Process.Start(commandInfosub);
Console.WriteLine(exeLocation + execString);
processsub.WaitForExit();
Thread.Sleep(100);
Console.WriteLine(lastfolderName + " exported ");
this.Invoke(new InvokeExpStatus(this.exportThreadMsg), new object[] { lastfolderName + " 導出完成 " });
}
}
foreach (var proc in Process.GetProcessesByName("FairyGUI-Editor"))
{
proc.Kill();
}
/// revert all change
ProcessStartInfo commandInfo = new ProcessStartInfo();
commandInfo.WorkingDirectory = FguiLocation;
commandInfo.UseShellExecute = false;
commandInfo.RedirectStandardInput = true;
commandInfo.RedirectStandardOutput = true;
commandInfo.FileName = "git.exe";
commandInfo.Arguments = "reset --hard";
Process process = Process.Start(commandInfo);
this.Invoke(new InvokeExpThDone(this.exportThreadDone), new object[] { expparm.ExportPath_Branch });
}
private delegate void InvokeExpThDone(string branchLoc);
private void exportThreadDone(string branchLoc)
{
MessageBox.Show("導出完成!", "FGUI Toolkit", MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
}
private delegate void InvokeExpStatus(string msg);
private void exportThreadMsg(string msg)
{
this.lbb_exportText.Text = msg;
}
}
}