2015-07-26 21:39:49 +00:00
|
|
|
#include <ctime>
|
|
|
|
#include <iostream>
|
2015-11-24 06:08:31 +00:00
|
|
|
#include <Common/TString.h>
|
2015-07-26 21:39:49 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
namespace Log
|
|
|
|
{
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
static const TString gskLogFilename = "primeworldeditor.log";
|
2015-11-24 10:22:37 +00:00
|
|
|
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4996) // Can't use fopen_s here without creating a separate init function for the log
|
2015-11-24 06:08:31 +00:00
|
|
|
FILE *gpLogFile = fopen(*gskLogFilename, "w");
|
2015-11-24 10:22:37 +00:00
|
|
|
#pragma warning(pop)
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void Write(const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
if (gpLogFile)
|
|
|
|
{
|
|
|
|
time_t RawTime;
|
|
|
|
time(&RawTime);
|
|
|
|
|
2015-11-24 10:22:37 +00:00
|
|
|
tm pTimeInfo;
|
|
|
|
localtime_s(&pTimeInfo, &RawTime);
|
|
|
|
|
2015-07-26 21:39:49 +00:00
|
|
|
char Buffer[80];
|
2015-11-24 10:22:37 +00:00
|
|
|
strftime(Buffer, 80, "[%H:%M:%S]", &pTimeInfo);
|
2015-07-26 21:39:49 +00:00
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
fprintf(gpLogFile, "%s %s\n", Buffer, *message);
|
2015-07-26 21:39:49 +00:00
|
|
|
fflush(gpLogFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void Error(const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
Write("ERROR: " + message);
|
2015-11-24 15:40:09 +00:00
|
|
|
std::cout << "ERROR: " << message << "\n";
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void Warning(const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
Write("Warning: " + message);
|
|
|
|
std::cout << "Warning: " << message << "\n";
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void FileWrite(const TString& filename, const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
Write(filename + " : " + message);
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void FileWrite(const TString& filename, unsigned long offset, const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
Write(filename + " : " + TString::HexString(offset) + " - " + message);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void FileError(const TString& filename, const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
Error(filename + " : " + message);
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void FileError(const TString& filename, unsigned long offset, const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
Error(filename + " : " + TString::HexString(offset) + " - " + message);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void FileWarning(const TString& filename, const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
|
|
|
Warning(filename + " : " + message);
|
|
|
|
}
|
|
|
|
|
2015-11-24 06:08:31 +00:00
|
|
|
void FileWarning(const TString& filename, unsigned long offset, const TString& message)
|
2015-07-26 21:39:49 +00:00
|
|
|
{
|
2015-11-24 06:08:31 +00:00
|
|
|
Warning(filename + " : " + TString::HexString(offset) + " - " + message);
|
2015-07-26 21:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|