From 99321a3f9362cc312b866a4017719a723d089423 Mon Sep 17 00:00:00 2001 From: ksherlock Date: Thu, 10 Dec 2009 02:18:05 +0000 Subject: [PATCH] git-svn-id: https://profuse.googlecode.com/svn/branches/v2@136 aa027e90-d47c-11dd-86d7-074df07e0730 --- pascal/File.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- pascal/File.h | 25 ++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/pascal/File.cpp b/pascal/File.cpp index 43c5e07..72916d9 100644 --- a/pascal/File.cpp +++ b/pascal/File.cpp @@ -142,7 +142,7 @@ FileEntry *VolumeEntry::fileAtIndex(unsigned i) const return i < _files.size() ? _files[i] : NULL; } -#if 0 + #pragma mark - #pragma mark FileEntry @@ -150,10 +150,49 @@ FileEntry *VolumeEntry::fileAtIndex(unsigned i) const FileEntry::FileEntry(void *vp) : Entry(vp) { - - + _status = Read8(vp, 0x05) & 0x01; + _fileNameLength = Read8(vp, 0x06); + std::memset(_fileName, 0, 16); + std::memcpy(_fileName, 0x07 + (uint8_t *)vp, _fileNameLength); + _lastByte = Read16(vp, 0x16); + _modification = DateRec(Read16(vp, 0x18)); } +FileEntry::~FileEntry() +{ + delete _pageLength; +} + + +unsigned FileEntry::fileSize() +{ + switch(fileKind()) + { + case kTextFile: + return textFileSize(); + break; + default: + return dataFileSize(); + break; + } +} + + +int FileEntry::read(uint8_t *buffer, unsigned size, unsigned offset) +{ + switch(fileKind()) + { + case kTextFile: + return textRead(buffer, size, offset); + break; + default: + return dataRead(buffer, size, offset); + break; + } +} + +#if 0 + unsigned File::fileSize() { return (_lastBlock - _firstBlock - 1) * 512 + _lastByte; } diff --git a/pascal/File.h b/pascal/File.h index c1d7f3c..c5297ee 100644 --- a/pascal/File.h +++ b/pascal/File.h @@ -11,6 +11,19 @@ namespace ProFUSE { namespace Pascal { + +enum { + kUntypedFile, + kBadBlockFile, + kCodeFile, + kTextFile, + kInfoFile, + kDataFile, + kGrafFile, + kFotoFile, + kSecureDir +}; + class FileEntry; class Entry { @@ -97,13 +110,19 @@ class FileEntry : public Entry { unsigned _lastByte; DateRec _modification; + // non-text files + unsigned dataFileSize(); + int dataRead(uint8_t *buffer, unsigned size, unsigned offset); + // for text files. + unsigned textFileSize(); + int textRead(uint8_t *buffer, unsigned size, unsigned offset); - unsigned readTextPage(unsigned block, uint8_t *in); - unsigned decodeTextPage(unsigned block, uint8_t *out); + unsigned textReadPage(unsigned block, uint8_t *in); + unsigned textDecodePage(unsigned block, uint8_t *out); - std::vector *_pageLengths; + std::vector *_pageLength; unsigned _fileSize; };