Made addon manager compiler with windows (though not working yet).

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7039 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2010-12-16 21:07:14 +00:00
parent fc4e59dc6e
commit f5662118c6
8 changed files with 53 additions and 29 deletions

View File

@ -22,6 +22,7 @@
#include <string.h>
#include <map>
#include <pthread.h>
#include <vector>
struct addons_prop

View File

@ -16,15 +16,22 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef ADDONS_MANAGER
#include "addons/network.hpp"
#include <curl/curl.h>
#include <stdio.h>
#include <string>
#include "addons/network.hpp"
#include "config/user_config.hpp"
#include "states_screens/main_menu_screen.hpp"
#include "states_screens/addons_screen.hpp"
#if defined(WIN32) && !defined(__CYGWIN__)
# define isnan _isnan
#else
# include <math.h>
#endif
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/main_menu_screen.hpp"
pthread_mutex_t download_mutex;
NetworkHttp * network_http = 0;
@ -76,29 +83,34 @@ 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 full_url=UserConfigParams::m_server_addons.toString()+"/"+url;
curl_easy_setopt(session, CURLOPT_URL, full_url.c_str());
std::string fout;
//from and out
curl_easy_setopt(session, CURLOPT_WRITEDATA, &fout);
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, &NetworkHttp::writeStr);
curl_easy_setopt(session, CURLOPT_WRITEDATA, &fout );
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, &NetworkHttp::writeStr);
int succes = curl_easy_perform(session);
int success = curl_easy_perform(session);
//stop curl
curl_easy_cleanup(session);
if (succes == 0) return fout;
if (success == 0) return fout;
else return "";
}
// ------------------------------------------------------------------------------------------------------
bool download(std::string file, std::string save, int * progress_data)
// ----------------------------------------------------------------------------
/** Download a file. The file name isn't absolute, the server in the config
* will be added to file.
* \param progress_data is used to have the state of the download (in %)
*/
bool download(std::string file, const std::string &save, int * progress_data)
{
CURL *session = curl_easy_init();
curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + file).c_str());
std::string full_url=UserConfigParams::m_server_addons.toString()+"/"+file;
curl_easy_setopt(session, CURLOPT_URL, full_url.c_str());
FILE * fout;
if(save != "")
fout = fopen(std::string(file_manager->getConfigDir() + std::string("/") + save).c_str(), "w");
@ -135,9 +147,10 @@ bool download(std::string file, std::string save, int * progress_data)
//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)
int progressDownload (void *clientp, float dltotal, float dlnow,
float ultotal, float ulnow)
{
int progress = dlnow/dltotal*100;
int progress = (int)(dlnow/dltotal*100);
if(isnan(dlnow/dltotal*100))
progress = 0;
pthread_mutex_lock(&download_mutex);

View File

@ -29,17 +29,18 @@ class NetworkHttp
public:
NetworkHttp();
static void * checkNewServer(void * obj);
static size_t writeStr(char str [], size_t size, size_t nb_char, std::string * stream);
static size_t writeStr(char str [], size_t size, size_t nb_char,
std::string * stream);
std::string downloadToStr(std::string url);
};
extern NetworkHttp * network_http;
/* * Download a file. The file name isn't absolute, the server in the config will be added to file.
* progress_data is used to have the state of the download (in %)*/
bool download(std::string file, std::string save = "", int * progress_data = 0);
extern NetworkHttp *network_http;
bool download(std::string file, const std::string &save = "",
int *progress_data = 0);
int progressDownload (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
int progressDownload (void *clientp, float dltotal, float dlnow,
float ultotal, float ulnow);
extern pthread_mutex_t download_mutex;
#endif

View File

@ -502,7 +502,7 @@ void FileManager::checkAndCreateConfigDir()
void FileManager::checkAndCreateAddonsDir()
{
#if defined(WIN32)
//TODO
m_addons_dir = m_config_dir;
#elif defined(__APPLE__)
m_addons_dir = getenv("HOME");
m_addons_dir += "/Library/Application Support/SuperTuxKart";
@ -707,6 +707,9 @@ bool FileManager::removeDirectory(char const *name)
#else
//FIXME : check this function, it is only for windows, but I'm on linux.
::RemoveDirectory(name);
return true;
#ifdef XX
SHFILEOPSTRUCT sh;
sh.hwnd = NULL;
sh.wFunc = FO_DELETE;
@ -719,6 +722,7 @@ bool FileManager::removeDirectory(char const *name)
return (SHFileOperation(&sh)==0);
#endif
#endif
}
#endif

View File

@ -611,6 +611,7 @@ void cleanTuxKart()
//delete in reverse order of what they were created in.
//see InitTuxkart()
if(race_manager) delete race_manager;
if(network_http) delete network_http;
if(network_manager) delete network_manager;
if(grand_prix_manager) delete grand_prix_manager;
if(highscore_manager) delete highscore_manager;

View File

@ -187,7 +187,7 @@ void AddonsLoading::close()
void * AddonsLoading::startInstall(void* pthis)
{
AddonsLoading * obj = (AddonsLoading*)pthis;
if(!addons_manager->IsInstalledAsBool() or addons_manager->NeedUpdate())
if(!addons_manager->IsInstalledAsBool() || addons_manager->NeedUpdate())
{
addons_manager->Install();
}

View File

@ -18,6 +18,7 @@
#ifndef HEADER_MAIN_MENU_SCREEN_HPP
#define HEADER_MAIN_MENU_SCREEN_HPP
#include <pthread.h>
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; }

View File

@ -906,14 +906,17 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id)
// ---- Fog
// It's important to execute this BEFORE the code that creates the skycube, otherwise the skycube node
// could be modified to have fog enabled, which we don't want
// It's important to execute this BEFORE the code that creates the skycube,
// otherwise the skycube node could be modified to have fog enabled, which
// we don't want
if (m_use_fog && !UserConfigParams::m_camera_debug)
{
/* NOTE: if LINEAR type, density does not matter, if EXP or EXP2, start
and end do not matter */
irr_driver->getVideoDriver()->setFog(m_fog_color, video::EFT_FOG_LINEAR,
m_fog_start, m_fog_end, m_fog_density);
/* NOTE: if LINEAR type, density does not matter, if EXP or EXP2, start
and end do not matter */
irr_driver->getVideoDriver()->setFog(m_fog_color,
video::EFT_FOG_LINEAR,
m_fog_start, m_fog_end,
m_fog_density);
}
// Enable for for all track nodes if fog is used