<commit_before>#include <limits.h>
#include "ISO9660.h"
#include "PtrMacro.h"
#include "StdStream.h"
#include "File.h"
#include "DirectoryRecord.h"
#include "stricmp.h"

using namespace Framework;
using namespace ISO9660;
using namespace std;

CISO9660::CISO9660(CStream* pStream) :
m_pStream(pStream),
m_volumeDescriptor(pStream),
m_pathTable(pStream, m_volumeDescriptor.GetLPathTableAddress())
{

}

CISO9660::~CISO9660()
{
	DELETEPTR(m_pStream);
}

void CISO9660::ReadBlock(uint32 nAddress, void* pData)
{
	//Caching mechanism?
	m_pStream->Seek(nAddress * BLOCKSIZE, Framework::STREAM_SEEK_SET);
	m_pStream->Read(pData, BLOCKSIZE);
}

bool CISO9660::GetFileRecord(CDirectoryRecord* pRecord, const char* sFilename)
{
	const char* sNext;
	unsigned int nRecord;
	unsigned int nAddress;

	//Remove the first '/'
	if(sFilename[0] == '/' || sFilename[0] == '\\') sFilename++;

	nRecord = m_pathTable.FindRoot();

	while(1)
	{
		//Find the next '/'
		sNext = strchr(sFilename, '/');
		if(sNext == NULL) break;

        string sDir(sFilename, sNext);
		nRecord = m_pathTable.FindDirectory(sDir.c_str(), nRecord);
		if(nRecord == 0)
		{
			return false;
		}

		sFilename = sNext + 1;
	}

	nAddress = m_pathTable.GetDirectoryAddress(nRecord);

	return GetFileRecordFromDirectory(pRecord, nAddress, sFilename);
}

bool CISO9660::GetFileRecordFromDirectory(CDirectoryRecord* pRecord, uint32 nAddress, const char* sFilename)
{
	CFile Directory(this, nAddress * BLOCKSIZE, ULLONG_MAX - (nAddress * BLOCKSIZE));

	while(1)
	{
		CDirectoryRecord Entry(&Directory);

		if(Entry.GetLength() == 0) break;
		if(Entry.IsDirectory()) continue;
		if(strnicmp(Entry.GetName(), sFilename, strlen(sFilename))) continue;<commit_msg>Allow CISO9660::GetFileRecordFromDirectory to return directory records. Function name should probably be changed. Was needed for Baldur's Gate: Dark Alliance<commit_after>#include <limits.h>
#include "ISO9660.h"
#include "PtrMacro.h"
#include "StdStream.h"
#include "File.h"
#include "DirectoryRecord.h"
#include "stricmp.h"

using namespace Framework;
using namespace ISO9660;
using namespace std;

CISO9660::CISO9660(CStream* pStream) :
m_pStream(pStream),
m_volumeDescriptor(pStream),
m_pathTable(pStream, m_volumeDescriptor.GetLPathTableAddress())
{

}

CISO9660::~CISO9660()
{
	DELETEPTR(m_pStream);
}

void CISO9660::ReadBlock(uint32 nAddress, void* pData)
{
	//Caching mechanism?
	m_pStream->Seek(nAddress * BLOCKSIZE, Framework::STREAM_SEEK_SET);
	m_pStream->Read(pData, BLOCKSIZE);
}

bool CISO9660::GetFileRecord(CDirectoryRecord* pRecord, const char* sFilename)
{
	const char* sNext;
	unsigned int nRecord;
	unsigned int nAddress;

	//Remove the first '/'
	if(sFilename[0] == '/' || sFilename[0] == '\\') sFilename++;

	nRecord = m_pathTable.FindRoot();

	while(1)
	{
		//Find the next '/'
		sNext = strchr(sFilename, '/');
		if(sNext == NULL) break;

        string sDir(sFilename, sNext);
		nRecord = m_pathTable.FindDirectory(sDir.c_str(), nRecord);
		if(nRecord == 0)
		{
			return false;
		}

		sFilename = sNext + 1;
	}

	nAddress = m_pathTable.GetDirectoryAddress(nRecord);

	return GetFileRecordFromDirectory(pRecord, nAddress, sFilename);
}

bool CISO9660::GetFileRecordFromDirectory(CDirectoryRecord* pRecord, uint32 nAddress, const char* sFilename)
{
	CFile Directory(this, nAddress * BLOCKSIZE, ULLONG_MAX - (nAddress * BLOCKSIZE));

	while(1)
	{
		CDirectoryRecord Entry(&Directory);

		if(Entry.GetLength() == 0) break;
		if(strnicmp(Entry.GetName(), sFilename, strlen(sFilename))) continue;
{'fraction_non_alphanumeric': 0.1373439273552781, 'fraction_numerical': 0.027809307604994324, 'mean_word_length': 5.701520912547529, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3484521', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1256, 'n_words': 257}