mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Refactoring
This commit is contained in:
@@ -52,7 +52,7 @@ PLError_t DoOpenDocAE (const AppleEvent *theAE, AppleEvent *reply, UInt32 ref)
|
|||||||
VFileInfo finderInfo;
|
VFileInfo finderInfo;
|
||||||
AEDescList docList;
|
AEDescList docList;
|
||||||
long itemsInList;
|
long itemsInList;
|
||||||
Size actualSize;
|
size_t actualSize;
|
||||||
AEKeyword keywd;
|
AEKeyword keywd;
|
||||||
DescType returnedType;
|
DescType returnedType;
|
||||||
PLError_t theErr, whoCares;
|
PLError_t theErr, whoCares;
|
||||||
@@ -162,7 +162,7 @@ PLError_t DoQuitAE (const AppleEvent *theAE, AppleEvent *reply, UInt32 ref)
|
|||||||
PLError_t MyGotRequiredParams (const AppleEvent *theAE)
|
PLError_t MyGotRequiredParams (const AppleEvent *theAE)
|
||||||
{
|
{
|
||||||
DescType returnedType;
|
DescType returnedType;
|
||||||
Size actualSize;
|
size_t actualSize;
|
||||||
|
|
||||||
return (AEGetAttributePtr(theAE, keyMissedKeywordAttr, typeWildCard,
|
return (AEGetAttributePtr(theAE, keyMissedKeywordAttr, typeWildCard,
|
||||||
&returnedType, 0L, 0, &actualSize) == errAEDescNotFound) ? PLErrors::kNone :
|
&returnedType, 0L, 0, &actualSize) == errAEDescNotFound) ? PLErrors::kNone :
|
||||||
|
@@ -58,7 +58,7 @@ Boolean CreateNewHouse (void)
|
|||||||
{
|
{
|
||||||
AEKeyword theKeyword;
|
AEKeyword theKeyword;
|
||||||
DescType actualType;
|
DescType actualType;
|
||||||
Size actualSize;
|
size_t actualSize;
|
||||||
VFileSpec tempSpec;
|
VFileSpec tempSpec;
|
||||||
VFileSpec theSpec;
|
VFileSpec theSpec;
|
||||||
PLError_t theErr;
|
PLError_t theErr;
|
||||||
|
@@ -42,7 +42,7 @@ void SaveGame2 (void)
|
|||||||
PortabilityLayer::InputManager::GetInstance()->ClearState();
|
PortabilityLayer::InputManager::GetInstance()->ClearState();
|
||||||
|
|
||||||
Str255 gameNameStr;
|
Str255 gameNameStr;
|
||||||
Size byteCount;
|
size_t byteCount;
|
||||||
houseType *thisHousePtr;
|
houseType *thisHousePtr;
|
||||||
roomType *srcRoom;
|
roomType *srcRoom;
|
||||||
savedRoom *destRoom;
|
savedRoom *destRoom;
|
||||||
|
@@ -1,117 +1,117 @@
|
|||||||
#include "CFileStream.h"
|
#include "CFileStream.h"
|
||||||
|
|
||||||
namespace PortabilityLayer
|
namespace PortabilityLayer
|
||||||
{
|
{
|
||||||
CFileStream::CFileStream(FILE *f)
|
CFileStream::CFileStream(FILE *f)
|
||||||
: m_file(f)
|
: m_file(f)
|
||||||
, m_readOnly(false)
|
, m_readOnly(false)
|
||||||
, m_writeOnly(false)
|
, m_writeOnly(false)
|
||||||
, m_seekable(true)
|
, m_seekable(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CFileStream::CFileStream(FILE *f, bool isReadOnly, bool isWriteOnly, bool isSeekable)
|
CFileStream::CFileStream(FILE *f, bool isReadOnly, bool isWriteOnly, bool isSeekable)
|
||||||
: m_file(f)
|
: m_file(f)
|
||||||
, m_readOnly(isReadOnly)
|
, m_readOnly(isReadOnly)
|
||||||
, m_writeOnly(isWriteOnly)
|
, m_writeOnly(isWriteOnly)
|
||||||
, m_seekable(isSeekable)
|
, m_seekable(isSeekable)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CFileStream::Read(void *bytesOut, size_t size)
|
size_t CFileStream::Read(void *bytesOut, size_t size)
|
||||||
{
|
{
|
||||||
if (!m_file || m_writeOnly)
|
if (!m_file || m_writeOnly)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return fread(bytesOut, 1, size, m_file);
|
return fread(bytesOut, 1, size, m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CFileStream::Write(const void *bytes, size_t size)
|
size_t CFileStream::Write(const void *bytes, size_t size)
|
||||||
{
|
{
|
||||||
if (!m_file || m_readOnly)
|
if (!m_file || m_readOnly)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return fwrite(bytes, 1, size, m_file);
|
return fwrite(bytes, 1, size, m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::IsSeekable() const
|
bool CFileStream::IsSeekable() const
|
||||||
{
|
{
|
||||||
return m_seekable;
|
return m_seekable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::IsReadOnly() const
|
bool CFileStream::IsReadOnly() const
|
||||||
{
|
{
|
||||||
return m_readOnly;
|
return m_readOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::IsWriteOnly() const
|
bool CFileStream::IsWriteOnly() const
|
||||||
{
|
{
|
||||||
return m_writeOnly;
|
return m_writeOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::SeekStart(UFilePos_t loc)
|
bool CFileStream::SeekStart(UFilePos_t loc)
|
||||||
{
|
{
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return fseek(m_file, static_cast<long>(loc), SEEK_SET) == 0;
|
return fseek(m_file, static_cast<long>(loc), SEEK_SET) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::SeekCurrent(FilePos_t loc)
|
bool CFileStream::SeekCurrent(FilePos_t loc)
|
||||||
{
|
{
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return fseek(m_file, static_cast<long>(loc), SEEK_CUR) == 0;;
|
return fseek(m_file, static_cast<long>(loc), SEEK_CUR) == 0;;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::SeekEnd(UFilePos_t loc)
|
bool CFileStream::SeekEnd(UFilePos_t loc)
|
||||||
{
|
{
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return fseek(m_file, static_cast<long>(loc), SEEK_END) == 0;
|
return fseek(m_file, static_cast<long>(loc), SEEK_END) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFileStream::Truncate(UFilePos_t loc)
|
bool CFileStream::Truncate(UFilePos_t loc)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UFilePos_t CFileStream::Tell() const
|
UFilePos_t CFileStream::Tell() const
|
||||||
{
|
{
|
||||||
if (!m_file)
|
if (!m_file)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return static_cast<UFilePos_t>(ftell(m_file));
|
return static_cast<UFilePos_t>(ftell(m_file));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFileStream::Close()
|
void CFileStream::Close()
|
||||||
{
|
{
|
||||||
if (m_file)
|
if (m_file)
|
||||||
{
|
{
|
||||||
fclose(m_file);
|
fclose(m_file);
|
||||||
m_file = nullptr;
|
m_file = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFileStream::Flush()
|
void CFileStream::Flush()
|
||||||
{
|
{
|
||||||
if (m_file)
|
if (m_file)
|
||||||
fflush(m_file);
|
fflush(m_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UFilePos_t CFileStream::Size() const
|
UFilePos_t CFileStream::Size() const
|
||||||
{
|
{
|
||||||
if (!m_file || !m_seekable)
|
if (!m_file || !m_seekable)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
long oldPos = ftell(m_file);
|
long oldPos = ftell(m_file);
|
||||||
fseek(m_file, 0, SEEK_END);
|
fseek(m_file, 0, SEEK_END);
|
||||||
const UFilePos_t endPos = static_cast<UFilePos_t>(ftell(m_file));
|
const UFilePos_t endPos = static_cast<UFilePos_t>(ftell(m_file));
|
||||||
fseek(m_file, oldPos, SEEK_SET);
|
fseek(m_file, oldPos, SEEK_SET);
|
||||||
|
|
||||||
return endPos;
|
return endPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,43 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifndef __PL_CFILESTREAM_H__
|
#ifndef __PL_CFILESTREAM_H__
|
||||||
#define __PL_CFILESTREAM_H__
|
#define __PL_CFILESTREAM_H__
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "CoreDefs.h"
|
#include "CoreDefs.h"
|
||||||
#include "IOStream.h"
|
#include "IOStream.h"
|
||||||
|
|
||||||
namespace PortabilityLayer
|
namespace PortabilityLayer
|
||||||
{
|
{
|
||||||
class CFileStream final : public IOStream
|
class CFileStream final : public IOStream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit CFileStream(FILE *f);
|
explicit CFileStream(FILE *f);
|
||||||
CFileStream(FILE *f, bool isReadOnly, bool isWriteOnly, bool isSeekable);
|
CFileStream(FILE *f, bool isReadOnly, bool isWriteOnly, bool isSeekable);
|
||||||
|
|
||||||
size_t Read(void *bytesOut, size_t size) override;
|
size_t Read(void *bytesOut, size_t size) override;
|
||||||
size_t Write(const void *bytes, size_t size) override;
|
size_t Write(const void *bytes, size_t size) override;
|
||||||
bool IsSeekable() const override;
|
bool IsSeekable() const override;
|
||||||
bool IsReadOnly() const override;
|
bool IsReadOnly() const override;
|
||||||
bool IsWriteOnly() const override;
|
bool IsWriteOnly() const override;
|
||||||
bool SeekStart(UFilePos_t loc) override;
|
bool SeekStart(UFilePos_t loc) override;
|
||||||
bool SeekCurrent(FilePos_t loc) override;
|
bool SeekCurrent(FilePos_t loc) override;
|
||||||
bool SeekEnd(UFilePos_t loc) override;
|
bool SeekEnd(UFilePos_t loc) override;
|
||||||
bool Truncate(UFilePos_t loc) override;
|
bool Truncate(UFilePos_t loc) override;
|
||||||
UFilePos_t Size() const override;
|
UFilePos_t Size() const override;
|
||||||
UFilePos_t Tell() const override;
|
UFilePos_t Tell() const override;
|
||||||
void Close() override;
|
void Close() override;
|
||||||
void Flush() override;
|
void Flush() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CFileStream(const CFileStream &other) GP_DELETED;
|
CFileStream(const CFileStream &other) GP_DELETED;
|
||||||
|
|
||||||
FILE *m_file;
|
FILE *m_file;
|
||||||
bool m_readOnly;
|
bool m_readOnly;
|
||||||
bool m_writeOnly;
|
bool m_writeOnly;
|
||||||
bool m_seekable;
|
bool m_seekable;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -19,13 +19,13 @@ PLError_t AECountItems(AEDescList *descList, long *count)
|
|||||||
return PLErrors::kNone;
|
return PLErrors::kNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLError_t AEGetNthPtr(AEDescList *descList, long index, DescType desiredType, AEKeyword *keyword, DescType *type, void *data, Size maxSize, Size *actualSize)
|
PLError_t AEGetNthPtr(AEDescList *descList, long index, DescType desiredType, AEKeyword *keyword, DescType *type, void *data, size_t maxSize, size_t *actualSize)
|
||||||
{
|
{
|
||||||
PL_NotYetImplemented();
|
PL_NotYetImplemented();
|
||||||
return PLErrors::kNone;
|
return PLErrors::kNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLError_t AEGetAttributePtr(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, DescType *type, void *data, Size maxSize, Size *actualSize)
|
PLError_t AEGetAttributePtr(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, DescType *type, void *data, size_t maxSize, size_t *actualSize)
|
||||||
{
|
{
|
||||||
PL_NotYetImplemented();
|
PL_NotYetImplemented();
|
||||||
return PLErrors::kNone;
|
return PLErrors::kNone;
|
||||||
|
@@ -22,8 +22,8 @@ typedef AEEventHandler AEEventHandlerUPP;
|
|||||||
PLError_t AEGetParamDesc(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, AEDescList *descList);
|
PLError_t AEGetParamDesc(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, AEDescList *descList);
|
||||||
PLError_t AEDisposeDesc(AEDescList *descList);
|
PLError_t AEDisposeDesc(AEDescList *descList);
|
||||||
PLError_t AECountItems(AEDescList *descList, long *count);
|
PLError_t AECountItems(AEDescList *descList, long *count);
|
||||||
PLError_t AEGetNthPtr(AEDescList *descList, long index, DescType desiredType, AEKeyword *keyword, DescType *type, void *data, Size maxSize, Size *actualSize);
|
PLError_t AEGetNthPtr(AEDescList *descList, long index, DescType desiredType, AEKeyword *keyword, DescType *type, void *data, size_t maxSize, size_t *actualSize);
|
||||||
PLError_t AEGetAttributePtr(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, DescType *type, void *data, Size maxSize, Size *actualSize);
|
PLError_t AEGetAttributePtr(const AppleEvent *evt, AEKeyword keyword, DescType desiredType, DescType *type, void *data, size_t maxSize, size_t *actualSize);
|
||||||
PLError_t AEInstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandlerUPP handler, UInt32 ref, bool isSysHandler);
|
PLError_t AEInstallEventHandler(AEEventClass eventClass, AEEventID eventID, AEEventHandlerUPP handler, UInt32 ref, bool isSysHandler);
|
||||||
PLError_t AESetInteractionAllowed(AEInteractAllowed level);
|
PLError_t AESetInteractionAllowed(AEInteractAllowed level);
|
||||||
|
|
||||||
|
@@ -561,7 +561,7 @@ void ExitToShell()
|
|||||||
PL_NotYetImplemented();
|
PL_NotYetImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle NewHandle(Size size)
|
Handle NewHandle(size_t size)
|
||||||
{
|
{
|
||||||
PortabilityLayer::MMHandleBlock *hBlock = PortabilityLayer::MemoryManager::GetInstance()->AllocHandle(size);
|
PortabilityLayer::MMHandleBlock *hBlock = PortabilityLayer::MemoryManager::GetInstance()->AllocHandle(size);
|
||||||
if (!hBlock)
|
if (!hBlock)
|
||||||
@@ -578,7 +578,7 @@ long GetHandleSize(Handle handle)
|
|||||||
return handle.MMBlock()->m_size;
|
return handle.MMBlock()->m_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLError_t SetHandleSize(Handle hdl, Size newSize)
|
PLError_t SetHandleSize(Handle hdl, size_t newSize)
|
||||||
{
|
{
|
||||||
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
|
PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance();
|
||||||
if (!mm->ResizeHandle(hdl.MMBlock(), newSize))
|
if (!mm->ResizeHandle(hdl.MMBlock(), newSize))
|
||||||
@@ -587,12 +587,12 @@ PLError_t SetHandleSize(Handle hdl, Size newSize)
|
|||||||
return PLErrors::kNone;
|
return PLErrors::kNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *NewPtr(Size size)
|
void *NewPtr(size_t size)
|
||||||
{
|
{
|
||||||
return PortabilityLayer::MemoryManager::GetInstance()->Alloc(size);
|
return PortabilityLayer::MemoryManager::GetInstance()->Alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *NewPtrClear(Size size)
|
void *NewPtrClear(size_t size)
|
||||||
{
|
{
|
||||||
void *data = NewPtr(size);
|
void *data = NewPtr(size);
|
||||||
if (data != nullptr && size != 0)
|
if (data != nullptr && size != 0)
|
||||||
|
@@ -36,8 +36,6 @@ typedef int16_t SInt16;
|
|||||||
typedef int32_t Int32;
|
typedef int32_t Int32;
|
||||||
typedef uint32_t UInt32;
|
typedef uint32_t UInt32;
|
||||||
|
|
||||||
typedef size_t Size;
|
|
||||||
|
|
||||||
typedef unsigned char Str15[16];
|
typedef unsigned char Str15[16];
|
||||||
typedef unsigned char Str31[32];
|
typedef unsigned char Str31[32];
|
||||||
typedef unsigned char Str63[64];
|
typedef unsigned char Str63[64];
|
||||||
@@ -256,13 +254,13 @@ void GetTime(DateTimeRec *dateTime);
|
|||||||
|
|
||||||
void FlushEvents();
|
void FlushEvents();
|
||||||
|
|
||||||
Handle NewHandle(Size size);
|
Handle NewHandle(size_t size);
|
||||||
long GetHandleSize(Handle handle);
|
long GetHandleSize(Handle handle);
|
||||||
|
|
||||||
PLError_t SetHandleSize(Handle hdl, Size newSize);
|
PLError_t SetHandleSize(Handle hdl, size_t newSize);
|
||||||
|
|
||||||
void *NewPtr(Size size);
|
void *NewPtr(size_t size);
|
||||||
void *NewPtrClear(Size size);
|
void *NewPtrClear(size_t size);
|
||||||
void DisposePtr(void *ptr);
|
void DisposePtr(void *ptr);
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user