void RocketStorageFileDialog::OnFilesSelected(const QStringList &filenames) { if (filenames.isEmpty()) return; // Pick new or existing directory if (fileMode() == QFileDialog::Directory) emit FolderSelected(filenames.first(), files); // Pick new or existing file else if (fileMode() == QFileDialog::AnyFile) emit FileSelected(filenames.first(), files); // Pick existing files else emit FilesSelected(filenames, confirmOverwrite_); }
CVMInt32 CVMioAvailable(CVMInt32 fd, CVMInt64 *bytes) { int mode; int stat; DWORD cur, end; long stdbytes; #ifndef WINCE if (fd == 0) { if (stdinAvailable(fd, &stdbytes)) { *bytes = (CVMInt64)stdbytes; return 1; } else { return 0; } } #endif stat = fileMode(WIN_GET_HANDLE((HANDLE)fd), &mode); if (stat == 0) { if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) { cur = (DWORD)CVMioSeek(fd, 0, FILE_CURRENT); end = (DWORD)CVMioSeek(fd, 0, FILE_END); if (CVMioSeek(fd, cur, FILE_BEGIN) != -1) { *bytes = CVMlongSub(end, cur); return 1; } } } return 0; }
CVMInt32 POSIXioAvailable(CVMInt32 fd, CVMInt64 *bytes) { CVMInt64 cur, end; int mode; if (fileMode(fd, &mode) >= 0) { if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { int n; if (ioctl(fd, FIONREAD, &n) >= 0) { /* %comment d003 */ *bytes = CVMint2Long(n); return 1; } } } { CVMInt32 cur32, end32; if ((cur32 = lseek(fd, 0L, SEEK_CUR)) == -1) { return 0; } else if ((end32 = lseek(fd, 0L, SEEK_END)) == -1) { return 0; } else if (lseek(fd, cur32, SEEK_SET) == -1) { return 0; } /* %comment d003 */ cur = CVMint2Long(cur32); end = CVMint2Long(end32); } *bytes = CVMlongSub(end, cur); return 1; }
void FileUtils::copyFile(const char* src, const char* dest) throw (IOException) { #ifdef PLATFORM_UNIX std::ifstream inputFile(src,std::ios::binary); std::ofstream outputFile(dest,std::ios::binary | std::ios::trunc); if (!inputFile.good()) { throw IOException("Failed to read file " + std::string(src)); } if (!outputFile.good()) { throw IOException("Failed to write file " + std::string(dest)); } outputFile << inputFile.rdbuf(); if (inputFile.bad()) { throw IOException("Error reading file " + std::string(src)); } if (outputFile.bad()) { throw IOException("Error writing file " + std::string(dest)); } chmod(dest,fileMode(src)); #else if (!CopyFile(src,dest,FALSE)) { throw IOException("Failed to copy " + std::string(src) + " to " + std::string(dest)); } #endif }
void EntityWithMetadataFS::metadata(const none_t t) { if (fileMode() == FileMode::ReadOnly) { throw std::runtime_error("EntityWithMetdata::metadata trying to set metadata in ReadOnly mode."); } if (hasMetadata()) { bfs::path p(location()), m("metadata"), other_loc(p/m); auto sec_tmp = std::make_shared<EntityWithMetadataFS>(file(), other_loc.string()); bfs::path p1(location()), p2("metadata"); sec_tmp->unlink(p1 / p2); bfs::remove_all(p1/p2); } forceUpdatedAt(); }
MYFILE* fopen2(char *pathname, char *mode) { int retaddr, state; int openmode; retaddr = locateFileName(pathname, &state); openmode = fileMode(mode); //ERROR in open mode if (openmode==0) return NULL; //If the file location fails, return -1 if (retaddr == -1) return NULL; //first, file does not exist if (state==0) { if (openmode == 2) { int blockaddr; int fid; char *temp; temp = extractLastName(pathname); blockaddr = createFile(temp , retaddr); fid = getFreeFid(); openFile(blockaddr, fid, openmode); return &fidtable[fid]; } else return NULL; } if (state != FILENODE) return NULL; { int fid; fid = getFreeFid(); openFile(retaddr, fid, openmode); return &fidtable[fid]; } }
void EntityWithMetadataFS::metadata(const std::string &id) { if (fileMode() == FileMode::ReadOnly) { throw std::runtime_error("EntityWithMetdata::metadata trying to set metadata in ReadOnly mode."); } if (id.empty()) throw EmptyString("metadata"); if (hasMetadata()) metadata(none); File tmp = file(); auto found = tmp.findSections(util::IdFilter<Section>(id)); if (found.empty()) throw std::runtime_error("EntityWithMetadataFS::metadata: Section not found in file!"); auto target = std::dynamic_pointer_cast<SectionFS>(found.front().impl()); bfs::path t(target->location()), p(location()), m("metadata"); target->createLink(p / m); }
CVMInt32 POSIXioOpen(const char *name, CVMInt32 openMode, CVMInt32 filePerm) { CVMInt32 fd = open(name, openMode, filePerm); if (fd >= 0) { int mode; int statres = fileMode(fd, &mode); if (statres == -1) { close(fd); return -1; } if (S_ISDIR(mode)) { close(fd); return -1; } } return fd; }
CVMInt32 CVMioOpen(const char *name, CVMInt32 openMode, CVMInt32 filePerm) { DWORD mode = openMode & 0x3; DWORD cFlag; HANDLE fd; int statres; switch (mode) { case _O_RDONLY: mode = GENERIC_READ; break; case _O_WRONLY: mode = GENERIC_WRITE; break; case _O_RDWR: mode = GENERIC_READ | GENERIC_WRITE; break; } cFlag = OPEN_EXISTING; if ((openMode & (_O_CREAT | _O_TRUNC)) == (_O_CREAT | _O_TRUNC)) cFlag = CREATE_ALWAYS; else if (openMode & _O_CREAT) cFlag = OPEN_ALWAYS; else if (openMode & _O_TRUNC) cFlag = TRUNCATE_EXISTING; if ((openMode & (_O_CREAT |_O_EXCL)) == (_O_CREAT |_O_EXCL)) cFlag = CREATE_NEW; #ifdef WINCE { WCHAR *wc; int fdIndex = -1; int i; EnterCriticalSection(&fdTableLock); /* for (i = 0; i < NUM_FDTABLE_ENTRIES; i++) { */ for (i = 3; i < NUM_FDTABLE_ENTRIES; i++) { if (fdTable[i] == INVALID_HANDLE_VALUE) { fdIndex = i; break; } } if (fdIndex == -1) { LeaveCriticalSection(&fdTableLock); return -1; } wc = createWCHAR(name); fdTable[fdIndex] = CreateFile(wc, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, cFlag, FILE_ATTRIBUTE_NORMAL, 0); printf("fdTable[fdIndex] = %d", fdTable[fdIndex]); //djm: Added: Testing if (fdTable[fdIndex] == INVALID_HANDLE_VALUE) { LeaveCriticalSection(&fdTableLock); free(wc); return -1; } fd = (HANDLE)(fdIndex + STD_FDS_BIAS); LeaveCriticalSection(&fdTableLock); free(wc); } #else fd = CreateFileA(name, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, cFlag, FILE_ATTRIBUTE_NORMAL, 0); if (fd == INVALID_HANDLE_VALUE) return -1; #endif statres = fileMode(WIN_GET_HANDLE(fd), &mode); if (statres == -1) { CloseHandle(WIN_GET_HANDLE(fd)); return -1; } if (mode & FILE_ATTRIBUTE_DIRECTORY) { CloseHandle(WIN_GET_HANDLE(fd)); return (CVMInt32)-1; } if (openMode & _O_APPEND) { if (SetFilePointer(WIN_GET_HANDLE(fd), 0, 0, FILE_END) == 0xFFFFFFFF) { CloseHandle(WIN_GET_HANDLE(fd)); return (CVMInt32)-1; } } return (CVMInt32)fd; }