Allow install full game assets from stk server
This commit is contained in:
parent
a1d0783f7a
commit
4200f0ca59
@ -86,6 +86,11 @@
|
||||
</div>
|
||||
|
||||
<spacer width="5" height="4%"/>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<spacer width="1%" height="100%"/>
|
||||
<button id="assets_settings" raw_text="Android specific options"/>
|
||||
</div>
|
||||
<spacer width="5" height="4%"/>
|
||||
</box>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -178,7 +178,7 @@
|
||||
|
||||
<urls donate="https://supertuxkart.net/Donate"
|
||||
password-reset="https://online.supertuxkart.net/password-reset.php"
|
||||
assets-download="https://downloads.sourceforge.net/project/supertuxkart/stk-assets-mobile/"/>
|
||||
assets-download="https://github.com/supertuxkart/stk-assets-mobile/releases/download/"/>
|
||||
|
||||
<!-- Skidmark data: maximum number of skid marks, and
|
||||
time for skidmarks to fade out. Maximum number will over
|
||||
|
@ -215,9 +215,9 @@ FileManager::FileManager()
|
||||
#ifdef MOBILE_STK
|
||||
m_stk_assets_download_dir = getenv("HOME");
|
||||
#ifdef IOS_STK
|
||||
m_stk_assets_download_dir += "/Library/Application Support/SuperTuxKart/stk-assets-full/";
|
||||
m_stk_assets_download_dir += "/Library/Application Support/SuperTuxKart/stk-assets/";
|
||||
#elif defined (ANDROID)
|
||||
m_stk_assets_download_dir += "/stk-assets-full/";
|
||||
m_stk_assets_download_dir += "/stk-assets/";
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
264
src/states_screens/dialogs/download_assets.cpp
Normal file
264
src/states_screens/dialogs/download_assets.cpp
Normal file
@ -0,0 +1,264 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2019 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifdef MOBILE_STK
|
||||
|
||||
#include "states_screens/dialogs/download_assets.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "online/http_request.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/extract_mobile_assets.hpp"
|
||||
#include "utils/download_assets_size.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace Online;
|
||||
using namespace irr::gui;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
class DownloadAssetsRequest : public HTTPRequest
|
||||
{
|
||||
private:
|
||||
bool m_extraction_error;
|
||||
virtual void afterOperation()
|
||||
{
|
||||
Online::HTTPRequest::afterOperation();
|
||||
if (isCancelled())
|
||||
return;
|
||||
m_extraction_error =
|
||||
!ExtractMobileAssets::extract(getFileName(),
|
||||
file_manager->getSTKAssetsDownloadDir());
|
||||
}
|
||||
public:
|
||||
DownloadAssetsRequest()
|
||||
: HTTPRequest("stk-assets.zip", /*manage mem*/false, /*priority*/5)
|
||||
{
|
||||
m_extraction_error = true;
|
||||
std::string download_url = stk_config->m_assets_download_url;
|
||||
download_url += STK_VERSION;
|
||||
download_url += "/stk-assets.zip";
|
||||
setURL(download_url);
|
||||
setDownloadAssetsRequest(true);
|
||||
}
|
||||
~DownloadAssetsRequest()
|
||||
{
|
||||
if (isCancelled())
|
||||
{
|
||||
const std::string& zip = getFileName();
|
||||
const std::string zip_part = zip + ".part";
|
||||
if (file_manager->fileExists(zip))
|
||||
file_manager->removeFile(zip);
|
||||
if (file_manager->fileExists(zip_part))
|
||||
file_manager->removeFile(zip_part);
|
||||
file_manager->removeDirectory(
|
||||
file_manager->getSTKAssetsDownloadDir());
|
||||
}
|
||||
}
|
||||
bool hadError() const { return hadDownloadError() || m_extraction_error; }
|
||||
}; // DownloadAssetsRequest
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Creates a modal dialog with given percentage of screen width and height
|
||||
*/
|
||||
DownloadAssets::DownloadAssets()
|
||||
: ModalDialog(0.8f, 0.8f)
|
||||
{
|
||||
m_download_request = NULL;
|
||||
|
||||
loadFromFile("addons_loading.stkgui");
|
||||
m_install_button = getWidget<IconButtonWidget> ("install" );
|
||||
m_progress = getWidget<ProgressBarWidget>("progress");
|
||||
|
||||
RibbonWidget* actions = getWidget<RibbonWidget>("actions");
|
||||
actions->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
actions->select("back", PLAYER_ID_GAME_MASTER);
|
||||
|
||||
if(m_progress)
|
||||
m_progress->setVisible(false);
|
||||
|
||||
IconButtonWidget* icon = getWidget<IconButtonWidget>("icon");
|
||||
icon->setImage(file_manager->getAsset(FileManager::GUI_ICON, "logo.png"),
|
||||
IconButtonWidget::ICON_PATH_TYPE_ABSOLUTE);
|
||||
|
||||
core::stringw unit = "";
|
||||
unsigned n = getDownloadAssetsSize();
|
||||
float f = ((int)(n/1024.0f/1024.0f*10.0f+0.5f))/10.0f;
|
||||
char s[32];
|
||||
sprintf(s, "%.1f", f);
|
||||
unit = _("%s MB", s);
|
||||
// I18N: File size of game assets or addons downloading
|
||||
core::stringw size = _("Size: %s", unit.c_str());
|
||||
getWidget<LabelWidget>("size")->setText(size, false);
|
||||
|
||||
// I18N: In download assets dialog
|
||||
core::stringw msg = _("SuperTuxKart will download full assets "
|
||||
"(including all tracks, high quality textures and music) for better "
|
||||
"gaming experience, this will use your mobile data if you don't have "
|
||||
"a wifi connection.");
|
||||
getWidget<BubbleWidget>("description")->setText(msg);
|
||||
} // DownloadAssets
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void DownloadAssets::beforeAddingWidgets()
|
||||
{
|
||||
getWidget("uninstall")->setVisible(false);
|
||||
} // beforeAddingWidgets
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void DownloadAssets::init()
|
||||
{
|
||||
getWidget("rating")->setVisible(false);
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool DownloadAssets::onEscapePressed()
|
||||
{
|
||||
stopDownload();
|
||||
ModalDialog::dismiss();
|
||||
return true;
|
||||
} // onEscapePressed
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation DownloadAssets::processEvent(const std::string& event_source)
|
||||
{
|
||||
GUIEngine::RibbonWidget* actions_ribbon =
|
||||
getWidget<GUIEngine::RibbonWidget>("actions");
|
||||
|
||||
if (event_source == "actions")
|
||||
{
|
||||
const std::string& selection =
|
||||
actions_ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (selection == "back")
|
||||
{
|
||||
stopDownload();
|
||||
dismiss();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (selection == "install")
|
||||
{
|
||||
m_progress->setValue(0);
|
||||
m_progress->setVisible(true);
|
||||
|
||||
actions_ribbon->setVisible(false);
|
||||
|
||||
startDownload();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
} // processEvent
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void DownloadAssets::onUpdate(float delta)
|
||||
{
|
||||
if (m_download_request)
|
||||
{
|
||||
float progress = m_download_request->getProgress();
|
||||
// Last 1% for unzipping
|
||||
m_progress->setValue(progress * 99.0f);
|
||||
if (progress < 0)
|
||||
{
|
||||
// Avoid displaying '-100%' in case of an error.
|
||||
m_progress->setVisible(false);
|
||||
dismiss();
|
||||
new MessageDialog(_("Sorry, downloading the add-on failed"));
|
||||
return;
|
||||
}
|
||||
else if (m_download_request->isDone())
|
||||
{
|
||||
// No sense to update state text, since it all
|
||||
// happens before the GUI is refrehsed.
|
||||
doInstall();
|
||||
return;
|
||||
}
|
||||
} // if (m_progress->isVisible())
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** This function is called when the user click on 'Install', 'Uninstall', or
|
||||
* 'Update'.
|
||||
**/
|
||||
void DownloadAssets::startDownload()
|
||||
{
|
||||
m_download_request = new DownloadAssetsRequest();
|
||||
m_download_request->queue();
|
||||
} // startDownload
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** This function is called when the user click on 'Back', 'Cancel' or press
|
||||
* escape.
|
||||
**/
|
||||
void DownloadAssets::stopDownload()
|
||||
{
|
||||
// Cancel a download only if we are installing/upgrading one
|
||||
// (and not uninstalling an installed one):
|
||||
if (m_download_request)
|
||||
{
|
||||
// In case of a cancel we can't free the memory, since the
|
||||
// request manager thread is potentially working on this request. So
|
||||
// in order to avoid a memory leak, we let the request manager
|
||||
// free the data. This is thread safe since freeing the data is done
|
||||
// when the request manager handles the result queue - and this is
|
||||
// done by the main thread (i.e. this thread).
|
||||
m_download_request->setManageMemory(true);
|
||||
m_download_request->cancel();
|
||||
m_download_request = NULL;
|
||||
}
|
||||
} // startDownload
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called when the asynchronous download of the addon finished.
|
||||
*/
|
||||
void DownloadAssets::doInstall()
|
||||
{
|
||||
core::stringw msg;
|
||||
if (m_download_request->hadError())
|
||||
{
|
||||
// Reset the download buttons so user can redownload if needed
|
||||
// I18N: Shown when there is download error for assets download
|
||||
// in the first run
|
||||
msg = _("Failed to download assets, check your storage space or internet connection and try again later.");
|
||||
}
|
||||
delete m_download_request;
|
||||
m_download_request = NULL;
|
||||
if (!msg.empty())
|
||||
{
|
||||
getWidget<BubbleWidget>("description")->setText(msg);
|
||||
}
|
||||
|
||||
if (!msg.empty())
|
||||
{
|
||||
m_progress->setVisible(false);
|
||||
|
||||
RibbonWidget* r = getWidget<RibbonWidget>("actions");
|
||||
r->setVisible(true);
|
||||
|
||||
m_install_button->setLabel(_("Try again"));
|
||||
}
|
||||
else
|
||||
{
|
||||
dismiss();
|
||||
ExtractMobileAssets::reinit();
|
||||
}
|
||||
} // doInstall
|
||||
|
||||
#endif
|
58
src/states_screens/dialogs/download_assets.hpp
Normal file
58
src/states_screens/dialogs/download_assets.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2019 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_DOWNLOAD_ASSETS_HPP
|
||||
#define HEADER_DOWNLOAD_ASSETS_HPP
|
||||
|
||||
#ifdef MOBILE_STK
|
||||
|
||||
#include "guiengine/widgets.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
||||
class DownloadAssetsRequest;
|
||||
|
||||
/**
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class DownloadAssets : public GUIEngine::ModalDialog
|
||||
{
|
||||
private:
|
||||
GUIEngine::ProgressBarWidget *m_progress;
|
||||
GUIEngine::IconButtonWidget *m_install_button;
|
||||
|
||||
void startDownload();
|
||||
void stopDownload();
|
||||
void doInstall();
|
||||
|
||||
/** A pointer to the download request, which gives access
|
||||
* to the progress of a download. */
|
||||
DownloadAssetsRequest* m_download_request;
|
||||
|
||||
public:
|
||||
DownloadAssets();
|
||||
|
||||
virtual GUIEngine::EventPropagation processEvent(const std::string& event_source) OVERRIDE;
|
||||
virtual void beforeAddingWidgets() OVERRIDE;
|
||||
virtual void init() OVERRIDE;
|
||||
void onUpdate(float delta) OVERRIDE;
|
||||
virtual bool onEscapePressed() OVERRIDE;
|
||||
}; // DownloadAssets
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,228 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2019 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/download_assets.hpp"
|
||||
#include "addons/zip.hpp"
|
||||
#include "config/stk_config.hpp"
|
||||
#include "guiengine/message_queue.hpp"
|
||||
#include "guiengine/widgets/check_box_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/progress_bar_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "online/http_request.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "utils/download_assets_size.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "main_loop.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
DownloadAssets::DownloadAssets() : GUIEngine::Screen("download_assets.stkgui")
|
||||
{
|
||||
} // OnlineLanScreen
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DownloadAssets::beforeAddingWidget()
|
||||
{
|
||||
|
||||
} // beforeAddingWidget
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DownloadAssets::updateDownloadSize()
|
||||
{
|
||||
m_progress->setValue(0);
|
||||
core::stringw unit="";
|
||||
unsigned n = getDownloadAssetsSize(m_all_tracks->getState(),
|
||||
m_hd_textures->getState());
|
||||
float f = ((int)(n/1024.0f/1024.0f*10.0f+0.5f))/10.0f;
|
||||
char s[32];
|
||||
sprintf(s, "%.1f", f);
|
||||
unit = _("%s MB", s);
|
||||
// I18N: File size of game assets or addons downloading
|
||||
core::stringw size = _("Size: %s", unit.c_str());
|
||||
m_progress->setText(size);
|
||||
} // updateDownloadSize
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DownloadAssets::init()
|
||||
{
|
||||
m_progress = getWidget<ProgressBarWidget>("progress");
|
||||
m_all_tracks = getWidget<CheckBoxWidget>("all-tracks");
|
||||
m_all_tracks->setActive(true);
|
||||
m_all_tracks->setVisible(true);
|
||||
m_all_tracks->setState(false);
|
||||
m_hd_textures = getWidget<CheckBoxWidget>("hd-textures");
|
||||
m_hd_textures->setActive(true);
|
||||
m_hd_textures->setVisible(true);
|
||||
m_hd_textures->setState(false);
|
||||
updateDownloadSize();
|
||||
m_ok = getWidget<IconButtonWidget>("ok");
|
||||
m_ok->setActive(true);
|
||||
m_ok->setVisible(true);
|
||||
m_downloading_now = false;
|
||||
m_download_request = NULL;
|
||||
// Remove any previous left over .zip (and part)
|
||||
const std::string& dir = file_manager->getAddonsDir();
|
||||
if (file_manager->fileExists(dir + "nonfull-nonhd.zip"))
|
||||
file_manager->removeFile(dir + "nonfull-nonhd.zip");
|
||||
if (file_manager->fileExists(dir + "full-nonhd.zip"))
|
||||
file_manager->removeFile(dir + "full-nonhd.zip");
|
||||
if (file_manager->fileExists(dir + "nonfull-hd.zip"))
|
||||
file_manager->removeFile(dir + "nonfull-hd.zip");
|
||||
if (file_manager->fileExists(dir + "full-hd.zip"))
|
||||
file_manager->removeFile(dir + "full-hd.zip");
|
||||
if (file_manager->fileExists(dir + "nonfull-nonhd.zip.part"))
|
||||
file_manager->removeFile(dir + "nonfull-nonhd.zip.part");
|
||||
if (file_manager->fileExists(dir + "full-nonhd.zip.part"))
|
||||
file_manager->removeFile(dir + "full-nonhd.zip.part");
|
||||
if (file_manager->fileExists(dir + "nonfull-hd.zip.part"))
|
||||
file_manager->removeFile(dir + "nonfull-hd.zip.part");
|
||||
if (file_manager->fileExists(dir + "full-hd.zip.part"))
|
||||
file_manager->removeFile(dir + "full-hd.zip.part");
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void DownloadAssets::eventCallback(Widget* widget, const std::string& name,
|
||||
const int player_id)
|
||||
{
|
||||
if (m_downloading_now)
|
||||
return;
|
||||
if (name == "all-tracks" || name == "hd-textures")
|
||||
updateDownloadSize();
|
||||
else if (name == "buttons")
|
||||
{
|
||||
const std::string& button = getWidget<GUIEngine::RibbonWidget>("buttons")
|
||||
->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (button == "ok")
|
||||
{
|
||||
m_downloading_now = true;
|
||||
m_ok->setActive(false);
|
||||
m_progress->setText("");
|
||||
m_progress->setValue(0);
|
||||
m_all_tracks->setActive(false);
|
||||
m_hd_textures->setActive(false);
|
||||
std::string download_url = stk_config->m_assets_download_url;
|
||||
std::string filename;
|
||||
|
||||
if (m_all_tracks->getState())
|
||||
filename = "full";
|
||||
else
|
||||
filename = "nonfull";
|
||||
filename += "-";
|
||||
if (m_hd_textures->getState())
|
||||
filename += "hd";
|
||||
else
|
||||
filename += "nonhd";
|
||||
filename += ".zip";
|
||||
|
||||
download_url += STK_VERSION;
|
||||
download_url += "/";
|
||||
download_url += filename;
|
||||
|
||||
m_download_request = new Online::HTTPRequest(filename,
|
||||
true/*manage_memory*/);
|
||||
m_download_request->setDownloadAssetsRequest(true);
|
||||
m_download_request->setURL(download_url);
|
||||
m_download_thread = std::thread([this]()
|
||||
{
|
||||
m_download_request->executeNow();
|
||||
const std::string& zip = m_download_request->getFileName();
|
||||
const std::string& dir =
|
||||
file_manager->getSTKAssetsDownloadDir();
|
||||
if (file_manager->fileExists(zip))
|
||||
{
|
||||
// Remove previous stk-assets version and create a new
|
||||
// one
|
||||
file_manager->removeDirectory(dir);
|
||||
file_manager->checkAndCreateDirectory(dir);
|
||||
if (extract_zip(zip, dir, true/*recursive*/))
|
||||
{
|
||||
std::string extract_ok =
|
||||
dir + "/stk-assets." + STK_VERSION;
|
||||
FILE* fp = fopen(extract_ok.c_str(), "wb");
|
||||
if (!fp)
|
||||
{
|
||||
Log::error("FileUtils",
|
||||
"Failed to create extract ok file.");
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(fp);
|
||||
file_manager->reinitAfterDownloadAssets();
|
||||
}
|
||||
}
|
||||
file_manager->removeFile(zip);
|
||||
}
|
||||
m_downloading_now = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool DownloadAssets::onEscapePressed()
|
||||
{
|
||||
if (m_downloading_now)
|
||||
return false;
|
||||
return true;
|
||||
} // onEscapePressed
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool DownloadAssets::needDownloadAssets()
|
||||
{
|
||||
const std::string& dir = file_manager->getSTKAssetsDownloadDir();
|
||||
if (dir.empty())
|
||||
return false;
|
||||
return !file_manager->fileExists(dir + "/stk-assets." + STK_VERSION);
|
||||
} // needDownloadAssets
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void DownloadAssets::onUpdate(float dt)
|
||||
{
|
||||
if (m_download_request)
|
||||
m_progress->setValue(m_download_request->getProgress() * 99.0f);
|
||||
if (m_download_thread.joinable())
|
||||
{
|
||||
if (m_downloading_now)
|
||||
return;
|
||||
if (!m_downloading_now)
|
||||
{
|
||||
m_download_thread.join();
|
||||
if (m_download_request)
|
||||
{
|
||||
delete m_download_request;
|
||||
m_download_request = NULL;
|
||||
}
|
||||
}
|
||||
if (!needDownloadAssets())
|
||||
main_loop->abort();
|
||||
else
|
||||
{
|
||||
// Reset the download buttons so user can redownload if needed
|
||||
// I18N: Shown when there is download error for assets download
|
||||
// in the first run
|
||||
core::stringw msg = _("Failed to download assets, check your storage space or internet connection and try again later.");
|
||||
MessageQueue::add(MessageQueue::MT_ERROR, msg);
|
||||
DownloadAssets::init();
|
||||
}
|
||||
}
|
||||
} // onUpdate
|
@ -1,85 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2019 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef HEADER_DOWNLOAD_ASSETS_HPP
|
||||
#define HEADER_DOWNLOAD_ASSETS_HPP
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <irrString.h>
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class CheckBoxWidget;
|
||||
class IconButtonWidget;
|
||||
class ProgressBarWidget;
|
||||
}
|
||||
|
||||
namespace Online
|
||||
{
|
||||
class HTTPRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class DownloadAssets : public GUIEngine::Screen, public GUIEngine::ScreenSingleton<DownloadAssets>
|
||||
{
|
||||
protected:
|
||||
DownloadAssets();
|
||||
|
||||
private:
|
||||
GUIEngine::ProgressBarWidget* m_progress;
|
||||
|
||||
GUIEngine::CheckBoxWidget* m_all_tracks;
|
||||
|
||||
GUIEngine::CheckBoxWidget* m_hd_textures;
|
||||
|
||||
GUIEngine::IconButtonWidget* m_ok;
|
||||
|
||||
std::atomic<bool> m_downloading_now;
|
||||
|
||||
Online::HTTPRequest* m_download_request;
|
||||
|
||||
std::thread m_download_thread;
|
||||
|
||||
void updateDownloadSize();
|
||||
public:
|
||||
friend class GUIEngine::ScreenSingleton<DownloadAssets>;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE {}
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name,
|
||||
const int playerID) OVERRIDE;
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void init() OVERRIDE;
|
||||
virtual bool onEscapePressed() OVERRIDE;
|
||||
virtual void onUpdate(float dt) OVERRIDE;
|
||||
bool needDownloadAssets();
|
||||
}; // class DownloadAssets
|
||||
|
||||
#endif
|
@ -38,6 +38,8 @@
|
||||
#include "guiengine/widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "online/request_manager.hpp"
|
||||
#include "states_screens/dialogs/download_assets.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/main_menu_screen.hpp"
|
||||
#include "states_screens/options/options_screen_audio.hpp"
|
||||
#include "states_screens/options/options_screen_input.hpp"
|
||||
@ -46,6 +48,7 @@
|
||||
#include "states_screens/options/options_screen_video.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/options/user_screen.hpp"
|
||||
#include "utils/extract_mobile_assets.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
@ -113,6 +116,24 @@ void OptionsScreenGeneral::init()
|
||||
assert( show_login!= NULL );
|
||||
show_login->setState( UserConfigParams::m_always_show_login_screen);
|
||||
|
||||
#ifdef MOBILE_STK
|
||||
if (ExtractMobileAssets::hasFullAssets())
|
||||
{
|
||||
// I18N: For mobile version for STK, uninstall the downloaded assets
|
||||
getWidget("assets_settings")->setText(_("Uninstall full game assets"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// I18N: For mobile version for STK, install the full game assets which
|
||||
// will download from stk server
|
||||
getWidget("assets_settings")->setText(_("Install full game assets"));
|
||||
}
|
||||
if (UserConfigParams::m_internet_status != RequestManager::IPERM_ALLOWED ||
|
||||
StateManager::get()->getGameState() == GUIEngine::INGAME_MENU)
|
||||
getWidget("assets_settings")->setActive(false);
|
||||
#else
|
||||
getWidget("assets_settings")->setVisible(false);
|
||||
#endif
|
||||
} // init
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -217,6 +238,29 @@ void OptionsScreenGeneral::eventCallback(Widget* widget, const std::string& name
|
||||
assert( difficulty != NULL );
|
||||
UserConfigParams::m_per_player_difficulty = difficulty->getState();
|
||||
}
|
||||
#ifdef MOBILE_STK
|
||||
else if (name=="assets_settings")
|
||||
{
|
||||
if (ExtractMobileAssets::hasFullAssets())
|
||||
{
|
||||
class AssetsDialogListener : public MessageDialog::IConfirmDialogListener
|
||||
{
|
||||
public:
|
||||
virtual void onConfirm() OVERRIDE
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
ExtractMobileAssets::uninstall();
|
||||
}
|
||||
}; // class AssetsDialogListener
|
||||
new MessageDialog(
|
||||
_("Are you sure to uninstall full game assets?"),
|
||||
MessageDialog::MESSAGE_DIALOG_OK_CANCEL,
|
||||
new AssetsDialogListener(), true);
|
||||
}
|
||||
else
|
||||
new DownloadAssets();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
} // eventCallback
|
||||
|
||||
|
@ -20,19 +20,10 @@
|
||||
#define HEADER_DOWNLOAD_ASSETS_SIZE_HPP
|
||||
/* Return .zip file size in bytes (as in ls -l)
|
||||
*/
|
||||
inline unsigned getDownloadAssetsSize(bool is_full, bool is_hd)
|
||||
inline unsigned getDownloadAssetsSize()
|
||||
{
|
||||
// Todo: generated from some sed script
|
||||
unsigned full_hd = 188442091;
|
||||
unsigned full_nonhd = 83487825;
|
||||
unsigned nonfull_hd = 166310030;
|
||||
unsigned nonfull_nonhd = 69282428;
|
||||
if (is_full && is_hd)
|
||||
return full_hd;
|
||||
if (is_full && !is_hd)
|
||||
return full_nonhd;
|
||||
if (!is_full && is_hd)
|
||||
return nonfull_hd;
|
||||
return nonfull_nonhd;
|
||||
unsigned stk_assets_size = 188442091;
|
||||
return stk_assets_size;
|
||||
}
|
||||
#endif
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "utils/extract_mobile_assets.hpp"
|
||||
#include "addons/zip.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "tracks/track_manager.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
@ -64,10 +66,27 @@ bool ExtractMobileAssets::extract(const std::string& zip_file,
|
||||
succeed = true;
|
||||
}
|
||||
}
|
||||
if (succeed)
|
||||
file_manager->reinitAfterDownloadAssets();
|
||||
file_manager->removeFile(zip_file);
|
||||
return succeed;
|
||||
} // extract
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ExtractMobileAssets::reinit()
|
||||
{
|
||||
file_manager->reinitAfterDownloadAssets();
|
||||
irr_driver->sameRestart();
|
||||
track_manager->loadTrackList();
|
||||
} // reinit
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ExtractMobileAssets::uninstall()
|
||||
{
|
||||
// Remove the version file in stk-assets folder first, so if it crashes /
|
||||
// restarted by mobile it will auto discard downloaded assets
|
||||
file_manager->removeFile(file_manager->getSTKAssetsDownloadDir() +
|
||||
"stk-assets." + STK_VERSION);
|
||||
file_manager->removeDirectory(file_manager->getSTKAssetsDownloadDir());
|
||||
reinit();
|
||||
} // uninstall
|
||||
|
||||
#endif
|
||||
|
@ -26,6 +26,8 @@ namespace ExtractMobileAssets
|
||||
{
|
||||
bool hasFullAssets();
|
||||
bool extract(const std::string& zip_file, const std::string& dst);
|
||||
void reinit();
|
||||
void uninstall();
|
||||
} // namespace FileUtils
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user