Tidy up logging + other minor fixes

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6647 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2010-11-19 17:19:13 +00:00
parent 72496d7a26
commit cb78ded2ed
11 changed files with 117 additions and 92 deletions

View File

@ -45,16 +45,20 @@ Addons* addons_manager = 0;
Addons::Addons()
{
this->index = -1;
std::cout << "Loading an xml file for addons: ";
int download_state = 0;
m_download_state = download_state;
pthread_mutex_init(&m_str_mutex, NULL);
/*It is _very_ dirty to save the list as a locale file since we have a
function to load it directly in a string.*/
download("list");
// FIXME: It is _very_ dirty to save the list as a locale file since we have a
// function to load it directly in a string.
const bool success = download("list");
if (!success)
{
fprintf(stderr, "Downloading 'list' failed\n");
}
std::string xml_file = file_manager->getConfigDir() + "/" + "list";
std::cout << xml_file << std::endl;
std::cout << "[Addons] Using file '" << xml_file << "'\n";
IrrXMLReader* xml = createIrrXMLReader(xml_file.c_str());
// strings for storing the data we want to get out of the file
@ -122,7 +126,7 @@ void Addons::GetInstalledAddons()
/* checking for installed addons */
std::cout << "Loading an xml file for installed addons: ";
std::cout << "[Addons] Loading an xml file for installed addons: ";
std::cout << this->file_installed << std::endl;
IrrXMLReader* xml = createIrrXMLReader(this->file_installed.c_str());
@ -161,7 +165,7 @@ void Addons::GetInstalledAddons()
{
this->m_addons_list[this->index].installed = true;
this->m_addons_list[this->index].installed_version = version;
std::cout << "An addons is already installed: " + id << std::endl;
std::cout << "[Addons] An addon is already installed: " << id << std::endl;
}
else
{
@ -323,10 +327,19 @@ void Addons::Install()
m_str_state = "Downloading...";
pthread_mutex_unlock(&m_str_mutex);
download(std::string("file/" + this->m_addons_list[this->index].file),
this->m_addons_list[this->index].name, &m_download_state);
std::string file = "file/" + this->m_addons_list[this->index].file;
bool success = download(file,
this->m_addons_list[this->index].name, &m_download_state);
if (!success)
{
// TODO: show a message in the interface
fprintf(stderr, "[Addons] Failed to download '%s'\n", file.c_str());
return;
}
file_manager->checkAndCreateDirForAddons(this->m_addons_list[this->index].name,
this->m_addons_list[this->index].type + "s/");
this->m_addons_list[this->index].type + "s/");
//extract the zip in the addons folder called like the addons name
std::string dest_file =file_manager->getAddonsDir() + "/" + "data" + "/" +
@ -339,11 +352,11 @@ void Addons::Install()
m_str_state = "Unzip the addons...";
pthread_mutex_unlock(&m_str_mutex);
const bool success = extract_zip(from, to);
success = extract_zip(from, to);
if (!success)
{
// TODO: show a message in the interface
std::cerr << "Failed to unzip " << from << " to " << to << std::endl;
std::cerr << "[Addons] Failed to unzip '" << from << "' to '" << to << "'\n";
return;
}
@ -351,7 +364,7 @@ void Addons::Install()
this->m_addons_list[this->index].installed_version = this->m_addons_list[this->index].version;
pthread_mutex_lock(&m_str_mutex);
m_str_state = "Reloaing karts list...";
m_str_state = "Reloading kart list...";
pthread_mutex_unlock(&m_str_mutex);
this->SaveInstalled();
}
@ -389,7 +402,7 @@ void Addons::SaveInstalled()
// ----------------------------------------------------------------------------
void Addons::UnInstall()
{
std::cout << "Uninstall: " << this->m_addons_list[this->index].name << std::endl;
std::cout << "[Addons] Uninstalling <" << this->m_addons_list[this->index].name << ">\n";
this->m_addons_list[this->index].installed = false;
//write the xml file with the informations about installed karts
@ -402,7 +415,9 @@ void Addons::UnInstall()
this->SaveInstalled();
}
// ----------------------------------------------------------------------------
int Addons::getDownloadState()
{
pthread_mutex_lock(&download_mutex);
@ -410,6 +425,9 @@ int Addons::getDownloadState()
pthread_mutex_unlock(&download_mutex);
return value;
}
// ----------------------------------------------------------------------------
std::string Addons::getDownloadStateAsStr()
{
pthread_mutex_lock(&m_str_mutex);
@ -418,8 +436,8 @@ std::string Addons::getDownloadStateAsStr()
return value;
}
// ----------------------------------------------------------------------------
bool Addons::NeedUpdate()
{
return GetInstalledVersion() < GetVersion();

View File

@ -27,34 +27,40 @@
#include "io/file_manager.hpp"
pthread_mutex_t download_mutex;
NetworkHttp * network_http = 0;
// ------------------------------------------------------------------------------------------------------
NetworkHttp::NetworkHttp()
{
pthread_t thread;
pthread_create(&thread, NULL, &NetworkHttp::checkNewServer, this);
}
// ---------------------------------------------------------------------------
void * NetworkHttp::checkNewServer(void * obj)
{
NetworkHttp * pthis = (NetworkHttp *)obj;
std::string newserver = pthis->downloadToStr("redirect");
if(newserver != "")
if (newserver != "")
{
newserver.replace(newserver.find("\n"), 1, "");
std::cout << "Current server: " << UserConfigParams::m_server_addons.toString() << std::endl;
std::cout << "[Addons] Current server: " << UserConfigParams::m_server_addons.toString() << std::endl;
UserConfigParams::m_server_addons = newserver;
std::cout << "New server: " << newserver << std::endl;
std::cout << "[Addons] New server: " << newserver << std::endl;
user_config->saveConfig();
}
else
{
std::cout << "No new server." << std::endl;
std::cout << "[Addons] No new server." << std::endl;
}
return NULL;
}
// ------------------------------------------------------------------------------------------------------
size_t NetworkHttp::writeStr(char ptr [], size_t size, size_t nb_char, std::string * stream)
{
static std::string str = std::string(ptr);
@ -64,17 +70,18 @@ size_t NetworkHttp::writeStr(char ptr [], size_t size, size_t nb_char, std::stri
return nb_char;
}
// ------------------------------------------------------------------------------------------------------
std::string NetworkHttp::downloadToStr(std::string url)
{
CURL *session = curl_easy_init();
curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + url).c_str());
std::string * fout = new std::string("");
std::string fout;
//from and out
curl_easy_setopt(session, CURLOPT_WRITEDATA, fout);
curl_easy_setopt(session, CURLOPT_WRITEDATA, &fout);
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, &NetworkHttp::writeStr);
int succes = curl_easy_perform(session);
@ -82,22 +89,15 @@ std::string NetworkHttp::downloadToStr(std::string url)
//stop curl
curl_easy_cleanup(session);
if(succes == 0)
{
std::cout << "Download successfull" << std::endl;
return *fout;
}
else
{
std::cout << "Download failed... check your network connexion" << std::endl;
return "";
}
if (succes == 0) return fout;
else return "";
}
// ------------------------------------------------------------------------------------------------------
bool download(std::string file, std::string save, int * progress_data)
{
CURL *session = curl_easy_init();
std::cout << "Downloading: " << std::string(UserConfigParams::m_server_addons.toString() + "/" + file) << std::endl;
curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + file).c_str());
FILE * fout;
if(save != "")
@ -120,7 +120,7 @@ bool download(std::string file, std::string save, int * progress_data)
//to update the progress bar
curl_easy_setopt(session, CURLOPT_PROGRESSDATA, progress_data);
int succes = curl_easy_perform(session);
int success = curl_easy_perform(session);
//close the file where we downloaded the content
fclose(fout);
@ -128,18 +128,12 @@ bool download(std::string file, std::string save, int * progress_data)
//stop curl
curl_easy_cleanup(session);
if(succes == 0)
{
std::cout << "Download successfull" << std::endl;
return true;
}
else
{
std::cout << "Download failed... check your network connexion" << std::endl;
return false;
}
return (success == 0);
}
//FIXME : this way is a bit ugly but the simpliesst at the moment
// ------------------------------------------------------------------------------------------------------
//FIXME : this way is a bit ugly but the simplest at the moment
int time_last_print = 0;
int progressDownload (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{

View File

@ -175,10 +175,6 @@ void Challenge::load(const XMLNode* challengesNode)
node->get("solved", &finished);
m_state = finished ? CH_SOLVED : CH_INACTIVE;
if(m_state == CH_SOLVED)
{
std::cout << "Solved challenge!! " << getId().c_str() << std::endl;
}
if(!finished) loadAdditionalInfo(node);
} // load

View File

@ -45,10 +45,11 @@ using namespace irr::video;
/** singleton */
IrrDriver *irr_driver = NULL;
const int MIN_SUPPORTED_HEIGHT = 480; //TODO: do some tests, 480 might be too small without a special menu
const int MIN_SUPPORTED_HEIGHT = 600; //TODO: do some tests, 600 might be too small without a special menu
const int MIN_SUPPORTED_WIDTH = 800;
// ----------------------------------------------------------------------------
IrrDriver::IrrDriver()
{
m_res_switching = false;
@ -58,13 +59,14 @@ IrrDriver::IrrDriver()
} // IrrDriver
// ----------------------------------------------------------------------------
IrrDriver::~IrrDriver()
{
//std::cout << "^^^^^^^^ Dropping m_device ^^^^^^^^\n";
assert(m_device != NULL);
m_device->drop();
m_device = NULL;
} // ~IrrDriver
// ----------------------------------------------------------------------------
void IrrDriver::initDevice()
@ -73,8 +75,8 @@ void IrrDriver::initDevice()
// ---- the first time, get a list of available video modes
if (firstTime)
{
//std::cout << "^^^^^^^^ Creating m_device (as NULL) ^^^^^^^^\n";
{
std::cout << "[IrrDriver] Creating NULL device\n";
m_device = createDevice(video::EDT_NULL);
video::IVideoModeList* modes = m_device->getVideoModeList();
@ -98,13 +100,7 @@ void IrrDriver::initDevice()
mode.height = h;
m_modes.push_back( mode );
}
//std::cout <<
//"bits : " << modes->getVideoModeDepth(i) <<
//" resolution=" << modes->getVideoModeResolution(i).Width <<
//"x" << modes->getVideoModeResolution(i).Height << std::endl;
}
//std::cout << "^^^^^^^^ Closing m_device ^^^^^^^^\n";
m_device->closeDevice();
// In some circumstances it would happen that a WM_QUIT message
// (apparently sent for this NULL device) is later received by
@ -120,8 +116,6 @@ void IrrDriver::initDevice()
} // end if firstTime
int numDrivers = 5;
// Test if user has chosen a driver or if we should try all to find a woring
@ -144,15 +138,16 @@ void IrrDriver::initDevice()
{
// Get the correct type.
type = getEngineDriverType( UserConfigParams::m_renderer );
} else {
} else
{
// Get the correct type.
type = getEngineDriverType( driver_type );
}
// Try 32 and, upon failure, 24 then 16 bit per pixels
for(int bits=32; bits>15; bits -=8)
for (int bits=32; bits>15; bits -=8)
{
//std::cout << "^^^^^^^^ CREATING m_device ^^^^^^^^\n";
std::cout << "[IrrDriver] Tring to create device with " << bits << " bits\n";
m_device = createDevice(type,
core::dimension2d<u32>(UserConfigParams::m_width,
UserConfigParams::m_height ),
@ -163,7 +158,7 @@ void IrrDriver::initDevice()
this // event receiver
);
if(m_device) break;
} // for bits=24, 16
} // for bits=32, 24, 16
if(m_device) break;
} // for edt_types
@ -283,7 +278,7 @@ video::E_DRIVER_TYPE IrrDriver::getEngineDriverType( int index )
}
// Ouput which render will be tried.
std::cout << "Trying " << rendererName << " rendering." << std::endl;
std::cout << "[IrrDriver] Trying " << rendererName << " rendering." << std::endl;
return type;
}
@ -746,8 +741,8 @@ video::ITexture *IrrDriver::getTexture(const std::string &filename)
#ifndef NDEBUG
if (out == NULL)
{
printf("Texture '%s' not found.\n", filename.c_str());
printf("Put a breakpoint at line %s:%i to debug!\n", __FILE__, __LINE__ );
printf("[IrrDriver] Texture '%s' not found; Put a breakpoint at line %s:%i to debug!\n",
filename.c_str(), __FILE__, __LINE__);
}
#endif
@ -930,7 +925,7 @@ bool IrrDriver::OnEvent(const irr::SEvent &event)
// Ignore 'normal' messages
if (event.LogEvent.Level>0)
{
printf("Level %d: %s\n",
printf("[IrrDriver Temp Logger] Level %d: %s\n",
event.LogEvent.Level,event.LogEvent.Text);
}
return true;

View File

@ -69,7 +69,7 @@ bool EventHandler::OnEvent (const SEvent &event)
else if (event.EventType == EET_LOG_TEXT_EVENT)
{
// Ignore 'normal' messages
if (event.LogEvent.Level>0)
if (event.LogEvent.Level > irr:: ELL_INFORMATION)
{
// Unfortunatly irrlicht produces some internal error/warnings
// messages that can't be avoided (see COpenGLTexture where
@ -83,8 +83,15 @@ bool EventHandler::OnEvent (const SEvent &event)
#else
return true; // EVENT_BLOCK
#endif
printf("Level %d: %s\n",
event.LogEvent.Level,event.LogEvent.Text);
if (event.LogEvent.Level == irr::ELL_WARNING)
{
printf("[Irrlicht Warning] %s\n", event.LogEvent.Text);
}
else if (event.LogEvent.Level == irr::ELL_ERROR)
{
printf("[Irrlicht Error] %s\n", event.LogEvent.Text);
}
}
return true;
}

View File

@ -73,7 +73,7 @@
bool macSetBundlePathIfRelevant(std::string& data_dir)
{
printf("checking whether we are using an app bundle... ");
printf("[FileManager] checking whether we are using an app bundle... ");
// the following code will enable STK to find its data when placed in an app bundle on mac OS X.
// returns true if path is set, returns false if path was not set
char path[1024];
@ -161,7 +161,7 @@ FileManager::FileManager(char *argv[])
#endif
// We can't use _() here, since translations will only be initalised
// after the filemanager (to get the path to the tranlsations from it)
fprintf(stderr, "Data files will be fetched from: '%s'\n",
fprintf(stderr, "[FileManager] Data files will be fetched from: '%s'\n",
m_root_dir.c_str() );
checkAndCreateConfigDir();
#ifdef ADDONS_MANAGER
@ -366,17 +366,18 @@ std::string FileManager::getConfigFile(const std::string& fname) const
//-----------------------------------------------------------------------------
/** If the directory specified in path does not exist, it is created.
* /params path Directory to test.
* /return True if the directory exists or could be created, false otherwise.
* \params path Directory to test.
* \return True if the directory exists or could be created, false otherwise.
*/
bool FileManager::checkAndCreateDirectory(const std::string &path)
{
std::cout << "creating...:" << path << std::endl;
// irrlicht apparently returns true for files and directory
// (using access/_access internally):
if(m_file_system->existFile(io::path(path.c_str())))
return true;
std::cout << "creating directory <" << path << ">" << std::endl;
// Otherwise try to create the directory:
#if defined(WIN32) && !defined(__CYGWIN__)
bool error = _mkdir(path.c_str()) != 0;
@ -386,25 +387,29 @@ bool FileManager::checkAndCreateDirectory(const std::string &path)
return !error;
} // checkAndCreateDirectory
//-----------------------------------------------------------------------------
bool FileManager::checkAndCreateDirectoryP(const std::string &path)
{
std::cout << "creating...:" << path << std::endl;
// irrlicht apparently returns true for files and directory
// (using access/_access internally):
if(m_file_system->existFile(io::path(path.c_str())))
return true;
std::cout << "creating directory(ies) <" << path << "> ..." << std::endl;
std::vector<std::string> split = StringUtils::split(path,'/');
std::string current_path ="";
for(unsigned int i=0; i<split.size(); i++)
std::string current_path = "";
for (unsigned int i=0; i<split.size(); i++)
{
current_path += split[i] + "/";
std::cout << "Checking for: " << current_path << std::endl;
if(m_file_system->existFile(io::path(current_path.c_str())))
std::cout << "The directory exist." << std::endl;
std::cout << " Checking for: " << current_path << std::endl;
if (m_file_system->existFile(io::path(current_path.c_str())))
{
//std::cout << "The directory exist." << std::endl;
}
else
{
if(!checkAndCreateDirectory(current_path))
if (!checkAndCreateDirectory(current_path))
{
fprintf(stderr, "Can't create dir '%s'",
current_path.c_str());

View File

@ -163,7 +163,7 @@ bool KartPropertiesManager::loadKart(const std::string &dir)
if (kart_properties->getVersion() < stk_config->m_min_kart_version ||
kart_properties->getVersion() > stk_config->m_max_kart_version)
{
fprintf(stderr, "Warning: kart '%s' is not supported by this binary, ignored.\n",
fprintf(stderr, "[KartPropertiesManager] Warning: kart '%s' is not supported by this binary, ignored.\n",
kart_properties->getIdent().c_str());
delete kart_properties;
return false;

View File

@ -572,7 +572,6 @@ void initRest()
KartPropertiesManager::addKartSearchDir(file_manager->getAddonsDir() + "/data/karts/");
track_manager->addTrackSearchDir(file_manager->getAddonsDir() + "/data/tracks/");
std::cout << "addons dir:" << file_manager->getAddonsDir() + "/data/karts/" << std::endl;
#endif
track_manager->loadTrackList();
music_manager->addMusicToTracks();

View File

@ -127,6 +127,7 @@ void AddonsScreen::eventCallback(GUIEngine::Widget* widget, const std::string& n
}
// ------------------------------------------------------------------------------------------------------
void AddonsScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
pthread_mutex_lock(&(this->mutex));
@ -136,6 +137,9 @@ void AddonsScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
}
pthread_mutex_unlock(&(this->mutex));
}
// ------------------------------------------------------------------------------------------------------
void AddonsScreen::init()
{
Screen::init();
@ -143,7 +147,7 @@ void AddonsScreen::init()
this->type = "kart";
pthread_mutex_init(&(this->mutex), NULL);
std::cout << "Addons dir:" + file_manager->getAddonsDir() << std::endl;
std::cout << "[Addons] Using directory <" + file_manager->getAddonsDir() << ">\n";
GUIEngine::ListWidget* w_list = this->getWidget<GUIEngine::ListWidget>("list_addons");
w_list->setIcons(m_icon_bank);
//w_list->clear();
@ -156,6 +160,7 @@ void AddonsScreen::init()
}
// ------------------------------------------------------------------------------------------------------
void * AddonsScreen::downloadList( void * pthis)
{
AddonsScreen * pt = (AddonsScreen*)pthis;

View File

@ -78,12 +78,18 @@ void AddonsLoading::loadInfo()
void * AddonsLoading::downloadIcon( void * pthis)
{
AddonsLoading * pt = (AddonsLoading*)pthis;
if(download("icon/" + addons_manager->GetIcon(), addons_manager->GetName() + ".png"))
std::string iconPath = "icon/" + addons_manager->GetIcon();
if (download(iconPath, addons_manager->GetName() + ".png"))
{
pthread_mutex_lock(&(pt->m_mutex_can_install));
pt->m_can_load_icon = true;
pthread_mutex_unlock(&(pt->m_mutex_can_install));
}
else
{
fprintf(stderr, "[Addons] Download icon '%s' failed\n", iconPath.c_str());
}
return NULL;
}

View File

@ -156,8 +156,8 @@ bool TrackManager::loadTrack(const std::string& dirname)
if(track->getVersion()<stk_config->m_min_track_version ||
track->getVersion()>stk_config->m_max_track_version)
{
fprintf(stderr, "Warning: track '%s' is not supported by this binary, ignored.\n",
track->getIdent().c_str());
fprintf(stderr, "[TrackManager] Warning: track '%s' is not supported by this binary, ignored.\n",
track->getIdent().c_str());
delete track;
return false;
}