1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Partial integration of Android patches, from Pelya.

This commit is contained in:
Frank Zago 2011-06-15 02:15:05 +00:00
parent 14efb9fd13
commit 4b7d0f3092
3 changed files with 67 additions and 9 deletions

View File

@ -510,7 +510,7 @@ void CClient::handlePack( CPack * pack )
}
else
{
tlog1 << "Message cannot be applied, cannot find applier!\n";
tlog1 << "Message cannot be applied, cannot find applier! TypeID " << typeList.getTypeID(pack) << std::endl;
}
delete pack;
}

View File

@ -10,6 +10,10 @@
using boost::logic::tribool;
#include <boost/cstdint.hpp>
#include <assert.h>
#ifdef ANDROID
#include <android/log.h>
#include <sstream>
#endif
//filesystem version 3 causes problems (and it's default as of boost 1.46)
#define BOOST_FILESYSTEM_VERSION 2
typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
@ -618,20 +622,43 @@ extern DLL_EXPORT CConsoleHandler *console;
class CLogger //logger, prints log info to console and saves in file
{
const int lvl;
#ifdef ANDROID
std::ostringstream buf;
int androidloglevel;
void outputAndroid()
{
int pos = buf.str().find("\n");
while( pos >= 0 )
{
__android_log_print(androidloglevel, "VCMI", "%s", buf.str().substr(0, pos).c_str() );
buf.str( buf.str().substr(pos+1) );
pos = buf.str().find("\n");
}
}
#endif
public:
CLogger& operator<<(std::ostream& (*fun)(std::ostream&))
{
#ifdef ANDROID
buf << fun;
outputAndroid();
#else
if(lvl < CONSOLE_LOGGING_LEVEL)
std::cout << fun;
if((lvl < FILE_LOGGING_LEVEL) && logfile)
*logfile << fun;
#endif
return *this;
}
template<typename T>
CLogger & operator<<(const T & data)
{
#ifdef ANDROID
buf << data;
outputAndroid();
#else
if(lvl < CONSOLE_LOGGING_LEVEL)
{
if(console)
@ -641,10 +668,25 @@ public:
}
if((lvl < FILE_LOGGING_LEVEL) && logfile)
*logfile << data << std::flush;
#endif
return *this;
}
CLogger(const int Lvl) : lvl(Lvl) {}
CLogger(const int Lvl) : lvl(Lvl)
{
#ifdef ANDROID
androidloglevel = ANDROID_LOG_INFO;
switch(lvl) {
case 0: androidloglevel = ANDROID_LOG_INFO; break;
case 1: androidloglevel = ANDROID_LOG_FATAL; break;
case 2: androidloglevel = ANDROID_LOG_ERROR; break;
case 3: androidloglevel = ANDROID_LOG_WARN; break;
case 4: androidloglevel = ANDROID_LOG_INFO; break;
case 5: androidloglevel = ANDROID_LOG_DEBUG; break;
case 6: case -2: androidloglevel = ANDROID_LOG_VERBOSE; break;
}
#endif
}
};
extern DLL_EXPORT CLogger tlog0; //green - standard progress info

View File

@ -1,3 +1,6 @@
#ifndef __VCMIDIRS_H__
#define __VCMIDIRS_H__
/*
* UserHome.h, part of VCMI engine
*
@ -14,7 +17,7 @@
#endif
/// Where to find the various VCMI files. This is mostly usefull for linux.
/// Where to find the various VCMI files. This is mostly useful for linux.
class VCMIDirs {
public:
std::string UserPath;
@ -24,14 +27,27 @@ public:
#ifdef _WIN32
UserPath = DATA_DIR;
#else
// Find vcmi user directory and create it if necessary
std::string home_dir = getenv("HOME");
UserPath = path(home_dir + "/.vcmi").string();
try {
#ifdef ANDROID
UserPath = DATA_DIR;
#else
// Find vcmi user directory and create it if necessary
std::string home_dir = ".";
if( getenv("HOME") != NULL )
home_dir = getenv("HOME");
create_directory(UserPath);
create_directory(UserPath + "/config");
create_directory(UserPath + "/Games");
UserPath = path(home_dir + "/.vcmi").string();
#endif
create_directory(UserPath);
create_directory(UserPath + "/config");
create_directory(UserPath + "/Games");
}
catch(const std::exception & e)
{
}
#endif
}
};
extern VCMIDirs GVCMIDirs;
#endif // __VCMIDIRS_H__