From: Patrick McIlroy Date: Wed, 22 Sep 2010 00:18:33 +0000 (+0000) Subject: Display transfer rate when uploading user packs X-Git-Tag: beta3~29 X-Git-Url: https://git.cameron1729.xyz/?a=commitdiff_plain;h=38fb1989c44b035a7eb791f9126ea188998b511c;p=openitg.git Display transfer rate when uploading user packs git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg/branches/dev@847 83fadc84-e282-4d84-a09a-c4228d6ae7e5 --- diff --git a/src/DiagnosticsUtil.cpp b/src/DiagnosticsUtil.cpp index 39bbed7b..c50c1142 100644 --- a/src/DiagnosticsUtil.cpp +++ b/src/DiagnosticsUtil.cpp @@ -50,43 +50,6 @@ CString DiagnosticsUtil::GetIP() return sError; } -namespace -{ - /* declared as floats so the division isn't implicitly cast to int */ - float KILOBYTE = 1024; - float MEGABYTE = 1024*KILOBYTE; - float GIGABYTE = 1024*MEGABYTE; - - CString FormatByteValue( uint64_t iBytes ) - { - CString sSuffix; - float fShownSpace = 0.0f; - - if( iBytes > GIGABYTE ) - { - fShownSpace = iBytes / GIGABYTE; - sSuffix = "GB"; - } - else if( iBytes > MEGABYTE ) - { - fShownSpace = iBytes / MEGABYTE; - sSuffix = "MB"; - } - else if( iBytes > KILOBYTE ) - { - fShownSpace = iBytes / KILOBYTE; - sSuffix = "KB"; - } - else - { - fShownSpace = float(iBytes); - sSuffix = "bytes"; - } - - return ssprintf( "%.02f %s", fShownSpace, sSuffix.c_str() ); - } -} - // XXX: we should probably take a parameter for these later on. // for now, return the only disk space value that matters to us. diff --git a/src/RageUtil.cpp b/src/RageUtil.cpp index 422fdc2b..e05f97c0 100755 --- a/src/RageUtil.cpp +++ b/src/RageUtil.cpp @@ -210,6 +210,61 @@ CString FormatNumberAndSuffix( int i ) return ssprintf("%i", i) + sSuffix; } +namespace +{ + /* declared as floats so the division isn't implicitly cast to int */ + float KILOBYTE = 1024; + float MEGABYTE = 1024*KILOBYTE; + float GIGABYTE = 1024*MEGABYTE; +} + +CString FormatByteValue( uint64_t iBytes ) +{ + CString sSuffix; + float fShownSpace = 0.0f; + if( iBytes > GIGABYTE ) + { + fShownSpace = iBytes / GIGABYTE; + sSuffix = "GB"; + } + else if( iBytes > MEGABYTE ) + { + fShownSpace = iBytes / MEGABYTE; + sSuffix = "MB"; + } + else if( iBytes > KILOBYTE ) + { + fShownSpace = iBytes / KILOBYTE; + sSuffix = "KB"; + } + else + { + fShownSpace = float(iBytes); + sSuffix = "bytes"; + } + return ssprintf( "%.02f %s", fShownSpace, sSuffix.c_str() ); +} + +CString FormatByteRateValue( float fRate ) +{ + CString sSuffix; + if( fRate > MEGABYTE ) + { + fRate /= MEGABYTE; + sSuffix = "MB/s"; + } + else if( fRate > KILOBYTE ) + { + fRate /= KILOBYTE; + sSuffix = "kb/s"; + } + else + { + sSuffix = "bytes/s"; + } + return ssprintf( "%.02f %s", fRate, sSuffix.c_str() ); +} + struct tm GetLocalTime() { const time_t t = time(NULL); diff --git a/src/RageUtil.h b/src/RageUtil.h index e6c194e8..6cf7f9e7 100755 --- a/src/RageUtil.h +++ b/src/RageUtil.h @@ -267,6 +267,9 @@ inline CString PrettyPercent( int fNumerator, int fDenominator ) { return Pretty CString Commify( int iNum ); CString FormatNumberAndSuffix( int i ); +CString FormatByteValue( uint64_t iBytes ); +CString FormatByteRateValue( float fRate ); + struct tm GetLocalTime(); diff --git a/src/ScreenUserPacks.cpp b/src/ScreenUserPacks.cpp index 15c27368..803303c2 100644 --- a/src/ScreenUserPacks.cpp +++ b/src/ScreenUserPacks.cpp @@ -243,6 +243,8 @@ void ScreenUserPacks::Input( const DeviceInput& DeviceI, const InputEventType ty CString g_CurXferFile; CString g_CurSelection; +unsigned long g_iLastCurrentBytes; +RageTimer g_UpdateDuration; void UpdateXferProgress( unsigned long iCurrent, unsigned long iTotal ) { @@ -268,10 +270,13 @@ void UpdateXferProgress( unsigned long iCurrent, unsigned long iTotal ) if( DrawTimer.Ago() < DRAW_UPDATE_TIME ) return; + float fXferRate = (iCurrent / g_UpdateDuration.Ago()) / 1024.0; float fPercent = iCurrent / (iTotal/100); - CString sMessage = ssprintf( "\n\n%s\n%.2f%%\n\n%s", + + CString sMessage = ssprintf( "\n\n%s\n%.2f%% %s\n\n%s", USER_PACK_WAIT_TEXT.GetValue().c_str(), fPercent, + FormatByteRateValue(fXferRate).c_str(), USER_PACK_CANCEL_TEXT.GetValue().c_str() ); SCREENMAN->OverlayMessage( sMessage ); @@ -372,6 +377,8 @@ m_PlayerSongLoadThread.Create( InitSASSongThread, this ) sError = ""; // ?? RageTimer start; DrawTimer.Touch(); + g_iLastCurrentBytes = 0; + g_UpdateDuration.Touch(); if (!UPACKMAN->TransferPack( g_CurXferFile, sSelection, UpdateXferProgress, sError ) ) { SCREENMAN->SystemMessage( "Transfer error:\n" + sError ); diff --git a/src/StepMania-net2008.vcproj b/src/StepMania-net2008.vcproj index e8805155..de67fc43 100644 --- a/src/StepMania-net2008.vcproj +++ b/src/StepMania-net2008.vcproj @@ -593,7 +593,7 @@ EnableIntrinsicFunctions="true" FavorSizeOrSpeed="2" AdditionalIncludeDirectories=".;vorbis;libjpeg;"lua-5.0\include";libusb\include;BaseClasses" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;WINDOWS;RELEASE" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;WINDOWS;RELEASE;_CRT_SECURE_NO_WARNINGS" StringPooling="true" MinimalRebuild="false" ExceptionHandling="0"