From 21bbc0124de1a14db8c90fecdb00fbce4d4dedb2 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 26 Nov 2004 23:14:35 +0000 Subject: [PATCH] simplify --- stepmania/src/ScreenPackages.cpp | 60 +++++++++++--------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/stepmania/src/ScreenPackages.cpp b/stepmania/src/ScreenPackages.cpp index b389ec7f93..4a1dc93e6f 100644 --- a/stepmania/src/ScreenPackages.cpp +++ b/stepmania/src/ScreenPackages.cpp @@ -10,7 +10,6 @@ #include "RageUtil.h" #include "RageFile.h" #include "ScreenTextEntry.h" -#include "ScreenNetSelectBase.h" //Used for Quad Utility #include "ScreenManager.h" #include @@ -647,6 +646,7 @@ void ScreenPackages::HTTPUpdate() { m_iDownloaded = m_sBUFFER.length(); } + if ( ( m_iTotalBytes <= m_iDownloaded && m_iTotalBytes != -1 ) || //We have the full doc. (And we knew how big it was) ( m_iTotalBytes == -1 && @@ -678,53 +678,33 @@ void ScreenPackages::HTTPUpdate() } } -bool ScreenPackages::ParseHTTPAddress( const CString & URL, CString & Proto, CString & Server, int & Port, CString & sAddress ) +bool ScreenPackages::ParseHTTPAddress( const CString &URL, CString &sProto, CString &sServer, int &iPort, CString &sAddress ) { - int i,j,k,l; - // [PROTO://]SERVER[:PORT][/URL] - if ( URL.length() == 0 ) + Regex re( + "^([A-Z]+)://" // [0]: HTTP:// + "([^/:]+)" // [1]: a.b.com + "(:([0-9]+))?" // [2], [3]: :1234 (optional, default 80) + "(/(.*))?$"); // [4], [5]: /foo.html (optional) + vector asMatches; + if( !re.Compare( URL, asMatches ) ) return false; + ASSERT( asMatches.size() == 6 ); - //PROTO - i = URL.Find( "://" ); - if ( i >= 0 ) + sProto = asMatches[0]; + sServer = asMatches[1]; + if( asMatches[3] != "" ) { - Proto = URL.substr( 0, i ); - i+=3; - } - else - i = 0; - //SERVER - j = URL.Find( '/', i ); - k = URL.Find( ':', i ); - if ( ( k >= 0 ) && ( j >= 0 ) ) - l = min ( j, k ); - else if ( k >= 0 ) - l = k; - else if ( j >= 0 ) - l = j; - else - l = URL.length(); - Server = URL.substr( i, l-i ); - - //PORT - if ( URL.substr( l, 1 ).compare(":")==0 ) - { - l++; - j = URL.Find( '/', l ); - if ( j < 0 ) - j = URL.length(); - Port = atoi( URL.substr( l, j-l ).c_str() ); - if (Port == 0) + iPort = atoi(asMatches[3]); + if( iPort == 0 ) return false; - l=j; } - if (l