// native fwrite(file, data, mode); static cell AMX_NATIVE_CALL amx_fwrite(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } cell data = params[2]; size_t size = params[3]; switch (size) { case BLOCK_CHAR: { char value = static_cast<char>(data); return fp->Write(&value, sizeof(value)); } case BLOCK_SHORT: { short value = static_cast<short>(data); return fp->Write(&value, sizeof(value)); } case BLOCK_INT: { int value = static_cast<int>(data); return fp->Write(&value, sizeof(value)); } } return 0; }
//------------------------------------------------------------------------------------- bool FileDataDownload::process() { ResourceObjectPtr fptr = Resmgr::getSingleton().openResource(path_.c_str(), "rb"); if(fptr == NULL || !fptr->valid()) { ERROR_MSG(fmt::format("FileDataDownload::process(): can't open {}.\n", Resmgr::getSingleton().matchRes(path_).c_str())); error_ = true; return false; } FileObject* f = static_cast<FileObject*>(fptr.get()); if(totalBytes_ == 0) { f->seek(0, SEEK_END); totalBytes_ = f->tell(); } f->seek(totalSentBytes_, SEEK_SET); remainSent_ = f->read(stream_, 65535); currSent_ = 0; if(remainSent_ == 0) remainSent_ = totalBytes_ - totalSentBytes_; return false; }
// native fprintf(file, const fmt[], any:...); static cell AMX_NATIVE_CALL amx_fprintf(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } int length; const char* string = format_amxstring(amx, params, 2, length); if (ValveFile *vfile = fp->AsValveFile()) { return g_FileSystem->FPrintf(vfile->handle(), const_cast<char*>("%s"), string); } else if (SystemFile *sysfile = fp->AsSystemFile()) { return fprintf(sysfile->handle(), "%s", string); } else { assert(false); } return 0; }
domCOLLADA* ColladaShapeLoader::readColladaFile(const String& path) { // Check if this file is already loaded into the database domCOLLADA* root = sDAE.getRoot(path.c_str()); if (root) return root; // Load the Collada file into memory FileObject fo; if (!fo.readMemory(path)) { daeErrorHandler::get()->handleError(avar("Could not read %s into memory", path.c_str())); return NULL; } root = sDAE.openFromMemory(path.c_str(), (const char*)fo.buffer()); if (!root || !root->getLibrary_visual_scenes_array().getCount()) { daeErrorHandler::get()->handleError(avar("Could not parse %s", path.c_str())); return NULL; } // Fixup issues in the model ColladaUtils::applyConditioners(root); // Recursively load external DAE references TSShapeLoader::updateProgress(TSShapeLoader::Load_ExternalRefs, "Loading external references..."); for (S32 iRef = 0; iRef < root->getDocument()->getReferencedDocuments().getCount(); iRef++) { String refPath = (daeString)root->getDocument()->getReferencedDocuments()[iRef]; if (refPath.endsWith(".dae") && !readColladaFile(refPath)) daeErrorHandler::get()->handleError(avar("Failed to load external reference: %s", refPath.c_str())); } return root; }
// native fwrite_blocks(file, const data[], blocks, mode); static cell AMX_NATIVE_CALL amx_fwrite_blocks(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } cell* data = get_amxaddr(amx, params[2]); cell blocks = params[3]; cell size = params[4]; size_t read = 0; switch (size) { case BLOCK_CHAR: { for (cell i = 0; i < blocks; ++i) { char value = data[i]; if (fp->Write(&value, sizeof(value)) != sizeof(value)) { break; } read += sizeof(value); } break; } case BLOCK_SHORT: { for (cell i = 0; i < blocks; ++i) { short value = data[i]; if (fp->Write(&value, sizeof(value)) != sizeof(value)) { break; } read += sizeof(value); } break; } case BLOCK_INT: { read = fp->Write(data, sizeof(cell) * blocks); break; } default: { return 0; } } return read / size; }
FileObject* FTPSession::FindPathObject(const char * filepath) { if (!filepath) return NULL; char tempstr[MAX_PATH]; strcpy(tempstr, filepath); FileObject * current = m_rootObject; char * curname = strtok (tempstr, "/"); while(curname) { if (current->GetChildCount() == 0) //search did not finish, but cannot find child return NULL; int i = 0; int count = current->GetChildCount(); for(i = 0; i < count; i++) { if ( !strcmp( current->GetChild(i)->GetName(), curname ) ) { current = current->GetChild(i); curname = strtok (NULL, "/"); break; } } if (i == count) //none of the children match return NULL; } return current; }
void FileCommands::edit(FileSystemUser* fileSystem, string fileName) { FileObject* fo = fileSystem->getFileObject(); fileName += "$"; int t = fo->getObject(fileName); if(t) { fo->setPos(t); string newContent; char buff[512]; cout<<"enter new content: "; cin.getline(buff, 512); newContent = buff; int begPos = fo->getBeginPos(); string sys = fileSystem->getSystem(); fo->go(fileName); int beg = fo->getPos(); fo->setEndPos(); int end = fo->getPos(); sys.erase(beg, end-beg + 1); sys.insert(beg, newContent); fileSystem->setNewSystem(sys); fo->setBeginPos(begPos); fo->setFileContent(fileName, newContent); }else { notFoundFile(fileName); return; } }
int FTPWindow::OnConnect(int code) { if (code != 0) //automated connect return 0; FileObject * root = m_ftpSession->GetRootObject(); m_treeview.AddRoot(root); FileObject * last = root; while(last->GetChildCount() > 0) { last = last->GetChild(0); } m_treeview.EnsureObjectVisible(last); TreeView_Select(m_treeview.GetHWND(), last->GetData(), TVGN_CARET); m_ftpSession->GetDirectory(last->GetPath()); TCHAR * info = SU::TSprintfNB(TEXT("Connected to %T"), m_ftpSession->GetCurrentProfile()->GetName()); SetInfo(info); delete [] info; SetToolbarState(); return 0; }
void FileCommands::lsdir(FileSystemUser* fileSystem) { FileObject* fo = fileSystem->getFileObject(); cout<<endl; vector<string> dirs = fo->getDirs(); for(int i = 0; i<dirs.size(); ++i) { cout<<dirs[i]<<endl; } cout<<endl; }
void FileCommands::lsfile(FileSystemUser* fileSystem) { FileObject* fo = fileSystem->getFileObject(); cout<<endl; vector<string> files = fo->getFiles(); for(int i = 0; i<files.size(); ++i) { cout<<files[i]<<endl; } cout<<endl; }
// native ftell(file); static cell AMX_NATIVE_CALL amx_ftell(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } return fp->Tell(); }
// native fflush(file); static cell AMX_NATIVE_CALL amx_fflush(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (fp) { return fp->Flush(); } return -1; }
// native feof(file); static cell AMX_NATIVE_CALL amx_feof(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (fp) { return fp->EndOfFile(); } return 1; }
// native fclose(file); static cell AMX_NATIVE_CALL amx_fclose(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (fp) { fp->Close(); } return 1; }
// native fseek(file, position, start); static cell AMX_NATIVE_CALL amx_fseek(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } return !fp->Seek(params[2], params[3]); }
void FileCommands::remfile(FileSystemUser* fileSystem, string file) { FileObject* fo = fileSystem->getFileObject(); if(!fo->containsObject(file)) { notFoundFile(file); return; } string sys = fileSystem->getSystem(); int t = fo->getObject(file); sys.erase(t, fo->getPos() - t - 1); fileSystem->setNewSystem(sys); fo->remObj(file); }
void FileCommands::show(FileSystemUser* fileSystem, string fileName) { FileObject* fo = fileSystem->getFileObject(); fileName += fileDelim; if(fo->containsObject(fileName)) { string content = fo->getFileContent(fileName); cout<<endl<<"\t"<<fileName<<endl<<endl<<content<<endl; }else { notFoundFile(fileName); return; } }
static cell File_WriteTyped(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } T value = static_cast<T>(params[2]); return !!(fp->Write(&value, sizeof(value)) == sizeof(value)); }
// native fread_raw(file, stream[], blocksize, blocks); static cell AMX_NATIVE_CALL amx_fread_raw(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } cell* data = get_amxaddr(amx, params[2]); return fp->Read(data, params[3] * params[4]); }
void FileCommands::mkdir(FileSystemUser* fileSystem, string dir) { FileObject* fo = fileSystem->getFileObject(); if(fo->containsObject(dir)) { duplicateNames(dir); return; } dir += "{"; dir += "}"; fo->setEndPos(); string sys = fileSystem->getSystem(); sys.insert(fo->getPos(), dir); fileSystem->setNewSystem(sys); fo->addObj(dir); }
HRESULT FTPWindow::OnDragOver(DWORD /*grfKeyState*/, POINTL pt, LPDWORD pdwEffect) { FileObject * fo = m_treeview.GetItemByPoint(pt); if (fo && fo->isDir()) { *pdwEffect = DROPEFFECT_COPY; TreeView_Select(m_treeview.GetHWND(), fo->GetData(), TVGN_DROPHILITE); m_currentDropObject = fo; return S_OK; } else { TreeView_Select(m_treeview.GetHWND(), NULL, TVGN_DROPHILITE); m_currentDropObject = NULL; } return S_OK; }
void FileCommands::mkfile(FileSystemUser* fileSystem, string file) { FileObject* fo = fileSystem->getFileObject(); if(fo->containsObject(file)) { duplicateNames(file); return; } file += fileDelim; file += openDelim; file += closeDelim; fo->setEndPos(); string sys = fileSystem->getSystem(); sys.insert(fo->getPos(), file); fileSystem->setNewSystem(sys); fo->addObj(file); }
// native fgets(file, buffer[], maxlength); static cell AMX_NATIVE_CALL amx_fgets(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } static char buffer[4096]; buffer[0] = '\0'; fp->ReadLine(buffer, sizeof(buffer) - 1); return set_amxstring_utf8(amx, params[2], buffer, strlen(buffer), params[3] + 1); // + EOS }
QModelIndex FileObjectModel::parent(const QModelIndex &child) const { if(!mFileService) { return QModelIndex(); } FileObject *obj = (FileObject*)child.internalPointer(); FileObject *pObj = obj->parent(); if(!pObj) { return QModelIndex(); } if(!pObj->parent()) { return createIndex(0, 0, pObj); } int i = pObj->parent()->children().indexOf(pObj); return createIndex(i, 0, pObj); }
//native fputc(file, data); static cell AMX_NATIVE_CALL amx_fputc(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } uint8_t val = static_cast<uint8_t>(params[2]); if (fp->Write(&val, sizeof(val)) != sizeof(val)) { return -1; } return val; }
//native fgetc(file); static cell AMX_NATIVE_CALL amx_fgetc(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } uint8_t val; if (fp->Read(&val, sizeof(val)) != sizeof(val)) { return -1; } return static_cast<cell>(val); }
FileObject* FTPSession::GetRootObject() { char dir[MAX_PATH]; strcpy(dir, m_currentProfile->GetInitialDir()); int res = 0; if (strlen(dir) < 1 || dir[0] != '/') { //no initial dir or invalid res = -1; } else { res = m_mainWrapper->Cwd(dir); } if (res == -1) { res = m_mainWrapper->Pwd(&dir[0], MAX_PATH); } if (res == -1 || strlen(dir) <= 1) return m_rootObject; FileObject * child = NULL; child = new FileObject(dir, true, false); FileObject * prevDir = NULL; prevDir = child; char * curDir; curDir = strrchr(dir, '/'); while(curDir != NULL) { if (curDir == dir) { child = m_rootObject; child->AddChild(prevDir); child->SetRefresh(false); break; } *curDir = 0; child = new FileObject(dir, true, false); child->AddChild(prevDir); child->SetRefresh(false); prevDir = child; curDir = strrchr(dir, '/'); } return m_rootObject; }
int main() { FileObject* f; File f1(10); f = &f1; f->set_name("name"); cout<<"FileObject f = &f1 :"<< f->MemoryInSpace() << endl; FileObject* f2[2]; f2[0] = f; Directory d(f2,1); cout<<"Directory d(f,1):"<< d.MemoryInSpace() << endl; f = &d; f->MemoryInSpace(); cout << "Directory f = &d:" << f->MemoryInSpace() << endl; }
//native ungetc(file, data); static cell AMX_NATIVE_CALL amx_ungetc(AMX *amx, cell *params) { FileObject* fp = reinterpret_cast<FileObject*>(params[1]); if (!fp) { return 0; } SystemFile* sysfile = fp->AsSystemFile(); if (!sysfile) { LogError(amx, AMX_ERR_NATIVE, "Can not ungetc to file in the Valve file system"); return 0; } return ungetc(static_cast<int>(params[2]), sysfile->handle()); }
void FileCommands::remdir(FileSystemUser* fileSystem, string dir) { FileObject* fo = fileSystem->getFileObject(); if(!fo->containsObject(dir)) { notFoundDir(dir); return; } string sys = fileSystem->getSystem(); int t = fo->getObject(dir); cout<<"t: "<<t<<" pos:"<<fo->getPos()<<endl; if(fo->getPos() == fo->getBeginPos()) { fo->setEndPos(); } sys.erase(t, fo->getPos() - t); fileSystem->setNewSystem(sys); fo->remObj(dir); }