enum CLocalFileSystem::local_fileType CLocalFileSystem::GetFileType(const wxString& path) { #ifdef __WXMSW__ DWORD result = GetFileAttributes(path); if (result == INVALID_FILE_ATTRIBUTES) return unknown; if (result & FILE_ATTRIBUTE_DIRECTORY) return dir; return file; #else if (path.Last() == wxFileName::GetPathSeparator() && path != wxFileName::GetPathSeparator()) { wxString tmp = path; tmp.RemoveLast(); return GetFileType(tmp); } wxStructStat buf; int result = wxLstat(path, &buf); if (result) return unknown; #ifdef S_ISLNK if (S_ISLNK(buf.st_mode)) return link; #endif if (S_ISDIR(buf.st_mode)) return dir; return file; #endif }
bool CLocalTreeView::HasSubdir(const wxString& dirname) { wxLogNull nullLog; wxDir dir(dirname); if (!dir.IsOpened()) return false; CFilterDialog filter; wxString file; for (bool found = dir.GetFirst(&file, _T(""), wxDIR_DIRS | wxDIR_HIDDEN); found; found = dir.GetNext(&file)) { int attributes; #ifdef __WXMSW__ DWORD tmp = GetFileAttributes(dirname + wxFileName::GetPathSeparator() + file); if (tmp == INVALID_FILE_ATTRIBUTES) attributes = 0; else attributes = tmp; #else wxStructStat buf; const int result = wxLstat(dirname + file, &buf); if (!result) attributes = buf.st_mode & 0x777; else attributes = -1; #endif //__WXMSWMM if (!filter.FilenameFiltered(file, true, -1, true, attributes)) return true; } return false; }
bool FileUtils::IsDirectory(const wxString& filename) { #ifdef __WXMSW__ DWORD dwAttrs = GetFileAttributesW(filename.c_str()); if(dwAttrs == INVALID_FILE_ATTRIBUTES) { return false; } return dwAttrs & FILE_ATTRIBUTE_DIRECTORY; #else wxStructStat buff; if(wxLstat(filename, &buff) != 0) { return false; } return S_ISDIR(buff.st_mode); #endif }
bool FileUtils::IsSymlink(const wxString& filename) { #ifdef __WXMSW__ DWORD dwAttrs = GetFileAttributesW(filename.c_str()); if(dwAttrs == INVALID_FILE_ATTRIBUTES) { return false; } return dwAttrs & FILE_ATTRIBUTE_REPARSE_POINT; #else wxStructStat buff; if(wxLstat(filename, &buff) != 0) { return false; } return S_ISLNK(buff.st_mode); #endif }
bool FileManager::Save(const wxString& name, const wxString& data, wxFontEncoding encoding, bool bom) { if (wxFileExists(name) == false) { wxFile f(name, wxFile::write_excl); return WriteWxStringToFile(f, data, encoding, bom); } else { if (!wxFile::Access(name, wxFile::write)) return false; wxString temp(name); temp.append(wxT(".temp")); wxStructStat buff; wxLstat( name, &buff ); wxFile f; f.Create(temp, true, buff.st_mode); if(WriteWxStringToFile(f, data, encoding, bom)) { f.Close(); if(platform::move(temp, name)) { return true; } else { wxString failed(name); failed.append(wxT(".save-failed")); platform::move(temp, failed); } } return false; } }
bool FileManager::SaveUTF8(const wxString& name, const char* data, size_t len) { if (wxFileExists(name) == false) { return wxFile(name, wxFile::write_excl).Write(data, len) == len; } else { if (!wxFile::Access(name, wxFile::write)) return false; wxString temp(name); temp.append(wxT(".temp")); wxStructStat buff; wxLstat( name, &buff ); wxFile f; f.Create(temp, true, buff.st_mode); if(f.Write(data, len) == len) { f.Close(); if(platform::move(temp, name)) { return true; } else { wxString failed(name); failed.append(wxT(".save-failed")); platform::move(temp, failed); } } return false; } }
enum CLocalFileSystem::local_fileType CLocalFileSystem::GetFileInfo(const wxString& path, bool &isLink, wxLongLong* size, wxDateTime* modificationTime, int *mode) { if (path.Last() == wxFileName::GetPathSeparator() && path != wxFileName::GetPathSeparator()) { wxString tmp = path; tmp.RemoveLast(); return GetFileInfo(tmp, isLink, size, modificationTime, mode); } #ifdef __WXMSW__ isLink = false; WIN32_FILE_ATTRIBUTE_DATA attributes; BOOL result = GetFileAttributesEx(path, GetFileExInfoStandard, &attributes); if (!result) { if (size) *size = -1; if (mode) *mode = 0; return unknown; } if (modificationTime) ConvertFileTimeToWxDateTime(*modificationTime, attributes.ftLastWriteTime); if (mode) *mode = (int)attributes.dwFileAttributes; if (attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (size) *size = -1; return dir; } if (size) *size = wxLongLong(attributes.nFileSizeHigh, attributes.nFileSizeLow); return file; #else wxStructStat buf; int result = wxLstat(path, &buf); if (result) { isLink = false; if (size) *size = -1; if (mode) *mode = -1; return unknown; } #ifdef S_ISLNK if (S_ISLNK(buf.st_mode)) { isLink = true; int result = wxStat(path, &buf); if (result) { if (size) *size = -1; if (mode) *mode = -1; return unknown; } } else #endif isLink = false; if (modificationTime) modificationTime->Set(buf.st_mtime); if (mode) *mode = buf.st_mode & 0x777; if (S_ISDIR(buf.st_mode)) { if (size) *size = -1; return dir; } if (size) *size = buf.st_size; return file; #endif }