Add: ScreenPackages
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 441 B |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -2477,6 +2477,60 @@ Fallback=ScreenOperatorMenu
|
||||
[ScreenBookkeeping]
|
||||
Fallback=ScreenOperatorMenu
|
||||
|
||||
[ScreenPackages]
|
||||
PackagesBGY=SCREEN_CENTER_Y
|
||||
PackagesBGX=SCREEN_WIDTH/4
|
||||
PackagesBGWidth=SCREEN_WIDTH/3
|
||||
PackagesBGOnCommand=diffusealpha,0.0;linear,0.9;diffusealpha,1.0
|
||||
PackagesBGOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
PackagesBGBackCommand=linear,0.2;diffuse,#CCCCCC;diffusealpha,0.9
|
||||
PackagesBGAwayCommand=linear,0.2;diffuse,#020101;diffusealpha,0.9
|
||||
WebBGY=SCREEN_CENTER_Y
|
||||
WebBGX=SCREEN_WIDTH*3.0/4.0
|
||||
WebBGWidth=SCREEN_WIDTH/3
|
||||
WebBGOnCommand=diffusealpha,0.0;linear,0.9;diffusealpha,1.0
|
||||
WebBGOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
WebBGAwayCommand=linear,0.2;diffuse,#020101;diffusealpha,0.9
|
||||
WebBGBackCommand=linear,0.2;diffuse,#CCCCCC;diffusealpha,0.9
|
||||
PackagesY=SCREEN_CENTER_Y+10
|
||||
PackagesX=SCREEN_WIDTH/4
|
||||
PackagesOnCommand=diffusealpha,0.0;linear,1.0;diffusealpha,1.0
|
||||
PackagesOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
NumPackagesShow=8
|
||||
WebY=SCREEN_CENTER_Y+10
|
||||
WebX=SCREEN_WIDTH*3.0/4.0
|
||||
WebOnCommand=diffusealpha,0.0;linear,1.0;diffusealpha,1.0
|
||||
WebOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
NumLinksShow=8
|
||||
WebSelY=SCREEN_CENTER_Y+10
|
||||
WebSelX=SCREEN_WIDTH*3.0/4.0
|
||||
WebSelColor=0.9,0.9,0.9,0.4
|
||||
WebSelOnCommand=diffusealpha,0.0;linear,1.0;diffusealpha,1.0
|
||||
WebSelOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
WebURLY=SCREEN_HEIGHT-40
|
||||
WebURLX=SCREEN_WIDTH*2.0/3.0
|
||||
WebURLOnCommand=diffusealpha,0.0;linear,1.0;diffusealpha,1.0;zoomx,0.4;zoomy,0.5
|
||||
WebURLOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
DownloadY=22
|
||||
DownloadX=SCREEN_WIDTH*4.0/7.0
|
||||
DownloadColor=0.1,0.1,0.1,0.5
|
||||
DownloadProgressColor=0.1,0.1,0.9,0.8
|
||||
DownloadOnCommand=diffusealpha,0.0;linear,1.0;diffusealpha,1.0
|
||||
DownloadOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
DownloadStatusY=22
|
||||
DownloadStatusX=SCREEN_WIDTH*4.0/7.0
|
||||
DownloadStatusOnCommand=diffusealpha,0.0;linear,1.0;diffusealpha,1.0
|
||||
DownloadStatusOffCommand=diffusealpha,1.0;linear,0.6;diffusealpha,0.0
|
||||
CanDL=1
|
||||
StyleIcon=
|
||||
MemoryCardIcons=
|
||||
TimerSeconds=
|
||||
HelpText=
|
||||
PrevScreen=ScreenTitleMenu
|
||||
NextScreen=ScreenStage
|
||||
NoSongsScreen=ScreenTitleMenu
|
||||
Fallback=ScreenWithMenuElements
|
||||
|
||||
[HoldGhostArrow]
|
||||
WarmUpSeconds=0.25
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ ScreenJukeboxMenu.cpp ScreenJukeboxMenu.h ScreenLogo.cpp ScreenLogo.h ScreenMapC
|
||||
ScreenMessage.h ScreenMiniMenu.cpp ScreenMiniMenu.h ScreenMusicScroll.cpp ScreenMusicScroll.h \
|
||||
ScreenNameEntry.cpp ScreenNameEntry.h ScreenNameEntryTraditional.cpp ScreenNameEntryTraditional.h \
|
||||
ScreenOptions.cpp ScreenOptions.h ScreenOptionsMaster.cpp ScreenOptionsMaster.h \
|
||||
ScreenOptionsMasterPrefs.cpp ScreenOptionsMasterPrefs.h ScreenPlayerOptions.cpp ScreenPlayerOptions.h ScreenNetworkOptions.h \
|
||||
ScreenOptionsMasterPrefs.cpp ScreenOptionsMasterPrefs.h ScreenPackages.cpp ScreenPackages.h ScreenPlayerOptions.cpp ScreenPlayerOptions.h ScreenNetworkOptions.h \
|
||||
ScreenNetworkOptions.cpp ScreenProfileOptions.cpp ScreenProfileOptions.h ScreenPrompt.cpp ScreenPrompt.h ScreenRanking.cpp ScreenRanking.h \
|
||||
ScreenReloadSongs.cpp ScreenReloadSongs.h ScreenResetToDefaults.cpp ScreenResetToDefaults.h ScreenSandbox.cpp ScreenSandbox.h \
|
||||
ScreenSelect.cpp ScreenSelect.h ScreenSelectCharacter.cpp ScreenSelectCharacter.h \
|
||||
|
||||
@@ -276,6 +276,7 @@ void Screen::ClearMessageQueue( const ScreenMessage SM )
|
||||
#include "ScreenNetSelectMusic.h"
|
||||
#include "ScreenNetRoom.h"
|
||||
#include "ScreenNetEvaluation.h"
|
||||
#include "ScreenPackages.h"
|
||||
#include "ScreenEz2SelectMusic.h"
|
||||
#include "ScreenRanking.h"
|
||||
#include "ScreenLogo.h"
|
||||
@@ -382,6 +383,7 @@ Screen* Screen::Create( CString sClassName )
|
||||
IF_RETURN( ScreenNetSelectMusic );
|
||||
IF_RETURN( ScreenNetRoom );
|
||||
IF_RETURN( ScreenNetEvaluation );
|
||||
IF_RETURN( ScreenPackages );
|
||||
#endif
|
||||
|
||||
RageException::Throw( "Invalid Screen class name '%s'", sClassName.c_str() );
|
||||
|
||||
@@ -0,0 +1,699 @@
|
||||
#include "global.h"
|
||||
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
#include "ScreenPackages.h"
|
||||
#include "GameConstantsAndTypes.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "RageDisplay.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
#include "RageFile.h"
|
||||
#include "ScreenTextEntry.h"
|
||||
#include "ScreenNetSelectBase.h" //Used for Quad Utility
|
||||
#include "ScreenManager.h"
|
||||
|
||||
#define EXISTINGBG_WIDTH THEME->GetMetricF(m_sName,"PackagesBGWidth")
|
||||
#define WEBBG_WIDTH THEME->GetMetricF(m_sName,"WebBGWidth")
|
||||
#define NUM_PACKAGES_SHOW THEME->GetMetricI(m_sName,"NumPackagesShow")
|
||||
#define NUM_LINKS_SHOW THEME->GetMetricI(m_sName,"NumLinksShow")
|
||||
|
||||
const ScreenMessage SM_BackFromURL = ScreenMessage(SM_User+2);
|
||||
|
||||
ScreenPackages::ScreenPackages( CString sClassName ) : ScreenWithMenuElements( sClassName )
|
||||
{
|
||||
m_iPackagesPos = 0;
|
||||
m_iLinksPos = 0;
|
||||
m_iDLorLST = 0;
|
||||
m_bIsDownloading = false;
|
||||
m_bCanDL = THEME->GetMetricB( sClassName, "CanDL" );
|
||||
m_sStatus = "";
|
||||
m_fLastUpdate = 0;
|
||||
m_iTotalBytes = 0;
|
||||
m_iDownloaded = 0;
|
||||
|
||||
m_sprExistingBG.SetName( "PackagesBG" );
|
||||
m_sprExistingBG.Load( THEME->GetPathG( m_sName, "PackagesBG" ) );
|
||||
SET_XY_AND_ON_COMMAND( m_sprExistingBG );
|
||||
this->AddChild( &m_sprExistingBG );
|
||||
|
||||
m_sprWebBG.SetName( "WebBG" );
|
||||
m_sprWebBG.Load( THEME->GetPathG( m_sName, "WebBG" ) );
|
||||
SET_XY_AND_ON_COMMAND( m_sprWebBG );
|
||||
this->AddChild( &m_sprWebBG );
|
||||
|
||||
COMMAND( m_sprExistingBG, "Back" );
|
||||
COMMAND( m_sprWebBG, "Away" );
|
||||
|
||||
m_textPackages.LoadFromFont( THEME->GetPathF(m_sName,"default") );
|
||||
m_textPackages.SetShadowLength( 0 );
|
||||
m_textPackages.SetName( "Packages" );
|
||||
m_textPackages.SetMaxWidth( EXISTINGBG_WIDTH );
|
||||
SET_XY_AND_ON_COMMAND( m_textPackages );
|
||||
this->AddChild( &m_textPackages );
|
||||
RefreshPackages();
|
||||
|
||||
m_textWeb.LoadFromFont( THEME->GetPathF(m_sName,"default") );
|
||||
m_textWeb.SetShadowLength( 0 );
|
||||
m_textWeb.SetName( "Web" );
|
||||
m_textWeb.SetMaxWidth( WEBBG_WIDTH );
|
||||
SET_XY_AND_ON_COMMAND( m_textWeb );
|
||||
this->AddChild( &m_textWeb);
|
||||
m_Links.push_back( " " );
|
||||
m_LinkTitles.push_back( "--Visit URL--" );
|
||||
|
||||
m_textURL.LoadFromFont( THEME->GetPathF( m_sName,"default") );
|
||||
m_textURL.SetShadowLength( 0 );
|
||||
m_textURL.SetName( "WebURL" );
|
||||
SET_XY_AND_ON_COMMAND( m_textURL );
|
||||
this->AddChild( &m_textURL );
|
||||
UpdateLinksList();
|
||||
|
||||
m_sprWebSel.SetName( "WebSel" );
|
||||
m_sprWebSel.Load( THEME->GetPathG( m_sName, "WebSel" ) );
|
||||
SET_XY_AND_ON_COMMAND( m_sprWebSel );
|
||||
this->AddChild( &m_sprWebSel );
|
||||
|
||||
m_sprDLBG.SetName( "Download" );
|
||||
m_sprDLBG.Load( THEME->GetPathG( m_sName, "DownloadBG" ) );
|
||||
SET_XY_AND_ON_COMMAND( m_sprDLBG );
|
||||
this->AddChild( &m_sprDLBG );
|
||||
|
||||
//(HTTP ELEMENTS)
|
||||
m_sprDL.SetName( "Download" );
|
||||
m_sprDL.Load( THEME->GetPathG( m_sName, "Download" ) );
|
||||
SET_XY_AND_ON_COMMAND( m_sprDL );
|
||||
this->AddChild( &m_sprDL );
|
||||
m_sprDL.SetDiffuse( THEME->GetMetricC( m_sName, "DownloadProgressColor" ) );
|
||||
|
||||
m_textStatus.LoadFromFont( THEME->GetPathF(m_sName,"default") );
|
||||
m_textStatus.SetShadowLength( 0 );
|
||||
m_textStatus.SetName( "DownloadStatus" );
|
||||
SET_XY_AND_ON_COMMAND( m_textStatus );
|
||||
this->AddChild( &m_textStatus );
|
||||
|
||||
UpdateProgress();
|
||||
}
|
||||
|
||||
void ScreenPackages::HandleScreenMessage( const ScreenMessage SM )
|
||||
{
|
||||
switch( SM )
|
||||
{
|
||||
case SM_GoToPrevScreen:
|
||||
SCREENMAN->SetNewScreen( THEME->GetMetric (m_sName, "PrevScreen") );
|
||||
break;
|
||||
case SM_GoToNextScreen:
|
||||
SCREENMAN->SetNewScreen( THEME->GetMetric (m_sName, "NextScreen") );
|
||||
break;
|
||||
case SM_BackFromURL:
|
||||
if ( !ScreenTextEntry::s_bCancelledLast )
|
||||
EnterURL( ScreenTextEntry::s_sLastAnswer );
|
||||
break;
|
||||
}
|
||||
ScreenWithMenuElements::HandleScreenMessage( SM );
|
||||
}
|
||||
|
||||
void ScreenPackages::Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI )
|
||||
{
|
||||
ScreenWithMenuElements::Input( DeviceI, type, GameI, MenuI, StyleI );
|
||||
}
|
||||
|
||||
void ScreenPackages::Update( float fDeltaTime )
|
||||
{
|
||||
HTTPUpdate();
|
||||
|
||||
m_fLastUpdate += fDeltaTime;
|
||||
if ( m_fLastUpdate >= 1.0 )
|
||||
{
|
||||
if ( m_bIsDownloading && m_bGotHeadder )
|
||||
m_sStatus = ssprintf( "DL @ %d KB/s", int((m_iDownloaded-m_bytesLastUpdate)/1024) );
|
||||
|
||||
m_bytesLastUpdate = m_iDownloaded;
|
||||
UpdateProgress();
|
||||
m_fLastUpdate = 0;
|
||||
}
|
||||
|
||||
ScreenWithMenuElements::Update(fDeltaTime);
|
||||
}
|
||||
|
||||
void ScreenPackages::MenuStart( PlayerNumber pn )
|
||||
{
|
||||
if ( m_iDLorLST == 1 )
|
||||
{
|
||||
if ( m_iLinksPos == 0 )
|
||||
SCREENMAN->TextEntry( SM_BackFromURL, "Enter URL:", "http://" );
|
||||
else
|
||||
EnterURL( m_Links[m_iLinksPos] );
|
||||
}
|
||||
ScreenWithMenuElements::MenuStart( pn );
|
||||
}
|
||||
|
||||
void ScreenPackages::MenuUp( PlayerNumber pn, const InputEventType type )
|
||||
{
|
||||
if ( m_bIsDownloading )
|
||||
return;
|
||||
if ( m_iDLorLST == 0)
|
||||
{
|
||||
if ( m_iPackagesPos > 0)
|
||||
{
|
||||
m_iPackagesPos--;
|
||||
UpdatePackagesList();
|
||||
}
|
||||
}
|
||||
else
|
||||
if ( m_iLinksPos > 0 )
|
||||
{
|
||||
m_iLinksPos--;
|
||||
UpdateLinksList();
|
||||
}
|
||||
ScreenWithMenuElements::MenuUp( pn, type );
|
||||
}
|
||||
|
||||
void ScreenPackages::MenuDown( PlayerNumber pn, const InputEventType type )
|
||||
{
|
||||
if ( m_bIsDownloading )
|
||||
return;
|
||||
|
||||
if ( m_iDLorLST == 0)
|
||||
{
|
||||
if ( m_iPackagesPos < m_Packages.size() - 1 )
|
||||
{
|
||||
m_iPackagesPos++;
|
||||
UpdatePackagesList();
|
||||
}
|
||||
}
|
||||
else
|
||||
if ( m_iLinksPos < m_LinkTitles.size() - 1 )
|
||||
{
|
||||
m_iLinksPos++;
|
||||
UpdateLinksList();
|
||||
}
|
||||
ScreenWithMenuElements::MenuDown( pn, type );
|
||||
}
|
||||
|
||||
void ScreenPackages::MenuLeft( PlayerNumber pn, const InputEventType type )
|
||||
{
|
||||
if ( m_bIsDownloading )
|
||||
return;
|
||||
if ( !m_bCanDL )
|
||||
return;
|
||||
|
||||
m_sprExistingBG.StopTweening( );
|
||||
m_sprWebBG.StopTweening( );
|
||||
|
||||
if ( m_iDLorLST == 0 )
|
||||
{
|
||||
m_iDLorLST = 1;
|
||||
COMMAND( m_sprExistingBG, "Away" );
|
||||
COMMAND( m_sprWebBG, "Back" );
|
||||
} else
|
||||
{
|
||||
m_iDLorLST = 0;
|
||||
COMMAND( m_sprExistingBG, "Back" );
|
||||
COMMAND( m_sprWebBG, "Away" );
|
||||
}
|
||||
ScreenWithMenuElements::MenuLeft( pn, type );
|
||||
}
|
||||
|
||||
void ScreenPackages::MenuRight( PlayerNumber pn, const InputEventType type )
|
||||
{
|
||||
if ( m_bIsDownloading )
|
||||
return;
|
||||
MenuLeft( pn, type );
|
||||
ScreenWithMenuElements::MenuRight( pn, type );
|
||||
}
|
||||
|
||||
void ScreenPackages::MenuBack( PlayerNumber pn )
|
||||
{
|
||||
if ( m_bIsDownloading )
|
||||
{
|
||||
SCREENMAN->SystemMessage( "Download Cancelled." );
|
||||
CancelDownload( );
|
||||
return;
|
||||
}
|
||||
|
||||
TweenOffScreen();
|
||||
Back( SM_GoToPrevScreen );
|
||||
ScreenWithMenuElements::MenuBack( pn );
|
||||
}
|
||||
|
||||
void ScreenPackages::TweenOffScreen( )
|
||||
{
|
||||
OFF_COMMAND( m_sprExistingBG );
|
||||
OFF_COMMAND( m_sprWebBG );
|
||||
OFF_COMMAND( m_sprWebSel );
|
||||
OFF_COMMAND( m_textPackages );
|
||||
OFF_COMMAND( m_textWeb );
|
||||
OFF_COMMAND( m_sprDL );
|
||||
OFF_COMMAND( m_sprDLBG );
|
||||
OFF_COMMAND( m_textStatus );
|
||||
|
||||
if ( m_fOutputFile.IsOpen() )
|
||||
m_fOutputFile.Close();
|
||||
}
|
||||
|
||||
void ScreenPackages::RefreshPackages()
|
||||
{
|
||||
GetDirListing( "Packages/*.*zip", m_Packages, false, false );
|
||||
|
||||
if ( m_iPackagesPos < 0 )
|
||||
m_iPackagesPos = 0;
|
||||
|
||||
if ( m_iPackagesPos >= m_Packages.size() )
|
||||
m_iPackagesPos = m_Packages.size() - 1;
|
||||
|
||||
UpdatePackagesList();
|
||||
}
|
||||
|
||||
void ScreenPackages::UpdatePackagesList()
|
||||
{
|
||||
CString TempText="";
|
||||
int min = m_iPackagesPos-NUM_PACKAGES_SHOW;
|
||||
int max = m_iPackagesPos+NUM_PACKAGES_SHOW;
|
||||
for (int i=min; i<max; i++ )
|
||||
{
|
||||
if ( ( i >= 0 ) && ( i < m_Packages.size() ) )
|
||||
TempText += m_Packages[i] + '\n';
|
||||
else
|
||||
TempText += '\n';
|
||||
}
|
||||
m_textPackages.SetText( TempText );
|
||||
}
|
||||
|
||||
void ScreenPackages::UpdateLinksList()
|
||||
{
|
||||
CString TempText="";
|
||||
if ( m_iLinksPos >= m_LinkTitles.size() )
|
||||
m_iLinksPos = m_LinkTitles.size() - 1;
|
||||
int min = m_iLinksPos-NUM_LINKS_SHOW;
|
||||
int max = m_iLinksPos+NUM_LINKS_SHOW;
|
||||
for (int i=min; i<max; i++ )
|
||||
{
|
||||
if ( ( i >= 0 ) && ( i < m_LinkTitles.size() ) )
|
||||
TempText += m_LinkTitles[i] + '\n';
|
||||
else
|
||||
TempText += '\n';
|
||||
}
|
||||
m_textWeb.SetText( TempText );
|
||||
if ( ( m_iLinksPos >=0 ) && ( m_iLinksPos < m_Links.size() ) )
|
||||
m_textURL.SetText( m_Links[m_iLinksPos] );
|
||||
else
|
||||
m_textURL.SetText( " " );
|
||||
}
|
||||
|
||||
void ScreenPackages::HTMLParse()
|
||||
{
|
||||
m_Links.clear();
|
||||
m_LinkTitles.clear();
|
||||
m_Links.push_back( " " );
|
||||
m_LinkTitles.push_back( "--Visit URL--" );
|
||||
|
||||
//XXX: VERY DIRTY HTML PARSER!
|
||||
//Only designed to find links on websites.
|
||||
int i = m_sBUFFER.Find( "<A " );
|
||||
int j = 0;
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
int m = 0;
|
||||
|
||||
for ( int mode = 0; mode < 2; mode++ )
|
||||
{
|
||||
while ( i>=0 )
|
||||
{
|
||||
k = m_sBUFFER.Find( ">", i+1 );
|
||||
l = m_sBUFFER.Find( "HREF", i+1);
|
||||
m = m_sBUFFER.Find( "=", l );
|
||||
|
||||
if ( ( l > k ) || ( m > k ) ) //no "href" in this tag.
|
||||
{
|
||||
if ( mode == 0 )
|
||||
i = m_sBUFFER.Find( "<A ", i+1 );
|
||||
else
|
||||
i = m_sBUFFER.Find( "<a ", i+1 );
|
||||
continue;
|
||||
}
|
||||
|
||||
l = m_sBUFFER.Find( "</", m+1 );
|
||||
|
||||
//Special case: There is exactly one extra tag in the link.
|
||||
j = m_sBUFFER.Find( ">", k+1 );
|
||||
if ( j < l )
|
||||
k = j;
|
||||
|
||||
CString TempLink = StripOutContainers( m_sBUFFER.substr(m+1,k-m-1) );
|
||||
if ( TempLink.substr(0,7).compare("http://") != 0 )
|
||||
TempLink = m_sBaseAddress + TempLink;
|
||||
|
||||
CString TempTitle = m_sBUFFER.substr( k+1, l-k-1 );
|
||||
|
||||
m_Links.push_back( TempLink );
|
||||
m_LinkTitles.push_back( TempTitle );
|
||||
|
||||
if ( mode == 0 )
|
||||
i = m_sBUFFER.Find( "<A ", i+1 );
|
||||
else
|
||||
i = m_sBUFFER.Find( "<a ", i+1 );
|
||||
}
|
||||
if ( mode == 0 )
|
||||
i = m_sBUFFER.Find( "<a " );
|
||||
}
|
||||
UpdateLinksList();
|
||||
}
|
||||
|
||||
CString ScreenPackages::URLEncode( const CString &URL )
|
||||
{
|
||||
CString Input = StripOutContainers( URL );
|
||||
CString Output;
|
||||
|
||||
for (int k = 0; k < Input.length(); k++ )
|
||||
{
|
||||
char t = Input.at( k );
|
||||
if ( ( t >= '!' ) && ( t <= 'z' ) )
|
||||
Output+=t;
|
||||
else
|
||||
{
|
||||
char out[2];
|
||||
itoa( t, out, 16 );
|
||||
Output += "%" + CString(out);
|
||||
}
|
||||
}
|
||||
return Output;
|
||||
}
|
||||
|
||||
CString ScreenPackages::StripOutContainers( const CString & In )
|
||||
{
|
||||
if ( In.length() == 0 )
|
||||
return "";
|
||||
|
||||
int i = 0;
|
||||
char t = In.at(i);
|
||||
while ( ( t == ' ' ) && ( i < In.length() ) )
|
||||
{
|
||||
t = In.at(++i);
|
||||
}
|
||||
|
||||
if ( ( t == '\"' ) || ( t == '\'' ) )
|
||||
{
|
||||
int j = i+1;
|
||||
char u = In.at(j);
|
||||
while ( ( u != t ) && ( j < In.length() ) )
|
||||
{
|
||||
u = In.at(++j);
|
||||
}
|
||||
if (j==i)
|
||||
return StripOutContainers( In.substr(i+1) );
|
||||
else
|
||||
return StripOutContainers( In.substr(i+1, j-i-1) );
|
||||
}
|
||||
return In.substr( i );
|
||||
}
|
||||
|
||||
void ScreenPackages::UpdateProgress()
|
||||
{
|
||||
float DownloadedRatio;
|
||||
|
||||
if ( m_iTotalBytes < 1 )
|
||||
DownloadedRatio = 0;
|
||||
else
|
||||
DownloadedRatio = float(m_iDownloaded) / float(m_iTotalBytes);
|
||||
|
||||
float dLY = DownloadedRatio / 2 * m_sprDLBG.GetUnzoomedWidth();
|
||||
|
||||
m_sprDL.SetX( m_sprDLBG.GetX() - m_sprDLBG.GetUnzoomedWidth() / 2.0 + dLY );
|
||||
m_sprDL.SetWidth( dLY * 2 );
|
||||
|
||||
m_textStatus.SetText( m_sStatus );
|
||||
}
|
||||
|
||||
void ScreenPackages::CancelDownload( )
|
||||
{
|
||||
m_wSocket.close();
|
||||
m_bIsDownloading = false;
|
||||
m_iDownloaded = 0;
|
||||
m_bGotHeadder = false;
|
||||
m_fOutputFile.Close();
|
||||
m_sStatus = "Failed.";
|
||||
m_sBUFFER = "";
|
||||
if ( ! FILEMAN->Remove( "Packages/" + m_sEndName ) )
|
||||
SCREENMAN->SystemMessage( "Packages/" + m_sEndName );
|
||||
}
|
||||
void ScreenPackages::EnterURL( const CString & sURL )
|
||||
{
|
||||
CString Proto;
|
||||
CString Server;
|
||||
int Port=80;
|
||||
CString Addy;
|
||||
|
||||
if ( !ParseHTTPAddress( sURL, Proto, Server, Port, Addy ) )
|
||||
{
|
||||
m_sStatus = "Invalid URL.";
|
||||
UpdateProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
//Determine if this is a website, or a package?
|
||||
//Criteria: does it end with *zip?
|
||||
if ( Addy.Right(3).CompareNoCase("zip") == 0 )
|
||||
m_bIsPackage=true;
|
||||
else
|
||||
m_bIsPackage = false;
|
||||
|
||||
int k=0,j=0;
|
||||
while ( k >= 0 )
|
||||
{
|
||||
j = k+1;
|
||||
k = Addy.Find( '/', j );
|
||||
}
|
||||
m_sEndName = Addy.Right( Addy.length() - j + 1 );
|
||||
|
||||
if ( Port == 80 )
|
||||
m_sBaseAddress = "http://" + Server + "/" + Addy.substr(0, j);
|
||||
else
|
||||
m_sBaseAddress = "http://" + Server + ssprintf( ":%d/", Port ) + Addy.substr(0, j);
|
||||
|
||||
//Open the file...
|
||||
|
||||
//First find out if a file by this name already exists
|
||||
//if so, then we gotta ditch out.
|
||||
//XXX: This should be fixed by a prompt or something?
|
||||
|
||||
//if we are not talking about a file, let's not worry
|
||||
if ( ( m_sEndName != "" ) && m_bIsPackage )
|
||||
{
|
||||
CStringArray AddTo;
|
||||
GetDirListing( "Packages/"+m_sEndName, AddTo, false, false );
|
||||
if ( AddTo.size() > 0 )
|
||||
{
|
||||
m_sStatus = "File Already Exists";
|
||||
UpdateProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_fOutputFile.Open( "Packages/"+m_sEndName, RageFile::WRITE ))
|
||||
{
|
||||
m_sStatus = m_fOutputFile.GetError();
|
||||
UpdateProgress();
|
||||
return;
|
||||
}
|
||||
}
|
||||
//Continue...
|
||||
|
||||
Addy = URLEncode( Addy );
|
||||
|
||||
if ( Addy != "/" )
|
||||
Addy = "/" + Addy;
|
||||
|
||||
m_wSocket.close();
|
||||
m_wSocket.create();
|
||||
|
||||
m_wSocket.blocking = true;
|
||||
|
||||
if (!m_wSocket.connect( Server, Port ))
|
||||
{
|
||||
m_sStatus = "Failed to connect.";
|
||||
UpdateProgress();
|
||||
return;
|
||||
}
|
||||
|
||||
//Produce HTTP headder
|
||||
|
||||
CString Headder="";
|
||||
|
||||
Headder = "GET "+Addy+" HTTP/1.0\r\n";
|
||||
Headder+= "Host: " + Server + "\r\n";
|
||||
Headder+= "Connection: closed\r\n\r\n";
|
||||
|
||||
m_wSocket.SendData( Headder.c_str(), Headder.length() );
|
||||
m_sStatus = "Headder Sent.";
|
||||
m_wSocket.blocking = false;
|
||||
m_bIsDownloading = true;
|
||||
m_sBUFFER = "";
|
||||
m_bGotHeadder = false;
|
||||
UpdateProgress();
|
||||
return;
|
||||
}
|
||||
void ScreenPackages::HTTPUpdate()
|
||||
{
|
||||
if ( m_bIsDownloading )
|
||||
{
|
||||
int BytesGot=0;
|
||||
//Keep this as a code block
|
||||
//as there may be need to "if" it out some time.
|
||||
{
|
||||
int Size = 1;
|
||||
while ( Size > 0 )
|
||||
{
|
||||
char Buffer[1024];
|
||||
Size = m_wSocket.ReadData( Buffer, 1024 );
|
||||
m_sBUFFER.append( Buffer, Size );
|
||||
BytesGot += Size;
|
||||
}
|
||||
if (!m_bGotHeadder)
|
||||
{
|
||||
m_sStatus = "Waiting for headder.";
|
||||
//We don't know if we are using unix-style or dos-style
|
||||
int HeadderEnd = m_sBUFFER.find("\n\n");
|
||||
if ( HeadderEnd < 0 )
|
||||
HeadderEnd = m_sBUFFER.find("\r\n\r\n");
|
||||
if ( HeadderEnd >= 0 )
|
||||
{
|
||||
int i = m_sBUFFER.find(" ");
|
||||
int j = m_sBUFFER.find(" ",i+1);
|
||||
int k = m_sBUFFER.Find("\n",j+1);
|
||||
if ( (i<0) || (j<0) || (k<0) )
|
||||
{
|
||||
m_iResponceCode = -100;
|
||||
m_iResponceName = "Malformed responce.";
|
||||
}
|
||||
m_iResponceCode = atoi(m_sBUFFER.substr(i+1,j-i).c_str());
|
||||
m_iResponceName = m_sBUFFER.substr( j+1, k-j).c_str();
|
||||
|
||||
i = m_sBUFFER.find("Content-Length:");
|
||||
j = m_sBUFFER.find("\n", i+1 );
|
||||
|
||||
if ( i > 0 )
|
||||
m_iTotalBytes = atoi(m_sBUFFER.substr(i+16,j-i).c_str());
|
||||
else
|
||||
m_iTotalBytes = -1; //We don't know, so go until disconnect
|
||||
|
||||
m_bGotHeadder = true;
|
||||
m_sBUFFER = m_sBUFFER.substr( HeadderEnd + 4 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_bIsPackage )
|
||||
{
|
||||
m_iDownloaded += m_sBUFFER.length();
|
||||
m_fOutputFile.Write( m_sBUFFER );
|
||||
m_sBUFFER = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
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 ) &&
|
||||
( ( m_wSocket.state == EzSockets::SockState::skERROR ) ||
|
||||
( m_wSocket.state == EzSockets::SockState::skDISCONNECTED ) ) ) )
|
||||
//We didn't know how big it was, and were disconnected
|
||||
//So that means we have it all.
|
||||
{
|
||||
m_wSocket.close();
|
||||
m_bIsDownloading = false;
|
||||
m_bGotHeadder=false;
|
||||
m_sStatus = ssprintf( "Done;%dB", int(m_iDownloaded) );
|
||||
|
||||
if ( ( m_iResponceCode < 200 ) || ( m_iResponceCode >= 400 ) )
|
||||
m_sStatus = ssprintf( "%d", m_iResponceCode ) + m_iResponceName;
|
||||
else
|
||||
if ( m_bIsPackage && ( m_iResponceCode < 300 ) )
|
||||
{
|
||||
m_fOutputFile.Close( );
|
||||
FlushDirCache( );
|
||||
RefreshPackages( );
|
||||
m_iDownloaded = 0;
|
||||
}
|
||||
else
|
||||
HTMLParse();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenPackages::ParseHTTPAddress( const CString & URL, CString & Proto, CString & Server, int & Port, CString & Addy )
|
||||
{
|
||||
int i,j,k,l;
|
||||
|
||||
// [PROTO://]SERVER[:PORT][/URL]
|
||||
|
||||
if ( URL.length() == 0 )
|
||||
return false;
|
||||
|
||||
//PROTO
|
||||
i = URL.Find( "://" );
|
||||
if ( i >= 0 )
|
||||
{
|
||||
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)
|
||||
return false;
|
||||
l=j;
|
||||
}
|
||||
if (l<URL.length())
|
||||
l++;
|
||||
Addy = URL.substr( l );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
/*
|
||||
* (c) 2004 Charles Lohr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -0,0 +1,124 @@
|
||||
#ifndef ScreenPackages_H
|
||||
#define ScreenPackages_H
|
||||
|
||||
#include "ScreenWithMenuElements.h"
|
||||
#include "BitmapText.h"
|
||||
#include "ezsockets.h"
|
||||
#include "RageFileManager.h"
|
||||
|
||||
#if !defined(WITHOUT_NETWORKING)
|
||||
|
||||
class ScreenPackages : public ScreenWithMenuElements
|
||||
{
|
||||
public:
|
||||
ScreenPackages( CString sName );
|
||||
|
||||
virtual void Input( const DeviceInput& DeviceI, const InputEventType type, const GameInput &GameI, const MenuInput &MenuI, const StyleInput &StyleI );
|
||||
virtual void HandleScreenMessage( const ScreenMessage SM );
|
||||
|
||||
virtual void MenuStart( PlayerNumber pn );
|
||||
virtual void MenuUp( PlayerNumber pn, const InputEventType type );
|
||||
virtual void MenuDown( PlayerNumber pn, const InputEventType type );
|
||||
virtual void MenuLeft( PlayerNumber pn, const InputEventType type );
|
||||
virtual void MenuRight( PlayerNumber pn, const InputEventType type );
|
||||
virtual void MenuBack( PlayerNumber pn );
|
||||
|
||||
virtual void TweenOffScreen( );
|
||||
virtual void Update(float f);
|
||||
|
||||
private:
|
||||
void UpdatePackagesList();
|
||||
void UpdateLinksList();
|
||||
void RefreshPackages();
|
||||
|
||||
void HTMLParse();
|
||||
|
||||
CString URLEncode( const CString &URL ); //Encode any string in URL-style
|
||||
CString StripOutContainers( const CString & In ); //Strip off "'s and ''s
|
||||
|
||||
Sprite m_sprExistingBG;
|
||||
Sprite m_sprWebBG;
|
||||
|
||||
Sprite m_sprWebSel;
|
||||
|
||||
BitmapText m_textPackages;
|
||||
BitmapText m_textWeb;
|
||||
|
||||
CStringArray m_Packages;
|
||||
|
||||
vector <CString> m_Links;
|
||||
vector <CString> m_LinkTitles;
|
||||
BitmapText m_textURL;
|
||||
|
||||
int m_iPackagesPos;
|
||||
int m_iLinksPos;
|
||||
|
||||
int m_iDLorLST;
|
||||
int m_bCanDL;
|
||||
|
||||
//HTTP portion
|
||||
void CancelDownload( );
|
||||
void EnterURL( const CString & sURL );
|
||||
void HTTPUpdate( );
|
||||
|
||||
//True if proper string, false if improper
|
||||
bool ParseHTTPAddress( const CString & URL, CString & Proto, CString & Server, int & Port, CString & Addy );
|
||||
|
||||
Sprite m_sprDL;
|
||||
Sprite m_sprDLBG;
|
||||
void UpdateProgress();
|
||||
|
||||
bool m_bIsDownloading;
|
||||
float m_fLastUpdate;
|
||||
long m_bytesLastUpdate;
|
||||
|
||||
CString m_sStatus;
|
||||
BitmapText m_textStatus;
|
||||
|
||||
EzSockets m_wSocket;
|
||||
|
||||
bool m_bGotHeadder;
|
||||
|
||||
RageFile m_fOutputFile;
|
||||
CString m_sEndName;
|
||||
bool m_bIsPackage;
|
||||
|
||||
CString m_sBaseAddress;
|
||||
//HTTP Headder information responce
|
||||
long m_iTotalBytes;
|
||||
long m_iDownloaded;
|
||||
|
||||
long m_iResponceCode;
|
||||
CString m_iResponceName;
|
||||
|
||||
//Raw HTTP Buffer
|
||||
CString m_sBUFFER;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
* (c) 2004 Charles Lohr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -423,6 +423,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\
|
||||
<File
|
||||
RelativePath="ScreenOptionsMasterPrefs.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPackages.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPackages.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPlayerOptions.cpp">
|
||||
</File>
|
||||
|
||||
@@ -2680,6 +2680,14 @@ SOURCE=.\ScreenOptionsMasterPrefs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ScreenPackages.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ScreenPackages.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ScreenPlayerOptions.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -415,6 +415,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\
|
||||
<File
|
||||
RelativePath="ScreenOptionsMasterPrefs.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPackages.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPackages.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPlayerOptions.cpp">
|
||||
</File>
|
||||
|
||||
@@ -554,6 +554,12 @@ cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\
|
||||
<File
|
||||
RelativePath="ScreenOptionsMasterPrefs.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPackages.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPackages.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="ScreenPlayerOptions.cpp">
|
||||
</File>
|
||||
|
||||
Reference in New Issue
Block a user