gfxconversion/mifconv/src/mifconv_iconbinaryconverter.cpp
branchRCL_3
changeset 11 e5e3f539dd55
parent 0 f453ebb75370
--- a/gfxconversion/mifconv/src/mifconv_iconbinaryconverter.cpp	Tue May 11 16:43:53 2010 +0300
+++ b/gfxconversion/mifconv/src/mifconv_iconbinaryconverter.cpp	Thu Jul 15 19:16:20 2010 +0300
@@ -175,9 +175,29 @@
  */
 void MifConvIconBinaryConverter::ConvertToBinaryFilename( MifConvString& input )
 {
+    // Change "/" into "\".
+    MifConvUtil::ReplaceChar(input, INCORRECT_DIR_SEPARATOR2, DIR_SEPARATOR2);      
+
+    // Change "\.\" into "_".
+    MifConvString replace_str = "";
+    replace_str += DIR_SEPARATOR2;
+    replace_str += '.';
+    replace_str += DIR_SEPARATOR2;
+    MifConvUtil::ReplaceStr(input, replace_str, "_");
+    
+    // Remove ".\" from start if existing.
+    replace_str = '.';
+    replace_str += DIR_SEPARATOR2;
+    MifConvString::size_type index = input.find(replace_str, 0);
+    if (index == 0) {
+        input = input.substr(replace_str.length(), input.length()-replace_str.length());
+    }
+    
+    // Change "\" into "_".
     MifConvUtil::ReplaceChar(input, DIR_SEPARATOR2, '_');
-    MifConvUtil::ReplaceChar(input, INCORRECT_DIR_SEPARATOR2, '_');
+    // Change ":" into "_".
     MifConvUtil::ReplaceChar(input, ':', '_');
+    // Change " " into "_".
     MifConvUtil::ReplaceChar(input, ' ', '_');
 }
 
@@ -186,6 +206,7 @@
  */
 void MifConvIconBinaryConverter::RunExtConverter()
 {      
+#ifdef WIN32
     MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
    
     // Build svgtbinencode command    
@@ -226,7 +247,7 @@
         // Build temp filename by replacing dir separator and ':' chars with '_':
         MifConvString tmpFileName(i->Filename());
         ConvertToBinaryFilename(tmpFileName);
-
+       
         // Copy source file to temp directory:
         MifConvString to(iTempDir + tmpFileName);        
         if( MifConvUtil::CopyFile(i->Filename(), to) == false )
@@ -238,6 +259,7 @@
         // enclosed with quotation marks. If the whole string is enclosed with quotation marks then it works...
         // For example: command '"\epoc32\tools\bmconv" "somefile"' does not work while command
         // '""\epoc32\tools\bmconv" "somefile""' does.
+               
         if( system(MifConvString("\""+extConverterCommand+"\""+to+"\"\"").c_str()) < 0 )
         {
             int ernro = errno;  // The error number must check straight away before any next system command
@@ -250,6 +272,98 @@
             THROW_ERROR_COMMON(errStr, MifConvString(__FILE__), __LINE__ );
         }
     }
+#else
+    MifConvArgumentManager* argMgr = MifConvArgumentManager::Instance();
+   
+    // Build svgtbinencode command    
+    MifConvString extConverterCommand("\""); // Open the " mark
+    MifConvString versionArgument;
+    MifConvString sourceArgument;    
+        
+    const MifConvString& extConverterPath = argMgr->StringValue(MifConvSvgencodePathArg);
+    const MifConvString& defaultExtConverterPath = GetDefaultExtConverterPath();
+    if( extConverterPath.length() > 0 )
+    {
+        extConverterCommand += extConverterPath; // If the path is given, use it.
+    }
+    else
+    {
+        extConverterCommand += defaultExtConverterPath; // Use default path
+    }
+
+    // Ensure that the last char of the path is dir-separator:
+    if( extConverterCommand.length() > 1 && extConverterCommand.at(extConverterCommand.length()-1) != DIR_SEPARATOR2 )
+        extConverterCommand += DIR_SEPARATOR;
+
+    // Then add SVGTBINENCODE executable call and close the " mark
+    extConverterCommand += SVGTBINENCODE_EXECUTABLE_NAME + MifConvString("\" ");
+   
+    // If SVGTBINENCODE version is given, use it also:
+    const MifConvString& extConverterVersion = argMgr->StringValue(MifConvSvgtVersionArg);
+    if( extConverterVersion.length() > 0 )
+    {        
+        versionArgument = SVGTBINENCODE_OPTION_PREFIX +
+            MifConvString(SVGTBINENCODE_VERSION_PARAMETER) + " " + extConverterVersion;
+        extConverterCommand += versionArgument + " ";
+    }
+   
+    // Run converter for each of the source files:
+    for( MifConvSourceFileList::iterator i = iSourceFiles.begin(); i != iSourceFiles.end(); ++i )
+    {        
+        // Build temp filename by replacing dir separator and ':' chars with '_':
+        MifConvString tmpFileName(i->Filename());
+        
+        MifConvString epoc = std::string(getenv("EPOCROOT"));
+        int len = epoc.length();
+        bool isLongName = (epoc == tmpFileName.substr(0, len));
+
+        ConvertToBinaryFilename(tmpFileName);
+        MifConvString orig=tmpFileName;
+
+       // temporarily skip EPOCROOT to avoid long filename problem in xercers and svgtbinencode
+       if(isLongName)
+           tmpFileName = tmpFileName.substr(len);
+
+       
+        // Copy source file to temp directory:
+        MifConvString to(iTempDir + tmpFileName);        
+        if( MifConvUtil::CopyFile(i->Filename(), to) == false )
+        {
+            THROW_ERROR_COMMON("File copy failed: " + to, MifConvString(__FILE__), __LINE__ );
+        }
+        iTempFilenames.push_back(iTempDir + orig);
+        // It seems that system() function does not work if the command consists of two separate parts 
+        // enclosed with quotation marks. If the whole string is enclosed with quotation marks then it works...
+        // For example: command '"\epoc32\tools\bmconv" "somefile"' does not work while command
+        // '""\epoc32\tools\bmconv" "somefile""' does.
+               
+        if( system(MifConvString(extConverterCommand+"\""+to+"\"").c_str()) < 0 )
+        {
+            int ernro = errno;  // The error number must check straight away before any next system command
+            
+            MifConvString errStr("Executing SVGTBINENCODE failed");
+            if( ernro )
+            {
+                errStr += ", system error = " + MifConvUtil::ToString(ernro);      // Possible system error.
+            }            
+            THROW_ERROR_COMMON(errStr, MifConvString(__FILE__), __LINE__ );
+        }
+       
+        if(isLongName)
+        {
+            // restore original long filename, corresponding to iSourceFiles.
+            rename(to.c_str(), (iTempDir + orig).c_str());
+
+            MifConvString n1 = MifConvUtil::FilenameWithoutExtension(tmpFileName) 
+                               + "." + SVGB_BINARY_FILE_EXTENSION;
+            MifConvString n2 = MifConvUtil::FilenameWithoutExtension(orig) 
+                               + "." + SVGB_BINARY_FILE_EXTENSION;
+
+            rename((iTempDir + n1).c_str(), (iTempDir + n2).c_str());
+        }
+    }
+
+#endif
 }
 
 /**