Commit 37a5eb60 authored by Gerhard Stein's avatar Gerhard Stein

Improved logging and more feedback when downloaded files are extracted.

parent bb9eedce
......@@ -16,12 +16,15 @@
CLogFile::CLogFile() {}
void CLogFile::CreateLogfile(const char *LogName,
bool CLogFile::CreateLogfile(const std::string &logFName,
const std::string &appName,
const std::string &version)
{
// Open and empty the log file
m_Logfile = OpenGameFile(LogName, "wt");
if( !OpenGameFileW(mLogStream, logFName) )
{
return false;
}
// Write the head
textOut("<html><head><title>LogFile</title></head>");
......@@ -77,19 +80,22 @@ void CLogFile::CreateLogfile(const char *LogName,
textOut("<a href='mailto:gerstrong@gmail.com?subject=CG Logfile'>");
textOut("Send E-Mail to me</a><br><br>");
fclose(m_Logfile);
m_Logfile = OpenGameFile(LogName, "at");
mLogStream.close();
// Reopen it in append mode for further wroting.
mLogStream = OpenGameFileW(logFName, std::ios_base::app);
return true;
}
// Function for writing the topic
void CLogFile::WriteTopic(const char *Topic, int Size)
{
{
textOut("<table cellspacing='0' cellpadding='0' width='100%%' bgcolor='#DFDFE5'>\n");
textOut("<tr>\n<tr>\n<td>\n");
ftextOut("<font face='arial' size='+%i'>\n", Size);
textOut(Topic);
textOut("</font>\n</td>\n</tr>\n</table>\n<br>");
fflush(m_Logfile);
}
// The main textOut function
......@@ -153,16 +159,16 @@ std::string CLogFile::removeHTML(const std::string& input)
return output;
}
void CLogFile::textOut(const std::string& Text)
{
void CLogFile::textOut(const std::string& text)
{
std::string output;
output = removeHTML(Text);
output = removeHTML(text);
if( output.length() > 0 ) {
notes << output << endl;
}
fprintf(m_Logfile,"%s",Text.c_str());
fflush(m_Logfile);
mLogStream << text;
}
void CLogFile::ftextOut(const char *Text, ...)
......@@ -224,8 +230,8 @@ void CLogFile::FunctionResult (const char *Name,bool Result)
}
}
CLogFile::~CLogFile() {
CLogFile::~CLogFile()
{
// Logfile End
textOut ("<br><br>End of logfile</font></body></html>");
fclose (m_Logfile);
}
......@@ -10,10 +10,12 @@
#include <base/Singleton.h>
#include <string>
#include <fstream>
const std::string APP_NAME = "Commander Genius";
#define gLogging CLogFile::get()
// Singleton macro
#define gLogging (CLogFile::get())
const int MAX_BUFFER = 1024;
......@@ -33,9 +35,18 @@ public:
CLogFile();
virtual ~CLogFile();
void CreateLogfile (const char *LogName,
/**
* @brief CreateLogfile Open the file for creating some content of general information like
* about the system and the application.
* @param logFName Name of the log file
* @param appName Name of the application
* @param version Version of the application
* @return true if everything went fine, otherwise false
*/
bool CreateLogfile (const std::string &logFName,
const std::string &appName,
const std::string &version);
void WriteTopic (const char *Topic, int Size);
void textOut (const std::string& Text);
void textOut (FONTCOLORS Color, const std::string& Text);
......@@ -46,8 +57,8 @@ public:
void FunctionResult (const char *Name, bool Result);
private:
FILE *m_Logfile;
std::ofstream mLogStream;
std::string removeHTML(const std::string& input);
};
......
......@@ -705,7 +705,30 @@ bool OpenGameFileR(std::ifstream& f, const std::string& path, std::ios_base::ope
return false;
}
bool OpenGameFileW(std::ofstream& f, const std::string& path, std::ios_base::openmode mode) {
std::ofstream OpenGameFileW(const std::string& path, const std::ios_base::openmode mode)
{
std::ofstream f;
if(path.size() == 0)
return f;
std::string fullfn = GetWriteFullFileName(path, true);
if(fullfn.size() != 0)
{
try
{
f.open(Utf8ToSystemNative(fullfn).c_str(), mode);
return f;
}
catch(...) {}
}
return f;
}
bool OpenGameFileW(std::ofstream& f, const std::string& path, std::ios_base::openmode mode)
{
if(path.size() == 0)
return false;
......
......@@ -188,6 +188,9 @@ FILE* OpenAbsFile(const std::string& path, const char *mode);
bool OpenGameFileR(std::ifstream& f, const std::string& path, std::ios_base::openmode mode = std::ios_base::in);
bool OpenGameFileW(std::ofstream& f, const std::string& path, std::ios_base::openmode mode = std::ios_base::out);
// Versions which return the stream directly
std::ofstream OpenGameFileW(const std::string& path, const std::ios_base::openmode mode);
std::string GetFileContents(const std::string& path, bool absolute = false);
std::string ExtractDirectory(const std::string& path);
......
......@@ -13,6 +13,7 @@
// joins 2 functors
/*
template<typename _F1, typename _F2>
class JoinedFunctors : _F1, _F2 {
private:
......@@ -38,6 +39,6 @@ public:
void operator()(_ParamType param) {}
};
*/
#endif
......@@ -285,6 +285,8 @@ void GsBitmap::draw(const int x, const int y) const
_draw( x, y, gVideoDriver.getBlitSurface() );
}
/**
* \brief The function that blits the sprite to dst
* \param x X-Coordinate, indicating the position on dst
......
......@@ -68,6 +68,7 @@ public:
std::string getName() const { return mName; }
void setName(const std::string &name) { mName = name; }
/**
* \brief The function that blits the sprite to the main blitSurface
* \param x X-Coordinate, indicating the position on dst
......
v1.9.9.X:
---------
- Improved log responsiveness
- Tidied up code
- More C++ use
v1.9.9.2:
---------
- Menu UI Fixes.
......
......@@ -96,7 +96,11 @@ int main(int argc, char *argv[])
InitThreadPool();
InitSearchPaths(g_pSettings->getConfigFileName());
gLogging.CreateLogfile("CGLog.html", APP_NAME, CGVERSION);
if( !gLogging.CreateLogfile("CGLog.html", APP_NAME, CGVERSION) )
{
errors << "I'm not even able to create \"CGLog.html\"." << endl;
return 1;
}
// Init Video Driver with SDL all together
......
......@@ -196,6 +196,7 @@ add_executable (CGeniusExe CGenius.cpp
CRingBuffer.h
CSingleton.h
fileio.h
../changelog.txt
${cg_obj_libs})
# Since some RefKeen is used, we also need C99 Standard
......@@ -285,10 +286,7 @@ IF(OPENGL)
target_link_libraries(CGeniusExe ${OPENGL_LIBRARIES})
ENDIF(OPENGL)
LINK_DIRECTORIES(/opt/local/lib)
#cotire(CGeniusExe)
# Stuff definitions in case we want to install it
INCLUDE(install.cmake)
......@@ -362,6 +362,10 @@ int GameDownloader::handle()
const int retVal = unzipFile(fullZipPath.c_str(), destDir.c_str());
gLogging.ftextOut( BLACK, "Extracting downloaded file \"%s\" to \"%s\".\n<br>",
fullZipPath.c_str(),
destDir.c_str() );
// If unpacking files fails, we should delete it.
if(retVal != 0)
{
......@@ -370,7 +374,9 @@ int GameDownloader::handle()
}
else
{
gLogging.ftextOut( GREEN, "File \"%s\" extracted succesfully.\n<br>", downloadGamePath.c_str() );
gLogging.ftextOut( GREEN, "File \"%s\" extracted successfully to \"%s\".\n<br>",
downloadGamePath.c_str(),
destDir.c_str());
}
}
else
......
......@@ -61,7 +61,7 @@ void CMapPlayGalaxy::pumpEvent(const CEvent *evPtr)
for( auto obj=mObjectPtr.rbegin() ; obj!=mObjectPtr.rend() ; obj++ )
{
galaxy::CInchWorm *inchworm = dynamic_cast<galaxy::CInchWorm*>(obj->get());
if( inchworm != NULL )
if( inchworm != nullptr )
{
inchworm->exists = false;
}
......
......@@ -369,7 +369,7 @@ bool CMapLoaderGalaxy::loadMap(CMap &Map, Uint8 level)
Map.drawAll();
gVideoDriver.updateScrollBuffer(Map.m_scrollx, Map.m_scrolly);
gLogging.textOut("Map got loaded succesfully!");
gLogging.textOut("Map got loaded successfully!");
return true;
}
......
......@@ -174,7 +174,7 @@ mp_processState(NULL)
m_dying = false;
xDirection = facedir;
memset(m_playcontrol, 0, PA_MAX_ACTIONS);
m_playcontrol.fill(0);
m_camera.setPosition(m_Pos);
mp_Map->calcVisibleArea();
......
......@@ -26,6 +26,7 @@
#include "graphics/effects/CDimDark.h"
#include "sdl/audio/music/CMusic.h"
#include <array>
struct EventEnterLevel : CEvent {
uint16_t data;
......@@ -240,7 +241,7 @@ protected:
unsigned short mPlayerNum;
Sint16 m_playcontrol[PA_MAX_ACTIONS];
std::array<Sint16, PA_MAX_ACTIONS> m_playcontrol;
int m_timer;
......
......@@ -258,7 +258,7 @@ void CShikadiMaster::processTeleporting()
if(!allow_teleport) continue;
// make it through previous nested loop == succesful tele
// make it through previous nested loop == successful tele
//KeenXVel = KeenYVel = 0;
moveToForce(tx<<CSF, ty<<CSF);
setAction(A_MASTER_STAND);
......
#ifndef __CG__VERSION_H__
#define __CG__VERSION_H__
#define CGVERSION "1.9.9.2-Beta"
#define CGVERSION "1.9.9.3-Beta"
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment