Added GetDiskSpaceFree/GetDiskSpaceTotal for Windows and Unix - Windows untested...
authorMark Cannon <vyhdycokio@gmail.com>
Thu, 29 Jul 2010 15:50:32 +0000 (15:50 +0000)
committerMark Cannon <vyhdycokio@gmail.com>
Thu, 29 Jul 2010 15:50:32 +0000 (15:50 +0000)
git-svn-id: https://openitg.svn.sourceforge.net/svnroot/openitg/branches/dev@771 83fadc84-e282-4d84-a09a-c4228d6ae7e5

src/RageFileManager.cpp
src/RageFileManager.h
src/StepMania.cpp
src/UserPackManager.cpp
src/arch/ArchHooks/ArchHooks.h
src/arch/ArchHooks/ArchHooks_Unix.cpp
src/arch/ArchHooks/ArchHooks_Unix.h
src/arch/ArchHooks/ArchHooks_Win32.cpp
src/arch/ArchHooks/ArchHooks_Win32.h
src/io/G15.cpp

index c714754..cf89af2 100755 (executable)
@@ -1,3 +1,4 @@
+
 #include "global.h"
 #include "RageFileManager.h"
 #include "RageFileDriver.h"
@@ -706,6 +707,44 @@ int RageFileManager::GetFileHash( const CString &sPath_ )
        return iRet;
 }
 
+CString RageFileManager::ResolvePath( const CString &sPath_ )
+{
+       CString sPath = sPath_;
+       NormalizePath( sPath );
+
+       CString sResolvedPath = "";
+
+       vector<LoadedDriver *> apDriverList;
+       ReferenceAllDrivers( apDriverList );
+
+       for( unsigned i = 0; i < apDriverList.size(); ++i )
+       {
+               LoadedDriver *pDriver = apDriverList[i];
+
+               if( pDriver->m_sType == "mountpoints" )
+                       continue;
+
+               const CString p = pDriver->GetPath(sPath);
+
+               if( p.empty() )
+                       continue;
+
+               sResolvedPath = pDriver->m_sRoot + p;
+
+               LOG->Debug( "p: %s, pDriver->m_sRoot: %s, sResolvedPath: %s",
+                       p.c_str(), pDriver->m_sRoot.c_str(), sResolvedPath.c_str() );
+
+               break;
+       }
+
+       UnreferenceAllDrivers( apDriverList );
+
+       NormalizePath( sResolvedPath );
+       LOG->Debug( "\"%s\" resolved to \"%s\".", sPath_.c_str(), sResolvedPath.c_str() );
+
+       return sResolvedPath;
+}
+
 static bool SortBySecond( const pair<int,int> &a, const pair<int,int> &b )
 {
        return a.second < b.second;
index 4cfc791..286c760 100755 (executable)
@@ -32,6 +32,8 @@ public:
        int GetFileSizeInBytes( const CString &sPath );
        int GetFileHash( const CString &sPath );
 
+       CString ResolvePath( const CString &sPath );
+
        bool Mount( const CString &Type, const CString &RealPath, const CString &MountPoint, bool bAddToEnd = true );
        void Unmount( const CString &Type, const CString &Root, const CString &MountPoint );
 
index fda8dcb..a0e2f34 100755 (executable)
@@ -1010,9 +1010,9 @@ int main(int argc, char* argv[])
        LOG                     = new RageLog();
 
        /* Whew--we should be able to crash safely now! */
-       LOG->Info( "%llu MB total, %llu MB remaining.", 
-               HOOKS->GetDiskSpaceTotal( argv[0] ) / (1024*1024), 
-               HOOKS->GetDiskSpaceFree( argv[0] ) / (1024*1024)
+       LOG->Info( "%llu bytes total, %llu bytes remaining.", 
+               HOOKS->GetDiskSpaceTotal( "UserPacks" ), 
+               HOOKS->GetDiskSpaceFree( "UserPacks" )
        );
 
        //
index 26c8f08..0b70c21 100644 (file)
@@ -5,6 +5,7 @@
 #include "Foreach.h"
 #include "RageLog.h"
 #include "RageFileDriverZip.h"
+#include "arch/ArchHooks/ArchHooks.h"
 
 UserPackManager* UPACKMAN = NULL; // global and accessable from anywhere in our program
 
@@ -113,6 +114,8 @@ bool UserPackManager::IsPackMountable( const CString &sPack, CString &sError )
 
 bool UserPackManager::IsPackTransferable( const CString sPack, CString &sError )
 {
+       
+
        CStringArray asSavedPacks;
        GetUserPacks( asSavedPacks );
        for ( unsigned i = 0; i < asSavedPacks.size(); i++ )
index c4a3a47..3f2ed12 100755 (executable)
@@ -25,10 +25,10 @@ public:
        /* Restart the entire computer, in case of installation updates, etc. */
        virtual void SystemReboot( bool bForceSync = true ) { }
 
-       /* Get API-specific machine information about the system
-        * which contains the given file or directory path. */
-       virtual uint64_t GetDiskSpaceTotal( const CString &sPath ) { return 0; }
-       virtual uint64_t GetDiskSpaceFree( const CString &sPath ) { return 0; }
+       /* Get disk space from the device that contains the given directory.
+        * The path given is in the VFS; we resolve the actual path here. */
+       virtual uint64_t GetDiskSpaceTotal( const CString &sDir ) { return 0; }
+       virtual uint64_t GetDiskSpaceFree( const CString &sDir ) { return 0; }
 
        /* Call this to temporarily enter a high-priority or realtime scheduling (depending
         * on the implementation) mode.  This is used to improve timestamp accuracy.  Do as
index fc49756..4638041 100755 (executable)
@@ -92,51 +92,44 @@ struct stat st;
 #endif // ITG_ARCADE
 }
 
-uint64_t ArchHooks_Unix::GetDiskSpaceTotal( const CString &sPath )
+static void GetDiskSpace( const CString &sDir, uint64_t *pSpaceFree, uint64_t *pSpaceTotal )
 {
+       CString sResolvedDir = FILEMAN->ResolvePath( sDir );
+
        struct statvfs fsdata;
-       if( statvfs(sPath.c_str(), &fsdata) != 0 )
+       if( statvfs(sResolvedDir.c_str(), &fsdata) != 0 )
        {
-               LOG->Warn( "GetDiskSpaceTotal(): statvfs() failed: %s", strerror(errno) );
-               return 0;
+               LOG->Warn( "GetDiskSpace(): statvfs() failed: %s", strerror(errno) );
+               return;
        }
 
-       // return blocksize x blocks available
-       return uint64_t(fsdata.f_frsize) * uint64_t(fsdata.f_blocks);
+       // block size * blocks available to user
+       if ( pSpaceFree )
+               *pSpaceFree = uint64_t(fsdata.f_bsize) * uint64_t(fsdata.f_bavail);
+
+       // fragment size * blocks on the FS
+       if( pSpaceTotal )
+               *pSpaceTotal = uint64_t(fsdata.f_frsize) * uint64_t(fsdata.f_blocks);
 }
 
-uint64_t ArchHooks_Unix::GetDiskSpaceFree( const CString &sPath )
+uint64_t ArchHooks_Unix::GetDiskSpaceFree( const CString &sDir )
 {
-       struct statvfs fsdata;
-       if( statvfs(sPath.c_str(), &fsdata) != 0 )
-       {
-               LOG->Warn( "GetDiskSpaceTotal(): statvfs() failed: %s", strerror(errno) );
-               return 0;
-       }
+       uint64_t iSpaceFree = 0;
+       GetDiskSpace( sDir, &iSpaceFree, NULL );
+       return iSpaceFree;
+}
 
-       // return blocksize x blocks available
-       return uint64_t(fsdata.f_frsize) * uint64_t(fsdata.f_bfree);
+uint64_t ArchHooks_Unix::GetDiskSpaceTotal( const CString &sDir )
+{
+       uint64_t iSpaceTotal = 0;
+       GetDiskSpace( sDir, NULL, &iSpaceTotal );
+       return iSpaceTotal;
 }
 
 bool ArchHooks_Unix::OpenMemoryRange( unsigned short start_port, unsigned short bytes )
 {
        LOG->Trace( "ArchHooks_Unix::OpenMemoryRange( %#x, %d )", start_port, bytes );
 
-/* XXX: this does not work at all for the MK3 driver. Why not? */
-#if 0
-       if( (start_port+bytes) <= 0x3FF )
-       {
-               int ret = ioperm( start_port, bytes, 1 );
-
-               if( ret != 0 )
-                       LOG->Warn( "OpenMemoryRange(): ioperm error: %s", strerror(errno) );
-
-               return (ret == 0);
-       }
-
-       LOG->Warn( "ArchHooks_Unix::OpenMemoryRange(): address range extends past ioperm, using iopl." );
-#endif
-
        int ret = iopl(3);
 
        if( ret != 0 )
@@ -183,9 +176,10 @@ bool ArchHooks_Unix::GetNetworkAddress( CString &sIP, CString &sNetmask, CString
                sIP = inet_ntoa(((struct sockaddr_in *)sad)->sin_addr);
                sNetmask = inet_ntoa(((struct sockaddr_in *)snm)->sin_addr);
        }
+
        freeifaddrs(ifaces);
 
-       if( sIP.empty() || sNetmask.empty() )
+       if( sIP.empty() && sNetmask.empty() )
        {
                sError = "Networking interface disabled";
                return false;
index 00e0d15..a7f658f 100755 (executable)
@@ -17,8 +17,8 @@ public:
        void BoostThreadPriority();
        void UnBoostThreadPriority();
 
-       uint64_t GetDiskSpaceTotal( const CString &sPath );
-       uint64_t GetDiskSpaceFree( const CString &sPath );
+       uint64_t GetDiskSpaceTotal( const CString &sDir );
+       uint64_t GetDiskSpaceFree( const CString &sDir );
 
        bool OpenMemoryRange( unsigned short start_port, unsigned short bytes );
        void CloseMemoryRange( unsigned short start_port, unsigned short bytes );
index 28bf320..051b9ef 100755 (executable)
@@ -223,9 +223,24 @@ uint64_t ArchHooks_Win32::GetDiskSpaceTotal( const CString &sPath )
        return 0;
 }
 
-uint64_t ArchHooks_Win32::GetDiskSpaceFree( const CString &sPath )
+static void GetDiskSpace( const CString &sDir, uint64_t *pSpaceFree, uint64_t *pSpaceTotal )
 {
-       return 0;
+       if( ::GetDiskSpaceFreeEx( sDir.c_str(), pSpaceFree, pSpaceTotal, NULL ) != 0 )
+               LOG->Warn( werr_ssprintf(GetLastError(), "GetDiskSpace() failed") );
+}              
+
+uint64_t ArchHooks_Win32::GetDiskSpaceFree( const CString &sDir )
+{
+       uint64_t iDiskSpaceFree;
+       GetDiskSpace( sDir, &iDiskSpaceFree, NULL );
+       return iDiskSpaceFree;
+}
+
+uint64_t ArchHooks_Win32::GetDiskSpaceTotal( const CString &sDir )
+{
+       uint64_t iDiskSpaceTotal;
+       GetDiskSpace( sDir, NULL, &iDiskSpaceTotal );
+       return iDiskSpaceTotal;
 }
 
 bool ArchHooks_Win32::OpenMemoryRange( unsigned short start_port, unsigned short bytes )
index 32ffe1c..e8dd91d 100755 (executable)
@@ -16,8 +16,8 @@ public:
        void RestartProgram();
        void SystemReboot( bool bForceSync = true );
 
-       uint64_t GetDiskSpaceTotal( const CString &sPath );
-       uint64_t GetDiskSpaceFree( const CString &sPath );
+       uint64_t GetDiskSpaceTotal( const CString &sDir );
+       uint64_t GetDiskSpaceFree( const CString &sDir );
 
        int OldThreadPriority;
        RageMutex *TimeCritMutex;
index dd2c92c..e76c460 100644 (file)
@@ -1,6 +1,7 @@
 #include "global.h"
 #include "io/G15.h"
 #include "RageLog.h"
+#include "RageUtil.h"
 
 void PixmapToLCDData( const unsigned char *pData, unsigned char *pLCD )
 {
@@ -21,12 +22,24 @@ void PixmapToLCDData( const unsigned char *pData, unsigned char *pLCD )
        }
 }
 
-/* right now, only supports G15 V2 keyboards */
+struct ID
+{
+       int VID, PID;
+};
+
+const ID DeviceIDs[2] =
+{
+       { 0x046D, 0xC227 },
+       { 0x046D, 0xC251 },
+};
+
 bool G15::Matches( int idVendor, int idProduct ) const
 {
-       if ( idVendor != 0x046d ) return false;
-       if ( idProduct != 0xc227 ) return false;
-       return true;
+       for( unsigned i = 0; i < ARRAYSIZE(DeviceIDs); ++i )
+               if( idVendor == DeviceIDs[i].VID && idProduct == DeviceIDs[i].PID )
+                       return true;
+
+       return false;
 }
 
 bool G15::WriteLCD( unsigned char *pData )