]> SALOME platform Git repositories - modules/multipr.git/blobdiff - src/MULTIPR/MULTIPR_Utils.cxx
Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPR / MULTIPR_Utils.cxx
index 6ce5e8ca7084d474b546eebe4a35abab4398382a..a5f9f0c50b33799120fbfeef93e5624c2f47bff0 100644 (file)
@@ -62,6 +62,69 @@ string multipr::removeExtension(const char* pFilename, const char* pExtension)
 }
 
 
+string multipr::getFilenameWithoutPath(const char* pFilename)
+{
+       char* res = strrchr(pFilename, '/');
+       if (res == NULL)
+       {
+               return pFilename;
+       }
+       else
+       {
+               char* name = res + 1;
+               return name;
+       }
+}
+
+
+string multipr::getPath(const char* pFilename)
+{
+       char* res = strrchr(pFilename, '/');
+       if (res == NULL)
+       {
+               return "";
+       }
+       else
+       {
+               int size = res - pFilename + 1;
+               char path[256];
+               memcpy(path, pFilename, size);
+               path[size] = '\0';
+               return path;
+       }
+}
+
+
+void multipr::copyFile(const char* pFilename, const char* pDestDir)
+{
+       const char* srcDir = multipr::getPath(pFilename).c_str();
+       if (strcmp(srcDir, pDestDir) == 0) return;
+       
+       const char* filenameWithoutPath = multipr::getFilenameWithoutPath(pFilename).c_str();
+       char pDstFilename[256];
+       sprintf(pDstFilename, "%s%s", pDestDir, filenameWithoutPath);
+       
+       FILE* src = fopen(pFilename, "rb");
+       if (src == NULL) return;
+       FILE* dst = fopen(pDstFilename, "wb");
+       if (dst == NULL) return;
+       
+       const int size = 65536;
+       char* buf = new char[size];
+       int ret;
+       ret = fread(buf, 1, size, src);
+       while (ret != 0)
+       {
+               fwrite(buf, 1, ret, dst);
+               ret = fread(buf, 1, size, src);
+       }
+       
+       delete[] buf;
+       fclose(src);
+       fclose(dst);
+}
+
+
 void multipr::printArray2D(
        const med_float* pData, 
        const int        pNumElt,