void Plugin::load(string new_path) throw (FileNotFound, LibHandleError) { if(new_path.empty()) { throw (FileNotFound ("loading of plugin failed. filename is empty.") ); } path.assign( new_path ); crusde_debug("%s, line: %d, Plugin %s load: %s ", __FILE__, __LINE__, name.c_str(), path.c_str()); // clear error flag dlerror(); LibHandle = dlopen(path.c_str(), RTLD_LAZY); if( LibHandle == NULL ) { throw (LibHandleError (dlerror() ) ); } //assign function pointer ... load functions func_get_name = get_dl_stringFunc("get_name"); func_get_version = get_dl_stringFunc("get_version"); func_get_authors = get_dl_stringFunc("get_authors"); func_get_description = get_dl_stringFunc("get_description"); func_get_category = get_categoryFunc("get_category"); func_run = get_dl_voidFunc("run"); func_register_parameter= get_dl_voidFunc("register_parameter"); func_register_output_fields= get_dl_voidFunc("register_output_fields"); func_request_plugins = get_dl_voidFunc("request_plugins"); func_init = get_dl_voidFunc("init"); func_release = get_dl_voidFunc("clear"); is_loaded = true; }
WavFileReadStream::WavFileReadStream(string path) : m_file(0), m_path(path), m_offset(0) { m_channelCount = 0; m_sampleRate = 0; m_fileInfo.format = 0; m_fileInfo.frames = 0; m_file = sf_open(m_path.c_str(), SFM_READ, &m_fileInfo); if (!m_file || m_fileInfo.frames <= 0 || m_fileInfo.channels <= 0) { cerr << "WavFileReadStream::initialize: Failed to open file \"" << path << "\" (" << sf_strerror(m_file) << ")" << endl; if (sf_error(m_file) == SF_ERR_SYSTEM) { m_error = string("Couldn't load audio file '") + m_path + "':\n" + sf_strerror(m_file); throw FileNotFound(m_path); } if (m_file) { m_error = string("Couldn't load audio file '") + m_path + "':\n" + sf_strerror(m_file); } else { m_error = string("Failed to open audio file '") + m_path + "'"; } throw InvalidFileFormat(m_path, m_error); } m_channelCount = m_fileInfo.channels; m_sampleRate = m_fileInfo.samplerate; sf_seek(m_file, 0, SEEK_SET); }
void Planar::reloadFile(string configFile) throw(FileNotFound) { ifstream fin(configFile); if (!fin.is_open()) { throw FileNotFound(configFile + " is missing and cannot be loaded."); } //Determine the number of vertices fin >> total; //Gather each of the vertices for(int i = 0; i < total; ++i) { glm::vec3 pt; fin >> pt.x; fin >> pt.y; fin >> pt.z; vertices.push_back(pt); } //Check for convexity convex = isConvex(); //Check for planarity planar = isPlanar(); //Build the geometry buildGeometry(); //Put all of the vertices into an array mesh.dump(); //Allocate the buffer space Geometry::buildBuffer(mesh.total, mesh.colors, mesh.normals, mesh.points); }
File::File(const std::string& path) : _path(path) , _impl(0) { if( ! File::exists( path.c_str() ) ) throw FileNotFound(path); }
File::File(const FileInfo& fi) : _path( fi.path() ) , _impl(0) { if( ! fi.isFile() ) throw FileNotFound(fi.path()); }
void Win32ThrowLastError(const char* fmt, ...) { DWORD err; char buff[HiME_MAX_MSG]; char* s; wchar_t winmsg[512]; char* ret; va_list lst; err = GetLastError(); if (err == ERROR_SUCCESS) return; s = buff; strcpy(s, "win32 error: "); s += strlen(s); if (fmt) { va_start(lst, fmt); s += _vsnprintf(s, HiME_MAX_MSG - (s - buff) - 2, fmt, lst); va_end(lst); strcat(s, ": "); s += 2; } FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), winmsg, sizeof(winmsg) / sizeof(winmsg[0]) - 1, NULL); OutputDebugStringW(winmsg); WideCharToMultiByte(CP_ACP, 0, winmsg, -1, (LPSTR)s, (int)(Exception::MAX_MSG - (s - buff) - 2), NULL, NULL); ret = strstr(buff, "\r\n"); if (ret) *ret = 0; switch (err) { case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: throw FileNotFound(buff, err); case ERROR_ACCESS_DENIED: case ERROR_SHARING_VIOLATION: throw AccessDenied(buff, err); break; default: throw Exception(buff, err); break; } }
bool ResourceGroupManager::loadFromFile(const std::string& nom) { std::ifstream file; file.open(nom); if (file.bad()) throw FileNotFound(nom); boost::property_tree::ini_parser::read_ini(file, m_ini); return true; }
void Netlist::process_file() { std::ifstream data(file_name.c_str()); if (!data) throw FileNotFound("Cannot open file \"" + file_name + "\""); std::string line; std::getline(data, title); number_of_nodes = atoi(title.c_str()); while (std::getline(data, line)) { handle_line(line); } }
FileModul::FileModul( gloox::Client *cl, const FileModul::string &fileName ) : Modul( cl ){ std::ifstream file( fileName.c_str() ); string tmp; if( file ) while( std::getline( file, tmp ) ) content.push_back( tmp ); else throw FileNotFound(); file.close(); }
void ShaderStage::ReadShaderSource(const std::string& filename) { // TODO: Handle file reading somewhere else std::ifstream file(filename, std::ios::in); if (file.fail()) { throw FileNotFound(filename); } file.seekg(0, std::ios::end); m_source.resize((unsigned int)file.tellg()); file.seekg(0, std::ios::beg); file.read(&m_source[0], m_source.size()); }
static void throw_errno(const String& path) { switch (errno) { case EACCES: throw AccessDenied(path.c_str()); case ENOENT: throw FileNotFound(path.c_str()); default: throw IOException(path.c_str()); } }
void WOFile::Open() { if(m_sFilename.empty()) { throw FileError("NULL Filename", EL_BAD, "WOFile::Open", "Filename is NULL!"); } Close(); m_File = fopen(m_sFilename.c_str(), "wb"); if(!m_File) { throw FileNotFound(m_sFilename.c_str()); } }
const sf::Font& FontManager::getFont(std::string filename) { if (fonts.find(filename) == fonts.end()) { std::unique_ptr<sf::Font> fontPtr(new sf::Font); if (!fontPtr->loadFromFile(fontDirectory + filename)) { throw FileNotFound(filename); } fonts.insert(std::make_pair(filename, std::move(fontPtr))); } return *fonts.at(filename); }
void Copy(fs::path const& from, fs::path const& to) { acs::CheckFileRead(from); CreateDirectory(to.parent_path()); acs::CheckDirWrite(to.parent_path()); if (!CopyFile(from.wstring().c_str(), to.wstring().c_str(), false)) { switch (GetLastError()) { case ERROR_FILE_NOT_FOUND: throw FileNotFound(from); case ERROR_ACCESS_DENIED: throw fs::WriteDenied("Could not overwrite " + to.string()); default: throw fs::WriteDenied("Could not copy: " + util::ErrorString(GetLastError())); } } }
string FindConfigFile(string fileName) { std::ifstream ifs; // Working directory ifs.open(fileName.c_str()); if (ifs.is_open()) { return fileName; } // Package data directory if (PACKAGE_DATA_DIRECTORY != "") { string prefixedFileName = PACKAGE_DATA_DIRECTORY + fileName; ifs.open(prefixedFileName.c_str()); if (ifs.is_open()) { return prefixedFileName; } } throw FileNotFound(fileName); }
template <typename DICT> DictPtr LoadDictWithPaths(const string& fileName) { // Working directory std::shared_ptr<DICT> dict; if (SerializableDict::TryLoadFromFile<DICT>(fileName, &dict)) { return dict; } // Configuration directory if ((configDirectory != "") && SerializableDict::TryLoadFromFile<DICT>( configDirectory + fileName, &dict)) { return dict; } // Package data directory if ((PACKAGE_DATA_DIRECTORY != "") && SerializableDict::TryLoadFromFile<DICT>( PACKAGE_DATA_DIRECTORY + fileName, &dict)) { return dict; } throw FileNotFound(fileName); }
string FindConfigFile(string fileName) { std::ifstream ifs; // Working directory ifs.open(UTF8Util::GetPlatformString(fileName).c_str()); if (ifs.is_open()) { return fileName; } // Package data directory if (PACKAGE_DATA_DIRECTORY != "") { string prefixedFileName = PACKAGE_DATA_DIRECTORY + fileName; ifs.open(UTF8Util::GetPlatformString(prefixedFileName).c_str()); if (ifs.is_open()) { return prefixedFileName; } prefixedFileName += ".json"; ifs.open(UTF8Util::GetPlatformString(prefixedFileName).c_str()); if (ifs.is_open()) { return prefixedFileName; } } throw FileNotFound(fileName); }
std::unique_ptr<MtpNode> MtpFolder::getNode(const FilesystemPath& path) { MtpNodeMetadata md = m_cache.getItem(m_id, *this); std::string filename = path.Head(); for(std::vector<MtpFileInfo>::iterator i = md.children.begin(); i!=md.children.end(); i++) { if (i->name == filename) { if (i->filetype != LIBMTP_FILETYPE_FOLDER) return std::unique_ptr<MtpNode>(new MtpFile(m_device, m_cache, i->id)); else { std::unique_ptr<MtpNode> n(new MtpFolder(m_device, m_cache, m_storageId, i->id)); FilesystemPath childPath = path.Body(); if (childPath.Empty()) return n; else return n->getNode(childPath); } } } throw FileNotFound(path.str()); }
//-------------------------------------------------------------------- Mesh* ObjLoader::Load(const std::string& file_name) const { // The original objloader Load method with some minor changes FILE* fp=0; fp = fopen(file_name.c_str(),"r"); if(NULL == fp) throw FileNotFound(file_name); /* this buffer boosts speed but lines are assumed to be no longer than kBufferSize characters. */ const int kBufferSize = 256; char buffer[kBufferSize]; Mesh* mesh = new Mesh(); // Verify that allocations succeeded if (NULL == mesh) { fclose(fp); fprintf(stderr, "Failed to allocate mesh object!\n"); return NULL; } /* go through the entire file and count how many times each tag exists */ while(!feof(fp)) { fgets(buffer,kBufferSize,fp); // texture coordinate tag if(strncmp("vt ",buffer,3)==0) ++mesh->tex_coord_count; else // normal tag if(strncmp("vn ",buffer,3) == 0 ) ++mesh->normal_count; else // vertex tag if(strncmp("v ",buffer,2)==0) ++mesh->vertex_count; else // face tag (triangle assumed) if(strncmp("f ",buffer,2)==0) mesh->triangle_count++; } fclose(fp); // if the file is degenerated, no model shall be returned at all if(mesh->triangle_count == 0 || mesh->vertex_count == 0) { delete mesh; throw FileError(file_name); } /* now that the count of every tag is known, allocate memory for all information dynamically */ // normalized //model->meshes=new Mesh[model->meshCount]; // adapted - the model variable is not available here mesh->triangles = new Mesh::Triangle[mesh->triangle_count]; mesh->vertices = new Mesh::Vertex[mesh->vertex_count]; mesh->normals = new vmml::Vector3f[mesh->normal_count]; mesh->texture_coordinates = new Mesh::TextureCoordinate[mesh->tex_coord_count]; // denormalized - for vertex array rendering mesh->indices = new unsigned int[mesh->triangle_count*3]; mesh->vertex_positions = new Mesh::Vertex[mesh->triangle_count*3]; mesh->vertex_normals = new vmml::Vector3f[mesh->triangle_count*3]; mesh->vertex_tex_coords = new Mesh::TextureCoordinate[mesh->triangle_count*3]; // Verify that allocations succeeded if (NULL == mesh->triangles || NULL == mesh->vertices || NULL == mesh->normals || NULL == mesh->texture_coordinates || NULL == mesh->indices || NULL == mesh->vertex_positions || NULL == mesh->vertex_normals || NULL == mesh->vertex_tex_coords) { fclose(fp); fprintf(stderr, "Failed to allocate memories for pointers of mesh!\n"); return NULL; } /* go through the file a second time and read in all information needed into the mesh struct */ fp = fopen(file_name.c_str(),"r"); unsigned int vertices_loaded=0; unsigned int normals_loaded=0; unsigned int texture_coordinates_loaded=0; unsigned int triangles_loaded=0; //unsigned int textures_loaded=0; // adapted - this is not used here anymore while(!feof(fp)) { fgets(buffer,kBufferSize,fp); if( strncmp("vn ",buffer,3) == 0 ) { sscanf((buffer+3),"%f%f%f", &mesh->normals[normals_loaded][0], &mesh->normals[normals_loaded][1], &mesh->normals[normals_loaded][2]); ++normals_loaded; } else if(strncmp("vt ",buffer,3) == 0) { sscanf((buffer+3),"%f%f", &mesh->texture_coordinates[texture_coordinates_loaded].s, &mesh->texture_coordinates[texture_coordinates_loaded].t); ++texture_coordinates_loaded; } else if( strncmp("v ",buffer,2) == 0 ) { sscanf((buffer+2),"%f%f%f", &mesh->vertices[vertices_loaded].coordinates[0], &mesh->vertices[vertices_loaded].coordinates[1], &mesh->vertices[vertices_loaded].coordinates[2]); ++vertices_loaded; } else if( strncmp("f ",buffer,2) == 0 ) { Mesh::Triangle* triangle = &mesh->triangles[triangles_loaded]; //read all data for this triangle (normalized) sscanf(buffer+2, "%d/%d/%d %d/%d/%d %d/%d/%d", &triangle->vertex_indices[0], &triangle->tex_coord_indices[0], &triangle->normal_indices[0], &triangle->vertex_indices[1], &triangle->tex_coord_indices[1], &triangle->normal_indices[1], &triangle->vertex_indices[2], &triangle->tex_coord_indices[2], &triangle->normal_indices[2]); //reduce the indices by 1 because array indices start at 0, while obj indices starts at 1 for(int i=0;i<3;++i) { --triangle->tex_coord_indices[i]; --triangle->normal_indices[i]; --triangle->vertex_indices[i]; } //read all data for this triangle (denormalized for vertex array rendering) mesh->vertex_positions[triangles_loaded*3+0]=mesh->vertices[triangle->vertex_indices[0]]; mesh->vertex_positions[triangles_loaded*3+1]=mesh->vertices[triangle->vertex_indices[1]]; mesh->vertex_positions[triangles_loaded*3+2]=mesh->vertices[triangle->vertex_indices[2]]; mesh->vertex_normals[triangles_loaded*3+0]=mesh->normals[triangle->normal_indices[0]]; mesh->vertex_normals[triangles_loaded*3+1]=mesh->normals[triangle->normal_indices[1]]; mesh->vertex_normals[triangles_loaded*3+2]=mesh->normals[triangle->normal_indices[2]]; mesh->vertex_tex_coords[triangles_loaded*3+0]=mesh->texture_coordinates[triangle->tex_coord_indices[0]]; mesh->vertex_tex_coords[triangles_loaded*3+1]=mesh->texture_coordinates[triangle->tex_coord_indices[1]]; mesh->vertex_tex_coords[triangles_loaded*3+2]=mesh->texture_coordinates[triangle->tex_coord_indices[2]]; mesh->indices[triangles_loaded*3+0]=triangles_loaded*3+0; mesh->indices[triangles_loaded*3+1]=triangles_loaded*3+1; mesh->indices[triangles_loaded*3+2]=triangles_loaded*3+2; ++triangles_loaded; } } fclose(fp); return mesh; }
NodePtr ShellFileSystem::open(const Path& path, const std::string& location) { if (!location.empty()) throw FileNotFound(location); return new ShellNode(this, path); }
int main(int argc, char* argv[]) { int iTestCase = 0; bErrorVerbose = true; char pszDecision[20]; for (;;) { // Get the pointers to the functions for disabling and enabling interception... getInterceptionDisablers(); uninterceptedPrint("=== HOLODECK FAULT TESTER 1.0 by TERRY LENTZ ===\n\n"); uninterceptedPrint("*** FILE FAULTS ***\n"); uninterceptedPrint("0 - File Not Found\t\t10 - File Cannot Be Created\n"); uninterceptedPrint("1 - File Cannot Be Accessed\t11 - Filename Too Long\n"); uninterceptedPrint("2 - Access Denied\t\t12 - Directory Read Only\n"); uninterceptedPrint("3 - Write Protected\t\t13 - Path Not Found\n"); uninterceptedPrint("4 - Crc Data Error\t\t14 - Directory Cannot Be Removed\n"); uninterceptedPrint("5 - Drive Cannot Seek Disk\t15 - Directory Not Empty\n"); uninterceptedPrint("6 - File In Use\t\t\t16 - Path Invalid\n"); uninterceptedPrint("7 - File Locked\t\t\t17 - Corrupt Structure\n"); uninterceptedPrint("8 - Disk Full\t\t\n"); uninterceptedPrint("9 - File Already Exists\t\t\n\n"); uninterceptedPrint("*** MEMORY FAULTS ***\n"); uninterceptedPrint("18 - Insufficient Memory\t\t21 - Invalid Address\n"); uninterceptedPrint("19 - Invalid Access To Location\t\t22 - Paging File Too Small\n"); uninterceptedPrint("20 - Segment Locked\t\t\n\n"); uninterceptedPrint("*** NETWORK FAULTS ***\n"); uninterceptedPrint("23 - Disconnected \t\t\t26 - Winsock Task Limit Reached\n"); uninterceptedPrint("24 - Network Not Installed\t\t27 - All Ports Unavailable\n"); uninterceptedPrint("25 - Wrong Winsock Version\t\t28 - Network is Down\n"); uninterceptedPrint("\nPlease enter the test that you would like to run: "); if (disableInterception != NULL) disableInterception(); scanf("%d", &iTestCase); if (enableInterception != NULL) enableInterception(); uninterceptedPrint("\n"); switch (iTestCase) { // FileNotFound case 0: uninterceptedPrint("=== TEST CASE: FileNotFound ===\n"); if (FileNotFound()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // FileCannotBeAccessed case 1: uninterceptedPrint("=== TEST CASE: FileCannotBeAccessed ===\n"); if (FileCannotBeAccessed()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // AccessDenied case 2: uninterceptedPrint("=== TEST CASE: AccessDenied ===\n"); if (AccessDenied()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // WriteProtected case 3: uninterceptedPrint("=== TEST CASE: WriteProtected ===\n"); if (WriteProtected()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // CrcDataError case 4: uninterceptedPrint("=== TEST CASE: CrcDataError ===\n"); if (CrcDataError()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // DriveCannotSeekDisk case 5: uninterceptedPrint("=== TEST CASE: DriveCannotSeekDisk ===\n"); if (DriveCannotSeekDisk()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // FileInUse case 6: uninterceptedPrint("=== TEST CASE: FileInUse ===\n"); if (FileInUse()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // FileLocked case 7: uninterceptedPrint("=== TEST CASE: FileLocked ===\n"); if (FileLocked()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // DiskFull case 8: uninterceptedPrint("=== TEST CASE: DiskFull ===\n"); if (DiskFull()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // FileAlreadyExists case 9: uninterceptedPrint("=== TEST CASE: FileAlreadyExists ===\n"); if (FileAlreadyExists()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // FileCannotBeCreated case 10: uninterceptedPrint("=== TEST CASE: FileCannotBeCreated ===\n"); if (FileCannotBeCreated()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // FileNameTooLong case 11: uninterceptedPrint("=== TEST CASE: FileNameTooLong ===\n"); if (FileNameTooLong()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // DirectoryReadOnly case 12: uninterceptedPrint("=== TEST CASE: DirectoryReadOnly ===\n"); if (DirectoryReadOnly()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // PathNotFound case 13: uninterceptedPrint("=== TEST CASE: PathNotFound ===\n"); if (PathNotFound()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // DirectoryCannotBeRemoved case 14: uninterceptedPrint("=== TEST CASE: DirectoryCannotBeRemoved ===\n"); if (DirectoryCannotBeRemoved()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // DirectoryNotEmpty case 15: uninterceptedPrint("=== TEST CASE: DirectoryNotEmpty ===\n"); if (DirectoryNotEmpty()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // PathInvalid case 16: uninterceptedPrint("=== TEST CASE: PathInvalid ===\n"); if (PathInvalid()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // CorruptStructure case 17: uninterceptedPrint("=== TEST CASE: CorruptStructure ===\n"); if (CorruptStructure()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // InsufficientMemory case 18: uninterceptedPrint("=== TEST CASE: InsufficientMemory ===\n"); if (InsufficientMemory()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // InvalidAccessToLocation case 19: uninterceptedPrint("=== TEST CASE: InvalidAccessToLocation ===\n"); if (InvalidAccessToLocation()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // SegmentLocked case 20: uninterceptedPrint("=== TEST CASE: SegmentLocked ===\n"); if (SegmentLocked()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // InvalidAddress case 21: uninterceptedPrint("=== TEST CASE: InvalidAddress ===\n"); if (InvalidAddress()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // PagingFileTooSmall case 22: uninterceptedPrint("=== TEST CASE: PagingFileTooSmall ===\n"); if (PagingFileTooSmall()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // Disconnected case 23: uninterceptedPrint("=== TEST CASE: Disconnected ===\n"); if (Disconnected()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // NetworkNotInstalled case 24: uninterceptedPrint("=== TEST CASE: NetworkNotInstalled ===\n"); if (NetworkNotInstalled()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // WrongWinsockVersion case 25: uninterceptedPrint("=== TEST CASE: WrongWinsockVersion ===\n"); if (WrongWinsockVersion()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // WinsockTaskLimitReached case 26: uninterceptedPrint("=== TEST CASE: WinsockTaskLimitReached ===\n"); if (WinsockTaskLimitReached()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // AllPortsUnavailable case 27: uninterceptedPrint("=== TEST CASE: AllPortsUnavailable ===\n"); if (AllPortsUnavailable()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; // NetworkIsDown case 28: uninterceptedPrint("=== TEST CASE: NetworkIsDown ===\n"); if (NetworkIsDown()) uninterceptedPrint("\nTEST Passed!\n"); else uninterceptedPrint("\nTEST Failed!\n"); break; } uninterceptedPrint("\nWould You Like to Run Another Test (Y/N) ? "); if (disableInterception != NULL) disableInterception(); scanf("%s", pszDecision); if (enableInterception != NULL) enableInterception(); if ((_stricmp(pszDecision, "y"))) break; } return 0; }
MatrixFile::MatrixFile(QString fileBase, Mode mode, size_t cellSize, size_t width, size_t height) : m_fd(-1), m_mode(mode), m_flags(0), m_fmode(0), m_cellSize(cellSize), m_width(width), m_height(height), m_headerSize(2 * sizeof(size_t)), m_setColumns(0), m_autoClose(false), m_readyToReadColumn(-1) { Profiler profiler("MatrixFile::MatrixFile", true); #ifdef DEBUG_MATRIX_FILE std::cerr << "MatrixFile::MatrixFile(" << fileBase.toStdString() << ", " << int(mode) << ", " << cellSize << ", " << width << ", " << height << ")" << std::endl; #endif m_createMutex.lock(); QDir tempDir(TempDirectory::getInstance()->getPath()); QString fileName(tempDir.filePath(QString("%1.mfc").arg(fileBase))); bool newFile = !QFileInfo(fileName).exists(); if (newFile && m_mode == ReadOnly) { std::cerr << "ERROR: MatrixFile::MatrixFile: Read-only mode " << "specified, but cache file does not exist" << std::endl; throw FileNotFound(fileName); } if (!newFile && m_mode == WriteOnly) { std::cerr << "ERROR: MatrixFile::MatrixFile: Write-only mode " << "specified, but file already exists" << std::endl; throw FileOperationFailed(fileName, "create"); } m_flags = 0; m_fmode = S_IRUSR | S_IWUSR; if (m_mode == WriteOnly) { m_flags = O_WRONLY | O_CREAT; } else { m_flags = O_RDONLY; } #ifdef _WIN32 m_flags |= O_BINARY; #endif #ifdef DEBUG_MATRIX_FILE std::cerr << "MatrixFile(" << this << ")::MatrixFile: opening " << fileName.toStdString() << "..." << std::endl; #endif if ((m_fd = ::open(fileName.toLocal8Bit(), m_flags, m_fmode)) < 0) { ::perror("Open failed"); std::cerr << "ERROR: MatrixFile::MatrixFile: " << "Failed to open cache file \"" << fileName.toStdString() << "\""; if (m_mode == WriteOnly) std::cerr << " for writing"; std::cerr << std::endl; throw FailedToOpenFile(fileName); } m_createMutex.unlock(); #ifdef DEBUG_MATRIX_FILE std::cerr << "MatrixFile(" << this << ")::MatrixFile: fd is " << m_fd << std::endl; #endif if (newFile) { initialise(); // write header and "unwritten" column tags } else { size_t header[2]; if (::read(m_fd, header, 2 * sizeof(size_t)) < 0) { ::perror("MatrixFile::MatrixFile: read failed"); std::cerr << "ERROR: MatrixFile::MatrixFile: " << "Failed to read header (fd " << m_fd << ", file \"" << fileName.toStdString() << "\")" << std::endl; throw FileReadFailed(fileName); } if (header[0] != m_width || header[1] != m_height) { std::cerr << "ERROR: MatrixFile::MatrixFile: " << "Dimensions in file header (" << header[0] << "x" << header[1] << ") differ from expected dimensions " << m_width << "x" << m_height << std::endl; throw FailedToOpenFile(fileName); } } m_fileName = fileName; ++m_refcount[fileName]; #ifdef DEBUG_MATRIX_FILE std::cerr << "MatrixFile[" << m_fd << "]::MatrixFile: File " << fileName.toStdString() << ", ref " << m_refcount[fileName] << std::endl; std::cerr << "MatrixFile[" << m_fd << "]::MatrixFile: Done, size is " << "(" << m_width << ", " << m_height << ")" << std::endl; #endif ++totalCount; ++openCount; }
CoreAudioReadStream::CoreAudioReadStream(string path) : m_path(path), m_d(new D) { m_channelCount = 0; m_sampleRate = 0; if (!QFile(m_path).exists()) { throw FileNotFound(m_path); } QByteArray ba = m_path.toLocal8Bit(); CFURLRef url = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const UInt8 *)ba.data(), (CFIndex)ba.length(), false); //!!! how do we find out if the file open fails because of DRM protection? #if (MACOSX_DEPLOYMENT_TARGET <= 1040 && MAC_OS_X_VERSION_MIN_REQUIRED <= 1040) FSRef fsref; if (!CFURLGetFSRef(url, &fsref)) { // returns Boolean, not error code m_error = "CoreAudioReadStream: Error looking up FS ref (file not found?)"; throw FileReadFailed(m_path); } m_d->err = ExtAudioFileOpen(&fsref, &m_d->file); #else m_d->err = ExtAudioFileOpenURL(url, &m_d->file); #endif CFRelease(url); if (m_d->err) { m_error = "CoreAudioReadStream: Error opening file: code " + codestr(m_d->err); throw InvalidFileFormat(path, "failed to open audio file"); } if (!m_d->file) { m_error = "CoreAudioReadStream: Failed to open file, but no error reported!"; throw InvalidFileFormat(path, "failed to open audio file"); } UInt32 propsize = sizeof(AudioStreamBasicDescription); m_d->err = ExtAudioFileGetProperty (m_d->file, kExtAudioFileProperty_FileDataFormat, &propsize, &m_d->asbd); if (m_d->err) { m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err); ExtAudioFileDispose(m_d->file); throw FileOperationFailed(m_path, "get basic description", codestr(m_d->err)); } m_channelCount = m_d->asbd.mChannelsPerFrame; m_sampleRate = m_d->asbd.mSampleRate; cerr << "CoreAudioReadStream: " << m_channelCount << " channels, " << m_sampleRate << " Hz" << std::endl; m_d->asbd.mSampleRate = getSampleRate(); m_d->asbd.mFormatID = kAudioFormatLinearPCM; m_d->asbd.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | kAudioFormatFlagsNativeEndian; m_d->asbd.mBitsPerChannel = sizeof(float) * 8; m_d->asbd.mBytesPerFrame = sizeof(float) * m_channelCount; m_d->asbd.mBytesPerPacket = sizeof(float) * m_channelCount; m_d->asbd.mFramesPerPacket = 1; m_d->asbd.mReserved = 0; m_d->err = ExtAudioFileSetProperty (m_d->file, kExtAudioFileProperty_ClientDataFormat, propsize, &m_d->asbd); if (m_d->err) { m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err); throw FileOperationFailed(m_path, "set client format", codestr(m_d->err)); } m_d->buffer.mNumberBuffers = 1; m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount; m_d->buffer.mBuffers[0].mDataByteSize = 0; m_d->buffer.mBuffers[0].mData = 0; }
void MoveFile(const std::string & from, const std::string & to) { BOOST_THROW_EXCEPTION(FileNotFound() << FileNameTag(from)); }