1 |
cycrow |
1 |
#include "spk.h"
|
|
|
2 |
|
|
|
3 |
namespace SPK {
|
197 |
cycrow |
4 |
s_int GetAutomaticFiletype(const Utils::WString &file, Utils::WString *extradir, bool bUseSpecial)
|
1 |
cycrow |
5 |
{
|
|
|
6 |
CFileIO File(file);
|
196 |
cycrow |
7 |
Utils::WString dir = File.GetDirIO().topDir();
|
1 |
cycrow |
8 |
|
196 |
cycrow |
9 |
Utils::WString basename = File.baseName();
|
1 |
cycrow |
10 |
// could be a script, text file or map
|
|
|
11 |
s_int type = -1;
|
196 |
cycrow |
12 |
if ( dir.Compare(L"types") || dir.Compare(L"mov") || dir.Compare(L"s") )
|
1 |
cycrow |
13 |
{
|
|
|
14 |
type = FILETYPE_EXTRA;
|
|
|
15 |
if ( extradir )
|
197 |
cycrow |
16 |
*extradir = dir;
|
1 |
cycrow |
17 |
}
|
196 |
cycrow |
18 |
else if ( File.isFileExtension(L"xml") || File.isFileExtension(L"pck") )
|
1 |
cycrow |
19 |
{
|
|
|
20 |
// TC text file
|
|
|
21 |
type = FILETYPE_SCRIPT;
|
196 |
cycrow |
22 |
if ( File.filename().contains(L"-L") && ((int)File.filename().left(4)) )
|
1 |
cycrow |
23 |
type = FILETYPE_TEXT;
|
196 |
cycrow |
24 |
if ( File.baseName().Compare(L"conversations") )
|
43 |
cycrow |
25 |
type = FILETYPE_TEXT;
|
1 |
cycrow |
26 |
// X2/X3 text file
|
170 |
cycrow |
27 |
else if ( basename.length() >= 5 && basename.length() <= 8 && ((int)File.baseName()) )
|
1 |
cycrow |
28 |
type = FILETYPE_TEXT;
|
196 |
cycrow |
29 |
else if ( dir.Compare(L"maps") )
|
1 |
cycrow |
30 |
type = FILETYPE_MAP;
|
196 |
cycrow |
31 |
else if ( dir.Compare(L"t") )
|
1 |
cycrow |
32 |
type = FILETYPE_TEXT;
|
196 |
cycrow |
33 |
else if ( (bUseSpecial) && (dir.Compare(L"scripts") && basename.contains(L"uninstall")) )
|
18 |
cycrow |
34 |
type = FILETYPE_SCRIPT_UNINSTALL;
|
196 |
cycrow |
35 |
else if ( dir.Compare(L"uninstall") || basename.contains(L"uninstall") )
|
1 |
cycrow |
36 |
type = FILETYPE_UNINSTALL;
|
196 |
cycrow |
37 |
else if ( dir.isin(L"uninstall") )
|
18 |
cycrow |
38 |
type = FILETYPE_UNINSTALL;
|
196 |
cycrow |
39 |
else if ( dir.Compare(L"director") )
|
1 |
cycrow |
40 |
type = FILETYPE_MISSION;
|
|
|
41 |
}
|
|
|
42 |
// could be a model file or scene file
|
196 |
cycrow |
43 |
else if ( File.isFileExtension(L"pbd") || File.isFileExtension(L"bod") )
|
1 |
cycrow |
44 |
{
|
196 |
cycrow |
45 |
if ( dir.isin(L"cockpit") || basename.contains(L"cockpit") )
|
1 |
cycrow |
46 |
type = FILETYPE_COCKPITSCENE;
|
|
|
47 |
else
|
|
|
48 |
type = FILETYPE_SHIPSCENE;
|
|
|
49 |
}
|
|
|
50 |
// can only be a model
|
196 |
cycrow |
51 |
else if ( File.isFileExtension(L"pbb") || File.isFileExtension(L"bob") )
|
1 |
cycrow |
52 |
type = FILETYPE_SHIPMODEL;
|
|
|
53 |
// texture file
|
196 |
cycrow |
54 |
else if ( File.isFileExtension(L"dds") )
|
1 |
cycrow |
55 |
type = FILETYPE_SHIPOTHER;
|
196 |
cycrow |
56 |
else if ( File.isFileExtension(L"txt") || dir.Compare(L"readme") )
|
1 |
cycrow |
57 |
type = FILETYPE_README;
|
196 |
cycrow |
58 |
else if ( File.isFileExtension(L"cat") || File.isFileExtension(L"dat") )
|
1 |
cycrow |
59 |
type = FILETYPE_MOD;
|
196 |
cycrow |
60 |
else if ( File.isFileExtension(L"mp3") )
|
1 |
cycrow |
61 |
type = FILETYPE_SOUND;
|
196 |
cycrow |
62 |
else if ( dir.Compare(L"loadscr") )
|
1 |
cycrow |
63 |
type = FILETYPE_SCREEN;
|
196 |
cycrow |
64 |
else if ( dir.Compare(L"graphics") )
|
1 |
cycrow |
65 |
type = FILETYPE_ADVERT;
|
196 |
cycrow |
66 |
else if ( File.isFileExtension(L"jpg") || File.isFileExtension(L"bmp") )
|
1 |
cycrow |
67 |
type = FILETYPE_SCREEN;
|
196 |
cycrow |
68 |
else if ( File.isFileExtension(L"gif") )
|
1 |
cycrow |
69 |
type = FILETYPE_ADVERT;
|
|
|
70 |
|
|
|
71 |
return type;
|
|
|
72 |
}
|
|
|
73 |
|
18 |
cycrow |
74 |
//TODO: check for special types
|
197 |
cycrow |
75 |
void AssignAutomaticFiletypes(const Utils::WStringList &list)
|
1 |
cycrow |
76 |
{
|
180 |
cycrow |
77 |
for(auto itr = list.begin(); itr != list.end(); itr++)
|
1 |
cycrow |
78 |
{
|
197 |
cycrow |
79 |
Utils::WString extradir;
|
180 |
cycrow |
80 |
s_int type = SPK::GetAutomaticFiletype((*itr)->str, &extradir, false);
|
1 |
cycrow |
81 |
|
170 |
cycrow |
82 |
if ( type == FILETYPE_EXTRA && !extradir.empty() )
|
197 |
cycrow |
83 |
(*itr)->data = Utils::WString::Number(type) + L" " + extradir;
|
1 |
cycrow |
84 |
else
|
197 |
cycrow |
85 |
(*itr)->data = Utils::WString::Number(type);
|
1 |
cycrow |
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
197 |
cycrow |
89 |
Utils::WString GetSizeString ( unsigned long lSize)
|
1 |
cycrow |
90 |
{
|
|
|
91 |
float size = (float)lSize;
|
|
|
92 |
|
|
|
93 |
int level = 0;
|
|
|
94 |
while ( size > 1000 )
|
|
|
95 |
{
|
|
|
96 |
size /= 1024;
|
|
|
97 |
++level;
|
|
|
98 |
if ( level >= 3 )
|
|
|
99 |
break;
|
|
|
100 |
}
|
|
|
101 |
|
134 |
cycrow |
102 |
Utils::String s;
|
1 |
cycrow |
103 |
char str[20];
|
|
|
104 |
switch ( level )
|
|
|
105 |
{
|
|
|
106 |
case 0:
|
|
|
107 |
SPRINTF(str, "%.0f"), size );
|
|
|
108 |
s = str;
|
|
|
109 |
s += "B";
|
|
|
110 |
break;
|
|
|
111 |
case 1:
|
|
|
112 |
SPRINTF(str, "%.2f"), size );
|
|
|
113 |
s = str;
|
|
|
114 |
s += "KB";
|
|
|
115 |
break;
|
|
|
116 |
case 2:
|
|
|
117 |
SPRINTF(str, "%.2f"), size );
|
|
|
118 |
s = str;
|
|
|
119 |
s += "MB";
|
|
|
120 |
break;
|
|
|
121 |
case 3:
|
|
|
122 |
SPRINTF(str, "%.3f"), size );
|
|
|
123 |
s = str;
|
|
|
124 |
s += "GB";
|
|
|
125 |
break;
|
|
|
126 |
}
|
197 |
cycrow |
127 |
return s.toWString();
|
1 |
cycrow |
128 |
}
|
|
|
129 |
|
197 |
cycrow |
130 |
bool WriteScriptStyleSheet(const Utils::WString &dest)
|
1 |
cycrow |
131 |
{
|
197 |
cycrow |
132 |
Utils::WStringList list;
|
|
|
133 |
list.pushBack(L"<?xml version=\"1.0\" ?>");
|
|
|
134 |
list.pushBack(L"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >");
|
|
|
135 |
list.pushBack(L"<xsl:template match=\"/\">");
|
|
|
136 |
list.pushBack(L"<html>");
|
|
|
137 |
list.pushBack(L"<head>");
|
|
|
138 |
list.pushBack(L"<title>X3TC Script: <xsl:value-of select=\"script/name\"/></title>");
|
|
|
139 |
list.pushBack(L"</head>");
|
|
|
140 |
list.pushBack(L"<body style=\"color:white;background-color:black\">");
|
|
|
141 |
list.pushBack(L"<xsl:apply-templates/>");
|
|
|
142 |
list.pushBack(L"</body>");
|
|
|
143 |
list.pushBack(L"</html>");
|
|
|
144 |
list.pushBack(L"</xsl:template>");
|
|
|
145 |
list.pushBack(L"<xsl:template match=\"script\">");
|
|
|
146 |
list.pushBack(L"<h1>Script <xsl:value-of select=\"name\"/></h1>");
|
|
|
147 |
list.pushBack(L"Version: <xsl:value-of select=\"version\"/><br/>");
|
|
|
148 |
list.pushBack(L"for Script Engine Version: <xsl:value-of select=\"engineversion\"/><br/>");
|
|
|
149 |
list.pushBack(L"<h3>Description</h3>");
|
|
|
150 |
list.pushBack(L"<xsl:value-of select=\"description\"/>");
|
|
|
151 |
list.pushBack(L"<xsl:apply-templates/>");
|
|
|
152 |
list.pushBack(L"<xsl:choose><xsl:when test=\"signature\"><br/>signed</xsl:when></xsl:choose>");
|
|
|
153 |
list.pushBack(L"</xsl:template>");
|
|
|
154 |
list.pushBack(L"<xsl:template match=\"name\">");
|
|
|
155 |
list.pushBack(L"</xsl:template>");
|
|
|
156 |
list.pushBack(L"<xsl:template match=\"version\">");
|
|
|
157 |
list.pushBack(L"</xsl:template>");
|
|
|
158 |
list.pushBack(L"<xsl:template match=\"engineversion\">");
|
|
|
159 |
list.pushBack(L"</xsl:template>");
|
|
|
160 |
list.pushBack(L"<xsl:template match=\"description\">");
|
|
|
161 |
list.pushBack(L"</xsl:template>");
|
|
|
162 |
list.pushBack(L"<xsl:template match=\"arguments\">");
|
|
|
163 |
list.pushBack(L"<h3>Arguments</h3>");
|
|
|
164 |
list.pushBack(L"<ul>");
|
|
|
165 |
list.pushBack(L"<xsl:apply-templates/>");
|
|
|
166 |
list.pushBack(L"</ul>");
|
|
|
167 |
list.pushBack(L"</xsl:template>");
|
|
|
168 |
list.pushBack(L"<xsl:template match=\"argument\">");
|
|
|
169 |
list.pushBack(L"<li>");
|
|
|
170 |
list.pushBack(L"<xsl:value-of select=\"@index\"/>: <xsl:value-of select=\"@name\"/> , <xsl:value-of select=\"@type\"/> , '<xsl:value-of select=\"@desc\"/>'");
|
|
|
171 |
list.pushBack(L"</li>");
|
|
|
172 |
list.pushBack(L"</xsl:template>");
|
|
|
173 |
list.pushBack(L"<xsl:template match=\"sourcetext\">");
|
|
|
174 |
list.pushBack(L"<h3>Source Text</h3>");
|
|
|
175 |
list.pushBack(L"<div style=\"color:white;background-color:darkgray\">");
|
|
|
176 |
list.pushBack(L"<br/>");
|
|
|
177 |
list.pushBack(L"<code>");
|
|
|
178 |
list.pushBack(L"<xsl:apply-templates/>");
|
|
|
179 |
list.pushBack(L"</code>");
|
|
|
180 |
list.pushBack(L"<br/>");
|
|
|
181 |
list.pushBack(L"</div>");
|
|
|
182 |
list.pushBack(L"</xsl:template>");
|
|
|
183 |
list.pushBack(L"<xsl:template match=\"line\">");
|
|
|
184 |
list.pushBack(L"<b style=\"color:blue\"><xsl:value-of select=\"@linenr\"/> <xsl:choose><xsl:when test=\"@interruptable\"><b style=\"color:cyan\"><xsl:value-of select=\"@interruptable\"/></b></xsl:when><xsl:otherwise> </xsl:otherwise></xsl:choose></b> <b style=\"color:#777777\"><xsl:value-of select=\"translate(@indent,' ','|ÿ')\"/></b><xsl:apply-templates/><br/>");
|
|
|
185 |
list.pushBack(L"</xsl:template>");
|
|
|
186 |
list.pushBack(L"<xsl:template match=\"text\">");
|
|
|
187 |
list.pushBack(L"<xsl:value-of select=\".\"/>");
|
|
|
188 |
list.pushBack(L"</xsl:template>");
|
|
|
189 |
list.pushBack(L"<xsl:template match=\"var\">");
|
|
|
190 |
list.pushBack(L"<b style=\"color:darkgreen\">");
|
|
|
191 |
list.pushBack(L"<xsl:value-of select=\".\"/>");
|
|
|
192 |
list.pushBack(L"</b>");
|
|
|
193 |
list.pushBack(L"</xsl:template>");
|
|
|
194 |
list.pushBack(L"<xsl:template match=\"comment\"><b style=\"color:black\"><xsl:value-of select=\".\"/></b></xsl:template>");
|
|
|
195 |
list.pushBack(L"<xsl:template match=\"call\">'<a><xsl:attribute name=\"href\"><xsl:value-of select=\".\"/>.xml</xsl:attribute><xsl:value-of select=\".\"/></a>'</xsl:template>");
|
|
|
196 |
list.pushBack(L"<xsl:template match=\"codearray\">");
|
|
|
197 |
list.pushBack(L"</xsl:template>");
|
|
|
198 |
list.pushBack(L"<xsl:template match=\"signature\">");
|
|
|
199 |
list.pushBack(L"</xsl:template>");
|
|
|
200 |
list.pushBack(L"</xsl:stylesheet>");
|
1 |
cycrow |
201 |
|
197 |
cycrow |
202 |
CFileIO File(dest + L"/x2script.xsl");
|
160 |
cycrow |
203 |
return File.writeFile(&list);
|
1 |
cycrow |
204 |
}
|
|
|
205 |
|
197 |
cycrow |
206 |
Utils::WString ConvertTimeString(time_t time)
|
1 |
cycrow |
207 |
{
|
|
|
208 |
struct tm *currDate;
|
|
|
209 |
char dateString[100];
|
|
|
210 |
|
|
|
211 |
time_t n = time;
|
|
|
212 |
currDate = localtime(&n);
|
|
|
213 |
strftime(dateString, sizeof dateString, "(%d/%m/%Y) %H:%M", currDate);
|
|
|
214 |
|
197 |
cycrow |
215 |
return Utils::WString(dateString);
|
1 |
cycrow |
216 |
}
|
|
|
217 |
|
197 |
cycrow |
218 |
Utils::WString FormatTextName(int id, int lang, bool newstyle)
|
1 |
cycrow |
219 |
{
|
|
|
220 |
if ( newstyle )
|
197 |
cycrow |
221 |
return Utils::WString::PadNumber(id, 4) + L"-L" + Utils::WString::PadNumber(lang, 3);
|
1 |
cycrow |
222 |
else
|
197 |
cycrow |
223 |
return Utils::WString::Number(lang) + Utils::WString::PadNumber(id, 4);
|
1 |
cycrow |
224 |
}
|
|
|
225 |
};
|