void begin_cp_task(void) { int sfd = do_open_file(src_file,O_RDONLY,0444); Log("sfd=%d",sfd); if(sfd <= 0) { Log("[Error]=file:%s open failed.",src_file); return 0; } int size = do_read_file(sfd,g_info.user_buf.buf,g_info.user_buf.len); Log("read size=%d",size); do_close_file(sfd); int dfd=do_open_file(dst_file,O_RDWR,0777); Log("dfd=%d",dfd); if(dfd <= 0) { Log("[Error]=file:%s open failed.",dst_file); return 0; } size = do_write_file(dfd, g_info.user_buf.buf,size); Log("write size=%d",size); do_close_file(dfd); }
void open_file(HWND hwnd) { Bool res; char ext_list[4096]; strcpy(ext_list, ""); gf_freeze_display(1); u32 count = gf_cfg_get_key_count(user.config, "MimeTypes"); for (u32 i=0; i<count; i++) { char szKeyList[1000], *sKey; const char *sMime = gf_cfg_get_key_name(user.config, "MimeTypes", i); const char *opt = gf_cfg_get_key(user.config, "MimeTypes", sMime); strcpy(szKeyList, opt+1); sKey = strrchr(szKeyList, '\"'); if (!sKey) continue; sKey[0] = 0; strcat(ext_list, szKeyList); strcat(ext_list, " "); } #ifdef _WIN32_WCE res = gf_file_dialog(g_hinst, hwnd, the_url, ext_list, user.config); #else res = 0; #endif gf_freeze_display(0); /*let's go*/ if (res) do_open_file(); }
void switch_playlist(Bool play_prev) { char szPLE[20]; u32 idx = 0; u32 count; const char *ple = gf_cfg_get_key(user.config, "General", "PLEntry"); if (ple) idx = atoi(ple); count = gf_cfg_get_key_count(user.config, "Playlist"); if (!count) return; /*not the first launch*/ if (strlen(the_url)) { if (!idx && play_prev) return; if (play_prev) idx--; else idx++; if (idx>=count) return; } else { if (idx>=count) idx=0; } ple = gf_cfg_get_key_name(user.config, "Playlist", idx); if (!ple) return; sprintf(szPLE, "%d", idx); gf_cfg_set_key(user.config, "General", "PLEntry", szPLE); strcpy(the_url, ple); do_open_file(); }
win_error impl_fuse_context::create_file(LPCWSTR file_name, DWORD access_mode, DWORD share_mode, DWORD creation_disposition, DWORD flags_and_attributes, PDOKAN_FILE_INFO dokan_file_info) { std::string fname=unixify(wchar_to_utf8_cstr(file_name)); dokan_file_info->Context=0; if (!ops_.getattr) return -EINVAL; struct FUSE_STAT stbuf={0}; //Check if the target file/directory exists if (ops_.getattr(fname.c_str(),&stbuf)<0) { //Nope. if (dokan_file_info->IsDirectory) return -EINVAL; //We can't create directories using CreateFile return do_create_file(file_name, creation_disposition, share_mode, access_mode, dokan_file_info); } else { if (S_ISLNK(stbuf.st_mode)) { //Get link's target CHECKED(resolve_symlink(fname,&fname)); CHECKED(ops_.getattr(fname.c_str(),&stbuf)); } if ((stbuf.st_mode&S_IFDIR)==S_IFDIR) { //Existing directory //TODO: add access control dokan_file_info->IsDirectory=TRUE; return do_open_dir(file_name,dokan_file_info); } else { //Existing file //Check if we'll be able to truncate or delete the opened file //TODO: race condition here? if (creation_disposition==CREATE_ALWAYS) { if (!ops_.unlink) return -EINVAL; CHECKED(ops_.unlink(fname.c_str())); //Delete file //And create it! return do_create_file(file_name,creation_disposition, share_mode, access_mode,dokan_file_info); } else if (creation_disposition==TRUNCATE_EXISTING) { if (!ops_.truncate) return -EINVAL; CHECKED(ops_.truncate(fname.c_str(),0)); } else if (creation_disposition==CREATE_NEW) { return win_error(ERROR_FILE_EXISTS, true); } return do_open_file(file_name, share_mode, access_mode, dokan_file_info); } } }
int impl_fuse_context::do_create_file(LPCWSTR FileName, DWORD Disposition, DWORD share_mode, DWORD Flags, PDOKAN_FILE_INFO DokanFileInfo) { std::string fname=unixify(wchar_to_utf8_cstr(FileName)); //Create file? if (Disposition!=CREATE_NEW && Disposition!=CREATE_ALWAYS && Disposition!=OPEN_ALWAYS) return -ENOENT; //No, we're trying to open an existing file! if (!ops_.create) { //Use mknod+open. if (!ops_.mknod || !ops_.open) return -EINVAL; CHECKED(ops_.mknod(fname.c_str(),filemask_,0)); return do_open_file(FileName, share_mode, Flags, DokanFileInfo); } std::auto_ptr<impl_file_handle> file; CHECKED(file_locks.get_file(fname,false,Flags,share_mode,file)); fuse_file_info finfo={0}; finfo.flags=O_CREAT | O_EXCL | convert_flags(Flags); //TODO: these flags should be OK for new files? CHECKED(ops_.create(fname.c_str(),filemask_,&finfo)); DokanFileInfo->Context=reinterpret_cast<ULONG64>(file.release()); return 0; }
void load_recent_file(u32 idx) { const char *sOpt = gf_cfg_get_key_name(user.config, "RecentFiles", idx); if (sOpt) { strcpy(the_url, sOpt); do_open_file(); } }
int impl_fuse_context::do_create_file(LPCWSTR FileName, DWORD Disposition, DWORD share_mode, DWORD Flags, PDOKAN_FILE_INFO DokanFileInfo) // Kernel mappsings: // Disposition = CreateDisposition // Flags = DesiredAccess // share_mode = ShareAccess { std::string fname = unixify(wchar_to_utf8_cstr(FileName)); // Create file? if (Disposition != FILE_CREATE && Disposition != FILE_SUPERSEDE && Disposition != FILE_OPEN_IF && Disposition != FILE_OVERWRITE_IF) { SetLastError(ERROR_FILE_NOT_FOUND); return -ENOENT; // No, we're trying to open an existing file! } if (!ops_.create) { // Use mknod+open. if (!ops_.mknod || !ops_.open) return -EINVAL; CHECKED(ops_.mknod(fname.c_str(), filemask_, 0)); return do_open_file(FileName, share_mode, Flags, DokanFileInfo); } std::unique_ptr<impl_file_handle> file; CHECKED(file_locks.get_file(fname, false, Flags, share_mode, file)); fuse_file_info finfo = {0}; finfo.flags = O_CREAT | O_EXCL | convert_flags(Flags); // TODO: these flags should be OK for new files? CHECKED(ops_.create(fname.c_str(), filemask_, &finfo)); file->set_finfo(finfo); DokanFileInfo->Context = reinterpret_cast<ULONG64>(file.release()); return 0; }