Subversion Repositories spk

Rev

Rev 196 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 196 Rev 197
Line 2... Line 2...
2
 
2
 
3
namespace SPK {
3
namespace SPK {
4
	s_int GetAutomaticFiletype(const Utils::String &file, Utils::String *extradir, bool bUseSpecial)
4
	s_int GetAutomaticFiletype(const Utils::WString &file, Utils::WString *extradir, bool bUseSpecial)
5
	{
5
	{
6
		CFileIO File(file);
6
		CFileIO File(file);
7
		Utils::WString dir = File.GetDirIO().topDir();
7
		Utils::WString dir = File.GetDirIO().topDir();
8
 
8
 
9
		Utils::WString basename = File.baseName();
9
		Utils::WString basename = File.baseName();
Line 11... Line 11...
11
		s_int type = -1;
11
		s_int type = -1;
12
		if ( dir.Compare(L"types") || dir.Compare(L"mov") || dir.Compare(L"s") )
12
		if ( dir.Compare(L"types") || dir.Compare(L"mov") || dir.Compare(L"s") )
13
		{
13
		{
14
			type = FILETYPE_EXTRA;
14
			type = FILETYPE_EXTRA;
15
			if ( extradir )
15
			if ( extradir )
16
				*extradir = dir.toString();
16
				*extradir = dir;
17
		}
17
		}
18
		else if ( File.isFileExtension(L"xml") || File.isFileExtension(L"pck") )
18
		else if ( File.isFileExtension(L"xml") || File.isFileExtension(L"pck") )
19
		{
19
		{
20
			// TC text file
20
			// TC text file
21
			type = FILETYPE_SCRIPT;
21
			type = FILETYPE_SCRIPT;
Line 70... Line 70...
70
 
70
 
71
		return type;
71
		return type;
72
	}
72
	}
73
 
73
 
74
	//TODO: check for special types
74
	//TODO: check for special types
75
	void AssignAutomaticFiletypes(const Utils::CStringList &list)	
75
	void AssignAutomaticFiletypes(const Utils::WStringList &list)	
76
	{
76
	{
77
		for(auto itr = list.begin(); itr != list.end(); itr++)
77
		for(auto itr = list.begin(); itr != list.end(); itr++)
78
		{
78
		{
79
			Utils::String extradir;
79
			Utils::WString extradir;
80
			s_int type = SPK::GetAutomaticFiletype((*itr)->str, &extradir, false);
80
			s_int type = SPK::GetAutomaticFiletype((*itr)->str, &extradir, false);
81
 
81
 
82
			if ( type == FILETYPE_EXTRA && !extradir.empty() )
82
			if ( type == FILETYPE_EXTRA && !extradir.empty() )
83
				(*itr)->data = Utils::String::Number(type) + " " + extradir;
83
				(*itr)->data = Utils::WString::Number(type) + L" " + extradir;
84
			else
84
			else
85
				(*itr)->data = Utils::String::Number(type);
85
				(*itr)->data = Utils::WString::Number(type);
86
		}
86
		}
87
	}
87
	}
88
 
88
 
89
	Utils::String GetSizeString ( unsigned long lSize)
89
	Utils::WString GetSizeString ( unsigned long lSize)
90
	{
90
	{
91
		float size = (float)lSize;
91
		float size = (float)lSize;
92
 
92
 
93
		int level = 0;
93
		int level = 0;
94
		while ( size > 1000 )
94
		while ( size > 1000 )
Line 122... Line 122...
122
				SPRINTF(str, "%.3f"), size );
122
				SPRINTF(str, "%.3f"), size );
123
				s = str;
123
				s = str;
124
				s += "GB";
124
				s += "GB";
125
				break;
125
				break;
126
		}
126
		}
127
		return s;
127
		return s.toWString();
128
	}
128
	}
129
 
129
 
130
	bool WriteScriptStyleSheet(const Utils::String &dest)
130
	bool WriteScriptStyleSheet(const Utils::WString &dest)
131
	{
131
	{
132
		Utils::CStringList list;
132
		Utils::WStringList list;
133
		list.pushBack("<?xml version=\"1.0\" ?>");
133
		list.pushBack(L"<?xml version=\"1.0\" ?>");
134
		list.pushBack("<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >");
134
		list.pushBack(L"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >");
135
		list.pushBack("<xsl:template match=\"/\">");
135
		list.pushBack(L"<xsl:template match=\"/\">");
136
		list.pushBack("<html>");
136
		list.pushBack(L"<html>");
137
		list.pushBack("<head>");
137
		list.pushBack(L"<head>");
138
		list.pushBack("<title>X3TC Script: <xsl:value-of select=\"script/name\"/></title>");
138
		list.pushBack(L"<title>X3TC Script: <xsl:value-of select=\"script/name\"/></title>");
139
		list.pushBack("</head>");
139
		list.pushBack(L"</head>");
140
		list.pushBack("<body style=\"color:white;background-color:black\">");
140
		list.pushBack(L"<body style=\"color:white;background-color:black\">");
141
		list.pushBack("<xsl:apply-templates/>");
141
		list.pushBack(L"<xsl:apply-templates/>");
142
		list.pushBack("</body>");
142
		list.pushBack(L"</body>");
143
		list.pushBack("</html>");
143
		list.pushBack(L"</html>");
144
		list.pushBack("</xsl:template>");
144
		list.pushBack(L"</xsl:template>");
145
		list.pushBack("<xsl:template match=\"script\">");
145
		list.pushBack(L"<xsl:template match=\"script\">");
146
		list.pushBack("<h1>Script <xsl:value-of select=\"name\"/></h1>");
146
		list.pushBack(L"<h1>Script <xsl:value-of select=\"name\"/></h1>");
147
		list.pushBack("Version: <xsl:value-of select=\"version\"/><br/>");
147
		list.pushBack(L"Version: <xsl:value-of select=\"version\"/><br/>");
148
		list.pushBack("for Script Engine Version: <xsl:value-of select=\"engineversion\"/><br/>");
148
		list.pushBack(L"for Script Engine Version: <xsl:value-of select=\"engineversion\"/><br/>");
149
		list.pushBack("<h3>Description</h3>");
149
		list.pushBack(L"<h3>Description</h3>");
150
		list.pushBack("<xsl:value-of select=\"description\"/>");
150
		list.pushBack(L"<xsl:value-of select=\"description\"/>");
151
		list.pushBack("<xsl:apply-templates/>");
151
		list.pushBack(L"<xsl:apply-templates/>");
152
		list.pushBack("<xsl:choose><xsl:when test=\"signature\"><br/>signed</xsl:when></xsl:choose>");
152
		list.pushBack(L"<xsl:choose><xsl:when test=\"signature\"><br/>signed</xsl:when></xsl:choose>");
153
		list.pushBack("</xsl:template>");
153
		list.pushBack(L"</xsl:template>");
154
		list.pushBack("<xsl:template match=\"name\">");
154
		list.pushBack(L"<xsl:template match=\"name\">");
155
		list.pushBack("</xsl:template>");
155
		list.pushBack(L"</xsl:template>");
156
		list.pushBack("<xsl:template match=\"version\">");
156
		list.pushBack(L"<xsl:template match=\"version\">");
157
		list.pushBack("</xsl:template>");
157
		list.pushBack(L"</xsl:template>");
158
		list.pushBack("<xsl:template match=\"engineversion\">");
158
		list.pushBack(L"<xsl:template match=\"engineversion\">");
159
		list.pushBack("</xsl:template>");
159
		list.pushBack(L"</xsl:template>");
160
		list.pushBack("<xsl:template match=\"description\">");
160
		list.pushBack(L"<xsl:template match=\"description\">");
161
		list.pushBack("</xsl:template>");
161
		list.pushBack(L"</xsl:template>");
162
		list.pushBack("<xsl:template match=\"arguments\">");
162
		list.pushBack(L"<xsl:template match=\"arguments\">");
163
		list.pushBack("<h3>Arguments</h3>");
163
		list.pushBack(L"<h3>Arguments</h3>");
164
		list.pushBack("<ul>");
164
		list.pushBack(L"<ul>");
165
		list.pushBack("<xsl:apply-templates/>");
165
		list.pushBack(L"<xsl:apply-templates/>");
166
		list.pushBack("</ul>");
166
		list.pushBack(L"</ul>");
167
		list.pushBack("</xsl:template>");
167
		list.pushBack(L"</xsl:template>");
168
		list.pushBack("<xsl:template match=\"argument\">");
168
		list.pushBack(L"<xsl:template match=\"argument\">");
169
		list.pushBack("<li>");
169
		list.pushBack(L"<li>");
170
		list.pushBack("<xsl:value-of select=\"@index\"/>: <xsl:value-of select=\"@name\"/> , <xsl:value-of select=\"@type\"/> , '<xsl:value-of select=\"@desc\"/>'");
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("</li>");
171
		list.pushBack(L"</li>");
172
		list.pushBack("</xsl:template>");
172
		list.pushBack(L"</xsl:template>");
173
		list.pushBack("<xsl:template match=\"sourcetext\">");
173
		list.pushBack(L"<xsl:template match=\"sourcetext\">");
174
		list.pushBack("<h3>Source Text</h3>");
174
		list.pushBack(L"<h3>Source Text</h3>");
175
		list.pushBack("<div style=\"color:white;background-color:darkgray\">");
175
		list.pushBack(L"<div style=\"color:white;background-color:darkgray\">");
176
		list.pushBack("<br/>");
176
		list.pushBack(L"<br/>");
177
		list.pushBack("<code>");
177
		list.pushBack(L"<code>");
178
		list.pushBack("<xsl:apply-templates/>");
178
		list.pushBack(L"<xsl:apply-templates/>");
179
		list.pushBack("</code>");
179
		list.pushBack(L"</code>");
180
		list.pushBack("<br/>");
180
		list.pushBack(L"<br/>");
181
		list.pushBack("</div>");
181
		list.pushBack(L"</div>");
182
		list.pushBack("</xsl:template>");
182
		list.pushBack(L"</xsl:template>");
183
		list.pushBack("<xsl:template match=\"line\">");
183
		list.pushBack(L"<xsl:template match=\"line\">");
184
		list.pushBack("<b style=\"color:blue\"><xsl:value-of select=\"@linenr\"/>&#160;<xsl:choose><xsl:when test=\"@interruptable\"><b style=\"color:cyan\"><xsl:value-of select=\"@interruptable\"/></b></xsl:when><xsl:otherwise>&#160;</xsl:otherwise></xsl:choose></b>&#160;<b style=\"color:#777777\"><xsl:value-of select=\"translate(@indent,'&#160;','|&#255;')\"/></b><xsl:apply-templates/><br/>");
184
		list.pushBack(L"<b style=\"color:blue\"><xsl:value-of select=\"@linenr\"/>&#160;<xsl:choose><xsl:when test=\"@interruptable\"><b style=\"color:cyan\"><xsl:value-of select=\"@interruptable\"/></b></xsl:when><xsl:otherwise>&#160;</xsl:otherwise></xsl:choose></b>&#160;<b style=\"color:#777777\"><xsl:value-of select=\"translate(@indent,'&#160;','|&#255;')\"/></b><xsl:apply-templates/><br/>");
185
		list.pushBack("</xsl:template>");
185
		list.pushBack(L"</xsl:template>");
186
		list.pushBack("<xsl:template match=\"text\">");
186
		list.pushBack(L"<xsl:template match=\"text\">");
187
		list.pushBack("<xsl:value-of select=\".\"/>");
187
		list.pushBack(L"<xsl:value-of select=\".\"/>");
188
		list.pushBack("</xsl:template>");
188
		list.pushBack(L"</xsl:template>");
189
		list.pushBack("<xsl:template match=\"var\">");
189
		list.pushBack(L"<xsl:template match=\"var\">");
190
		list.pushBack("<b style=\"color:darkgreen\">");
190
		list.pushBack(L"<b style=\"color:darkgreen\">");
191
		list.pushBack("<xsl:value-of select=\".\"/>");
191
		list.pushBack(L"<xsl:value-of select=\".\"/>");
192
		list.pushBack("</b>");
192
		list.pushBack(L"</b>");
193
		list.pushBack("</xsl:template>");
193
		list.pushBack(L"</xsl:template>");
194
		list.pushBack("<xsl:template match=\"comment\"><b style=\"color:black\"><xsl:value-of select=\".\"/></b></xsl:template>");
194
		list.pushBack(L"<xsl:template match=\"comment\"><b style=\"color:black\"><xsl:value-of select=\".\"/></b></xsl:template>");
195
		list.pushBack("<xsl:template match=\"call\">'<a><xsl:attribute name=\"href\"><xsl:value-of select=\".\"/>.xml</xsl:attribute><xsl:value-of select=\".\"/></a>'</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("<xsl:template match=\"codearray\">");
196
		list.pushBack(L"<xsl:template match=\"codearray\">");
197
		list.pushBack("</xsl:template>");
197
		list.pushBack(L"</xsl:template>");
198
		list.pushBack("<xsl:template match=\"signature\">");
198
		list.pushBack(L"<xsl:template match=\"signature\">");
199
		list.pushBack("</xsl:template>");
199
		list.pushBack(L"</xsl:template>");
200
		list.pushBack("</xsl:stylesheet>");
200
		list.pushBack(L"</xsl:stylesheet>");
201
 
201
 
202
		CFileIO File(dest + "/x2script.xsl");
202
		CFileIO File(dest + L"/x2script.xsl");
203
		return File.writeFile(&list);
203
		return File.writeFile(&list);
204
	}
204
	}
205
 
205
 
206
	Utils::String ConvertTimeString(time_t time)
206
	Utils::WString ConvertTimeString(time_t time)
207
	{
207
	{
208
		struct tm   *currDate;
208
		struct tm   *currDate;
209
		char    dateString[100];
209
		char    dateString[100];
210
 
210
 
211
		time_t n = time;
211
		time_t n = time;
212
		currDate = localtime(&n);
212
		currDate = localtime(&n);
213
		strftime(dateString, sizeof dateString, "(%d/%m/%Y) %H:%M", currDate);
213
		strftime(dateString, sizeof dateString, "(%d/%m/%Y) %H:%M", currDate);
214
 
214
 
215
		return Utils::String(dateString);
215
		return Utils::WString(dateString);
216
	}
216
	}
217
 
217
 
218
	Utils::String FormatTextName(int id, int lang, bool newstyle)
218
	Utils::WString FormatTextName(int id, int lang, bool newstyle)
219
	{
219
	{
220
		if ( newstyle )
220
		if ( newstyle )
221
			return Utils::String::PadNumber(id, 4) + "-L" + Utils::String::PadNumber(lang, 3);
221
			return Utils::WString::PadNumber(id, 4) + L"-L" + Utils::WString::PadNumber(lang, 3);
222
		else
222
		else
223
			return Utils::String::Number(lang) + Utils::String::PadNumber(id, 4);
223
			return Utils::WString::Number(lang) + Utils::WString::PadNumber(id, 4);
224
	}
224
	}
225
};
225
};