Esempio n. 1
0
uint32 WinFont::getFontIndex(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry) {
	uint16 numFonts = stream.readUint16LE();

	// Probably not possible, so this is really a sanity check
	if (numFonts == 0) {
		warning("No fonts in exe");
		return 0xffffffff;
	}

	// Scour the directory for our matching name
	for (uint16 i = 0; i < numFonts; i++) {
		uint16 id = stream.readUint16LE();

		// Use the first name when empty
		if (dirEntry.faceName.empty())
			return id;

		WinFontDirEntry entry = readDirEntry(stream);

		if (dirEntry.faceName.equalsIgnoreCase(entry.faceName) && dirEntry.points == entry.points) // Match!
			return id;
	}

	return 0xffffffff;
}
Esempio n. 2
0
void Runner::run()
{
	if((device.fd=open(device.filename.c_str(), O_RDONLY))==-1)
    {
    	std::cout <<"Cannot open device"<< std::endl;
    	return;
    }

	if(readBootEntry()==-1)		return;
	if(readFAT()==-1)			return;
	if(readDirEntry()==-1)		return;

	switch(action)
	{
		case PRINTBOOT:
			printFSinfo();
			break;
		case LISTDIR:
			listDir();
			break;
		case EIGHTPTHREE:
			eightPthree();
			break;
		case LONGFN:
			longFN();
			break;
		default:
			std::cout <<"what should I do?"<< std::endl;
	}

	close(device.fd);
}
Esempio n. 3
0
File: rfs.c Progetto: karajrish/OS
int closeDir(int dirhandle){
	// Find the corresponding open file object and remove it
	int i;
	struct InCoreINode icn;
	struct DirEntry d;
	struct INode in;
	int inodeNo = isOpen(dirhandle, &icn);
	if( inodeNo==-1 ){
		printf("Directory not open!\n");
		return -1;
	}
	if( icn.ic_inode.i_nlinks==0 ){
		// readDirEntry(icn.ic_inode, )
		printf("Not a directory!%d\n", icn.ic_ino);
		return -1;
	}
	for(i=1; i<icn.ic_inode.i_nlinks; i++){
		readDirEntry(icn.ic_dev, &icn.ic_inode, i, &d);
		readINode(icn.ic_dev, d.d_entry.d_inode, &in);
		if( in.i_nlinks==0 )	closeFile(d.d_entry.d_inode);
		else					closeDir(d.d_entry.d_inode);
	}
	removeOpenFile(dirhandle);

}
Esempio n. 4
0
File: rfs.c Progetto: karajrish/OS
int freeDirEntry(int fd, struct INode* in, int linkNo){
	struct DirEntry last;
	readDirEntry(fd, in, in->i_nlinks-1, &last);
	writeDirEntry(fd, in, linkNo, &last);
	lseek(fd, getDirEntryAddress(in->i_nlinks-1, in), SEEK_SET);
	write(fd, &nullbuf, sizeof(struct DirEntry));
	in->i_nlinks--;
}
Esempio n. 5
0
File: rfs.c Progetto: karajrish/OS
int fileExists(int fd, char *name, struct INode in, struct DirEntry* d){
	int i=0;
	for(i=0; i<in.i_nlinks; i++){
		readDirEntry(fd, &in, i, d);
		printf("Searching %s\n", d->d_entry.d_name);
		if( strcmp(d->d_entry.d_name, name)==0 ){
			return i;
		}
	}
	return -1;
}
Esempio n. 6
0
File: rfs.c Progetto: karajrish/OS
// Delete directory (if it is empty)
int removeDirHelper(int fd, char *dname, int parINodeNo){
	int i;
	struct INode parent_in;
	// Tokenize the name and find its parent directory
	readINode(fd, parINodeNo, &parent_in);

	// Find dname in parent directory and read its inode
	struct DirEntry d;
	int linkNo = fileExists(fd, dname, parent_in, &d);
	int inodeNo = d.d_entry.d_inode;
	if( linkNo==-1 ){
		printf("Directory does not exist!\n");
		return -1;
	}
	if( inodeNo == s.sb_rootdir ){
		printf("Cannot delete root directory!\n");
		return -1;
	}
	struct INode in;
	readINode(fd, inodeNo, &in);

	// On each of the link in its inode call recursive delete after taking permission
	if( in.i_nlinks==0 ){
		printf("Not a valid directory!\n");
		return -1;
	}
	if( in.i_nlinks>2 ){
		printf("Directory not empty! Do you want to proceed[y]? ");
		char c;
		scanf("%c",&c);
		if( c!='y' || c!='Y' ){
			return -1;
		}
		struct DirEntry temp;
		struct INode tempINode;
		for(i=1; i<in.i_nlinks; i++){
			readDirEntry(fd, i, &temp);
			if( strcmp(temp.d_entry.d_name, "..")==0 )	continue;
			readINode(fd, temp.d_entry.d_inode, &tempINode);
			if( tempINode.i_nlinks==0 )		freeINode(fd, temp.d_entry.d_inode);
			else{
				removeDirHelper(fd, temp.d_entry.d_name, inodeNo);
			}
		}
	}
	freeINode(fd, inodeNo);
	freeDirEntry(fd, &parent_in, linkNo);
	printf("Directory successfully deleted!\n");
}
Esempio n. 7
0
bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
	// TODO: PE libraries (If it's used anywhere by a ScummVM game)

	Common::NEResources exe;

	if (!exe.loadFromEXE(fileName))
		return false;

	// Let's pull out the font directory
	Common::SeekableReadStream *fontDirectory = exe.getResource(Common::kNEFontDir, Common::String("FONTDIR"));
	if (!fontDirectory) {
		warning("No font directory in '%s'", fileName.c_str());
		return false;
	}

	uint16 numFonts = fontDirectory->readUint16LE();

	// Probably not possible, so this is really a sanity check
	if (numFonts == 0) {
		warning("No fonts in '%s'", fileName.c_str());
		return false;
	}

	// Scour the directory for our matching name
	int fontId = -1;
	for (uint16 i = 0; i < numFonts; i++) {
		uint16 id = fontDirectory->readUint16LE();

		if (dirEntry.faceName.empty()) {
			// Use the first name when empty
			fontId = id;
			break;
		}

		WinFontDirEntry entry = readDirEntry(*fontDirectory);

		if (dirEntry.faceName.equalsIgnoreCase(entry.faceName) && dirEntry.points == entry.points) {
			// Match!
			fontId = id;
			break;
		}
	}

	delete fontDirectory;

	// Couldn't match the face name
	if (fontId < 0) {
		warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str());
		return false;
	}

	// Actually go get our font now...
	Common::SeekableReadStream *fontStream = exe.getResource(Common::kNEFont, fontId);
	if (!fontStream) {
		warning("Could not find font %d in %s", fontId, fileName.c_str());
		return false;
	}

	bool ok = loadFromFNT(*fontStream);
	delete fontStream;
	return ok;
}