Fixed enabling internet in the GUI (i.e. re-init of
news manager and addons manager will happen now). For online menu a dialog is now presented to explain why it can't be selected if internet is disabled. Addons can be selected with internet is disabled if there are existing addons (so that it's possible to remove addons without internet access). git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@15035 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
428f74d859
commit
d53e3180ac
@ -98,14 +98,18 @@ void AddonsManager::init(const XMLNode *xml,
|
||||
}
|
||||
|
||||
include->get("file", &addon_list_url);
|
||||
int frequency = 0;
|
||||
include->get("frequency", &frequency);
|
||||
|
||||
int64_t tmp;
|
||||
include->get("mtime", &tmp);
|
||||
mtime = tmp;
|
||||
|
||||
bool download = mtime > UserConfigParams::m_addons_last_updated ||
|
||||
force_refresh ||
|
||||
!file_manager->fileExists(filename);
|
||||
bool download =
|
||||
( mtime > UserConfigParams::m_addons_last_updated +frequency ||
|
||||
force_refresh ||
|
||||
!file_manager->fileExists(filename) )
|
||||
&& UserConfigParams::m_internet_status == RequestManager::IPERM_ALLOWED;
|
||||
|
||||
if (download)
|
||||
{
|
||||
@ -445,6 +449,14 @@ int AddonsManager::getAddonIndex(const std::string &id) const
|
||||
}
|
||||
return -1;
|
||||
} // getAddonIndex
|
||||
// ----------------------------------------------------------------------------
|
||||
bool AddonsManager::anyAddonsInstalled() const
|
||||
{
|
||||
for(unsigned int i=0; i<m_addons_list.getData().size(); i++)
|
||||
if(m_addons_list.getData()[i].isInstalled())
|
||||
return true;
|
||||
return false;
|
||||
} // anyAddonsInstalled
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Installs or updates (i.e. = install on top of an existing installation) an
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
bool install(const Addon &addon);
|
||||
bool uninstall(const Addon &addon);
|
||||
void reInit();
|
||||
bool anyAddonsInstalled() const;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if the list of online addons has been downloaded. This is
|
||||
* used to grey out the 'addons' entry till a network connections could be
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "online/http_request.hpp"
|
||||
#include "online/request_manager.hpp"
|
||||
#include "states_screens/addons_screen.hpp"
|
||||
#include "states_screens/main_menu_screen.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
@ -28,6 +29,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace Online;
|
||||
|
||||
NewsManager *NewsManager::m_news_manager=NULL;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -96,16 +99,17 @@ void* NewsManager::downloadNews(void *obj)
|
||||
// or if the time of the last update was more than news_frequency ago,
|
||||
// or because a 'refresh' was explicitly requested by the user, or no
|
||||
// news.xml file exists.
|
||||
bool download = UserConfigParams::m_news_last_updated==0 ||
|
||||
UserConfigParams::m_news_last_updated
|
||||
+UserConfigParams::m_news_frequency
|
||||
< StkTime::getTimeSinceEpoch() ||
|
||||
me->m_force_refresh ||
|
||||
!news_exists;
|
||||
bool download = ( UserConfigParams::m_news_last_updated==0 ||
|
||||
UserConfigParams::m_news_last_updated
|
||||
+UserConfigParams::m_news_frequency
|
||||
< StkTime::getTimeSinceEpoch() ||
|
||||
me->m_force_refresh ||
|
||||
!news_exists )
|
||||
&& UserConfigParams::m_internet_status==RequestManager::IPERM_ALLOWED;
|
||||
|
||||
const XMLNode *xml = NULL;
|
||||
|
||||
if(!download)
|
||||
if(!download && news_exists)
|
||||
{
|
||||
// If (so far) we don't need to download, there should be an existing
|
||||
// file. Try to read this, and do some basic checks
|
||||
@ -131,7 +135,7 @@ void* NewsManager::downloadNews(void *obj)
|
||||
{
|
||||
core::stringw error_message("");
|
||||
|
||||
Online::HTTPRequest *download_req = new Online::HTTPRequest("news.xml");
|
||||
HTTPRequest *download_req = new HTTPRequest("news.xml");
|
||||
download_req->setAddonsURL("news.xml");
|
||||
// Initialise the online portion of the addons manager.
|
||||
if(UserConfigParams::logAddons())
|
||||
@ -147,7 +151,7 @@ void* NewsManager::downloadNews(void *obj)
|
||||
delete download_req;
|
||||
// We need a new object, since the state of the old
|
||||
// download request is now done.
|
||||
download_req = new Online::HTTPRequest("news.xml");
|
||||
download_req = new HTTPRequest("news.xml");
|
||||
UserConfigParams::m_server_addons.revertToDefaults();
|
||||
// make sure the new server address is actually used
|
||||
download_req->setAddonsURL("news.xml");
|
||||
@ -191,14 +195,6 @@ void* NewsManager::downloadNews(void *obj)
|
||||
return 0; // prevent warning
|
||||
} // downloadNews
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Initialises the online part of the network manager. It downloads the
|
||||
* news.xml file from the server (if the frequency of downloads makes this
|
||||
* necessary), and (again if necessary) the addons.xml file.
|
||||
* \return 0 if an error happened and no online connection will be available,
|
||||
* 1 otherwise.
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** Checks if a redirect is received, causing a new server to be used for
|
||||
* downloading addons.
|
||||
|
@ -57,6 +57,9 @@ namespace Online
|
||||
int priority)
|
||||
: Request(manage_memory, priority, 0)
|
||||
{
|
||||
// A http request should not even be created when internet is disabled
|
||||
assert(UserConfigParams::m_internet_status ==
|
||||
RequestManager::IPERM_ALLOWED);
|
||||
assert(filename.size()>0);
|
||||
init();
|
||||
m_filename = file_manager->getAddonsFile(filename);
|
||||
@ -70,6 +73,9 @@ namespace Online
|
||||
int priority)
|
||||
: Request(manage_memory, priority, 0)
|
||||
{
|
||||
// A http request should not even be created when internet is disabled
|
||||
assert(UserConfigParams::m_internet_status ==
|
||||
RequestManager::IPERM_ALLOWED);
|
||||
init();
|
||||
m_filename = file_manager->getAddonsFile(filename);
|
||||
} // HTTPRequest(filename ...)
|
||||
@ -188,8 +194,11 @@ namespace Online
|
||||
m_parameters.erase(m_parameters.size()-1);
|
||||
}
|
||||
|
||||
Log::info("HTTPRequest", "Sending %s to %s",
|
||||
m_parameters.c_str(), m_url.c_str());
|
||||
if(m_parameters.size()==0)
|
||||
Log::info("HTTPRequest", "Downloading %s", m_url.c_str());
|
||||
else
|
||||
Log::info("HTTPRequest", "Sending %s to %s",
|
||||
m_parameters.c_str(), m_url.c_str());
|
||||
curl_easy_setopt(m_curl_session, CURLOPT_POSTFIELDS,
|
||||
m_parameters.c_str());
|
||||
std::string uagent( std::string("SuperTuxKart/") + STK_VERSION );
|
||||
|
@ -48,16 +48,16 @@ namespace Online
|
||||
*/
|
||||
class RequestManager
|
||||
{
|
||||
public:
|
||||
/** If stk has permission to access the internet (for news
|
||||
* server etc).
|
||||
* IPERM_NOT_ASKED: The user needs to be asked if he wants to
|
||||
* grant permission
|
||||
* IPERM_ALLOWED: STK is allowed to access server.
|
||||
* IPERM_NOT_ALLOWED: STK must not access external servers. */
|
||||
enum InternetPermission {IPERM_NOT_ASKED =0,
|
||||
IPERM_ALLOWED =1,
|
||||
IPERM_NOT_ALLOWED=2 };
|
||||
public:
|
||||
/** If stk has permission to access the internet (for news
|
||||
* server etc).
|
||||
* IPERM_NOT_ASKED: The user needs to be asked if he wants to
|
||||
* grant permission
|
||||
* IPERM_ALLOWED: STK is allowed to access server.
|
||||
* IPERM_NOT_ALLOWED: STK must not access external servers. */
|
||||
enum InternetPermission {IPERM_NOT_ASKED =0,
|
||||
IPERM_ALLOWED =1,
|
||||
IPERM_NOT_ALLOWED=2 };
|
||||
protected:
|
||||
|
||||
float m_time_since_poll;
|
||||
|
@ -372,10 +372,29 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
}
|
||||
else if (selection == "online")
|
||||
{
|
||||
if(UserConfigParams::m_internet_status!=RequestManager::IPERM_ALLOWED)
|
||||
{
|
||||
new MessageDialog(_("You can not play online without internet access. "
|
||||
"If you want to play online, go to options, select "
|
||||
" tab 'User Interface', and edit "
|
||||
"\"Allow STK to connect to the Internet\"."));
|
||||
return;
|
||||
}
|
||||
StateManager::get()->pushScreen(OnlineScreen::getInstance());
|
||||
}
|
||||
else if (selection == "addons")
|
||||
{
|
||||
// Don't go to addons if there is no internet, unless some addons are
|
||||
// already installed (so that you can delete addons without being online).
|
||||
if(UserConfigParams::m_internet_status!=RequestManager::IPERM_ALLOWED &&
|
||||
!addons_manager->anyAddonsInstalled())
|
||||
{
|
||||
new MessageDialog(_("You can not download addons without internet access. "
|
||||
"If you want to download addons, go to options, select "
|
||||
" tab 'User Interface', and edit "
|
||||
"\"Allow STK to connect to the Internet\"."));
|
||||
return;
|
||||
}
|
||||
StateManager::get()->pushScreen(AddonsScreen::getInstance());
|
||||
}
|
||||
} // eventCallback
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "states_screens/options_screen_ui.hpp"
|
||||
|
||||
#include "addons/news_manager.hpp"
|
||||
#include "audio/music_manager.hpp"
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "audio/sfx_base.hpp"
|
||||
@ -228,11 +229,16 @@ void OptionsScreenUI::eventCallback(Widget* widget, const std::string& name, con
|
||||
}
|
||||
else if (name=="enable-internet")
|
||||
{
|
||||
CheckBoxWidget* news = getWidget<CheckBoxWidget>("enable-internet");
|
||||
assert( news != NULL );
|
||||
CheckBoxWidget* internet = getWidget<CheckBoxWidget>("enable-internet");
|
||||
assert( internet != NULL );
|
||||
UserConfigParams::m_internet_status =
|
||||
news->getState() ? RequestManager::IPERM_ALLOWED
|
||||
: RequestManager::IPERM_NOT_ALLOWED;
|
||||
internet->getState() ? RequestManager::IPERM_ALLOWED
|
||||
: RequestManager::IPERM_NOT_ALLOWED;
|
||||
// If internet gets enabled, re-initialise the addon manager (which
|
||||
// happens in a separate thread) so that news.xml etc can be
|
||||
// downloaded if necessary.
|
||||
if(internet->getState())
|
||||
NewsManager::get()->init(false);
|
||||
}
|
||||
else if (name == "language")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user