Moved Log to Common and made some changes to log formatting

This commit is contained in:
parax0 2016-02-15 05:28:20 -07:00
parent d39a9dd1c1
commit a35044ef83
31 changed files with 149 additions and 115 deletions

View File

@ -68,7 +68,8 @@ HEADERS += \
ETransformSpace.h \
Flags.h \
TString.h \
types.h
types.h \
Log.h
# Source Files
SOURCES += \
@ -79,4 +80,5 @@ SOURCES += \
CompressionUtil.cpp \
CTimer.cpp \
CUniqueID.cpp \
TString.cpp
TString.cpp \
Log.cpp

View File

@ -1,22 +1,29 @@
#include <Common/TString.h>
#include "CTimer.h"
#include "Log.h"
#include "TString.h"
#include <ctime>
#include <iostream>
namespace Log
{
TStringList ErrorLog;
static const TString gskLogFilename = "primeworldeditor.log";
TStringList gErrorLog;
TString gLogFilename;
FILE *gpLogFile;
#pragma warning(push)
#pragma warning(disable: 4996) // Can't use fopen_s here without creating a separate init function for the log
FILE *gpLogFile = fopen(*gskLogFilename, "w");
#pragma warning(pop)
double gAppStartTime = CTimer::GlobalTime();
void Write(const TString& rkMessage)
{
if (gpLogFile)
bool gInitialized = false;
TStringList gPreInitLogs;
bool InitLog(const TString& rkFilename)
{
fopen_s(&gpLogFile, *rkFilename, "w");
gLogFilename = rkFilename;
if (!gpLogFile) return false;
// Print initial message to log
time_t RawTime;
time(&RawTime);
@ -24,9 +31,31 @@ void Write(const TString& rkMessage)
localtime_s(&pTimeInfo, &RawTime);
char Buffer[80];
strftime(Buffer, 80, "[%H:%M:%S]", &pTimeInfo);
strftime(Buffer, 80, "%m/%d/%y %H:%M:%S", &pTimeInfo);
fprintf(gpLogFile, "%s %s\n", Buffer, *rkMessage);
fprintf(gpLogFile, "Opened log file at %s\n", Buffer);
fflush(gpLogFile);
// Print any messages that were attempted before we initialized
if (!gPreInitLogs.empty())
{
for (auto it = gPreInitLogs.begin(); it != gPreInitLogs.end(); it++)
Write(*it);
}
gInitialized = true;
return true;
}
void Write(const TString& rkMessage)
{
if (!gInitialized)
gPreInitLogs.push_back(rkMessage);
else if (gpLogFile)
{
double Time = CTimer::GlobalTime() - gAppStartTime;
fprintf(gpLogFile, "[%08.3f] %s\n", Time, *rkMessage);
fflush(gpLogFile);
}
}
@ -35,7 +64,7 @@ void Error(const TString& rkMessage)
{
TString FullMessage = "ERROR: " + rkMessage;
Write(FullMessage);
ErrorLog.push_back(FullMessage);
gErrorLog.push_back(FullMessage);
std::cout << FullMessage << "\n";
}
@ -43,7 +72,7 @@ void Warning(const TString& rkMessage)
{
TString FullMessage = "Warning: " + rkMessage;
Write(FullMessage);
ErrorLog.push_back(FullMessage);
gErrorLog.push_back(FullMessage);
std::cout << FullMessage << "\n";
}
@ -79,12 +108,12 @@ void FileWarning(const TString& rkFilename, u32 Offset, const TString& rkMessage
const TStringList& GetErrorLog()
{
return ErrorLog;
return gErrorLog;
}
void ClearErrorLog()
{
ErrorLog.clear();
gErrorLog.clear();
}
}

View File

@ -6,6 +6,7 @@
namespace Log
{
bool InitLog(const TString& rkFilename);
void Write(const TString& rkMessage);
void Error(const TString& rkMessage);
void Warning(const TString& rkMessage);

View File

@ -157,7 +157,6 @@ HEADERS += \
CAreaAttributes.h \
CLightParameters.h \
CRayCollisionTester.h \
Log.h \
SRayIntersection.h \
OpenGL/CDynamicVertexBuffer.h \
OpenGL/CFramebuffer.h \
@ -251,7 +250,6 @@ SOURCES += \
ScriptExtra/CWaypointExtra.cpp \
CAreaAttributes.cpp \
CRayCollisionTester.cpp \
Log.cpp \
OpenGL/CDynamicVertexBuffer.cpp \
OpenGL/CFramebuffer.cpp \
OpenGL/CGL.cpp \

View File

@ -1,7 +1,7 @@
#include "CDrawUtil.h"
#include "CGraphics.h"
#include "Core/Resource/CResCache.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <Math/CTransform4f.h>
#include <iostream>

View File

@ -1,7 +1,7 @@
#include "CGraphics.h"
#include "Core/OpenGL/CShader.h"
#include "Core/Resource/CMaterial.h"
#include "Core/Log.h"
#include <Common/Log.h>
// ************ MEMBER INITIALIZATION ************
CUniformBuffer* CGraphics::mpMVPBlockBuffer;

View File

@ -1,7 +1,7 @@
#include "CAnimationParameters.h"
#include "CAnimSet.h"
#include "CResCache.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
CAnimationParameters::CAnimationParameters()

View File

@ -9,7 +9,7 @@
#include "Core/Resource/Factory/CStringLoader.h"
#include "Core/Resource/Factory/CTextureDecoder.h"
#include "Core/Resource/Factory/CWorldLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <Common/TString.h>
#include <FileIO/FileIO.h>

View File

@ -1,6 +1,6 @@
#include "CAreaCooker.h"
#include "CScriptCooker.h"
#include <Core/Log.h>
#include <Common/Log.h>
CAreaCooker::CAreaCooker()
{

View File

@ -1,6 +1,6 @@
#include "CAnimSetLoader.h"
#include "Core/Resource/CResCache.h"
#include "Core/Log.h"
#include <Common/Log.h>
CAnimSetLoader::CAnimSetLoader()
{
@ -75,7 +75,6 @@ void CAnimSetLoader::LoadPASDatabase(IInputStream& PAS4)
CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& ANCS)
{
if (!ANCS.IsValid()) return nullptr;
Log::Write("Loading " + ANCS.GetSourceString());
u32 magic = ANCS.ReadLong();
if (magic != 0x00010001)
@ -172,7 +171,6 @@ CAnimSet* CAnimSetLoader::LoadANCS(IInputStream& ANCS)
CAnimSet* CAnimSetLoader::LoadCHAR(IInputStream &CHAR)
{
if (!CHAR.IsValid()) return nullptr;
Log::Write("Loading " + CHAR.GetSourceString());
CAnimSetLoader loader;
u8 check = CHAR.ReadByte();

View File

@ -3,7 +3,7 @@
#include "CModelLoader.h"
#include "CMaterialLoader.h"
#include "CScriptLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <Common/CFourCC.h>
#include <Common/CompressionUtil.h>
@ -613,7 +613,6 @@ CGameArea* CAreaLoader::LoadMREA(IInputStream& MREA)
// Validation
if (!MREA.IsValid()) return nullptr;
Log::Write("Loading " + MREA.GetSourceString());
u32 deadbeef = MREA.ReadLong();
if (deadbeef != 0xdeadbeef)

View File

@ -1,5 +1,5 @@
#include "CCollisionLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
CCollisionLoader::CCollisionLoader()

View File

@ -1,5 +1,5 @@
#include "CFontLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
CFontLoader::CFontLoader()
@ -82,7 +82,6 @@ CFont* CFontLoader::LoadFont(IInputStream& FONT)
CFont* CFontLoader::LoadFONT(IInputStream& FONT)
{
if (!FONT.IsValid()) return nullptr;
Log::Write("Loading " + FONT.GetSourceString());
CFourCC Magic(FONT);
if (Magic != "FONT")

View File

@ -1,7 +1,7 @@
#include "CMaterialLoader.h"
#include "Core/Resource/CResCache.h"
#include "Core/OpenGL/GLCommon.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
#include <iomanip>

View File

@ -1,6 +1,6 @@
#include "CModelLoader.h"
#include "CMaterialLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <map>
CModelLoader::CModelLoader()
@ -382,7 +382,6 @@ SSurface* CModelLoader::LoadAssimpMesh(const aiMesh *pMesh, CMaterialSet *pSet)
CModel* CModelLoader::LoadCMDL(IInputStream& CMDL)
{
CModelLoader Loader;
Log::Write("Loading " + CMDL.GetSourceString());
// CMDL header - same across the three Primes, but different structure in DKCR
u32 Magic = CMDL.ReadLong();

View File

@ -1,6 +1,6 @@
#include "CScanLoader.h"
#include "Core/Resource/CResCache.h"
#include "Core/Log.h"
#include <Common/Log.h>
CScanLoader::CScanLoader()
{
@ -142,7 +142,6 @@ void CScanLoader::LoadParamsMP3(IInputStream& SCAN)
CScan* CScanLoader::LoadSCAN(IInputStream &SCAN)
{
if (!SCAN.IsValid()) return nullptr;
Log::Write("Loading " + SCAN.GetSourceString());
/* Switching to EGame enum here isn't really useful unfortunately
* because the MP1 demo can be 1, 2, or 3, while MP1 is 5 and MP2+ is 2

View File

@ -2,7 +2,7 @@
#include "CTemplateLoader.h"
#include "Core/Resource/Script/CMasterTemplate.h"
#include "Core/Resource/CResCache.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
#include <sstream>

View File

@ -1,5 +1,5 @@
#include "CStringLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
CStringLoader::CStringLoader()
{
@ -162,7 +162,6 @@ CStringTable* CStringLoader::LoadSTRG(IInputStream& STRG)
{
// Verify that this is a valid STRG
if (!STRG.IsValid()) return nullptr;
Log::Write("Loading " + STRG.GetSourceString());
u32 Magic = STRG.ReadLong();
EGame Version = eUnknownVersion;

View File

@ -1,7 +1,7 @@
#include "CTemplateLoader.h"
#include "CAreaLoader.h"
#include "Core/Resource/Script/IPropertyTemplate.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <boost/filesystem.hpp>
const TString CTemplateLoader::mskTemplatesDir = "../templates/";

View File

@ -1,5 +1,5 @@
#include "CTextureDecoder.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <Common/CColor.h>
// A cleanup is warranted at some point. Trying to support both partial + full decode ended up really messy.
@ -127,7 +127,6 @@ CTexture* CTextureDecoder::DoFullDecode(CTexture*)
void CTextureDecoder::ReadTXTR(IInputStream& TXTR)
{
// Read TXTR header
Log::Write("Loading " + TXTR.GetSourceString());
mTexelFormat = ETexelFormat(TXTR.ReadLong());
mWidth = TXTR.ReadShort();
mHeight = TXTR.ReadShort();
@ -151,8 +150,6 @@ void CTextureDecoder::ReadTXTR(IInputStream& TXTR)
void CTextureDecoder::ReadDDS(IInputStream& DDS)
{
Log::Write("Loading " + DDS.GetSourceString());
// Header
CFourCC Magic(DDS);
if (Magic != "DDS ")

View File

@ -1,6 +1,6 @@
#include "CWorldLoader.h"
#include "Core/Resource/CResCache.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
CWorldLoader::CWorldLoader()
@ -285,7 +285,6 @@ void CWorldLoader::LoadReturnsMLVL(IInputStream& MLVL)
CWorld* CWorldLoader::LoadMLVL(IInputStream& MLVL)
{
if (!MLVL.IsValid()) return nullptr;
Log::Write("Loading " + MLVL.GetSourceString());
u32 Magic = MLVL.ReadLong();
if (Magic != 0xDEAFBABE)

View File

@ -1,6 +1,6 @@
#include "CMasterTemplate.h"
#include "Core/Resource/Factory/CWorldLoader.h"
#include "Core/Log.h"
#include <Common/Log.h>
CMasterTemplate::CMasterTemplate()
{

View File

@ -3,7 +3,7 @@
#include "CMasterTemplate.h"
#include "Core/Resource/CResCache.h"
#include "Core/Resource/CAnimSet.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include <iostream>
#include <string>

View File

@ -2,7 +2,7 @@
#define IPROPERTYVALUE_H
#include "EPropertyType.h"
#include "Core/Log.h"
#include <Common/Log.h>
#include "Core/Resource/CAnimationParameters.h"
#include "Core/Resource/CResource.h"
#include "Core/Resource/CResourceInfo.h"

View File

@ -177,7 +177,7 @@ void CScene::SetActiveArea(CGameArea *pArea)
}
mRanPostLoad = false;
Log::Write( TString::FromInt32(CSceneNode::NumNodes()) + " nodes" );
Log::Write( TString::FromInt32(CSceneNode::NumNodes(), 0, 10) + " nodes" );
}
void CScene::SetActiveWorld(CWorld* pWorld)

View File

@ -1,7 +1,7 @@
#include "CErrorLogDialog.h"
#include "ui_CErrorLogDialog.h"
#include "UICommon.h"
#include <Core/Log.h>
#include <Common/Log.h>
CErrorLogDialog::CErrorLogDialog(QWidget *parent) :
QDialog(parent),

View File

@ -3,7 +3,7 @@
#include <Core/Render/CDrawUtil.h>
#include <Core/Render/CRenderer.h>
#include <Core/Resource/CResCache.h>
#include <Core/Log.h>
#include <Common/Log.h>
#include <iostream>
#include <QApplication>

View File

@ -57,11 +57,16 @@ void CStartWindow::FillWorldUI()
TWideString WorldName = pWorldName->GetString("ENGL", 0);
ui->WorldNameLabel->setText( QString("<font size=5><b>") + TO_QSTRING(WorldName) + QString("</b></font>") );
ui->WorldNameSTRGLineEdit->setText(TO_QSTRING(pWorldName->Source()));
// hack to get around lack of UTF16 -> UTF8 support
TString WorldNameTStr = TO_TSTRING(QString::fromStdWString(WorldName.ToStdString()));
Log::Write("Loaded " + mpWorld->Source() + " (" + WorldNameTStr + ")");
}
else
{
ui->WorldNameLabel->clear();
ui->WorldNameSTRGLineEdit->clear();
Log::Write("Loaded " + mpWorld->Source() + " (unnamed world)");
}
CStringTable *pDarkWorldName = mpWorld->GetDarkWorldName();

View File

@ -14,7 +14,7 @@
#include <Core/Render/CDrawUtil.h>
#include <Core/Resource/Cooker/CAreaCooker.h>
#include <Core/Scene/CSceneIterator.h>
#include <Core/Log.h>
#include <Common/Log.h>
#include <iostream>
#include <QComboBox>
@ -188,11 +188,17 @@ void CWorldEditor::SetArea(CWorld *pWorld, CGameArea *pArea, u32 AreaIndex)
AreaName = "[Untitled Area]";
setWindowTitle(QString("Prime World Editor - %1 - %2[*]").arg(TO_QSTRING(WorldName)).arg(TO_QSTRING(AreaName)));
Log::Write("Loaded area: " + mpArea->Source() + " (" + TO_TSTRING(TO_QSTRING(AreaName)) + ")");
}
else
{
setWindowTitle(QString("Prime World Editor - %1[*]").arg(TO_QSTRING(WorldName)));
QString LevelName;
if (pWorldNameTable) LevelName = TO_QSTRING(WorldName);
else LevelName = "!" + TO_QSTRING(mpWorld->GetAreaInternalName(AreaIndex));
setWindowTitle(QString("Prime World Editor - %1[*]").arg(LevelName));
Log::Write("Loaded level: World " + mpWorld->Source() + " / Area " + mpArea->Source() + " (" + TO_TSTRING(LevelName) + ")");
}
// Emit signals

View File

@ -1,9 +1,10 @@
#include "CStartWindow.h"
#include "CDarkStyle.h"
#include <Common/Log.h>
#include <Core/Resource/Factory/CTemplateLoader.h>
#include <iostream>
#include <QApplication>
#include <QMessageBox>
#include <QStyleFactory>
#include <QtGlobal>
@ -26,10 +27,10 @@ int main(int argc, char *argv[])
// Create application
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
QApplication app(argc, argv);
CStartWindow w;
w.show();
// Set up debug redirect
// Init log
bool Initialized = Log::InitLog("primeworldeditor.log");
if (!Initialized) QMessageBox::warning(0, "Error", "Couldn't open log file. Logging will not work for this session.");
qInstallMessageHandler(QtLogRedirect);
// Load templates
@ -58,5 +59,8 @@ int main(int argc, char *argv[])
qApp->setPalette(darkPalette);
// Execute application
CStartWindow w;
w.show();
return app.exec();
}

View File

@ -6,55 +6,55 @@
<enum ID="0xB8AFCF21">
<default>0x98C5AED7</default>
<enumerators>
<enumerator ID="0x98C5AED7" name="Unknown 1"/>
<enumerator ID="0x3D1A78AC" name="Unknown 2"/>
<enumerator ID="0x136F5286" name="Unknown 3"/>
<enumerator ID="0x370F508E" name="Unknown 4"/>
<enumerator ID="0x29837C6C" name="Unknown 5"/>
<enumerator ID="0x49069735" name="Unknown 6"/>
<enumerator ID="0x14B45D36" name="Unknown 7"/>
<enumerator ID="0x766ED410" name="Unknown 8"/>
<enumerator ID="0x7E025D14" name="Unknown 9"/>
<enumerator ID="0x8838D84A" name="Unknown 10"/>
<enumerator ID="0x2CB1471C" name="Unknown 11"/>
<enumerator ID="0xCFC89663" name="Unknown 12"/>
<enumerator ID="0xD871451E" name="Unknown 13"/>
<enumerator ID="0x661EC9E0" name="Unknown 14"/>
<enumerator ID="0x1C7FDCAB" name="Unknown 15"/>
<enumerator ID="0xE13871E3" name="Unknown 16"/>
<enumerator ID="0x90031E91" name="Unknown 17"/>
<enumerator ID="0x96AB6130" name="Unknown 18"/>
<enumerator ID="0x698AAB1A" name="Unknown 19"/>
<enumerator ID="0x83888007" name="Unknown 20"/>
<enumerator ID="0x171CB7CB" name="Unknown 21"/>
<enumerator ID="0xC15AB262" name="Unknown 22"/>
<enumerator ID="0x05FE350B" name="Unknown 23"/>
<enumerator ID="0x982A42A3" name="Unknown 24"/>
<enumerator ID="0x73810303" name="Unknown 25"/>
<enumerator ID="0xE03046EA" name="Unknown 26"/>
<enumerator ID="0x9EAEB97A" name="Unknown 27"/>
<enumerator ID="0xFF6D9BE6" name="Unknown 28"/>
<enumerator ID="0xFE41E1E9" name="Unknown 29"/>
<enumerator ID="0xD8AD2D4A" name="Unknown 30"/>
<enumerator ID="0x8F226F1D" name="Unknown 31"/>
<enumerator ID="0x9349C56D" name="Unknown 32"/>
<enumerator ID="0x441AEE66" name="Unknown 33"/>
<enumerator ID="0xE5518864" name="Unknown 34"/>
<enumerator ID="0x502B7B92" name="Unknown 35"/>
<enumerator ID="0x83B00647" name="Unknown 36"/>
<enumerator ID="0x7F0CE328" name="Unknown 37"/>
<enumerator ID="0x6FC986EA" name="Unknown 38"/>
<enumerator ID="0x7E8C0D33" name="Unknown 39"/>
<enumerator ID="0xD7E2F62F" name="Unknown 40"/>
<enumerator ID="0xDFE51E86" name="Unknown 41"/>
<enumerator ID="0x4E081CFA" name="Unknown 42"/>
<enumerator ID="0xE6642737" name="Unknown 43"/>
<enumerator ID="0x129C99C0" name="Unknown 44"/>
<enumerator ID="0xFDF2D16C" name="Unknown 45"/>
<enumerator ID="0x0FF38718" name="Unknown 46"/>
<enumerator ID="0x48D158B9" name="Unknown 47"/>
<enumerator ID="0xCD71412F" name="Unknown 48"/>
<enumerator ID="0xDA5AF6F3" name="Unknown 49"/>
<enumerator ID="0x98C5AED7" name="What"/>
<enumerator ID="0x3D1A78AC" name="Function 1"/>
<enumerator ID="0x136F5286" name="Function 2"/>
<enumerator ID="0x370F508E" name="Boss Energy Bar"/>
<enumerator ID="0x29837C6C" name="Cinematic Skip"/>
<enumerator ID="0x49069735" name="Function 5"/>
<enumerator ID="0x14B45D36" name="Function 6"/>
<enumerator ID="0x766ED410" name="Function 7"/>
<enumerator ID="0x7E025D14" name="End Game"/>
<enumerator ID="0x8838D84A" name="Game End Choice"/>
<enumerator ID="0x2CB1471C" name="ExtraRenderClipPlane"/>
<enumerator ID="0xCFC89663" name="Function 12"/>
<enumerator ID="0xD871451E" name="Function 13"/>
<enumerator ID="0x661EC9E0" name="GameStateEnvVar"/>
<enumerator ID="0x1C7FDCAB" name="HUD Target"/>
<enumerator ID="0xE13871E3" name="Function 16"/>
<enumerator ID="0x90031E91" name="Launch Player"/>
<enumerator ID="0x96AB6130" name="Inventory Thing 1"/>
<enumerator ID="0x698AAB1A" name="Modify Inventory"/>
<enumerator ID="0x83888007" name="Permanent Hypermode"/>
<enumerator ID="0x171CB7CB" name="Function 21"/>
<enumerator ID="0xC15AB262" name="Function 22"/>
<enumerator ID="0x05FE350B" name="Object Follow Something"/>
<enumerator ID="0x982A42A3" name="Object Follow Locator"/>
<enumerator ID="0x73810303" name="Object Follow Object"/>
<enumerator ID="0xE03046EA" name="Function 26"/>
<enumerator ID="0x9EAEB97A" name="Occlusion Relay"/>
<enumerator ID="0xFF6D9BE6" name="Player Follow Locator"/>
<enumerator ID="0xFE41E1E9" name="Player In Area"/>
<enumerator ID="0xD8AD2D4A" name="Function 30"/>
<enumerator ID="0x8F226F1D" name="Set SuitType"/>
<enumerator ID="0x9349C56D" name="Inventory Thing 2"/>
<enumerator ID="0x441AEE66" name="Function 33"/>
<enumerator ID="0xE5518864" name="Function 34"/>
<enumerator ID="0x502B7B92" name="Tin Can Score"/>
<enumerator ID="0x83B00647" name="Function 36"/>
<enumerator ID="0x7F0CE328" name="Function 37"/>
<enumerator ID="0x6FC986EA" name="Rotate Skybox"/>
<enumerator ID="0x7E8C0D33" name="Static World Render Controller"/>
<enumerator ID="0xD7E2F62F" name="Sun Generator"/>
<enumerator ID="0xDFE51E86" name="Function 41"/>
<enumerator ID="0x4E081CFA" name="Disable In Time Attack"/>
<enumerator ID="0xE6642737" name="Function 43"/>
<enumerator ID="0x129C99C0" name="View Frustum Tester"/>
<enumerator ID="0xFDF2D16C" name="Function 45"/>
<enumerator ID="0x0FF38718" name="Disable In Mirror Mode"/>
<enumerator ID="0x48D158B9" name="Function 47"/>
<enumerator ID="0xCD71412F" name="Function 48"/>
<enumerator ID="0xDA5AF6F3" name="Function 49"/>
</enumerators>
</enum>
<property ID="0x9D7A576D" type="string"/>