IDataSource * choosePalette() { FileSystem * filesys = FileSystem::get_instance(); GtkWidget *file_sel; gchar *filename; gboolean selected = FALSE; file_sel = gtk_file_selection_new( "Choose a Palette" ); gtk_window_set_modal( GTK_WINDOW( file_sel ), TRUE ); gtk_signal_connect( GTK_OBJECT( file_sel ), "destroy", GTK_SIGNAL_FUNC( file_sel_delete ), &file_sel ); gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( file_sel )->cancel_button ), "clicked", GTK_SIGNAL_FUNC( file_sel_delete ), &file_sel ); gtk_signal_connect( GTK_OBJECT( GTK_FILE_SELECTION( file_sel )->ok_button ), "clicked", GTK_SIGNAL_FUNC( file_selected ), &selected ); gtk_widget_show( file_sel ); while( ( ! selected ) && ( file_sel ) ) gtk_main_iteration(); /* canceled or window was closed */ if( ! selected ) return 0; /* ok */ filename = g_strdup( gtk_file_selection_get_filename( GTK_FILE_SELECTION( file_sel ) ) ); gtk_widget_destroy( file_sel ); IDataSource * ds = filesys->ReadFile(filename); return ds; }
bool DirFile::exists(const std::string& name) { FileSystem* filesys = FileSystem::get_instance(); IDataSource* ids = filesys->ReadFile(path + name); if (!ids) return false; delete ids; return true; }
uint32 DirFile::getSize(const std::string& name) { FileSystem* filesys = FileSystem::get_instance(); IDataSource* ids = filesys->ReadFile(path + name); if (!ids) return 0; uint32 size = ids->getSize(); delete ids; return size; }
uint8* DirFile::getObject(const std::string& name, uint32* sizep) { FileSystem* filesys = FileSystem::get_instance(); IDataSource* ids = filesys->ReadFile(path + name); if (!ids) return 0; uint32 size = ids->getSize(); if (size == 0) return 0; uint8* buf = new uint8[size]; ids->read(buf, size); delete ids; if (sizep) *sizep = size; return buf; }
bool TransportHandlerFile::Transfer(TransportInfo* pTInfo, bool& bStateComplete) { using namespace EA::WebKit; bool bResult = true; FileInfo* pFileInfo = (FileInfo*)pTInfo->mTransportHandlerData; EAW_ASSERT(pFileInfo != NULL); char* pBuffer = GetFileDownloadBuffer(); if((pFileInfo->mFileObject != FileSystem::kFileObjectInvalid) && (pBuffer)) { FileSystem* pFS = GetFileSystem(); EAW_ASSERT(pFS != NULL); if(pFileInfo->mbRead) // If we need to read a file from disk and send it to the TransportServer. { if(pFileInfo->mFileSize < 0) // If this is the first time through... { pFileInfo->mFileSize = pFS->GetFileSize(pFileInfo->mFileObject); pTInfo->mpTransportServer->SetExpectedLength(pTInfo, pFileInfo->mFileSize); // pTInfo->mpTransportServer->SetEncoding(pTInfo, char* pEncoding); // pTInfo->mpTransportServer->SetMimeType(pTInfo); // pTInfo->mpTransportServer->HeadersReceived(pTInfo); } // To consider: Enable reading more than just one chunk at a time. However, by doing // so we could block the current thread for an undesirable period of time. const int64_t size = pFS->ReadFile(pFileInfo->mFileObject, pBuffer, kFileDownloadBufferSize); if(size >= 0) // If no error... { if(size > 0) pTInfo->mpTransportServer->DataReceived(pTInfo, pBuffer, size); else { bStateComplete = true; bResult = true; } } else { bStateComplete = true; bResult = false; } } else // Else we need to read a file from the TransportServer and write it to disk. { const int64_t size = pTInfo->mpTransportServer->ReadData(pTInfo, pBuffer, kFileDownloadBufferSize); if(size >= 0) // If no error... { if(size > 0) { if(!pFS->WriteFile(pFileInfo->mFileObject, pBuffer, size)) { bStateComplete = true; bResult = false; } } else { bStateComplete = true; bResult = true; } } else { bStateComplete = true; bResult = false; } } } else { bStateComplete = true; bResult = false; } // For now, set it to either 200 (OK) or 404 (not found). if(bResult) pTInfo->mResultCode = 200; else pTInfo->mResultCode = 404; if(bStateComplete) pTInfo->mpTransportServer->DataDone(pTInfo, bResult); return true; }