Show download size for addons pack
This commit is contained in:
parent
1a423e11e7
commit
a45d4fe9f2
@ -90,7 +90,8 @@ namespace Online
|
||||
m_filename = "";
|
||||
m_parameters = "";
|
||||
m_curl_code = CURLE_OK;
|
||||
m_progress.setAtomic(0);
|
||||
m_progress.store(0.0f);
|
||||
m_total_size.store(-1.0);
|
||||
m_disable_sending_log = false;
|
||||
} // init
|
||||
|
||||
@ -368,6 +369,7 @@ namespace Online
|
||||
}
|
||||
|
||||
float f;
|
||||
request->setTotalSize(download_total);
|
||||
if (download_now < download_total)
|
||||
{
|
||||
f = (float)download_now / (float)download_total;
|
||||
|
@ -22,11 +22,11 @@
|
||||
#include "online/request.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/synchronised.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
#include <atomic>
|
||||
#include <curl/curl.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
@ -49,7 +49,9 @@ namespace Online
|
||||
* packet is downloaded. Guaranteed to be <1 while the download
|
||||
* is in progress, it will be set to either -1 (error) or 1
|
||||
* (everything ok) at the end. */
|
||||
Synchronised<float> m_progress;
|
||||
std::atomic<float> m_progress;
|
||||
|
||||
std::atomic<double> m_total_size;
|
||||
|
||||
/** The url to download. */
|
||||
std::string m_url;
|
||||
@ -171,11 +173,11 @@ namespace Online
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Returns the current progress. */
|
||||
float getProgress() const { return m_progress.getAtomic(); }
|
||||
float getProgress() const { return m_progress.load(); }
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Sets the current progress. */
|
||||
void setProgress(float f) { m_progress.setAtomic(f); }
|
||||
void setProgress(float f) { m_progress.store(f); }
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
const std::string & getURL() const { assert(isBusy()); return m_url;}
|
||||
@ -189,6 +191,10 @@ namespace Online
|
||||
} // setURL
|
||||
// --------------------------------------------------------------------
|
||||
const std::string& getFileName() const { return m_filename; }
|
||||
// --------------------------------------------------------------------
|
||||
double getTotalSize() const { return m_total_size.load(); }
|
||||
// --------------------------------------------------------------------
|
||||
void setTotalSize(double d) { m_total_size.store(d); }
|
||||
}; // class HTTPRequest
|
||||
} //namespace Online
|
||||
#endif // HEADER_HTTP_REQUEST_HPP
|
||||
|
@ -171,25 +171,7 @@ void AddonsLoading::beforeAddingWidgets()
|
||||
|
||||
// Display the size
|
||||
// ================
|
||||
int n = m_addon.getSize();
|
||||
core::stringw unit="";
|
||||
if(n>1024*1024)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if(n>1024)
|
||||
{
|
||||
float f = ((int)(n/1024.0f*10.0f+0.5f))/10.0f;
|
||||
char s[32];
|
||||
sprintf(s, "%.1f", f);
|
||||
unit = _("%s KB", s);
|
||||
}
|
||||
else
|
||||
// Anything smaller just let it be 1 KB
|
||||
unit = _("%s KB", 1);
|
||||
core::stringw unit = StringUtils::getReadableFileSize(m_addon.getSize());
|
||||
core::stringw size = _("Size: %s", unit.c_str());
|
||||
getWidget<LabelWidget>("size")->setText(size, false);
|
||||
#endif
|
||||
|
@ -97,7 +97,8 @@ AddonsPack::AddonsPack(const std::string& url) : ModalDialog(0.8f, 0.8f)
|
||||
{
|
||||
loadFromFile("addons_loading.stkgui");
|
||||
getWidget<IconButtonWidget>("install")->setVisible(false);
|
||||
getWidget<LabelWidget>("size")->setVisible(false);
|
||||
m_size = getWidget<LabelWidget>("size");
|
||||
m_size->setVisible(false);
|
||||
getWidget<BubbleWidget>("description")->setText(
|
||||
StringUtils::utf8ToWide(url));
|
||||
|
||||
@ -160,6 +161,15 @@ void AddonsPack::onUpdate(float delta)
|
||||
{
|
||||
if (m_download_request)
|
||||
{
|
||||
if (!m_size->isVisible() && m_download_request->getTotalSize() > 0)
|
||||
{
|
||||
m_size->setVisible(true);
|
||||
core::stringw unit = StringUtils::getReadableFileSize(
|
||||
m_download_request->getTotalSize());
|
||||
core::stringw size = _("Size: %s", unit.c_str());
|
||||
m_size->setText(size, false);
|
||||
}
|
||||
|
||||
float progress = m_download_request->getProgress();
|
||||
// Last 1% for unzipping
|
||||
m_progress->setValue(progress * 99.0f);
|
||||
|
@ -30,7 +30,9 @@ class AddonsPackRequest;
|
||||
class AddonsPack : public GUIEngine::ModalDialog
|
||||
{
|
||||
private:
|
||||
GUIEngine::ProgressBarWidget *m_progress;
|
||||
GUIEngine::ProgressBarWidget* m_progress;
|
||||
|
||||
GUIEngine::LabelWidget* m_size;
|
||||
|
||||
void stopDownload();
|
||||
void doInstall();
|
||||
|
@ -96,12 +96,8 @@ DownloadAssets::DownloadAssets()
|
||||
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);
|
||||
core::stringw unit =
|
||||
StringUtils::getReadableFileSize(getDownloadAssetsSize());
|
||||
// I18N: File size of game assets or addons downloading
|
||||
core::stringw size = _("Size: %s", unit.c_str());
|
||||
getWidget<LabelWidget>("size")->setText(size, false);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "utils/constants.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/time.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
#include "utils/types.hpp"
|
||||
#include "utils/utf8.h"
|
||||
#include "irrArray.h"
|
||||
@ -1414,7 +1415,29 @@ namespace StringUtils
|
||||
#endif
|
||||
return uagent;
|
||||
} // getUserAgentString
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
irr::core::stringw getReadableFileSize(uint64_t n)
|
||||
{
|
||||
irr::core::stringw unit="";
|
||||
if(n>1024*1024)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if(n>1024)
|
||||
{
|
||||
float f = ((int)(n/1024.0f*10.0f+0.5f))/10.0f;
|
||||
char s[32];
|
||||
sprintf(s, "%.1f", f);
|
||||
unit = _("%s KB", s);
|
||||
}
|
||||
else
|
||||
// Anything smaller just let it be 1 KB
|
||||
unit = _("%s KB", 1);
|
||||
return unit;
|
||||
} // getReadableFileSize
|
||||
} // namespace StringUtils
|
||||
|
||||
/* EOF */
|
||||
|
@ -21,6 +21,7 @@
|
||||
#ifndef HEADER_STRING_UTILS_HPP
|
||||
#define HEADER_STRING_UTILS_HPP
|
||||
|
||||
#include "utils/types.hpp"
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -284,6 +285,7 @@ namespace StringUtils
|
||||
std::string utf32ToUtf8(const std::u32string& input);
|
||||
std::string findAndReplace(const std::string& source, const std::string& find, const std::string& replace);
|
||||
std::string removeWhitespaces(const std::string& input);
|
||||
irr::core::stringw getReadableFileSize(uint64_t n);
|
||||
void breakText(const std::wstring& input, std::vector<std::wstring> &output,
|
||||
unsigned int max_width, irr::gui::IGUIFont* font, bool right_to_left=false);
|
||||
bool breakable (wchar_t c);
|
||||
|
Loading…
x
Reference in New Issue
Block a user