173 /** |
173 /** |
174 * |
174 * |
175 */ |
175 */ |
176 void MifConvIconBinaryConverter::ConvertToBinaryFilename( MifConvString& input ) |
176 void MifConvIconBinaryConverter::ConvertToBinaryFilename( MifConvString& input ) |
177 { |
177 { |
|
178 // Change "/" into "\". |
|
179 MifConvUtil::ReplaceChar(input, INCORRECT_DIR_SEPARATOR2, DIR_SEPARATOR2); |
|
180 |
|
181 // Change "\.\" into "_". |
|
182 MifConvString replace_str = ""; |
|
183 replace_str += DIR_SEPARATOR2; |
|
184 replace_str += '.'; |
|
185 replace_str += DIR_SEPARATOR2; |
|
186 MifConvUtil::ReplaceStr(input, replace_str, "_"); |
|
187 |
|
188 // Remove ".\" from start if existing. |
|
189 replace_str = '.'; |
|
190 replace_str += DIR_SEPARATOR2; |
|
191 MifConvString::size_type index = input.find(replace_str, 0); |
|
192 if (index == 0) { |
|
193 input = input.substr(replace_str.length(), input.length()-replace_str.length()); |
|
194 } |
|
195 |
|
196 // Change "\" into "_". |
178 MifConvUtil::ReplaceChar(input, DIR_SEPARATOR2, '_'); |
197 MifConvUtil::ReplaceChar(input, DIR_SEPARATOR2, '_'); |
179 MifConvUtil::ReplaceChar(input, INCORRECT_DIR_SEPARATOR2, '_'); |
198 // Change ":" into "_". |
180 MifConvUtil::ReplaceChar(input, ':', '_'); |
199 MifConvUtil::ReplaceChar(input, ':', '_'); |
|
200 // Change " " into "_". |
181 MifConvUtil::ReplaceChar(input, ' ', '_'); |
201 MifConvUtil::ReplaceChar(input, ' ', '_'); |
182 } |
202 } |
183 |
203 |
184 /** |
204 /** |
185 * |
205 * |
186 */ |
206 */ |
187 void MifConvIconBinaryConverter::RunExtConverter() |
207 void MifConvIconBinaryConverter::RunExtConverter() |
188 { |
208 { |
|
209 #ifdef WIN32 |
189 MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance(); |
210 MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance(); |
190 |
211 |
191 // Build svgtbinencode command |
212 // Build svgtbinencode command |
192 MifConvString extConverterCommand("\""); // Open the " mark |
213 MifConvString extConverterCommand("\""); // Open the " mark |
193 MifConvString versionArgument; |
214 MifConvString versionArgument; |
224 for( MifConvSourceFileList::iterator i = iSourceFiles.begin(); i != iSourceFiles.end(); ++i ) |
245 for( MifConvSourceFileList::iterator i = iSourceFiles.begin(); i != iSourceFiles.end(); ++i ) |
225 { |
246 { |
226 // Build temp filename by replacing dir separator and ':' chars with '_': |
247 // Build temp filename by replacing dir separator and ':' chars with '_': |
227 MifConvString tmpFileName(i->Filename()); |
248 MifConvString tmpFileName(i->Filename()); |
228 ConvertToBinaryFilename(tmpFileName); |
249 ConvertToBinaryFilename(tmpFileName); |
229 |
250 |
230 // Copy source file to temp directory: |
251 // Copy source file to temp directory: |
231 MifConvString to(iTempDir + tmpFileName); |
252 MifConvString to(iTempDir + tmpFileName); |
232 if( MifConvUtil::CopyFile(i->Filename(), to) == false ) |
253 if( MifConvUtil::CopyFile(i->Filename(), to) == false ) |
233 { |
254 { |
234 THROW_ERROR_COMMON("File copy failed: " + to, MifConvString(__FILE__), __LINE__ ); |
255 THROW_ERROR_COMMON("File copy failed: " + to, MifConvString(__FILE__), __LINE__ ); |
236 iTempFilenames.push_back(to); |
257 iTempFilenames.push_back(to); |
237 // It seems that system() function does not work if the command consists of two separate parts |
258 // It seems that system() function does not work if the command consists of two separate parts |
238 // enclosed with quotation marks. If the whole string is enclosed with quotation marks then it works... |
259 // enclosed with quotation marks. If the whole string is enclosed with quotation marks then it works... |
239 // For example: command '"\epoc32\tools\bmconv" "somefile"' does not work while command |
260 // For example: command '"\epoc32\tools\bmconv" "somefile"' does not work while command |
240 // '""\epoc32\tools\bmconv" "somefile""' does. |
261 // '""\epoc32\tools\bmconv" "somefile""' does. |
|
262 |
241 if( system(MifConvString("\""+extConverterCommand+"\""+to+"\"\"").c_str()) < 0 ) |
263 if( system(MifConvString("\""+extConverterCommand+"\""+to+"\"\"").c_str()) < 0 ) |
242 { |
264 { |
243 int ernro = errno; // The error number must check straight away before any next system command |
265 int ernro = errno; // The error number must check straight away before any next system command |
244 |
266 |
245 MifConvString errStr("Executing SVGTBINENCODE failed"); |
267 MifConvString errStr("Executing SVGTBINENCODE failed"); |
248 errStr += ", system error = " + MifConvUtil::ToString(ernro); // Possible system error. |
270 errStr += ", system error = " + MifConvUtil::ToString(ernro); // Possible system error. |
249 } |
271 } |
250 THROW_ERROR_COMMON(errStr, MifConvString(__FILE__), __LINE__ ); |
272 THROW_ERROR_COMMON(errStr, MifConvString(__FILE__), __LINE__ ); |
251 } |
273 } |
252 } |
274 } |
|
275 #else |
|
276 MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance(); |
|
277 |
|
278 // Build svgtbinencode command |
|
279 MifConvString extConverterCommand("\""); // Open the " mark |
|
280 MifConvString versionArgument; |
|
281 MifConvString sourceArgument; |
|
282 |
|
283 const MifConvString& extConverterPath = argMgr->StringValue(MifConvSvgencodePathArg); |
|
284 const MifConvString& defaultExtConverterPath = GetDefaultExtConverterPath(); |
|
285 if( extConverterPath.length() > 0 ) |
|
286 { |
|
287 extConverterCommand += extConverterPath; // If the path is given, use it. |
|
288 } |
|
289 else |
|
290 { |
|
291 extConverterCommand += defaultExtConverterPath; // Use default path |
|
292 } |
|
293 |
|
294 // Ensure that the last char of the path is dir-separator: |
|
295 if( extConverterCommand.length() > 1 && extConverterCommand.at(extConverterCommand.length()-1) != DIR_SEPARATOR2 ) |
|
296 extConverterCommand += DIR_SEPARATOR; |
|
297 |
|
298 // Then add SVGTBINENCODE executable call and close the " mark |
|
299 extConverterCommand += SVGTBINENCODE_EXECUTABLE_NAME + MifConvString("\" "); |
|
300 |
|
301 // If SVGTBINENCODE version is given, use it also: |
|
302 const MifConvString& extConverterVersion = argMgr->StringValue(MifConvSvgtVersionArg); |
|
303 if( extConverterVersion.length() > 0 ) |
|
304 { |
|
305 versionArgument = SVGTBINENCODE_OPTION_PREFIX + |
|
306 MifConvString(SVGTBINENCODE_VERSION_PARAMETER) + " " + extConverterVersion; |
|
307 extConverterCommand += versionArgument + " "; |
|
308 } |
|
309 |
|
310 // Run converter for each of the source files: |
|
311 for( MifConvSourceFileList::iterator i = iSourceFiles.begin(); i != iSourceFiles.end(); ++i ) |
|
312 { |
|
313 // Build temp filename by replacing dir separator and ':' chars with '_': |
|
314 MifConvString tmpFileName(i->Filename()); |
|
315 |
|
316 MifConvString epoc = std::string(getenv("EPOCROOT")); |
|
317 int len = epoc.length(); |
|
318 bool isLongName = (epoc == tmpFileName.substr(0, len)); |
|
319 |
|
320 ConvertToBinaryFilename(tmpFileName); |
|
321 MifConvString orig=tmpFileName; |
|
322 |
|
323 // temporarily skip EPOCROOT to avoid long filename problem in xercers and svgtbinencode |
|
324 if(isLongName) |
|
325 tmpFileName = tmpFileName.substr(len); |
|
326 |
|
327 |
|
328 // Copy source file to temp directory: |
|
329 MifConvString to(iTempDir + tmpFileName); |
|
330 if( MifConvUtil::CopyFile(i->Filename(), to) == false ) |
|
331 { |
|
332 THROW_ERROR_COMMON("File copy failed: " + to, MifConvString(__FILE__), __LINE__ ); |
|
333 } |
|
334 iTempFilenames.push_back(iTempDir + orig); |
|
335 // It seems that system() function does not work if the command consists of two separate parts |
|
336 // enclosed with quotation marks. If the whole string is enclosed with quotation marks then it works... |
|
337 // For example: command '"\epoc32\tools\bmconv" "somefile"' does not work while command |
|
338 // '""\epoc32\tools\bmconv" "somefile""' does. |
|
339 |
|
340 if( system(MifConvString(extConverterCommand+"\""+to+"\"").c_str()) < 0 ) |
|
341 { |
|
342 int ernro = errno; // The error number must check straight away before any next system command |
|
343 |
|
344 MifConvString errStr("Executing SVGTBINENCODE failed"); |
|
345 if( ernro ) |
|
346 { |
|
347 errStr += ", system error = " + MifConvUtil::ToString(ernro); // Possible system error. |
|
348 } |
|
349 THROW_ERROR_COMMON(errStr, MifConvString(__FILE__), __LINE__ ); |
|
350 } |
|
351 |
|
352 if(isLongName) |
|
353 { |
|
354 // restore original long filename, corresponding to iSourceFiles. |
|
355 rename(to.c_str(), (iTempDir + orig).c_str()); |
|
356 |
|
357 MifConvString n1 = MifConvUtil::FilenameWithoutExtension(tmpFileName) |
|
358 + "." + SVGB_BINARY_FILE_EXTENSION; |
|
359 MifConvString n2 = MifConvUtil::FilenameWithoutExtension(orig) |
|
360 + "." + SVGB_BINARY_FILE_EXTENSION; |
|
361 |
|
362 rename((iTempDir + n1).c_str(), (iTempDir + n2).c_str()); |
|
363 } |
|
364 } |
|
365 |
|
366 #endif |
253 } |
367 } |
254 |
368 |
255 /** |
369 /** |
256 * |
370 * |
257 */ |
371 */ |