// Open directory to path, return true if ok. FXbool FXDir::open(const FXString& path){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[MAXPATHLEN]; utf2ncs(buffer,MAXPATHLEN,path.text(),path.length()+1); wcsncat(buffer,TEXT("\\*"),MAXPATHLEN); #else FXchar buffer[MAXPATHLEN]; strncpy(buffer,path.text(),MAXPATHLEN); strncat(buffer,"\\*",MAXPATHLEN); #endif ((SPACE*)space)->handle=FindFirstFile(buffer,&((SPACE*)space)->result); if(((SPACE*)space)->handle!=INVALID_HANDLE_VALUE){ ((SPACE*)space)->first=true; return true; } #else ((SPACE*)space)->handle=opendir(path.text()); if(((SPACE*)space)->handle!=NULL){ return true; } #endif } return false; }
// Rename directory FXbool FXDir::rename(const FXString& srcpath,const FXString& dstpath){ if(srcpath!=dstpath){ #ifdef WIN32 #ifdef UNICODE FXnchar oldname[MAXPATHLEN],newname[MAXPATHLEN]; utf2ncs(oldname,MAXPATHLEN,srcpath.text(),srcpath.length()+1); utf2ncs(newname,MAXPATHLEN,dstpath.text(),dstpath.length()+1); return ::MoveFileExW(oldname,newname,MOVEFILE_REPLACE_EXISTING)!=0; #else return ::MoveFileExA(srcpath.text(),dstpath.text(),MOVEFILE_REPLACE_EXISTING)!=0; #endif #else return ::rename(srcpath.text(),dstpath.text())==0; #endif } return false; }
// Link file bool FXFile::link(const FXString& oldfile,const FXString& newfile){ if(newfile!=oldfile){ #ifdef WIN32 #ifdef UNICODE FXnchar oldname[1024],newname[1024]; utf2ncs(oldname,oldfile.text(),oldfile.length()+1); utf2ncs(newname,newfile.text(),newfile.length()+1); return MyCreateHardLink(newname,oldname,NULL)!=0; #else return MyCreateHardLink(newfile.text(),oldfile.text(),NULL)!=0; #endif #else return ::link(oldfile.text(),newfile.text())==0; #endif } return false; }
// Rename file bool FXFile::rename(const FXString& srcfile,const FXString& dstfile){ if(srcfile!=dstfile){ #ifdef WIN32 #ifdef UNICODE FXnchar oldname[1024],newname[1024]; utf2ncs(oldname,srcfile.text(),srcfile.length()+1); utf2ncs(newname,dstfile.text(),dstfile.length()+1); return ::MoveFileExW(oldname,newname,MOVEFILE_REPLACE_EXISTING)!=0; #else return ::MoveFileExA(srcfile.text(),dstfile.text(),MOVEFILE_REPLACE_EXISTING)!=0; #endif #else return ::rename(srcfile.text(),dstfile.text())==0; #endif } return false; }
// Return true if files are identical bool FXFile::identical(const FXString& file1,const FXString& file2){ if(file1!=file2){ #ifdef WIN32 BY_HANDLE_FILE_INFORMATION info1,info2; HANDLE hFile1,hFile2; bool same=false; #ifdef UNICODE FXnchar name1[1024],name2[1024]; utf2ncs(name1,file1.text(),file1.length()+1); utf2ncs(name2,file2.text(),file2.length()+1); hFile1=::CreateFile(name1,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile1!=INVALID_HANDLE_VALUE){ hFile2=::CreateFile(name2,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile2!=INVALID_HANDLE_VALUE){ if(::GetFileInformationByHandle(hFile1,&info1) && ::GetFileInformationByHandle(hFile2,&info2)){ same=(info1.nFileIndexLow==info2.nFileIndexLow && info1.nFileIndexHigh==info2.nFileIndexHigh && info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber); } ::CloseHandle(hFile2); } ::CloseHandle(hFile1); } return same; #else hFile1=::CreateFile(file1.text(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile1!=INVALID_HANDLE_VALUE){ hFile2=::CreateFile(file2.text(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile2!=INVALID_HANDLE_VALUE){ if(::GetFileInformationByHandle(hFile1,&info1) && ::GetFileInformationByHandle(hFile2,&info2)){ same=(info1.nFileIndexLow==info2.nFileIndexLow && info1.nFileIndexHigh==info2.nFileIndexHigh && info1.dwVolumeSerialNumber==info2.dwVolumeSerialNumber); } ::CloseHandle(hFile2); } ::CloseHandle(hFile1); } return same; #endif #else struct stat stat1,stat2; return !::lstat(file1.text(),&stat1) && !::lstat(file2.text(),&stat2) && stat1.st_ino==stat2.st_ino && stat1.st_dev==stat2.st_dev; #endif } return true; }
// Change current directory FXbool FXSystem::setCurrentDirectory(const FXString& path){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE TCHAR buffer[MAXPATHLEN]; utf2ncs(buffer,path.text(),path.length()+1); return SetCurrentDirectory(buffer); #else return SetCurrentDirectory(path.text()); #endif #else return chdir(path.text())==0; #endif } return FALSE; }
// Remove directory FXbool FXDir::remove(const FXString& path){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[MAXPATHLEN]; utf2ncs(buffer,MAXPATHLEN,path.text(),path.length()+1); return RemoveDirectoryW(buffer)!=0; #else return RemoveDirectoryA(path.text())!=0; #endif #else return ::rmdir(path.text())==0; #endif } return false; }
// Create new directory FXbool FXDir::create(const FXString& path,FXuint perm){ if(!path.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[MAXPATHLEN]; utf2ncs(buffer,MAXPATHLEN,path.text(),path.length()+1); return CreateDirectoryW(buffer,NULL)!=0; #else return CreateDirectoryA(path.text(),NULL)!=0; #endif #else return ::mkdir(path.text(),perm)==0; #endif } return false; }
// Remove a file bool FXFile::remove(const FXString& file){ if(!file.empty()){ #ifdef WIN32 #ifdef UNICODE FXnchar buffer[1024]; utf2ncs(buffer,file.text(),file.length()+1); return ::DeleteFileW(buffer)!=0; #else return ::DeleteFileA(file.text())!=0; #endif #else return ::unlink(file.text())==0; #endif } return false; }