Salome HOME
Merge branch 'occ/new_mg_licnese' of https://codev-tuleap.cea.fr/plugins/git/salome...
[modules/smesh.git] / src / SMESHUtils / SMESH_MGLicenseKeyGen.cxx
index 99336c6a34a28e226cae3228ba8be9858bdfaec1..ec06d988548ae0d1a1a1010a6e161dda1fc55e62 100644 (file)
@@ -152,12 +152,16 @@ namespace
                                  0,
                                  NULL
                                  );
-    if ( msgLen > 0 )
-      error = (char*) cstr;
-
-    LocalFree(cstr);
+    if ( msgLen > 0 ) {
+#  if defined( UNICODE )
+      error = Kernel_Utils::encode_s((wchar_t*)cstr);
+#  else
+      error = (char*)cstr;
+#  endif
+      LocalFree(cstr);
+    }
 
-    return msgLen;
+    return (bool)msgLen;
 
 #endif
   }
@@ -259,11 +263,11 @@ namespace
 
 #ifdef WIN32
 
-    std::string outFile = tmpDir + "libMeshGemsKeyGenerator.dll";
+    std::string outFile = tmpDir + "MeshGemsKeyGenerator.dll";
 
     // use wget (== Invoke-WebRequest) PowerShell command available since Windows 7
     std::string psCmd = "wget -Uri " + url + " -OutFile " + outFile;
-    std::string   cmd = "start powershell.exe " + psCmd;
+    std::string   cmd = "powershell.exe " + psCmd;
 
 #else
 
@@ -290,6 +294,8 @@ namespace
 
     if ( ok )
       libraryFile._name = outFile;
+    else
+      error = "Can't download file " + url;
 
     return ok;
   }
@@ -372,27 +378,27 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
     if ( !loadLibrary( error, libraryFile ))
       return false;
 
+    bool ok = false;
     typedef bool (*SignFun)(void* );
-    SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignCAD" ); 
+    SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignCAD" );
     if ( !signFun )
     {
       if ( ! getLastError( error ))
         error = SMESH_Comment( "Can't find symbol 'SignCAD' in '") << getenv( theEnvVar ) << "'";
     }
+    else
+    {
+      SMESH_TRY;
 
-    bool ok;
-
-    SMESH_TRY;
-
-    ok = signFun( meshgems_cad );
-
-    SMESH_CATCH( SMESH::returnError );
+      ok = signFun( meshgems_cad );
 
-    if ( !error.empty() )
-      ok = false;
-    else if ( !ok )
-      error = "SignCAD() failed (located in '" + libraryFile._name + "')";
+      SMESH_CATCH( SMESH::returnError );
 
+      if ( !error.empty() )
+        ok = false;
+      else if ( !ok )
+        error = "SignCAD() failed (located in '" + libraryFile._name + "')";
+    }
     return ok;
   }
 
@@ -411,6 +417,7 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
     if ( !loadLibrary( error, libraryFile ))
       return false;
 
+    bool ok = false;
     typedef bool (*SignFun)(void* );
     SignFun signFun = (SignFun) GetProc( theLibraryHandle, "SignMesh" );
     if ( !signFun )
@@ -418,19 +425,19 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
       if ( ! getLastError( error ))
         error = SMESH_Comment( "Can't find symbol 'SignMesh' in '") << getenv( theEnvVar ) << "'";
     }
-    bool ok;
-
-    SMESH_TRY;
-
-    ok = signFun( meshgems_mesh );
+    else
+    {
+      SMESH_TRY;
 
-    SMESH_CATCH( SMESH::returnError );
+      ok = signFun( meshgems_mesh );
 
-    if ( !error.empty() )
-      ok = false;
-    else if ( !ok )
-      error = "SignMesh() failed (located in '" + libraryFile._name + "')";
+      SMESH_CATCH( SMESH::returnError );
 
+      if ( !error.empty() )
+        ok = false;
+      else if ( !ok )
+        error = "SignMesh() failed (located in '" + libraryFile._name + "')";
+    }
     return ok;
   }
 
@@ -463,8 +470,10 @@ namespace SMESHUtils_MGLicenseKeyGen // API implementation
       if ( ! getLastError( error ))
         error = SMESH_Comment( "Can't find symbol 'GetKey' in '") << getenv( theEnvVar ) << "'";
     }
-    key = keyFun( gmfFile, nbVertex, nbEdge, nbFace, nbVol );
-
+    else
+    {
+      key = keyFun( gmfFile, nbVertex, nbEdge, nbFace, nbVol );
+    }
     if ( key.empty() )
       error = "GetKey() failed (located in '" + libraryFile._name + "')";