From ad1590aa86f1dfb6c41acc023ed1a231f103563b Mon Sep 17 00:00:00 2001 From: Patrick McIlroy Date: Sat, 23 Feb 2008 10:11:37 +0000 Subject: [PATCH] git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg@37 83fadc84-e282-4d84-a09a-c4228d6ae7e5 --- src/LuaManager.cpp | 429 ----------------------------------------------------- src/Makefile.am | 1 + src/MiscITG.cpp | 168 +++++++++++++++++++++ src/MiscITG.h | 9 ++ 4 files changed, 178 insertions(+), 429 deletions(-) create mode 100644 src/MiscITG.cpp create mode 100644 src/MiscITG.h diff --git a/src/LuaManager.cpp b/src/LuaManager.cpp index efcab4fc..7f6f7583 100644 --- a/src/LuaManager.cpp +++ b/src/LuaManager.cpp @@ -458,441 +458,12 @@ static size_t FindEndOfHeaders( const CString &buf ) else return string::npos; } -// If you need this, we can uncomment it. I don't think it's being used, though. -// - Vyhd -// Progress Indicator for loading custom songs. -- Matt1360 -/* -void UpdateLoadingProgress( float fProgress ) -{ - CString sText = ssprintf( "Please wait ... Copying Patch: \n%u%%\n\n\n" - "Removing the USB drive will cancel this Patch,\n" - "May corrupt USB drive if removed while mounted", - (int)(fProgress*100) ); - - SCREENMAN->OverlayMessage( sText ); - SCREENMAN->Draw(); -} -*/ - -#if 0 -// Get Newest Revision -// This is the ugliest shit (And iUpdate()) that I've ever fucking written -// -- Matt1360 -static int newRevision() { - -// FILE * newRevF; -// char newRev [32]; - -// system ( "wget http://www.jeffrey1790.com/machine/currentrev -O /tmp/currentrev" ); -// newRevF = fopen ( "/tmp/currentrev" , "r" ); -// if ( newRevF != NULL ) { -// fgets ( newRev , 32 , newRevF ); -// fclose ( newRevF ); -// system ( "rm /tmp/currentrev" ); -// } - -// return atoi ( newRev ); - - // My attempt at an efficient Machine Update - // -- Matt1360 - #ifdef WITHOUT_NETWORKING - return 0; // In the theme, returning 0 will make it be dead connect. - #endif // Does this work? - - EzSockets m_wSocket; - - m_wSocket.close(); - m_wSocket.create(); - - m_wSocket.blocking = true; - - CString Server = "jeffrey1790.com"; - int Port = 80; - - if( !m_wSocket.connect( Server , (short) Port ) ) - { - return 0; // Eventually, make it return 0 if it fails, this way - // In the theme we can make it not show anything - // Except "Update Check Failed ... Check Network Connection" - // Or some bullshit. - // -- Matt1360 - } - - //Produce HTTP header - CString Header=""; - - Header = "GET http://www.jeffrey1790.com/machine/currentrev HTTP/1.0\r\n"; - Header+= "Host: " + Server + "\r\n"; - Header+= "Connection: closed\r\n\r\n"; - - m_wSocket.blocking = false; - - m_wSocket.SendData( Header.c_str(), Header.length() ); - - CString m_sBUFFER = ""; - int m_iBytesGot = 0; - - while(1) - { - char Buffer[1024]; - int iSize = m_wSocket.pReadData( Buffer ); - - if( iSize <= 0 ) - break; - - m_sBUFFER.append( Buffer, iSize ); - m_iBytesGot += iSize; // Use something like this for logging - } - - int i = m_sBUFFER.find ( "text/plain" ); - int j = m_sBUFFER.GetLength(); - - int iRevision = atoi( m_sBUFFER.substr( i + 14 , j ).c_str() ); - - return iRevision; -} -// Install Latest Update -static bool iUpdate() { - // First, we need a clean working directory. - system ( "rm -R /patches/ *" ); - - int newRev = newRevision(); - - if ( newRev > REVISION ) { - char tempvar [512]; - sprintf(tempvar, "wget http://www.jeffrey1790.com/machine/r%u.dxl -O /patches/revision.dxl", newRev ); - system(tempvar); - - FILE * exist; - exist = fopen("/patches/revision.dxl","r"); //Hacky hacky - if (exist != NULL) { - fclose ( exist ); - //system("cd /patches/;unzip revision.dxl;rm revision.dxl;/bin/sh setup.sh"); - //debug (1 line): - system("cd /patches/;unzip -o revision.dxl;rm revision.dxl"); - system ( "chmod +x /patches/ *" ); - return true; - } - } else { - return false; - }*/ - - // First, we remove the current patches that were left behind. - // Also, we kill it after to be safe. - - #ifdef WITHOUT_NETWORKING - PREFSMAN->m_bUsbUpdate == true; // If there's no connection, we can't be oline. - #endif - - bool bStyle = PREFSMAN->m_bUsbUpdate; - - if ( bStyle == true ) // Updating with USB Manually, no connection. - { - /* Steps to do this Shit... - * Mount each card - * Search each card for the update file - * Something like "DXL r##.dxl" - * Compare that with current revision! - * Compare it for encryption - * RSA check the last 128 bytes - * Copy, Extract, Text the encryption on patch.zip - * Place a shell script - * Reboot - */ - - // We need this, so it calls on the foreach for the sDir. -- Matt1360 - int iPn = 1; - - // First, we check each players' Memory Card. - FOREACH_PlayerNumber( pn ) { - if ( !MEMCARDMAN->MountCard( pn ) ) { - iPn++; - break; - } - - // Make sure the card is mounted, and ready. - if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) { - iPn++; - break; - } - - // So now we've established, a card is mounted...Lets get the directory. - CString sDir = ssprintf( "/@mc%i/" , iPn ); - - // Lets find all the .dxl files. - CStringArray aFiles; - GetDirListing( sDir+"*.dxl" , aFiles , false , false ); - - // Just call the first one. That's all we need. We can't update multiples. -- Matt1360 - if ( aFiles.size() == 0 ) { - LOG->Warn ( "No DXL File(s) Found!!" ); - iPn++; - break; - } - - CString sFullDir = sDir + aFiles[0]; - LOG->Warn ( "Patch Found: %s at %s" , aFiles[0].c_str() , sDir.c_str() ); - - CString sText = ""; - // Next copy the file Using that Pointer Function... - CString out = "Patches/" + aFiles[0]; - CustomCopy( sFullDir , out , &UpdateLoadingProgress ); - SCREENMAN->HideSystemMessage(); - - MEMCARDMAN->UnmountCard( pn ); - // Don't put a iPn++ here, because we found a patch. We only want one... - // TODO: Check that this works with 2 players... Check that it works with only Player 2. - } - - } else { // Updating online. - - int iThisRevision = REVISION; - int iNewRevision = newRevision(); - - if ( !iNewRevision >= iThisRevision ) // If the new revision isn't greater than ours... - return false; // Then we're up to date... - - EzSockets m_wSocket; - RageFile m_fNewFile; - - m_wSocket.close(); - m_wSocket.create(); - - m_wSocket.blocking = true; - - CString Server = "jeffrey1790.com"; - int Port = 80; - - if( !m_wSocket.connect( Server , (short) Port ) ) // If it can't connect - return false; // Then we're in crap. "Up to Date" - - //Produce HTTP header - CString Header=""; - // UGLY: Clean this up...Seriously one variable is good enough. - CString sUpdateDir = "http://www.jeffrey1790.com/machine/"; - CString sUpdateFile = ssprintf( "r%i.dxl" , iNewRevision ); - CString sUpdateAddr = ssprintf( "http://www.jeffrey1790.com/machine/%s" , sUpdateFile.c_str() ); - - Header = "GET " + sUpdateAddr + " HTTP/1.0\r\n"; - Header+= "Host: " + Server + "\r\n"; - Header+= "Connection: closed\r\n\r\n"; - - m_wSocket.blocking = false; - - m_wSocket.SendData( Header.c_str(), Header.length() ); - - // First thing's first... Major cleanup. - // I'm going to use a vector array (ooh fuckin' fancy) to hold every file in Patches/ - // From there they will be for looped and FILEMAN->Remove'd - // -- Matt1360 - - // Better Idea. Use the startup script to clean it out. - // This way, there are -no- crashes. It's impossible, nearly. - // The basic workaround: "rm -R /root/stepmania/Patches/*" - // Possibly add -f to the command to force it. - // Also, there will surely be a requirement for chmodding the directory. - // -- Matt1360 - -// CStringArray aFiles; // Fix: Faster with an array. -// GetDirListing( "Patches/" , aFiles, false, false ); -// for ( unsigned i = 0; aFiles.size(); i++ ) { -// if( !aFiles.size() ) // If there is no size? -// break; -// FILEMAN->Remove ( "Patches/" + aFiles[i] ); -// LOG->Warn( "Killed: %s" , aFiles[i].c_str() ); -// } -// LOG->Warn ("KILLED ALL FILES"); - - if ( !m_fNewFile.Open ( "Patches/" + sUpdateFile , RageFile::WRITE | RageFile::STREAMED ) ) - return false; // Something wrong if we hit this. Bad disk? - - CString m_sBUFFER = ""; - - while(1) - { - char Buffer[1024]; - int iSize = m_wSocket.pReadData( Buffer ); - - if( iSize <= 0 ) - break; - - m_sBUFFER.append( Buffer, iSize ); -// m_iBytesGot += iSize; // Use something like this for logging - } - - // Kill the fucking header. Using that ScreenPackages function. - // GOD this is a lifesaver! - // -- Matt1360 - size_t iHeaderEnd = FindEndOfHeaders( m_sBUFFER ); - if( iHeaderEnd == m_sBUFFER.npos ) - return false; - m_sBUFFER.erase( 0, iHeaderEnd ); - - m_fNewFile.Write( m_sBUFFER ); - - return true; - } - - // Here, we will take care of the file after it's been loaded to the Patches Directory. - // REMEMBER: ShutdownGame() when complete! In StepMania.h/cpp - // ExitGame() May be safer? Research! All in StepMania.h/cpp - - // Make it false, just in case. You never know what might not fall through. - // -- Matt1360 - return false; - -} -#endif - -// This is how I chose to find the Crash Log size. -// -- Matt1360 -static int GetNumCrashLogs() -{ - // Give ourselves a variable. - CStringArray aLogs; - - // Get them all. - GetDirListing( "/stats/crashlog-*.txt" , aLogs ); - - return aLogs.size(); -} - -static int GetNumMachineEdits() -{ - CStringArray aEdits; - CString sDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_SUBDIR; - - GetDirListing( sDir , aEdits ); - - return aEdits.size(); -} - -static int GetIP() -{ - return 0; -} - -static int GetRevision() -{ - // Create the XML Handler, and clear it, for practice. - XNode *xml = new XNode; - xml->Clear(); - xml->m_sName = "patch"; - - // Check for the file existing - if( !IsAFile( "/Data/patch/patch.xml" ) ) - { - LOG->Trace( "There is no patch file (patch.xml)" ); - return 1; - } - - // Make sure you can read it - if( !xml->LoadFromFile( "/Data/patch/patch.xml" ) ) - { - LOG->Trace( "patch.xml unloadable" ); - return 1; - } - - // Check the node x - if( !xml->GetChild( "Revision" ) ) - { - LOG->Trace( "Revision node missing! (patch.xml)" ); - return 1; - } - - // Return as an integer - return atoi( xml->GetChildValue( "Revision" ) ); -} - -static int GetNumMachineScores() -{ - // Create the XML Handler and clear it, for practice - XNode *xml = new XNode; - xml->Clear(); - - // Check for the file existing - if( !IsAFile( "/Data/MachineProfile/Stats.xml" ) ) - { - LOG->Trace( "There is no stats file!" ); - return 1; - } - - // Make sure you can read it - if( !xml->LoadFromFile( "/Data/MachineProfile/Stats.xml" ) ) - { - LOG->Trace( "Stats.xml unloadable!" ); - return 1; - } - - const XNode *pData = xml->GetChild( "SongScores" ); - - if( pData == NULL ) - { - LOG->Warn( "Error loading scores: node missing" ); - return 0; - } - - int iScoreCount = 0; - - // Named here, for LoadFromFile() renames it to "Stats" - xml->m_sName = "SongScores"; - - // For each pData Child, or the Child in SongScores... - FOREACH_CONST_Child( pData , p ) - iScoreCount++; - - return iScoreCount; -} LuaFunction( Trace, Trace(SArg(1)) ); // Log Traces /* - * [ScreenArcadeDiagnostics] - * - * All ITG2AC Functions here - * Mostly...Implemented - * - * Work Log! - * - * Work started 2/9/08, after 10 PM - 2:30 AM - * ProductName, Revision, Uptime, Crashlogs, - * Machine edits, done! - * - * Work, 2/10/08 7 PM - 9:30 PM - * Did work on GetNumMachineScores() ... That sucked - * Somewhat complete...Can't do IO Errors, an ITG-IO - * exclusive, it seems. - * - * Total Hours: ~6 - */ -LuaFunction( GetProductName , CString( PRODUCT_NAME ) ); // Return the product's name from ProductInfo.h [ScreenArcadeDiagnostics] -LuaFunction( GetRevision , GetRevision() ); // Return current Revision ( ProductInfo.h ) [ScreenArcadeDiagnostics] -LuaFunction( GetUptime , SecondsToMMSSMsMsMs( RageTimer::GetTimeSinceStart() ) ); // Uptime calling [ScreenArcadeDiagnostics] -LuaFunction( GetIP , GetIP() ); // Calling the IP [ScreenArcadeDiagnostics] -LuaFunction( GetNumCrashLogs , GetNumCrashLogs() ); // Count the crashlogs [ScreenArcadeDiagnostics] -LuaFunction( GetNumMachineEdits , GetNumMachineEdits() ); // Count the machine edits [ScreenArcadeDiagnostics] -LuaFunction( GetNumIOErrors , 0 ); // Call the number of I/O Errors [ScreenArcadeDiagnostics] -LuaFunction( GetNumMachineScores, GetNumMachineScores() ); // Call the machine score count [ScreenArcadeDiagnostics] - -/* - * [ScreenArcadePatch] - * - * Work Started 2/11/08 9:30 PM - * - */ - -/* - * - * LuaFunction( gRev, REVISION ); // Returns Revision (ProductInfo.h) - * LuaFunction( newRev , newRevision() ); // Returns Newest Revision - * LuaFunction( iUpdate , iUpdate() ); // Initiates an update...Checks Revision First. - * LuaFunction( uptime , SecondsToMMSSMsMsMs(RageTimer::GetTimeSinceStart()) ); // Returns the current Uptime - * - */ - -/* * (c) 2004 Glenn Maynard * (c) 2008 BoXoRRoXoRs * All rights reserved. diff --git a/src/Makefile.am b/src/Makefile.am index bdb380d8..cbe27ced 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -104,6 +104,7 @@ FileTypes = IniFile.cpp IniFile.h \ StepMania = StdString.h \ StepMania.cpp StepMania.h \ + MiscITG.cpp MiscITG.h \ global.cpp global.h LoadingWindow = arch/LoadingWindow/LoadingWindow.h \ diff --git a/src/MiscITG.cpp b/src/MiscITG.cpp new file mode 100644 index 00000000..9802f3f3 --- /dev/null +++ b/src/MiscITG.cpp @@ -0,0 +1,168 @@ +#include "global.h" +#include "XmlFile.h" +#include "RageUtil.h" +#include "ProfileManager.h" +#include "RageLog.h" +#include "RageTimer.h" +#include "SongManager.h" +#include "ProductInfo.h" + +// This is how I chose to find the Crash Log size. +// -- Matt1360 +int GetNumCrashLogs() +{ + // Give ourselves a variable. + CStringArray aLogs; + + // Get them all. + GetDirListing( "/stats/crashlog-*.txt" , aLogs ); + + return aLogs.size(); +} + +int GetNumMachineEdits() +{ + CStringArray aEdits; + CString sDir = PROFILEMAN->GetProfileDir(PROFILE_SLOT_MACHINE) + EDIT_SUBDIR; + + GetDirListing( sDir , aEdits ); + + return aEdits.size(); +} + +int GetIP() +{ + return 0; +} + +int GetRevision() +{ + // Create the XML Handler, and clear it, for practice. + XNode *xml = new XNode; + xml->Clear(); + xml->m_sName = "patch"; + int rev; + + // Check for the file existing + if( !IsAFile( "/Data/patch/patch.xml" ) ) + { + LOG->Trace( "There is no patch file (patch.xml)" ); + return 1; + } + + // Make sure you can read it + if( !xml->LoadFromFile( "/Data/patch/patch.xml" ) ) + { + LOG->Trace( "patch.xml unloadable" ); + return 1; + } + + // Check the node x + if( !xml->GetChild( "Revision" ) ) + { + LOG->Trace( "Revision node missing! (patch.xml)" ); + return 1; + } + + // Return as an integer + xml->GetChild("Revision")->GetValue(rev); + return rev; +} + +int GetNumMachineScores() +{ + // Create the XML Handler and clear it, for practice + XNode *xml = new XNode; + xml->Clear(); + + // Check for the file existing + if( !IsAFile( "/Data/MachineProfile/Stats.xml" ) ) + { + LOG->Trace( "There is no stats file!" ); + return 1; + } + + // Make sure you can read it + if( !xml->LoadFromFile( "/Data/MachineProfile/Stats.xml" ) ) + { + LOG->Trace( "Stats.xml unloadable!" ); + return 1; + } + + const XNode *pData = xml->GetChild( "SongScores" ); + + if( pData == NULL ) + { + LOG->Warn( "Error loading scores: node missing" ); + return 0; + } + + int iScoreCount = 0; + + // Named here, for LoadFromFile() renames it to "Stats" + xml->m_sName = "SongScores"; + + // For each pData Child, or the Child in SongScores... + FOREACH_CONST_Child( pData , p ) + iScoreCount++; + + return iScoreCount; +} + +/* + * [ScreenArcadeDiagnostics] + * + * All ITG2AC Functions here + * Mostly...Implemented + * + * Work Log! + * + * Work started 2/9/08, after 10 PM - 2:30 AM + * ProductName, Revision, Uptime, Crashlogs, + * Machine edits, done! + * + * Work, 2/10/08 7 PM - 9:30 PM + * Did work on GetNumMachineScores() ... That sucked + * Somewhat complete...Can't do IO Errors, an ITG-IO + * exclusive, it seems. + * + * Total Hours: ~6 + * + * this doesn't belong in LuaManager.cpp --infamouspat + */ +#include "LuaFunctions.h" +LuaFunction_NoArgs( GetProductName , CString( PRODUCT_NAME ) ); // Return the product's name from ProductInfo.h [ScreenArcadeDiagnostics] +LuaFunction_NoArgs( GetRevision , GetRevision() ); // Return current Revision ( ProductInfo.h ) [ScreenArcadeDiagnostics] +// do we really need it by the millisecond? +LuaFunction_NoArgs( GetUptime , SecondsToMMSSMsMsMs( RageTimer::GetTimeSinceStart() ) ); // Uptime calling [ScreenArcadeDiagnostics] +LuaFunction_NoArgs( GetIP , GetIP() ); // Calling the IP [ScreenArcadeDiagnostics] +LuaFunction_NoArgs( GetNumCrashLogs , GetNumCrashLogs() ); // Count the crashlogs [ScreenArcadeDiagnostics] +LuaFunction_NoArgs( GetNumMachineEdits , GetNumMachineEdits() ); // Count the machine edits [ScreenArcadeDiagnostics] +LuaFunction_NoArgs( GetNumIOErrors , 0 ); // Call the number of I/O Errors [ScreenArcadeDiagnostics] +LuaFunction_NoArgs( GetNumMachineScores, GetNumMachineScores() ); // Call the machine score count [ScreenArcadeDiagnostics] + +/* + * (c) 2004 Glenn Maynard + * (c) 2008 Matt1360, Vyhd + * 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. + */ diff --git a/src/MiscITG.h b/src/MiscITG.h new file mode 100644 index 00000000..4484124a --- /dev/null +++ b/src/MiscITG.h @@ -0,0 +1,9 @@ +#ifndef MISC_ITG_H +#define MISC_ITG_H +int GetNumCrashLogs(); +int GetNumMachineEdits(); +int GetIP(); +int GetRevision(); +int GetNumMachineScores(); +#endif + -- 2.11.0