Fix #1516. Also fixed (probably unrelated) bug that first time STK

is started with internet permission, the addon server would not be
accessible. Note: any current configuration will not be read anymore
(if you need it, you can just move the files and directories from
.../supertuxkart into .../supertuxkart/0.8.2  (except addons, whic
stays in .../supertuxkart/addons!!).
This commit is contained in:
hiker 2014-09-25 09:05:46 +10:00
parent 3be8fdf82c
commit 7c66dd1865
3 changed files with 33 additions and 20 deletions

View File

@ -57,28 +57,31 @@ NewsManager::~NewsManager()
*/
void NewsManager::init(bool force_refresh)
{
// The rest (which potentially involves downloading news.xml) is handled
// in a separate thread, so that the GUI remains responsive.
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// Should be the default, but just in case:
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
//pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
m_force_refresh = force_refresh;
pthread_t thread_id;
int error = pthread_create(&thread_id, &attr,
&NewsManager::downloadNews, this);
if(error)
// The rest (which potentially involves downloading news.xml) is handled
// in a separate thread, so that the GUI remains responsive. It is only
// started if internet access is enabled, else nothing is done in the
// thread anyway (and the addons menu is disabled as a result).
if(UserConfigParams::m_internet_status==RequestManager::IPERM_ALLOWED)
{
Log::warn("news", "Could not create thread, error=%d", error);
// In this case just execute the downloading code with this thread
downloadNews(this);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// Should be the default, but just in case:
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
//pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
pthread_t thread_id;
int error = pthread_create(&thread_id, &attr,
&NewsManager::downloadNews, this);
if (error)
{
Log::warn("news", "Could not create thread, error=%d", error);
// In this case just execute the downloading code with this thread
downloadNews(this);
}
pthread_attr_destroy(&attr);
}
pthread_attr_destroy(&attr);
} //init

View File

@ -813,7 +813,8 @@ void FileManager::checkAndCreateConfigDir()
if(m_user_config_dir.size()>0 && *m_user_config_dir.rbegin()!='/')
m_user_config_dir += "/";
if(!checkAndCreateDirectory(m_user_config_dir))
m_user_config_dir +="0.8.2/";
if(!checkAndCreateDirectoryP(m_user_config_dir))
{
Log::warn("FileManager", "Can not create config dir '%s', "
"falling back to '.'.", m_user_config_dir.c_str());
@ -830,7 +831,7 @@ void FileManager::checkAndCreateConfigDir()
void FileManager::checkAndCreateAddonsDir()
{
#if defined(WIN32) || defined(__CYGWIN__)
m_addons_dir = m_user_config_dir+"addons/";
m_addons_dir = m_user_config_dir+"../addons/";
#elif defined(__APPLE__)
m_addons_dir = getenv("HOME");
m_addons_dir += "/Library/Application Support/SuperTuxKart/Addons/";

View File

@ -1127,8 +1127,17 @@ void askForInternetPermission()
public:
virtual void onConfirm()
{
// Typically internet is disabled here (just better safe
// than sorry). If internet should be allowed, the news
// manager needs to be started (which in turn activates
// the addons manager).
bool need_to_start_news_manager =
UserConfigParams::m_internet_status!=
Online::RequestManager::IPERM_ALLOWED;
UserConfigParams::m_internet_status =
Online::RequestManager::IPERM_ALLOWED;
if(need_to_start_news_manager)
NewsManager::get()->init(false);
GUIEngine::ModalDialog::dismiss();
} // onConfirm
// --------------------------------------------------------