/*--------------------------------------------------------------------------*/ int openHDF5File(const char *name, int _iAppendMode) { hid_t file; char *pathdest = getPathFilename(name); char *currentpath = NULL; char *filename = getFilenameWithExtension(name); int ierr = 0; void *oldclientdata = NULL; /* Used to avoid stack trace to be displayed */ H5E_auto2_t oldfunc; /* TO DO : remove when HDF5 will be fixed ... */ /* HDF5 does not manage no ANSI characters */ /* UGLY workaround :( */ /* We split path, move in this path, open file */ /* and return in previous place */ /* see BUG 6440 */ currentpath = scigetcwd(&ierr); //prevent error msg to change directory to "" if (strcmp(pathdest, "") != 0) { scichdir(pathdest); } /* Save old error handler */ H5Eget_auto2(H5E_DEFAULT, &oldfunc, &oldclientdata); /* Turn off error handling */ H5Eset_auto2(H5E_DEFAULT, NULL, NULL); if (_iAppendMode == 0) { //read only file = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); } else { //read write to append file = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT); } /* The following test will display the backtrace in case of error */ /* Deactivated because displayed each time we call 'load' to open a non-HDF5 file */ /*if (file < 0) { H5Eprint(stderr); }*/ /* Restore previous error handler */ H5Eset_auto2(H5E_DEFAULT, oldfunc, oldclientdata); scichdir(currentpath); FREE(currentpath); FREE(filename); FREE(pathdest); return file; }
bool FileSystemUtil::fileExists(const Common::String &filename) { Common::File f; if (f.exists(filename)) return true; // Check if the file exists in the save folder Common::FSNode folder(PersistenceService::getSavegameDirectory()); Common::FSNode fileNode = folder.getChild(getPathFilename(filename)); return fileNode.exists(); }
/*--------------------------------------------------------------------------*/ int createHDF5File(const char *name) { hid_t file; hid_t fapl = H5Pcreate(H5P_FILE_ACCESS); char *pathdest = getPathFilename(name); char *currentpath = NULL; char *filename = getFilenameWithExtension(name); int ierr = 0; //H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG); /* TO DO : remove when HDF5 will be fixed ... */ /* HDF5 does not manage no ANSI characters */ /* UGLY workaround :( */ /* We split path, move in this path, open file */ /* and return in previous place */ /* see BUG 6440 */ currentpath = scigetcwd(&ierr); //prevent error msg to change directory to "" if (strcmp(pathdest, "") != 0) { scichdir(pathdest); } FREE(pathdest); /*bug 5629 : to prevent replace directory by file*/ if (isdir(filename)) { FREE(filename); FREE(currentpath); return -2; } if (FileExist(filename)) { deleteafile(filename); } /* * Create a new file using the default properties. */ file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); scichdir(currentpath); FREE(currentpath); FREE(filename); return file; }
/*--------------------------------------------------------------------------*/ int isHDF5File(const char* _pstFilename) { int iRet = 0; char *pathdest = getPathFilename(_pstFilename); char *currentpath = NULL; char *filename = getFilenameWithExtension(_pstFilename); int ierr = 0; /* TO DO : remove when HDF5 will be fixed ... */ /* HDF5 does not manage no ANSI characters */ /* UGLY workaround :( */ /* We split path, move in this path, open file */ /* and return in previous place */ /* see BUG 6440 */ currentpath = scigetcwd(&ierr); //prevent error msg to change directory to "" if (strcmp(pathdest, "") != 0) { scichdir(pathdest); } FREE(pathdest); iRet = H5Fis_hdf5(filename); if (iRet == 0) { HDF5ErrorCleanup(); } FREE(filename); scichdir(currentpath); FREE(currentpath); return iRet > 0 ? 1 : 0; }