NodeSmartReference ModelResource_load(ModelLoader* loader, const char* name) { ScopeDisableScreenUpdates disableScreenUpdates(path_get_filename_start(name), "Loading Model"); NodeSmartReference model(g_nullModel); { ArchiveFile* file = GlobalFileSystem().openFile(name); if(file != 0) { globalOutputStream() << "Loaded Model: \"" << name << "\"\n"; model = loader->loadModel(*file); file->release(); } else { globalErrorStream() << "Model load failed: \"" << name << "\"\n"; } } model.get().m_isRoot = true; return model; }
TestArchive() { { Archive* archive = OpenArchive(""); archive->release(); } { Archive* archive = OpenArchive("NONEXISTANTFILE"); archive->release(); } { Archive* archive = OpenArchive("c:/quake/id1/quake101.wad"); ArchiveFile* file = archive->openFile("textures/sky1.mip"); if(file != 0) { unsigned char* buffer = new unsigned char[file->size()]; file->getInputStream().read((InputStream::byte_type*)buffer, file->size()); delete[] buffer; file->release(); } TestVisitor visitor; archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), ""); archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), ""); archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), "textures/"); archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 1), "textures/"); archive->release(); } }
void test1() { Archive* archive = OpenArchive("d:/quake/id1/"); ArchiveFile* file = archive->openFile("quake101.wad"); if(file != 0) { char buffer[1024]; file->getInputStream().read(buffer, 1024); file->release(); } TestVisitor visitor; archive->forEachFile(Archive::VisitorFunc(&visitor, Archive::eFilesAndDirectories, 0), ""); archive->release(); }
// NOTE: when loading a file, you have to allocate one extra byte and set it to \0 std::size_t LoadFile (const char *filename, void **bufferptr, int index) { char fixed[PATH_MAX+1]; strncpy (fixed, filename, PATH_MAX); fixed[PATH_MAX] = '\0'; FixDOSName (fixed); ArchiveFile* file = OpenFile(fixed); if(file != 0) { *bufferptr = malloc (file->size()+1); // we need to end the buffer with a 0 ((char*) (*bufferptr))[file->size()] = 0; std::size_t length = file->getInputStream().read((InputStream::byte_type*)*bufferptr, file->size()); file->release(); return length; } *bufferptr = 0; return 0; }