-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
141 lines (126 loc) · 5.9 KB
/
MainWindow.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace RagemakerToPDF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
status.Text = "Status:";
}
private async void LoadRageXML_Click(object sender, RoutedEventArgs e)
{
Ragecomic comic = new Ragecomic();
System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
//ofd.InitialDirectory = ".";
ofd.RestoreDirectory = true;
ofd.Filter = "Ragemaker .xml file (*.xml)|*.xml";
ofd.Title = "Select ragemaker .xml file to convert to PDF";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string filename = ofd.FileNames[0];
// Open File
using (FileStream fs = new FileStream(filename, FileMode.Open))
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.Async = true;
// Read XML
using (XmlReader reader = XmlReader.Create(fs, settings))
{
while (await reader.ReadAsync())
{
string elementName = reader.Name;
switch (elementName)
{
/*
* <panels>8</panels>
* <gridLinesArray>111001110011100</gridLinesArray>
* <gridAboveAll>true</gridAboveAll>
* <showGrid>true</showGrid>
* <redditWatermark>false</redditWatermark>
*/
case "panels":
int panels = int.Parse(reader.ReadInnerXml());
status.Text += "panels: " + panels.ToString() + "\n";
comic.panels = panels;
break;
case "gridLinesArray":
string gridLinesArray = reader.ReadInnerXml();
status.Text += "gridLinesArray: " + gridLinesArray+ "\n";
int matrices = gridLinesArray.Length / 5;
comic.gridLines = new int[matrices, 5];
for(var i = 0; i < gridLinesArray.Length; i++)
{
int matrixIndex = (int)Math.Floor((double)i / 5);
int subIndex = i % 5;
comic.gridLines[matrixIndex,subIndex] = int.Parse(gridLinesArray[i].ToString());
//status.Text += comic.gridLines[i] + "\n";
}
//comic.panels = panels;
break;
case "gridAboveAll":
comic.gridAboveAll = bool.Parse(reader.ReadInnerXml());
status.Text += "gridAboveAll: " + comic.gridAboveAll + "\n";
break;
case "showGrid":
comic.showGrid = bool.Parse(reader.ReadInnerXml());
status.Text += "showGrid: " + comic.showGrid + "\n";
break;
case "redditWatermark":
comic.redditWatermark = bool.Parse(reader.ReadInnerXml());
status.Text += "redditWatermark: " + comic.redditWatermark + "\n";
break;
case "Face":
case "Text":
case "AnyFont":
case "Draw":
case "Image":
if (reader.NodeType == XmlNodeType.EndElement) break;
using(XmlReader subtreeReader = reader.ReadSubtree())
{
RageItem newItem = await RageItem.createRageItem(elementName, subtreeReader);
comic.items.Add(newItem);
status.Text += "new item: " + newItem.ToString() + "\n";
}
break;
default:
break;
}
}
}
}
status.Text += filename + " was parsed successfully.\n\n\nProceeding to PDF generation\n\n\n";
RagecomicToPDF.MakePDF(comic, filename + ".pdf");
}
else
{
MessageBox.Show("error");
}
Thread thread = new Thread(LoadAndProcessRageXML);
thread.Start();
}
private void LoadAndProcessRageXML()
{
}
}
}