//************************************************************************************** // Filename: CErrorLog.cp // Copyright © 1999 Tomasz Kukielka. All rights reserved. // // Description: // //************************************************************************************** // Revision History: // Monday, June 14, 1999 - Original //************************************************************************************** #include "CErrorLog.h" #include "CycloneConstants.h" #include #include #include "MoreFilesX.h" #include "AFileFork.h" extern StrFileName gCurrFileName; CErrorLog::CErrorLog() { } CErrorLog::~CErrorLog() { } void CErrorLog::AddError(OSStatus inErr) { ErrorRec theRecord; theRecord.errNumber = inErr; LString::CopyPStr(gCurrFileName, theRecord.fileName, sizeof(StrFileName) ); mErrorArr.AddItem( theRecord ); } void CErrorLog::ShowLog() { } Boolean CErrorLog::SaveLog(const FSRef &lastFileRef) { UInt32 errorCount = mErrorArr.GetCount(); if(errorCount == 0) return true;//everything is OK FSRef parentRef; ::memset(&parentRef, 0, sizeof(FSRef)); OSErr err = FSGetParentRef(&lastFileRef, &parentRef); if(err != noErr) { //? alert here that we cannot save error log ? return false; } const UniChar *errLogName = (const UniChar *)"\0C\0y\0c\0l\0o\0n\0e\0 \0E\0r\0r\0o\0r\0 \0L\0o\0g\0\0"; FSCatalogInfo newFileInfo; newFileInfo.textEncodingHint = kTextEncodingMacRoman; FInfo finderInfo; ::memset(&finderInfo, 0, sizeof(FInfo)); finderInfo.fdType = kErrorLogFileType; finderInfo.fdCreator = kAppSignature; *((FInfo*)&newFileInfo.finderInfo) = finderInfo; FSRef newRef; ::memset(&newRef, 0, sizeof(FSRef)); err = FSCreateFileUnicode( &parentRef, 17, errLogName, kFSCatInfoTextEncoding | kFSCatInfoFinderInfo, &newFileInfo, &newRef, NULL); /* error will be thrown anyway if we try to access the file if(err != noErr) { //check what error //? alert here that we cannot save error log ? return false; } */ ARefFork logFileStream(newRef, fsRdWrPerm);//destructor will close the file if(err == noErr) { //we do not catch anything here - any throws will be cought outside logFileStream.SetPosition( 0, fsFromLEOF); DateTimeRec time; ::GetTime(&time); LStr255 string(rMiscStrings, 12);//error log generated... string += time.day; string += '-'; string += time.month; string += '-'; string += time.year; string += "\p, "; string += time.hour; string += ':'; string += time.minute; string += ':'; string += time.second; string += "\p\n\n"; logFileStream.Write( string.Length(), string.TextPtr() ); string.Assign( rMiscStrings, 11);//the following files: string += '\n'; logFileStream.Write( string.Length(), string.TextPtr() ); ErrorRec errorRecord; for( ArrayIndexT i = 1; i<= errorCount; i++) { mErrorArr.FetchItemAt(i, errorRecord); string = '\t'; string += (ConstStringPtr)(errorRecord.fileName); if(errorRecord.errNumber != noErr) //if error number is set { string += "\p\nError: "; string += (errorRecord.errNumber); string += "\p\n"; } logFileStream.Write( string.Length(), string.TextPtr() ); } string = "\p\n---------\n"; logFileStream.Write( string.Length(), string.TextPtr() ); return true; } return false; }