1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
|
#if !defined(AFX_ADFWRAPPER_H__20001226_7276_AC4A_215B_0080AD509054__INCLUDED_)
#define AFX_ADFWRAPPER_H__20001226_7276_AC4A_215B_0080AD509054__INCLUDED_
#pragma once
//
// These classes are C++ wrappers for the ADFlib (Amiga Disk File library).
// ADFlib is developed by Laurent Clvy.
//
// They do not extend the functionality of ADFlib in any way,
// except that they give me: nice C++ classes, dtor cleanup,
// more const-ness, Windows datatypes, MBCS and UNICODE compilation.
//
#ifndef __ATLBASE_H__
#error adfwrappers.h requires atlbase.h to be included first
#endif
#ifdef _DEBUG
#pragma comment(lib, "adflib\\libs\\adfdbg.lib")
#else
#pragma comment(lib, "adflib\\libs\\adf.lib")
#endif
#include "adflib\include\adflib.h"
extern "C" {
#include "adflib\include\adf_util.h"
#include "adflib\include\adf_dir.h"
#include "adflib\include\Win32\adf_nativ.h"
}
extern "C" struct Env adfEnv;
class CAdfDevice;
class CAdfVolume;
class CAdfFile;
class CAdfDirList;
class CAdfDelList;
class CAdf
{
public:
CAdf()
{
// System initialize...
adfEnvInitDefault();
// Use the dir cache blocks
BOOL boolPr = TRUE;
adfChgEnvProp(PR_USEDIRC, (void*)&boolPr);
// Need to set callbacks to prevent Console output
adfSetEnvFct(ADFError, ADFWarning, ADFVerbose);
adfEnv.rwhAccess = ADFAccess;
adfEnv.progressBar = ADFProgress;
adfEnv.useRWAccess = TRUE;
adfEnv.useProgressBar = TRUE;
adfEnv.useDirCache = FALSE;
}
virtual ~CAdf()
{
// Shutdown ADF system
adfEnvCleanUp();
}
LPCSTR GetVersionNumber() { return adfGetVersionNumber(); };
LPCSTR GetVersionDate() { return adfGetVersionDate(); };
BOOL IsSilent() const { return m_bSilent; };
void SetSilent(BOOL bSilent) { m_bSilent = bSilent; };
// Attributes
private:
static BOOL m_bSilent; // Supress error/warnings?
// Needs to be static because it's used by the callbacks.
// Callbacks
private:
static VOID ADFError(char *strMessage)
{
USES_CONVERSION;
if( !m_bSilent ) ::MessageBox(NULL, A2CT(strMessage), NULL, MB_OK | MB_ICONERROR);
}
static VOID ADFWarning(char *strMessage)
{
strMessage;
#ifdef _DEBUG
USES_CONVERSION;
if( !m_bSilent ) ::MessageBox(NULL, A2CT(strMessage), _T("Warning"), MB_OK | MB_ICONWARNING);
#endif
}
static VOID ADFVerbose(char *strMessage)
{
strMessage;
#ifdef _DEBUG
USES_CONVERSION;
if( !m_bSilent ) ::MessageBox(NULL, A2CT(strMessage), _T("Verbose Warning"), MB_OK | MB_ICONINFORMATION);
#endif
}
static VOID ADFAccess(SECTNUM physical, SECTNUM logical, BOOL write)
{
physical;
logical;
write;
}
static VOID ADFProgress(int perCentDone)
{
perCentDone;
}
};
__declspec(selectany) BOOL CAdf::m_bSilent = FALSE;
class CAdfFile
{
friend CAdfVolume;
protected:
File *m_file;
public:
CAdfFile()
{
m_file = NULL;
}
virtual ~CAdfFile()
{
if( m_file!=NULL ) adfCloseFile(m_file);
}
BOOL IsOpen() const { return m_file!=NULL; };
UINT GetType() const { return m_file->fileHdr->secType; };
BOOL IsDirectory() const { return _IsDirectory(GetType()); };
BOOL IsLink() const { return _IsLink(GetType()); };
ULONG Read(LPVOID pv, ULONG cb)
{
return (ULONG)adfReadFile(m_file, cb, (unsigned char *)pv);
}
ULONG Write(LPCVOID pv, ULONG cb)
{
return (ULONG)adfWriteFile(m_file, cb, (unsigned char *)pv);
}
BOOL Eof()
{
return adfEndOfFile(m_file);
}
BOOL Seek(DWORD dwPos)
{
adfFileSeek(m_file, dwPos);
return TRUE; // Erh?
}
DWORD GetPos() const
{
return m_file->pos;
}
DWORD GetAccess() const
{
return m_file->fileHdr->access;
}
static void ConvertAccess(DWORD dwAccess, LPTSTR pstrAccess)
{
USES_CONVERSION;
_tcscpy( pstrAccess, A2CT(adfAccess2String(dwAccess)) );
}
FILETIME GetFileTime()
{
int y,m,d;
adfDays2Date(m_file->fileHdr->days, &y, &m, &d);
SYSTEMTIME st;
st.wYear = (WORD)y;
st.wMonth = (WORD)m;
st.wDay = (WORD)d;
st.wHour = (WORD)((m_file->fileHdr->mins / 60)+1);
st.wMinute = (WORD)((m_file->fileHdr->mins % 60)+1);
st.wSecond = (WORD)((m_file->fileHdr->ticks / 50));
FILETIME ft;
::SystemTimeToFileTime(&st, &ft);
FILETIME ftLocal;
::FileTimeToLocalFileTime(&ft, &ftLocal);
return ftLocal;
}
void Flush()
{
adfFlushFile(m_file);
}
void Close()
{
adfCloseFile(m_file);
m_file = NULL;
}
void GetName(LPTSTR pstrName, UINT cbChars)
{
USES_CONVERSION;
cbChars--;
_tcsncpy( pstrName, m_file->fileHdr->fileName==NULL ? _T("") : A2CT(m_file->fileHdr->fileName), cbChars);
if( m_file->fileHdr->nameLen < (int)cbChars ) cbChars = (UINT)m_file->fileHdr->nameLen;
pstrName[cbChars] = _T('\0');
}
DWORD GetSize() const
{
return m_file->fileHdr->byteSize;
}
DWORD GetActualSize(DWORD dwDataBlockSize=LOGICAL_BLOCK_SIZE)
{
return _CalcBlocksNeeded(GetSize(), dwDataBlockSize);
}
static DWORD _CalcBlocksNeeded(DWORD dwFileSize, DWORD dwDataBlockSize=LOGICAL_BLOCK_SIZE)
{
return (DWORD)adfFileRealSize(dwFileSize, dwDataBlockSize, NULL, NULL);
}
static BOOL _IsDirectory(DWORD dwAccess)
{
return dwAccess==ST_DIR || dwAccess==ST_LDIR;
}
static BOOL _IsLink(DWORD dwAccess)
{
return dwAccess==ST_LDIR || dwAccess==ST_LFILE || dwAccess==ST_LSOFT;
}
};
class CAdfDirList
{
friend CAdfVolume;
protected:
List *m_list;
public:
CAdfDirList()
{
m_list = NULL;
}
virtual ~CAdfDirList()
{
if( m_list!=NULL ) adfFreeDirList(m_list);
}
operator List *() const
{
return m_list;
};
};
class CAdfDelList
{
friend CAdfVolume;
protected:
List *m_list;
public:
CAdfDelList()
{
m_list = NULL;
}
virtual ~CAdfDelList()
{
if( m_list!=NULL ) adfFreeDelList(m_list);
}
operator List *() const
{
return m_list;
};
};
class CAdfVolume
{
friend CAdfDevice;
protected:
Volume *m_vol;
public:
CAdfVolume()
{
m_vol = NULL;
}
virtual ~CAdfVolume()
{
if( m_vol!=NULL ) adfUnMount(m_vol);
}
BOOL IsOpen() const { return m_vol!=NULL; };
void GetName(LPTSTR pstrName, UINT cbChars)
{
USES_CONVERSION;
cbChars--;
_tcsncpy( pstrName, m_vol->volName==NULL ? _T("") : A2CT(m_vol->volName), cbChars);
pstrName[cbChars] = _T('\0');
}
SECTNUM GetDirectoryPtr() const { return m_vol->curDirPtr; };
SECTNUM GetFirstBlock() const { return m_vol->firstBlock; };
SECTNUM GetLastBlock() const { return m_vol->lastBlock; };
SECTNUM GetRootBlock() const { return m_vol->rootBlock; };
DWORD GetDataBlockSize() const { return m_vol->datablockSize; };
DWORD GetFreeBlockCount() { return adfCountFreeBlocks(m_vol); };
BOOL IsBootable() const { return m_vol->bootCode; };
BOOL IsReadOnly() const { return m_vol->readOnly; };
int GetDOSType() const { return (int)(m_vol->dosType); };
BOOL GetFile(LPCTSTR pstrFileName, LPCTSTR pstrAccess, CAdfFile &AmigaFile)
{
USES_CONVERSION;
File * file = adfOpenFile(m_vol,
T2A(const_cast<LPTSTR>(pstrFileName)),
T2A(const_cast<LPTSTR>(pstrAccess)));
if( file==NULL ) return FALSE;
AmigaFile.m_file = file;
return TRUE;
}
BOOL CreateDirectory(SECTNUM nSector, LPCTSTR pstrName)
{
USES_CONVERSION;
return adfCreateDir(m_vol, nSector, T2A(const_cast<LPTSTR>(pstrName)))==RC_OK;
}
BOOL GetDirctory(SECTNUM nSector, CAdfDirList &DirList)
{
List *dir = adfGetDirEnt(m_vol, nSector);
if( dir==NULL ) return TRUE; // Empty?
DirList.m_list = dir;
return TRUE;
}
BOOL GetCurrentDirctory(CAdfDirList &DirList)
{
return GetDirctory(GetDirectoryPtr(), DirList);
}
BOOL ChangeDirectoryParent()
{
return( adfParentDir(m_vol)==RC_OK );
}
BOOL ChangeDirectory(LPCTSTR pstrPath)
{
USES_CONVERSION;
if( *pstrPath==_T('\0') ) return TRUE;
// In the case where only one subdir is requested we just pass
// the value. This is the only type ADFlib supports.
if( _tcschr(pstrPath, _T('/'))==NULL ) {
return adfChangeDir(m_vol, T2A(const_cast<LPTSTR>(pstrPath)))==RC_OK;
}
// If a complete path is given, we need to do the parsing
// ourselves! So start by going to root dir..
if( *pstrPath == _T('/') ) {
pstrPath++;
adfToRootDir(m_vol);
}
// Otherwise parse remaining sub-dirs
LPTSTR p;
while( (p = _tcschr(pstrPath, _T('/')))!=NULL ) {
TCHAR szPath[MAXNAMELEN+1];
int size = p - pstrPath;
_tcsncpy( szPath, pstrPath, size);
szPath[ size ] = _T('\0');
if( adfChangeDir(m_vol, T2A(szPath))!=RC_OK ) return FALSE;
pstrPath = p+1;
}
if( *pstrPath!=_T('\0') ) {
return adfChangeDir(m_vol, T2A(const_cast<LPTSTR>(pstrPath)))==RC_OK;
}
return TRUE;
}
BOOL GetDeletedEntries(CAdfDelList &DelList)
{
List *dir = adfGetDelEnt(m_vol);
if( dir==NULL ) return TRUE; // Empty?
DelList.m_list = dir;
return TRUE;
}
BOOL CheckDeletedFile(SECTNUM nSector, int nLevel=0)
{
return adfCheckEntry(m_vol, nSector, nLevel)==RC_OK;
}
BOOL UndeleteFile(SECTNUM nParentSector, SECTNUM nSector)
{
return adfUndelEntry(m_vol, nParentSector, nSector)==RC_OK;
}
BOOL SetFileAccess(LPCTSTR pstrName, SECTNUM nSector, DWORD dwAccess)
{
USES_CONVERSION;
return adfSetEntryAccess(m_vol, nSector, T2A(const_cast<LPTSTR>(pstrName)), (long)dwAccess)==RC_OK;
}
BOOL SetFileComment(LPCTSTR pstrName, SECTNUM nSector, LPCTSTR pstrComment)
{
USES_CONVERSION;
return adfSetEntryComment(m_vol, nSector, T2A(const_cast<LPTSTR>(pstrName)), T2A(const_cast<LPTSTR>(pstrComment)))==RC_OK;
}
BOOL Rename(SECTNUM nOldSector, LPCTSTR pstrOldName,
SECTNUM nNewSector, LPCTSTR pstrNewName)
{
USES_CONVERSION;
return adfRenameEntry(m_vol,
nOldSector, T2A(const_cast<LPTSTR>(pstrOldName)),
nNewSector, T2A(const_cast<LPTSTR>(pstrNewName)))==RC_OK;
}
BOOL Delete(SECTNUM nParentSector, LPCTSTR pstrName)
{
USES_CONVERSION;
return adfRemoveEntry(m_vol, nParentSector, T2A(const_cast<LPTSTR>(pstrName)))==RC_OK;
}
};
class CAdfDevice
{
protected:
Device *m_dev;
public:
CAdfDevice()
{
m_dev = NULL;
}
virtual ~CAdfDevice()
{
if( m_dev!=NULL ) adfUnMountDev(m_dev);
}
static BOOL _IsNativeDevice(LPCTSTR pstrDeviceName)
{
USES_CONVERSION;
nativeFunctions *nFct = (struct nativeFunctions *)adfEnv.nativeFct;
return (*nFct->adfIsDevNative)(T2A(const_cast<LPTSTR>(pstrDeviceName)));
}
BOOL IsOpen() const { return m_dev!=NULL; };
BOOL Open(LPCTSTR pstrFileName, BOOL bReadOnly=FALSE)
{
USES_CONVERSION;
m_dev = adfMountDev(T2A(const_cast<LPTSTR>(pstrFileName)), bReadOnly);
if( m_dev==NULL ) return FALSE;
switch( m_dev->devType ) {
case DEVTYPE_FLOPDD:
case DEVTYPE_FLOPHD:
case DEVTYPE_HARDDISK:
case DEVTYPE_HARDFILE:
break;
case -1:
// Invalid device read! ADFlib will crash on adfUnMountDev()
// BUG: Causes memory-leak.
m_dev = NULL;
return FALSE;
}
return TRUE;
}
BOOL Close()
{
if( m_dev==NULL ) return TRUE;
adfUnMountDev(m_dev);
return TRUE;
}
UINT GetType() const { return m_dev->devType; };
BOOL IsReadOnly() const { return m_dev->readOnly; };
DWORD GetDiskSize() const { return m_dev->size; };
DWORD GetPartitionCount() const { return m_dev->nVol; };
BOOL Mount(DWORD nPartition, BOOL bReadOnly, CAdfVolume &volume)
{
Volume *vol = adfMount(m_dev, (int)nPartition, bReadOnly);
if( vol==NULL ) return FALSE;
volume.m_vol = vol;
return TRUE;
}
};
#endif // !defined(AFX_ADFWRAPPER_H__20001226_7276_AC4A_215B_0080AD509054__INCLUDED_)
|