1 |
cycrow |
1 |
#pragma once
|
|
|
2 |
|
|
|
3 |
using namespace System;
|
|
|
4 |
using namespace System::Xml;
|
|
|
5 |
using namespace System::ComponentModel;
|
|
|
6 |
using namespace System::Collections;
|
|
|
7 |
using namespace System::Windows::Forms;
|
|
|
8 |
using namespace System::Data;
|
|
|
9 |
using namespace System::Drawing;
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
namespace Creator {
|
|
|
13 |
|
|
|
14 |
/// <summary>
|
|
|
15 |
/// Summary for LoadText
|
|
|
16 |
///
|
|
|
17 |
/// WARNING: If you change the name of this class, you will need to change the
|
|
|
18 |
/// 'Resource File Name' property for the managed resource compiler tool
|
|
|
19 |
/// associated with all .resx files this class depends on. Otherwise,
|
|
|
20 |
/// the designers will not be able to interact properly with localized
|
|
|
21 |
/// resources associated with this form.
|
|
|
22 |
/// </summary>
|
|
|
23 |
public ref class LoadText : public System::Windows::Forms::Form
|
|
|
24 |
{
|
|
|
25 |
public:
|
|
|
26 |
LoadText(CLinkList<SGameDir> *dirs, CPackages *p, Collections::Hashtable ^text)
|
|
|
27 |
{
|
|
|
28 |
InitializeComponent();
|
|
|
29 |
|
|
|
30 |
m_pTextList = text;
|
|
|
31 |
m_pCurrentDir = NULL;
|
|
|
32 |
m_pPackages = p;
|
|
|
33 |
m_lDirs = dirs;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
void Start()
|
|
|
37 |
{
|
|
|
38 |
if ( m_pCurrentDir ) this->label2->Text = SystemStringFromCyString(m_pCurrentDir->sDir);
|
|
|
39 |
this->backgroundWorker1->RunWorkerAsync();
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
void DoWork()
|
|
|
43 |
{
|
|
|
44 |
if ( !m_pCurrentDir ) return;
|
|
|
45 |
|
|
|
46 |
int game = m_pCurrentDir->sGame.GetToken(" ", 1, 1).ToInt();
|
|
|
47 |
int flags = m_pPackages->GetGameExe()->GetGameFlags(game);
|
|
|
48 |
|
|
|
49 |
CyString textFile = SPK::FormatTextName(1, m_pPackages->GetLanguage(), (flags & EXEFLAG_TCTEXT)) + ".pck";
|
|
|
50 |
|
|
|
51 |
// find the latest text file
|
|
|
52 |
if ( m_pPackages->ExtractGameFile(CyString("t/") + textFile, m_pPackages->GetTempDirectory() + "/text.xml", m_pCurrentDir->sDir) )
|
|
|
53 |
this->ReadTextFromFile(SystemStringFromCyString(m_pPackages->GetTempDirectory() + "/text.xml"), game);
|
|
|
54 |
|
|
|
55 |
if ( !m_pCurrentDir->bLoad ) return;
|
|
|
56 |
|
|
|
57 |
// extract any text files in the t directory
|
|
|
58 |
cli::array<String ^> ^files = IO::Directory::GetFiles(SystemStringFromCyString(m_pCurrentDir->sDir.FindReplace("/", "\\") + "\\t"), "*.xml");
|
|
|
59 |
for ( int i = 0; i < files->Length; i++ )
|
|
|
60 |
this->ReadTextFromFile(files[i], game);
|
|
|
61 |
|
|
|
62 |
cli::array<String ^> ^filespck = IO::Directory::GetFiles(SystemStringFromCyString(m_pCurrentDir->sDir.FindReplace("/", "\\") + "\\t"), "*.pck");
|
|
|
63 |
for ( int i = 0; i < filespck->Length; i++ )
|
|
|
64 |
{
|
|
|
65 |
// extract the t file
|
|
|
66 |
C_File F(CyStringFromSystemString(filespck[i]));
|
|
|
67 |
if ( F.UnPCKFile() )
|
|
|
68 |
{
|
|
|
69 |
if ( F.WriteToFile(m_pPackages->GetTempDirectory() + "/text.xml") )
|
|
|
70 |
this->ReadTextFromFile(SystemStringFromCyString(m_pPackages->GetTempDirectory() + "/text.xml"), game);
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
void Next()
|
|
|
76 |
{
|
|
|
77 |
m_pCurrentDir = m_lDirs->Next();
|
|
|
78 |
if ( m_pCurrentDir )
|
|
|
79 |
this->Start();
|
|
|
80 |
else
|
|
|
81 |
this->Close();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
void ReadTextFromFile(String ^file, int game)
|
|
|
85 |
{
|
|
|
86 |
|
|
|
87 |
XmlTextReader ^reader = gcnew XmlTextReader(file);
|
|
|
88 |
int inPage = -1;
|
|
|
89 |
int inID = -1;
|
|
|
90 |
while ( reader->Read() )
|
|
|
91 |
{
|
|
|
92 |
switch(reader->NodeType)
|
|
|
93 |
{
|
|
|
94 |
case XmlNodeType::Element:
|
|
|
95 |
if ( String::Compare(reader->Name, "page") == 0 )
|
|
|
96 |
{
|
|
|
97 |
while (reader->MoveToNextAttribute())
|
|
|
98 |
{
|
|
|
99 |
if ( String::Compare(reader->Name, "id") == 0 )
|
|
|
100 |
{
|
|
|
101 |
inPage = Convert::ToInt32(reader->Value);
|
|
|
102 |
if ( inPage >= 10000 )
|
|
|
103 |
inPage %= 10000;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
else if ( inPage > 0 && String::Compare(reader->Name, "t") == 0 )
|
|
|
108 |
{
|
|
|
109 |
while (reader->MoveToNextAttribute())
|
|
|
110 |
{
|
|
|
111 |
if ( String::Compare(reader->Name, "id") == 0 )
|
|
|
112 |
inID = Convert::ToInt32(reader->Value);
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
break;
|
|
|
116 |
case XmlNodeType::Text:
|
|
|
117 |
if ( inID > 0 )
|
|
|
118 |
{
|
|
|
119 |
String ^key = Convert::ToString(game) + "," + Convert::ToString(inPage) + "," + Convert::ToString(inID);
|
|
|
120 |
String ^t = reader->Value;
|
|
|
121 |
while ( t->IndexOf('(') != -1 && t->IndexOf(')') != -1 )
|
|
|
122 |
{
|
|
|
123 |
int s = t->IndexOf('(');
|
|
|
124 |
t = t->Remove(s, t->IndexOf(')') - s + 1);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
if ( m_pTextList->ContainsKey(key) )
|
|
|
128 |
m_pTextList[key] = t;
|
|
|
129 |
else
|
|
|
130 |
m_pTextList->Add(key, t);
|
|
|
131 |
}
|
|
|
132 |
break;
|
|
|
133 |
case XmlNodeType::EndElement:
|
|
|
134 |
if ( String::Compare(reader->Name, "page") == 0 )
|
|
|
135 |
inPage = -1;
|
|
|
136 |
else if ( String::Compare(reader->Name, "t") == 0 )
|
|
|
137 |
inID = -1;
|
|
|
138 |
break;
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
protected:
|
|
|
147 |
/// <summary>
|
|
|
148 |
/// Clean up any resources being used.
|
|
|
149 |
/// </summary>
|
|
|
150 |
~LoadText()
|
|
|
151 |
{
|
|
|
152 |
if (components)
|
|
|
153 |
{
|
|
|
154 |
delete components;
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
private: System::Windows::Forms::Label^ label1;
|
|
|
158 |
protected:
|
|
|
159 |
private: System::Windows::Forms::Label^ label2;
|
|
|
160 |
private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;
|
|
|
161 |
|
|
|
162 |
private:
|
|
|
163 |
Collections::Hashtable ^m_pTextList;
|
|
|
164 |
CPackages *m_pPackages;
|
|
|
165 |
SGameDir *m_pCurrentDir;
|
|
|
166 |
CLinkList<SGameDir> *m_lDirs;
|
|
|
167 |
/// <summary>
|
|
|
168 |
/// Required designer variable.
|
|
|
169 |
/// </summary>
|
|
|
170 |
System::ComponentModel::Container ^components;
|
|
|
171 |
|
|
|
172 |
#pragma region Windows Form Designer generated code
|
|
|
173 |
/// <summary>
|
|
|
174 |
/// Required method for Designer support - do not modify
|
|
|
175 |
/// the contents of this method with the code editor.
|
|
|
176 |
/// </summary>
|
|
|
177 |
void InitializeComponent(void)
|
|
|
178 |
{
|
|
|
179 |
this->label1 = (gcnew System::Windows::Forms::Label());
|
|
|
180 |
this->label2 = (gcnew System::Windows::Forms::Label());
|
|
|
181 |
this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
|
|
|
182 |
this->SuspendLayout();
|
|
|
183 |
//
|
|
|
184 |
// label1
|
|
|
185 |
//
|
|
|
186 |
this->label1->Dock = System::Windows::Forms::DockStyle::Top;
|
|
|
187 |
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
|
|
|
188 |
static_cast<System::Byte>(0)));
|
|
|
189 |
this->label1->Location = System::Drawing::Point(10, 10);
|
|
|
190 |
this->label1->Name = L"label1";
|
|
|
191 |
this->label1->Size = System::Drawing::Size(231, 32);
|
|
|
192 |
this->label1->TabIndex = 0;
|
|
|
193 |
this->label1->Text = L"Loading Text";
|
|
|
194 |
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
|
|
|
195 |
this->label1->UseWaitCursor = true;
|
|
|
196 |
//
|
|
|
197 |
// label2
|
|
|
198 |
//
|
|
|
199 |
this->label2->Dock = System::Windows::Forms::DockStyle::Fill;
|
|
|
200 |
this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Italic, System::Drawing::GraphicsUnit::Point,
|
|
|
201 |
static_cast<System::Byte>(0)));
|
|
|
202 |
this->label2->Location = System::Drawing::Point(10, 42);
|
|
|
203 |
this->label2->Name = L"label2";
|
|
|
204 |
this->label2->Size = System::Drawing::Size(231, 23);
|
|
|
205 |
this->label2->TabIndex = 1;
|
|
|
206 |
this->label2->TextAlign = System::Drawing::ContentAlignment::TopCenter;
|
|
|
207 |
this->label2->UseWaitCursor = true;
|
|
|
208 |
//
|
|
|
209 |
// backgroundWorker1
|
|
|
210 |
//
|
|
|
211 |
this->backgroundWorker1->DoWork += gcnew System::ComponentModel::DoWorkEventHandler(this, &LoadText::backgroundWorker1_DoWork);
|
|
|
212 |
this->backgroundWorker1->RunWorkerCompleted += gcnew System::ComponentModel::RunWorkerCompletedEventHandler(this, &LoadText::backgroundWorker1_RunWorkerCompleted);
|
|
|
213 |
//
|
|
|
214 |
// LoadText
|
|
|
215 |
//
|
|
|
216 |
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
|
|
|
217 |
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
|
|
|
218 |
this->BackColor = System::Drawing::Color::Gray;
|
|
|
219 |
this->ClientSize = System::Drawing::Size(251, 75);
|
|
|
220 |
this->ControlBox = false;
|
|
|
221 |
this->Controls->Add(this->label2);
|
|
|
222 |
this->Controls->Add(this->label1);
|
|
|
223 |
this->Cursor = System::Windows::Forms::Cursors::WaitCursor;
|
|
|
224 |
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
|
|
|
225 |
this->Name = L"LoadText";
|
|
|
226 |
this->Padding = System::Windows::Forms::Padding(10);
|
|
|
227 |
this->ShowInTaskbar = false;
|
|
|
228 |
this->SizeGripStyle = System::Windows::Forms::SizeGripStyle::Hide;
|
|
|
229 |
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
|
|
|
230 |
this->Text = L"LoadText";
|
|
|
231 |
this->TopMost = true;
|
|
|
232 |
this->UseWaitCursor = true;
|
|
|
233 |
this->Load += gcnew System::EventHandler(this, &LoadText::LoadText_Load);
|
|
|
234 |
this->ResumeLayout(false);
|
|
|
235 |
|
|
|
236 |
}
|
|
|
237 |
#pragma endregion
|
|
|
238 |
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e) {
|
|
|
239 |
this->DoWork();
|
|
|
240 |
}
|
|
|
241 |
private: System::Void LoadText_Load(System::Object^ sender, System::EventArgs^ e) {
|
|
|
242 |
m_pCurrentDir = m_lDirs->First();
|
|
|
243 |
this->Start();
|
|
|
244 |
}
|
|
|
245 |
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e) {
|
|
|
246 |
this->Next();
|
|
|
247 |
}
|
|
|
248 |
};
|
|
|
249 |
}
|