Remove legacy network code
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include "ScreenManager.h"
|
||||
#include "Preference.h"
|
||||
#include "RageLog.h"
|
||||
#include "FileDownload.h"
|
||||
#include "json/json.h"
|
||||
#include "JsonUtil.h"
|
||||
#include "SpecialFiles.h"
|
||||
@@ -120,168 +119,6 @@ void InstallSmzipOsArg( const RString &sOsZipFile, PlayAfterLaunchInfo &out )
|
||||
FILEMAN->Unmount( "dir", sOsDir, TEMP_OS_MOUNT_POINT );
|
||||
}
|
||||
|
||||
struct FileCopyResult
|
||||
{
|
||||
FileCopyResult( RString _sFile, RString _sComment ) : sFile(_sFile), sComment(_sComment) {}
|
||||
RString sFile, sComment;
|
||||
};
|
||||
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
Preference<RString> g_sCookie( "Cookie", "" );
|
||||
|
||||
class DownloadTask
|
||||
{
|
||||
FileTransfer *m_pTransfer;
|
||||
vector<RString> m_vsQueuedPackageUrls;
|
||||
RString m_sCurrentPackageTempFile;
|
||||
enum
|
||||
{
|
||||
control,
|
||||
packages
|
||||
} m_DownloadState;
|
||||
PlayAfterLaunchInfo m_playAfterLaunchInfo;
|
||||
public:
|
||||
DownloadTask(const RString &sControlFileUri)
|
||||
{
|
||||
//SCREENMAN->SystemMessage( "Downloading control file." );
|
||||
m_pTransfer = new FileTransfer();
|
||||
m_pTransfer->StartDownload( sControlFileUri, "" );
|
||||
m_DownloadState = control;
|
||||
}
|
||||
~DownloadTask()
|
||||
{
|
||||
SAFE_DELETE(m_pTransfer);
|
||||
}
|
||||
RString GetStatus()
|
||||
{
|
||||
if( m_pTransfer == nullptr )
|
||||
return "";
|
||||
else
|
||||
return m_pTransfer->GetStatus();
|
||||
}
|
||||
bool UpdateAndIsFinished( float fDeltaSeconds, PlayAfterLaunchInfo &playAfterLaunchInfo )
|
||||
{
|
||||
m_pTransfer->Update( fDeltaSeconds );
|
||||
switch( m_DownloadState )
|
||||
{
|
||||
case control:
|
||||
if( m_pTransfer->IsFinished() )
|
||||
{
|
||||
SCREENMAN->SystemMessage( "Downloading required .smzip" );
|
||||
|
||||
RString sResponse = m_pTransfer->GetResponse();
|
||||
SAFE_DELETE( m_pTransfer );
|
||||
|
||||
Json::Value root;
|
||||
RString sError;
|
||||
if( !JsonUtil::LoadFromString(root, sResponse, sError) )
|
||||
{
|
||||
SCREENMAN->SystemMessage( sError );
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse the JSON response, make a list of all packages need to be downloaded.
|
||||
{
|
||||
if( root["Cookie"].isString() )
|
||||
g_sCookie.Set( root["Cookie"].asString() );
|
||||
Json::Value require = root["Require"];
|
||||
if( require.isArray() )
|
||||
{
|
||||
for (Json::Value const &iter : require)
|
||||
{
|
||||
if( iter["Dir"].isString() )
|
||||
{
|
||||
RString sDir = iter["Dir"].asString();
|
||||
Parse( sDir, m_playAfterLaunchInfo );
|
||||
if( DoesFileExist( sDir ) )
|
||||
continue;
|
||||
}
|
||||
|
||||
RString sUri;
|
||||
if( iter["Uri"].isString() )
|
||||
{
|
||||
sUri = iter["Uri"].asString();
|
||||
m_vsQueuedPackageUrls.push_back( sUri );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
// TODO: Validate that this zip contains files for this version of StepMania
|
||||
|
||||
bool bFileExists = DoesFileExist( SpecialFiles::PACKAGES_DIR + sFilename + sExt );
|
||||
if( FileCopy( TEMP_MOUNT_POINT + sFilename + sExt, SpecialFiles::PACKAGES_DIR + sFilename + sExt ) )
|
||||
vSucceeded.push_back( FileCopyResult(*s,bFileExists ? "overwrote existing file" : "") );
|
||||
else
|
||||
vFailed.push_back( FileCopyResult(*s,ssprintf("error copying file to '%s'",sOsDir.c_str())) );
|
||||
|
||||
}
|
||||
*/
|
||||
m_DownloadState = packages;
|
||||
if( !m_vsQueuedPackageUrls.empty() )
|
||||
{
|
||||
RString sUrl = m_vsQueuedPackageUrls.back();
|
||||
m_vsQueuedPackageUrls.pop_back();
|
||||
m_sCurrentPackageTempFile = MakeTempFileName(sUrl);
|
||||
ASSERT(m_pTransfer == nullptr);
|
||||
m_pTransfer = new FileTransfer();
|
||||
m_pTransfer->StartDownload( sUrl, m_sCurrentPackageTempFile );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case packages:
|
||||
{
|
||||
if( m_pTransfer->IsFinished() )
|
||||
{
|
||||
SAFE_DELETE( m_pTransfer );
|
||||
InstallSmzip( m_sCurrentPackageTempFile, m_playAfterLaunchInfo );
|
||||
FILEMAN->Remove( m_sCurrentPackageTempFile ); // Harmless if this fails because download didn't finish
|
||||
}
|
||||
if( !m_vsQueuedPackageUrls.empty() )
|
||||
{
|
||||
RString sUrl = m_vsQueuedPackageUrls.back();
|
||||
m_vsQueuedPackageUrls.pop_back();
|
||||
m_sCurrentPackageTempFile = MakeTempFileName(sUrl);
|
||||
ASSERT(m_pTransfer == nullptr);
|
||||
m_pTransfer = new FileTransfer();
|
||||
m_pTransfer->StartDownload( sUrl, m_sCurrentPackageTempFile );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
bool bFinished = m_DownloadState == packages &&
|
||||
m_vsQueuedPackageUrls.empty() &&
|
||||
m_pTransfer == nullptr;
|
||||
if( bFinished )
|
||||
{
|
||||
Message msg( "DownloadFinished" );
|
||||
MESSAGEMAN->Broadcast(msg);
|
||||
|
||||
playAfterLaunchInfo = m_playAfterLaunchInfo;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
static RString MakeTempFileName( RString s )
|
||||
{
|
||||
return SpecialFiles::CACHE_DIR + "Downloads/" + Basename(s);
|
||||
}
|
||||
};
|
||||
static vector<DownloadTask*> g_pDownloadTasks;
|
||||
#endif
|
||||
|
||||
static bool IsStepManiaProtocol(const RString &arg)
|
||||
{
|
||||
// for now, only load from the StepMania domain until the security implications of this feature are better understood.
|
||||
//return BeginsWith(arg,"stepmania://beta.stepmania.com/");
|
||||
return BeginsWith(arg,"stepmania://");
|
||||
}
|
||||
|
||||
static bool IsPackageFile(const RString &arg)
|
||||
{
|
||||
RString ext = GetExtension(arg);
|
||||
@@ -294,15 +131,7 @@ PlayAfterLaunchInfo DoInstalls( CommandLineActions::CommandLineArgs args )
|
||||
for( int i = 0; i<(int)args.argv.size(); i++ )
|
||||
{
|
||||
RString s = args.argv[i];
|
||||
if( IsStepManiaProtocol(s) )
|
||||
{
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
g_pDownloadTasks.push_back( new DownloadTask(s) );
|
||||
#else
|
||||
// TODO: Figure out a meaningful log message.
|
||||
#endif
|
||||
}
|
||||
else if( IsPackageFile(s) )
|
||||
if( IsPackageFile(s) )
|
||||
InstallSmzipOsArg(s, ret);
|
||||
}
|
||||
return ret;
|
||||
@@ -347,28 +176,6 @@ void ScreenInstallOverlay::Update( float fDeltaTime )
|
||||
PlayAfterLaunchInfo pali2 = DoInstalls( args );
|
||||
playAfterLaunchInfo.OverlayWith( pali2 );
|
||||
}
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
for(int i=g_pDownloadTasks.size()-1; i>=0; --i)
|
||||
{
|
||||
DownloadTask *p = g_pDownloadTasks[i];
|
||||
PlayAfterLaunchInfo pali;
|
||||
if( p->UpdateAndIsFinished( fDeltaTime, pali) )
|
||||
{
|
||||
playAfterLaunchInfo.OverlayWith(pali);
|
||||
SAFE_DELETE(p);
|
||||
g_pDownloadTasks.erase( g_pDownloadTasks.begin()+i );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
vector<RString> vsMessages;
|
||||
for (DownloadTask *pDT : g_pDownloadTasks)
|
||||
{
|
||||
vsMessages.push_back( pDT->GetStatus() );
|
||||
}
|
||||
m_textStatus.SetText( join("\n", vsMessages) );
|
||||
}
|
||||
#endif
|
||||
if( playAfterLaunchInfo.bAnySongChanged )
|
||||
SONGMAN->Reload( false, nullptr );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user