Browse Source

Fix building plStatusLog.

Darryl Pogue 13 years ago
parent
commit
a980fe454f
  1. 57
      Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

57
Sources/Plasma/PubUtilLib/plStatusLog/plStatusLog.cpp

@ -66,7 +66,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStlUtils.h" #include "hsStlUtils.h"
#include "plFile/hsFiles.h" #include "plFile/hsFiles.h"
#include "plUnifiedTime/plUnifiedTime.h" #include "plUnifiedTime/plUnifiedTime.h"
#include "pnUtils/pnUtils.h"
#include "pnProduct/pnProduct.h" #include "pnProduct/pnProduct.h"
#include "plEncryptLogLine.h" #include "plEncryptLogLine.h"
@ -91,7 +90,8 @@ plStatusLogMgr::plStatusLogMgr()
fDrawer = nil; fDrawer = nil;
fLastLogChangeTime = 0; fLastLogChangeTime = 0;
PathGetLogDirectory(fBasePath, arrsize(fBasePath)); plFileUtils::ConcatFileName(fBasePath, L"log");
plFileUtils::EnsureFilePathExists(fBasePath);
} }
plStatusLogMgr::~plStatusLogMgr() plStatusLogMgr::~plStatusLogMgr()
@ -352,6 +352,7 @@ bool plStatusLogMgr::DumpLogs( const wchar *newFolderName )
newPath = newFolderName; newPath = newFolderName;
IEnsurePathExists(newPath.c_str()); IEnsurePathExists(newPath.c_str());
#if HS_BUILD_FOR_WIN32
hsWFolderIterator folderIterator; hsWFolderIterator folderIterator;
if (fBasePath) if (fBasePath)
folderIterator.SetPath(fBasePath); folderIterator.SetPath(fBasePath);
@ -382,6 +383,7 @@ bool plStatusLogMgr::DumpLogs( const wchar *newFolderName )
bool succeeded = (CopyFileW(source.c_str(), destination.c_str(), FALSE) != 0); bool succeeded = (CopyFileW(source.c_str(), destination.c_str(), FALSE) != 0);
retVal = retVal && succeeded; retVal = retVal && succeeded;
} }
#endif
return retVal; return retVal;
} }
@ -468,21 +470,21 @@ bool plStatusLog::IReOpen( void )
{ {
wchar work[MAX_PATH], work2[MAX_PATH]; wchar work[MAX_PATH], work2[MAX_PATH];
swprintf(work, MAX_PATH, L"%s.3%s",fileNoExt,ext); swprintf(work, MAX_PATH, L"%s.3%s",fileNoExt,ext);
_wremove(work); plFileUtils::RemoveFile(work);
swprintf(work2, MAX_PATH, L"%s.2%s",fileNoExt,ext); swprintf(work2, MAX_PATH, L"%s.2%s",fileNoExt,ext);
_wrename(work2, work); plFileUtils::FileMove(work2, work);
swprintf(work, MAX_PATH, L"%s.1%s",fileNoExt,ext); swprintf(work, MAX_PATH, L"%s.1%s",fileNoExt,ext);
_wrename(work, work2); plFileUtils::FileMove(work, work2);
_wrename(fileToOpen, work); plFileUtils::FileMove(fileToOpen, work);
} }
if (fFlags & kAppendToLast) if (fFlags & kAppendToLast)
{ {
fFileHandle = _wfopen( fileToOpen, fEncryptMe ? L"ab" : L"at" ); fFileHandle = hsWFopen( fileToOpen, fEncryptMe ? L"ab" : L"at" );
} }
else else
{ {
fFileHandle = _wfopen( fileToOpen, fEncryptMe ? L"wb" : L"wt" ); fFileHandle = hsWFopen( fileToOpen, fEncryptMe ? L"wb" : L"wt" );
// if we need to reopen lets just append // if we need to reopen lets just append
fFlags |= kAppendToLast; fFlags |= kAppendToLast;
} }
@ -542,7 +544,7 @@ void plStatusLog::IParseFileName(wchar* file, size_t fnsize, wchar* fileNoExt, w
else else
{ {
wcscpy(fileNoExt, file); wcscpy(fileNoExt, file);
*ext = L""; *ext = L'\0';
} }
} }
@ -649,7 +651,7 @@ bool plStatusLog::AddLine( const char *line, UInt32 color )
for( str = (char *)line; ( c = strchr( str, '\n' ) ) != nil; str = c + 1 ) for( str = (char *)line; ( c = strchr( str, '\n' ) ) != nil; str = c + 1 )
{ {
// So if we got here, c points to a carriage return... // So if we got here, c points to a carriage return...
ret = IAddLine( str, (UInt32)c - (UInt32)str, color ); ret = IAddLine( str, (unsigned_ptr)c - (unsigned_ptr)str, color );
} }
/// We might have some left over /// We might have some left over
@ -789,49 +791,44 @@ bool plStatusLog::IPrintLineToFile( const char *line, UInt32 count )
{ {
if ( fFlags & kTimestamp ) if ( fFlags & kTimestamp )
{ {
StrPrintf(work, arrsize(work), "(%s) ", plUnifiedTime(kNow).Format("%m/%d %H:%M:%S").c_str()); snprintf(work, arrsize(work), "(%s) ", plUnifiedTime(kNow).Format("%m/%d %H:%M:%S").c_str());
StrPack(buf, work, arrsize(buf)); strncat(buf, work, arrsize(work));
} }
if ( fFlags & kTimestampGMT ) if ( fFlags & kTimestampGMT )
{ {
StrPrintf(work, arrsize(work), "(%s) ", plUnifiedTime::GetCurrentTime().Format("%m/%d %H:%M:%S UTC").c_str()); snprintf(work, arrsize(work), "(%s) ", plUnifiedTime::GetCurrentTime().Format("%m/%d %H:%M:%S UTC").c_str());
StrPack(buf, work, arrsize(buf)); strncat(buf, work, arrsize(work));
} }
if ( fFlags & kTimeInSeconds ) if ( fFlags & kTimeInSeconds )
{ {
StrPrintf(work, arrsize(work), "(%lu) ", (unsigned long)plUnifiedTime(kNow).GetSecs()); snprintf(work, arrsize(work), "(%lu) ", (unsigned long)plUnifiedTime(kNow).GetSecs());
StrPack(buf, work, arrsize(buf)); strncat(buf, work, arrsize(work));
} }
if ( fFlags & kTimeAsDouble ) if ( fFlags & kTimeAsDouble )
{ {
StrPrintf(work, arrsize(work), "(%f) ", plUnifiedTime(kNow).GetSecsDouble()); snprintf(work, arrsize(work), "(%f) ", plUnifiedTime(kNow).GetSecsDouble());
StrPack(buf, work, arrsize(buf)); strncat(buf, work, arrsize(work));
} }
if (fFlags & kRawTimeStamp) if (fFlags & kRawTimeStamp)
{ {
StrPrintf(work, arrsize(work), "[t=%10u] ", hsTimer::GetSeconds()); snprintf(work, arrsize(work), "[t=%10u] ", hsTimer::GetSeconds());
StrPack(buf, work, arrsize(buf)); strncat(buf, work, arrsize(work));
} }
if (fFlags & kThreadID) if (fFlags & kThreadID)
{ {
StrPrintf(work, arrsize(work), "[t=%u] ", hsThread::GetMyThreadId()); snprintf(work, arrsize(work), "[t=%u] ", hsThread::GetMyThreadId());
StrPack(buf, work, arrsize(buf)); strncat(buf, work, arrsize(work));
} }
// find the size of the buf plus the size of the line and only pack that much strncat(buf, line, arrsize(line));
unsigned BufAndLine = StrLen(buf)+count+1;
if ( BufAndLine > arrsize(buf) )
BufAndLine = arrsize(buf);
StrPack(buf, line, BufAndLine );
if(!fEncryptMe ) if(!fEncryptMe )
{ {
StrPack(buf, "\n", arrsize(buf)); strncat(buf, "\n", 1);
} }
} }
unsigned length = StrLen(buf); unsigned length = strlen(buf);
#ifdef PLASMA_EXTERNAL_RELEASE #ifdef PLASMA_EXTERNAL_RELEASE
// Print to a separate line, since we have to encrypt it // Print to a separate line, since we have to encrypt it

Loading…
Cancel
Save