Further improvements to addons loading. Addons are now downloaded and installed,
but the kart icon display is still messed up (restarting stk solves that) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7221 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
4a6b709685
commit
7e34b5d970
@ -35,6 +35,7 @@
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "states_screens/kart_selection.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
|
||||
AddonsManager* addons_manager = 0;
|
||||
|
||||
@ -184,20 +185,7 @@ int AddonsManager::getAddonIndex(const std::string &id) const
|
||||
// ----------------------------------------------------------------------------
|
||||
void AddonsManager::install(const Addon &addon)
|
||||
{
|
||||
//download of the addons file
|
||||
|
||||
m_str_state = "Downloading...";
|
||||
|
||||
std::string file = "file/" + addon.getFile();
|
||||
network_http->downloadFileAsynchron(file, addon.getName());
|
||||
//FIXME , &m_download_state);
|
||||
bool success=true;
|
||||
if (!success)
|
||||
{
|
||||
// TODO: show a message in the interface
|
||||
fprintf(stderr, "[Addons] Failed to download '%s'\n", file.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
file_manager->checkAndCreateDirForAddons(addon.getName(),
|
||||
addon.getType()+ "s/");
|
||||
@ -205,8 +193,9 @@ void AddonsManager::install(const Addon &addon)
|
||||
//extract the zip in the addons folder called like the addons name
|
||||
std::string dest_file = file_manager->getAddonsDir() + "/"
|
||||
+ addon.getType()+ "s/" + addon.getName() + "/" ;
|
||||
std::string from = file_manager->getConfigDir() + "/" + addon.getName();
|
||||
std::string to = dest_file;
|
||||
std::string base_name = StringUtils::getBasename(addon.getFile());
|
||||
std::string from = file_manager->getAddonsFile(base_name);
|
||||
std::string to = dest_file;
|
||||
|
||||
m_str_state = "Unzip the addons...";
|
||||
|
||||
|
@ -41,9 +41,10 @@ AddonsLoading::AddonsLoading(const float w, const float h,
|
||||
: ModalDialog(w, h)
|
||||
, m_icon_loaded(ICON_NOT_LOADED)
|
||||
{
|
||||
m_addon = *(addons_manager->getAddon(id));
|
||||
|
||||
loadFromFile("addons_view_dialog.stkgui");
|
||||
|
||||
m_addon = *(addons_manager->getAddon(id));
|
||||
m_progress = NULL;
|
||||
m_can_install = false;
|
||||
m_percent_update = false;
|
||||
pthread_mutex_init(&m_mutex_can_install, NULL);
|
||||
@ -118,6 +119,7 @@ GUIEngine::EventPropagation
|
||||
}
|
||||
if(eventSource == "install")
|
||||
{
|
||||
assert(m_progress==NULL);
|
||||
m_progress = new ProgressBarWidget();
|
||||
m_progress->m_x = 180;
|
||||
m_progress->m_y = m_area.getHeight()-45;
|
||||
@ -149,8 +151,7 @@ GUIEngine::EventPropagation
|
||||
*/
|
||||
getWidget<ButtonWidget>("install")->setDeactivated();
|
||||
m_percent_update = true;
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL, &AddonsLoading::startInstall, this);
|
||||
startInstall();
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
} // processEvent
|
||||
@ -158,6 +159,37 @@ GUIEngine::EventPropagation
|
||||
// ----------------------------------------------------------------------------
|
||||
void AddonsLoading::onUpdate(float delta)
|
||||
{
|
||||
if(m_progress)
|
||||
{
|
||||
float progress = network_http->getProgress();
|
||||
m_progress->setValue((int)(progress*100.0f));
|
||||
if(progress<0)
|
||||
{
|
||||
// TODO: show a message in the interface
|
||||
fprintf(stderr, "[Addons] Failed to download '%s'\n",
|
||||
m_addon.getFile().c_str());
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
else if(progress>=1.0f)
|
||||
{
|
||||
printf("Download finished.\n");
|
||||
endInstall();
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// See if the icon is loaded (but not yet displayed)
|
||||
if(m_icon_loaded.get()==ICON_LOADED)
|
||||
{
|
||||
const std::string icon = StringUtils::getBasename(m_addon.getIcon());
|
||||
m_icon->setImage( file_manager->getAddonsFile(icon).c_str(),
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE );
|
||||
m_icon_loaded.set(ICON_SHOWN);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&(m_mutex_can_install));
|
||||
if(m_can_install)
|
||||
@ -169,13 +201,6 @@ void AddonsLoading::onUpdate(float delta)
|
||||
m_progress->setValue(addons_manager->getDownloadState());
|
||||
m_state->setText(addons_manager->getDownloadStateAsStr().c_str());
|
||||
}
|
||||
if(m_icon_loaded.get()==ICON_LOADED)
|
||||
{
|
||||
const std::string icon = StringUtils::getBasename(m_addon.getIcon());
|
||||
m_icon->setImage( file_manager->getAddonsFile(icon).c_str(),
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE );
|
||||
m_icon_loaded.set(ICON_SHOWN);
|
||||
}
|
||||
pthread_mutex_unlock(&(m_mutex_can_install));
|
||||
} // onUpdate
|
||||
|
||||
@ -188,22 +213,26 @@ void AddonsLoading::close()
|
||||
} // close
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void * AddonsLoading::startInstall(void* pthis)
|
||||
/** This function is called when the user click on 'Install', 'Uninstall', or
|
||||
* 'Update'.
|
||||
**/
|
||||
void AddonsLoading::startInstall()
|
||||
{
|
||||
AddonsLoading * obj = (AddonsLoading*)pthis;
|
||||
if(!obj->m_addon.isInstalled() || obj->m_addon.needsUpdate())
|
||||
std::string file = "file/" + m_addon.getFile();
|
||||
std::string save = StringUtils::getBasename(m_addon.getFile());
|
||||
network_http->downloadFileAsynchron(file, save);
|
||||
} // startInstall
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void AddonsLoading::endInstall()
|
||||
{
|
||||
if(!m_addon.isInstalled() || m_addon.needsUpdate())
|
||||
{
|
||||
addons_manager->install(obj->m_addon);
|
||||
addons_manager->install(m_addon);
|
||||
}
|
||||
else
|
||||
{
|
||||
addons_manager->uninstall(obj->m_addon);
|
||||
addons_manager->uninstall(m_addon);
|
||||
}
|
||||
pthread_mutex_lock(&(obj->m_mutex_can_install));
|
||||
obj->m_can_install = true;
|
||||
obj->m_percent_update = false;
|
||||
pthread_mutex_unlock(&(obj->m_mutex_can_install));
|
||||
return NULL;
|
||||
} // startInstall
|
||||
} // endInstall
|
||||
#endif
|
||||
|
@ -44,11 +44,9 @@ private:
|
||||
|
||||
/** The addon to load. */
|
||||
Addon m_addon;
|
||||
/**
|
||||
* This function is called when the user click on 'Install', 'Uninstall', or
|
||||
* 'Update'. It is started using a thread.
|
||||
* */
|
||||
static void * startInstall(void*);
|
||||
void startInstall();
|
||||
void endInstall();
|
||||
|
||||
/**
|
||||
* This function handle the downllading of the addons icon.
|
||||
* It is started using a thread. When it is ended, it change the flag
|
||||
|
Loading…
Reference in New Issue
Block a user