[Download] Small fixes

This commit is contained in:
momo5502 2017-01-19 21:21:59 +01:00
parent 06bb09e1f0
commit 07b0a42f45
5 changed files with 31 additions and 20 deletions

View File

@ -15,7 +15,7 @@ namespace Components
Localization::SetTemp("MPUI_PROGRESS_DL", "(0/0) %");
Localization::SetTemp("MPUI_TRANS_RATE", "0.0 MB/s");
Command::Execute("openmenu mod_download_popmenu", true);
Command::Execute("openmenu mod_download_popmenu", false);
Download::CLDownload.running = true;
Download::CLDownload.mod = mod;
@ -83,7 +83,12 @@ namespace Components
fDownload->download->downBytes += bytes;
fDownload->download->timeStampBytes += bytes;
double progress = (100.0 / fDownload->download->totalBytes) * fDownload->download->downBytes;
double progress = 0;
if (fDownload->download->totalBytes)
{
progress = (100.0 / fDownload->download->totalBytes) * fDownload->download->downBytes;
}
Localization::SetTemp("MPUI_PROGRESS_DL", Utils::String::VA("(%d/%d) %d%%", fDownload->index + 1, fDownload->download->files.size(), static_cast<unsigned int>(progress)));
int delta = Game::Sys_Milliseconds() - fDownload->download->lastTimeStamp;
@ -93,8 +98,13 @@ namespace Components
fDownload->download->lastTimeStamp = Game::Sys_Milliseconds();
size_t dataLeft = fDownload->download->totalBytes - fDownload->download->downBytes;
double timeLeftD = ((1.0 * dataLeft) / fDownload->download->timeStampBytes) * delta;
int timeLeft = static_cast<int>(timeLeftD);
int timeLeft = 0;
if (fDownload->download->timeStampBytes)
{
double timeLeftD = ((1.0 * dataLeft) / fDownload->download->timeStampBytes) * delta;
timeLeft = static_cast<int>(timeLeftD);
}
if (doFormat)
{
@ -208,7 +218,7 @@ namespace Components
if (download->terminateThread) return;
static std::string mod = download->mod;
std::string mod = download->mod;
for (unsigned int i = 0; i < download->files.size(); ++i)
{
@ -222,10 +232,9 @@ namespace Components
download->thread.detach();
download->clear();
QuickPatch::Once([] ()
QuickPatch::Once([mod] ()
{
Dvar::Var("partyend_reason").set(mod);
mod.clear();
Localization::ClearTemp();
Command::Execute("closemenu mod_download_popmenu");
@ -242,16 +251,14 @@ namespace Components
download->clear();
// Run this on the main thread
QuickPatch::Once([] ()
QuickPatch::Once([mod] ()
{
auto fsGame = Dvar::Var("fs_game");
fsGame.set(mod);
fsGame.get<Game::dvar_t*>()->modified = true;
mod.clear();
Localization::ClearTemp();
Command::Execute("closemenu mod_download_popmenu", true);
Command::Execute("closemenu mod_download_popmenu", false);
if (Dvar::Var("cl_modVidRestart").get<bool>())
{

View File

@ -2,7 +2,7 @@
namespace Components
{
std::mutex Localization::LocalizeMutex;
std::recursive_mutex Localization::LocalizeMutex;
Dvar::Var Localization::UseLocalization;
Utils::Memory::Allocator Localization::MemAllocator;
std::unordered_map<std::string, Game::LocalizeEntry*> Localization::LocalizeMap;
@ -10,7 +10,7 @@ namespace Components
void Localization::Set(std::string key, std::string value)
{
std::lock_guard<std::mutex> _(Localization::LocalizeMutex);
std::lock_guard<std::recursive_mutex> _(Localization::LocalizeMutex);
if (Localization::LocalizeMap.find(key) != Localization::LocalizeMap.end())
{
@ -49,7 +49,7 @@ namespace Components
if (!Localization::UseLocalization.get<bool>()) return key;
Game::LocalizeEntry* entry = nullptr;
std::lock_guard<std::mutex> _(Localization::LocalizeMutex);
std::lock_guard<std::recursive_mutex> _(Localization::LocalizeMutex);
if (Localization::TempLocalizeMap.find(key) != Localization::TempLocalizeMap.end())
{
@ -62,9 +62,7 @@ namespace Components
if (!entry || !entry->value)
{
Localization::LocalizeMutex.unlock();
entry = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY, key).localize;
Localization::LocalizeMutex.lock();
}
if (entry && entry->value)
@ -77,7 +75,7 @@ namespace Components
void Localization::SetTemp(std::string key, std::string value)
{
std::lock_guard<std::mutex> _(Localization::LocalizeMutex);
std::lock_guard<std::recursive_mutex> _(Localization::LocalizeMutex);
if (Localization::TempLocalizeMap.find(key) != Localization::TempLocalizeMap.end())
{
@ -111,7 +109,7 @@ namespace Components
void Localization::ClearTemp()
{
std::lock_guard<std::mutex> _(Localization::LocalizeMutex);
std::lock_guard<std::recursive_mutex> _(Localization::LocalizeMutex);
for (auto i = Localization::TempLocalizeMap.begin(); i != Localization::TempLocalizeMap.end(); ++i)
{
@ -164,7 +162,7 @@ namespace Components
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_LOCALIZE_ENTRY, [] (Game::XAssetType, std::string filename)
{
Game::XAssetHeader header = { 0 };
std::lock_guard<std::mutex> _(Localization::LocalizeMutex);
std::lock_guard<std::recursive_mutex> _(Localization::LocalizeMutex);
if (Localization::TempLocalizeMap.find(filename) != Localization::TempLocalizeMap.end())
{

View File

@ -17,7 +17,7 @@ namespace Components
static void ClearTemp();
private:
static std::mutex LocalizeMutex;
static std::recursive_mutex LocalizeMutex;
static Utils::Memory::Allocator MemAllocator;
static std::unordered_map<std::string, Game::LocalizeEntry*> LocalizeMap;
static std::unordered_map<std::string, Game::LocalizeEntry*> TempLocalizeMap;

View File

@ -14,7 +14,9 @@ namespace Components
{
__asm
{
pushad
call Renderer::FrameHandler
popad
jmp Renderer::DrawFrameHook.original
}
}
@ -33,7 +35,9 @@ namespace Components
{
__asm
{
pushad
call Renderer::BackendFrameHandler
popad
mov eax, ds:66E1BF0h
mov ecx, 536A85h

View File

@ -153,6 +153,8 @@ namespace Utils
"TB"
};
if (!milliseconds) return "0.00 B/s";
double bytesPerSecond = (1000.0 / milliseconds) * bytes;
int i = 0;