diff --git a/stepmania/Themes/default/Languages/en.ini b/stepmania/Themes/default/Languages/en.ini index 58f06a01bb..7378d686ba 100644 --- a/stepmania/Themes/default/Languages/en.ini +++ b/stepmania/Themes/default/Languages/en.ini @@ -64,6 +64,7 @@ Medium=STANDARD [EditInstallations] You must type a program directory before clicking Add.=You must type a program directory before clicking Add. +'%s' is not a valid installation directory.='%s' is not a valid installation directory. [EditMenuAction] Create=Create New @@ -142,6 +143,7 @@ Failed to delete file '%s'.=Failed to delete file '%s'. Failed to open '%s': %s=Failed to open '%s': %s Music file=Music file Success. Created the song '%s'=Success. Created the song '%s' +The song directory '%s' already exists. You cannot override an existing song.=The song directory '%s' already exists. You cannot override an existing song. [MenuButton] Coin=Coin @@ -1444,4 +1446,17 @@ StepMania Tools Main Menu=StepMania Tools Main Menu Troubleshooting=Troubleshooting [ChangeGameSettings] -Error writing file '%s': %s=Error writing file '%s': %s \ No newline at end of file +Error writing file '%s': %s=Error writing file '%s': %s + +[Tools-Name Your Package] +Name Your Package=Name Your Package +Enter a name for your new package:=Enter a name for your new package: +OK=OK +Cancel=Cancel +Note: leave off the ".smzip" extention=Note: leave off the ".smzip" extention + +[Tools-StepMania Tools] +Finish >=Finish > +Cancel=Cancel +< Back=< Back +Install a package=Install a package \ No newline at end of file diff --git a/stepmania/src/ProductInfo.h b/stepmania/src/ProductInfo.h index 7cad8023e3..06345a9936 100644 --- a/stepmania/src/ProductInfo.h +++ b/stepmania/src/ProductInfo.h @@ -25,6 +25,8 @@ #define VIDEO_TROUBLESHOOTING_URL "http://www.stepmania.com/stepmania/mediawiki.php?title=Video_Driver_Troubleshooting" #define REPORT_BUG_URL "http://sourceforge.net/tracker/?func=add&group_id=37892&atid=421366" +#define CAN_INSTALL_PACKAGES true + #endif /* diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index efa9052315..a1f4f0e0d9 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -871,6 +871,23 @@ void GetDirListingRecursive( const RString &sDir, const RString &sMatch, vector< } } +void GetDirListingRecursive( RageFileDriver *prfd, const RString &sDir, const RString &sMatch, vector &AddTo ) +{ + ASSERT( sDir.Right(1) == "/" ); + prfd->GetDirListing( sDir+sMatch, AddTo, false, true ); + prfd->GetDirListing( sDir+"*", AddTo, true, true ); + for( unsigned i=0; iGetFileType(AddTo[i]) == RageFileManager::TYPE_DIR ) + { + prfd->GetDirListing( AddTo[i]+"/"+sMatch, AddTo, false, true ); + prfd->GetDirListing( AddTo[i]+"/*", AddTo, true, true ); + AddTo.erase( AddTo.begin()+i ); + i--; + } + } +} + bool DeleteRecursive( const RString &sDir ) { ASSERT( sDir.Right(1) == "/" ); diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index a67573bcdc..7d4ca68a1e 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -1839,7 +1839,7 @@ void FileWrite( RageFileBasic& f, float fWrite ) f.PutLine( ssprintf("%f", fWrite) ); } -bool FileCopy( RString sSrcFile, RString sDstFile ) +bool FileCopy( const RString &sSrcFile, const RString &sDstFile ) { if( !sSrcFile.CompareNoCase(sDstFile) ) { diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index ec4a73f7a9..b2c3024ec0 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -6,6 +6,7 @@ #include #include #include "Foreach.h" +class RageFileDriver; #define SAFE_DELETE(p) { delete (p); (p)=NULL; } #define SAFE_DELETE_ARRAY(p) { delete[] (p); (p)=NULL; } @@ -435,6 +436,7 @@ typedef basic_string istring; * declared here since they're used in many places. */ void GetDirListing( const RString &sPath, vector &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false ); void GetDirListingRecursive( const RString &sDir, const RString &sMatch, vector &AddTo ); /* returns path too */ +void GetDirListingRecursive( RageFileDriver *prfd, const RString &sDir, const RString &sMatch, vector &AddTo ); /* returns path too */ bool DeleteRecursive( const RString &sDir ); /* delete the dir and all files/subdirs inside it */ bool DoesFileExist( const RString &sPath ); bool IsAFile( const RString &sPath ); @@ -470,7 +472,7 @@ void FileWrite( RageFileBasic& f, int iWrite ); void FileWrite( RageFileBasic& f, size_t uWrite ); void FileWrite( RageFileBasic& f, float fWrite ); -bool FileCopy( RString sSrcFile, RString sDstFile ); +bool FileCopy( const RString &sSrcFile, const RString &sDstFile ); bool FileCopy( RageFileBasic &in, RageFileBasic &out, RString &sError, bool *bReadError = NULL ); template diff --git a/stepmania/src/archutils/Win32/RegistryAccess.cpp b/stepmania/src/archutils/Win32/RegistryAccess.cpp index 00f3424a85..cf8819b5e6 100644 --- a/stepmania/src/archutils/Win32/RegistryAccess.cpp +++ b/stepmania/src/archutils/Win32/RegistryAccess.cpp @@ -36,7 +36,8 @@ static bool GetRegKeyType( const RString &sIn, RString &sOut, HKEY &key ) /* Given a full key, eg. "HKEY_LOCAL_MACHINE\hardware\foo", open it and return it. * On error, return NULL. */ -static HKEY OpenRegKey( const RString &sKey, bool bWarnOnError = true ) +enum RegKeyMode { READ, WRITE }; +static HKEY OpenRegKey( const RString &sKey, RegKeyMode mode, bool bWarnOnError = true ) { RString sSubkey; HKEY hType; @@ -44,7 +45,7 @@ static HKEY OpenRegKey( const RString &sKey, bool bWarnOnError = true ) return NULL; HKEY hRetKey; - LONG retval = RegOpenKeyEx( hType, sSubkey, 0, KEY_READ, &hRetKey ); + LONG retval = RegOpenKeyEx( hType, sSubkey, 0, (mode==READ) ? KEY_READ:KEY_WRITE, &hRetKey ); if ( retval != ERROR_SUCCESS ) { if( bWarnOnError ) @@ -57,7 +58,7 @@ static HKEY OpenRegKey( const RString &sKey, bool bWarnOnError = true ) bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, RString &sVal ) { - HKEY hKey = OpenRegKey( sKey ); + HKEY hKey = OpenRegKey( sKey, READ ); if( hKey == NULL ) return false; @@ -83,7 +84,7 @@ bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, RSt bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, int &iVal, bool bWarnOnError ) { - HKEY hKey = OpenRegKey( sKey, bWarnOnError ); + HKEY hKey = OpenRegKey( sKey, READ, bWarnOnError ); if( hKey == NULL ) return false; @@ -112,7 +113,7 @@ bool RegistryAccess::GetRegValue( const RString &sKey, const RString &sName, boo bool RegistryAccess::GetRegSubKeys( const RString &sKey, vector &lst, const RString ®ex, bool bReturnPathToo ) { - HKEY hKey = OpenRegKey( sKey ); + HKEY hKey = OpenRegKey( sKey, READ ); if( hKey == NULL ) return false; @@ -152,7 +153,7 @@ bool RegistryAccess::GetRegSubKeys( const RString &sKey, vector &lst, c bool RegistryAccess::SetRegValue( const RString &sKey, const RString &sName, const RString &sVal ) { - HKEY hKey = OpenRegKey( sKey ); + HKEY hKey = OpenRegKey( sKey, WRITE ); if( hKey == NULL ) return false; @@ -164,9 +165,8 @@ bool RegistryAccess::SetRegValue( const RString &sKey, const RString &sName, con strcpy( sz, sVal.c_str() ); - if (::RegSetValueEx(hKey, LPCTSTR(sName), 0, - REG_SZ, (LPBYTE)sz, strlen(sz) + 1) - != ERROR_SUCCESS) + LONG lResult = ::RegSetValueEx(hKey, LPCTSTR(sName), 0, REG_SZ, (LPBYTE)sz, strlen(sz) + 1); + if( lResult != ERROR_SUCCESS ) bSuccess = false; ::RegCloseKey(hKey); @@ -175,7 +175,7 @@ bool RegistryAccess::SetRegValue( const RString &sKey, const RString &sName, con bool RegistryAccess::SetRegValue( const RString &sKey, const RString &sName, bool bVal ) { - HKEY hKey = OpenRegKey( sKey ); + HKEY hKey = OpenRegKey( sKey, WRITE ); if( hKey == NULL ) return false; diff --git a/stepmania/src/smpackage/EditInsallations.cpp b/stepmania/src/smpackage/EditInsallations.cpp index 5993644dff..42a182d4f3 100644 --- a/stepmania/src/smpackage/EditInsallations.cpp +++ b/stepmania/src/smpackage/EditInsallations.cpp @@ -10,6 +10,7 @@ #include "archutils/Win32/DialogUtil.h" #include ".\editinsallations.h" #include "LocalizedString.h" +#include "RageUtil.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -64,12 +65,10 @@ BOOL EditInsallations::OnInitDialog() for( unsigned i=0; i vs; for( int i=0; i m_vsReturnedInstallDirs; - // Dialog Data //{{AFX_DATA(EditInsallations) enum { IDD = IDD_EDIT_INSTALLATIONS }; diff --git a/stepmania/src/smpackage/MainMenuDlg.cpp b/stepmania/src/smpackage/MainMenuDlg.cpp index c3e81cb1ad..84b3fe71ec 100644 --- a/stepmania/src/smpackage/MainMenuDlg.cpp +++ b/stepmania/src/smpackage/MainMenuDlg.cpp @@ -20,6 +20,7 @@ #include ".\mainmenudlg.h" #include "archutils/Win32/DialogUtil.h" #include "LocalizedString.h" +#include "RageFileManager.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -107,12 +108,11 @@ RString GetLastErrorString() return s; } -static LocalizedString MUSIC_FILE ( "MainMenuDlg", "Music file" ); -static LocalizedString FAILED_TO_CREATE_DIRECTORY ( "MainMenuDlg", "Failed to create directory '%s': %s" ); -static LocalizedString FAILED_TO_CREATE_SONG_DIRECTORY ( "MainMenuDlg", "Failed to create song directory '%s': %s" ); +static LocalizedString MUSIC_FILE ( "MainMenuDlg", "Music file" ); +static LocalizedString THE_SONG_DIRECTORY_ALREADY_EXISTS ( "MainMenuDlg", "The song directory '%s' already exists. You cannot override an existing song." ); static LocalizedString FAILED_TO_COPY_MUSIC_FILE ( "MainMenuDlg", "Failed to copy music file '%s' to '%s': %s" ); -static LocalizedString FAILED_TO_CREATE_THE_SONG_FILE ( "MainMenuDlg", "Failed to create the song file '%s'" ); -static LocalizedString SUCCESS_CREATED_THE_SONG ( "MainMenuDlg", "Success. Created the song '%s'" ); +static LocalizedString FAILED_TO_CREATE_THE_SONG_FILE ( "MainMenuDlg", "Failed to create the song file '%s'" ); +static LocalizedString SUCCESS_CREATED_THE_SONG ( "MainMenuDlg", "Success. Created the song '%s'" ); void MainMenuDlg::OnCreateSong() { // TODO: Add your control notification handler code here @@ -123,58 +123,44 @@ void MainMenuDlg::OnCreateSong() NULL, // default file extension NULL, // default file name OFN_HIDEREADONLY | OFN_NOCHANGEDIR, // flags - ""//MUSIC_FILE.GetValue()+" (*.mp3;*.ogg)|*.mp3;*.ogg|||" + ConvertUTF8ToACP(MUSIC_FILE.GetValue()+" (*.mp3;*.ogg)|*.mp3;*.ogg|||").c_str() ); int iRet = dialog.DoModal(); RString sMusicFile = dialog.GetPathName(); if( iRet != IDOK ) return; - BOOL bSuccess; + RString sSongDirectory = "Songs/My Creations/" + GetFileNameWithoutExtension(sMusicFile) + "/"; + RString sNewMusicFile = sSongDirectory + Basename(sMusicFile); - RString sSongDirectory = "Songs\\My Creations\\"; - bSuccess = CreateDirectory( sSongDirectory, NULL ); - if( !bSuccess ) + if( DoesFileExist(sSongDirectory) ) { - DWORD dwError = ::GetLastError(); - switch( dwError ) - { - case ERROR_ALREADY_EXISTS: - // This failure is ok. We probably created this directory already while importing another song. - break; - default: - MessageBox( ssprintf(FAILED_TO_CREATE_DIRECTORY.GetValue(),sSongDirectory.c_str(),GetLastErrorString().c_str()) ); - return; - } - } - - sSongDirectory += Basename( sMusicFile ); - bSuccess = CreateDirectory( sSongDirectory, NULL ); // CreateDirectory doesn't like a trailing slash - if( !bSuccess ) - { - MessageBox( ssprintf(FAILED_TO_CREATE_SONG_DIRECTORY.GetValue(),sSongDirectory.c_str(),GetLastErrorString().c_str()) ); + MessageBox( ssprintf(THE_SONG_DIRECTORY_ALREADY_EXISTS.GetValue(),sSongDirectory.c_str()) ); return; } - sSongDirectory += "\\"; - RString sNewMusicFile = sSongDirectory + Basename(sMusicFile); - bSuccess = CopyFile( sMusicFile, sNewMusicFile, TRUE ); + RageFileOsAbsolute fileIn; + fileIn.Open( sMusicFile, RageFile::READ ); + RageFile fileOut; + fileOut.Open( sNewMusicFile, RageFile::WRITE ); + RString sError; + bool bSuccess = FileCopy( fileIn, fileOut, sError ); if( !bSuccess ) { - MessageBox( ssprintf(FAILED_TO_COPY_MUSIC_FILE.GetValue(),sMusicFile.c_str(),sNewMusicFile.c_str(),GetLastErrorString().c_str()) ); + MessageBox( ssprintf(FAILED_TO_COPY_MUSIC_FILE.GetValue(),sMusicFile.c_str(),sNewMusicFile.c_str(),sError.c_str()) ); return; } // create a blank .sm file RString sNewSongFile = sMusicFile; SetExtension( sNewSongFile, "sm" ); - FILE *fp = fopen( sNewSongFile, "w" ); - if( fp == NULL ) + RageFile file; + if( file.Open(sNewSongFile, RageFile::WRITE) ) { MessageBox( ssprintf(FAILED_TO_CREATE_THE_SONG_FILE.GetValue(),sNewSongFile.c_str()) ); return; } - fclose( fp ); + file.Close(); MessageBox( ssprintf(SUCCESS_CREATED_THE_SONG.GetValue(),sSongDirectory.c_str()) ); } @@ -197,8 +183,9 @@ BOOL MainMenuDlg::OnInitDialog() // EXCEPTION: OCX Property Pages should return FALSE } -static LocalizedString FAILED_TO_DELETE_FILE ( "MainMenuDlg", "Failed to delete file '%s'." ); -static LocalizedString IS_ALREADY_CLEARED ( "MainMenuDlg", "'%s' is already cleared." ); +static LocalizedString FAILED_TO_DELETE_FILE ( "MainMenuDlg", "Failed to delete file '%s'." ); +static LocalizedString IS_ALREADY_CLEARED ( "MainMenuDlg", "'%s' is already cleared." ); +static LocalizedString CLEARED( "MainMenuDlg", "'%s' cleared" ); void MainMenuDlg::OnBnClickedClearKeymaps() { // TODO: Add your control notification handler code here @@ -206,12 +193,13 @@ void MainMenuDlg::OnBnClickedClearKeymaps() if( !DoesFileExist( SpecialFiles::KEYMAPS_PATH ) ) { MessageBox( ssprintf(IS_ALREADY_CLEARED.GetValue(),SpecialFiles::KEYMAPS_PATH.c_str()) ); + return; } - else - { - if( !DeleteFile( SpecialFiles::KEYMAPS_PATH ) ) - MessageBox( ssprintf(FAILED_TO_DELETE_FILE.GetValue(), SpecialFiles::KEYMAPS_PATH.c_str()) ); - } + + if( !FILEMAN->Remove(SpecialFiles::KEYMAPS_PATH) ) + MessageBox( ssprintf(FAILED_TO_DELETE_FILE.GetValue(), SpecialFiles::KEYMAPS_PATH.c_str()) ); + + MessageBox( ssprintf(CLEARED.GetValue(),SpecialFiles::PREFERENCES_INI_PATH.c_str()) ); } void MainMenuDlg::OnBnClickedChangePreferences() @@ -237,17 +225,16 @@ void MainMenuDlg::OnBnClickedOpenPreferences() } } -static LocalizedString CLEARED( "MainMenuDlg", "'%s' cleared" ); void MainMenuDlg::OnBnClickedClearPreferences() { // TODO: Add your control notification handler code here - if( !DoesFileExist( SpecialFiles::PREFERENCES_INI_PATH ) ) + if( !DoesFileExist(SpecialFiles::PREFERENCES_INI_PATH) ) { MessageBox( ssprintf(IS_ALREADY_CLEARED.GetValue(),SpecialFiles::PREFERENCES_INI_PATH.c_str()) ); return; } - if( !DeleteFile( SpecialFiles::PREFERENCES_INI_PATH ) ) + if( !FILEMAN->Remove(SpecialFiles::PREFERENCES_INI_PATH) ) { MessageBox( ssprintf(FAILED_TO_DELETE_FILE.GetValue(),SpecialFiles::PREFERENCES_INI_PATH.c_str()) ); return; diff --git a/stepmania/src/smpackage/SMPackageInstallDlg.cpp b/stepmania/src/smpackage/SMPackageInstallDlg.cpp index fef8b68512..c40aa5164f 100644 --- a/stepmania/src/smpackage/SMPackageInstallDlg.cpp +++ b/stepmania/src/smpackage/SMPackageInstallDlg.cpp @@ -24,13 +24,11 @@ static char THIS_FILE[] = __FILE__; #endif -static const RString TEMP_MOUNT_POINT = "/@package/"; - ///////////////////////////////////////////////////////////////////////////// // CSMPackageInstallDlg dialog -CSMPackageInstallDlg::CSMPackageInstallDlg(CString sPackagePath, CWnd* pParent /*=NULL*/) +CSMPackageInstallDlg::CSMPackageInstallDlg(RString sPackagePath, CWnd* pParent /*=NULL*/) : CDialog(CSMPackageInstallDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSMPackageInstallDlg) @@ -87,8 +85,12 @@ BOOL CSMPackageInstallDlg::OnInitDialog() DialogUtil::LocalizeDialogAndContents( *this ); DialogUtil::SetHeaderFont( *this, IDC_STATIC_HEADER_TEXT ); + ASSERT(0); // TEST ME + // mount the zip - if( !FILEMAN->Mount( "zip", m_sPackagePath, TEMP_MOUNT_POINT ) ) + RageFileDriverZip fileDriver; + int iErr; + if( !fileDriver.Open(m_sPackagePath, RageFile::READ, iErr) ) { AfxMessageBox( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(), m_sPackagePath), MB_ICONSTOP ); exit( 1 ); @@ -114,7 +116,7 @@ BOOL CSMPackageInstallDlg::OnInitDialog() // { vector vs; - GetDirListingRecursive( TEMP_MOUNT_POINT, "*.*", vs ); + GetDirListingRecursive( &fileDriver, "", "*", vs ); CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2); RString sText = "\t" + join( "\r\n\t", vs ); pEdit2->SetWindowText( sText ); @@ -169,12 +171,16 @@ void CSMPackageInstallDlg::OnPaint() #include #include ".\smpackageinstalldlg.h" -bool CSMPackageInstallDlg::CheckPackages() +static bool CheckPackages( RageFileDriverZip &fileDriver ) { - IniFile ini; - if( !ini.ReadFile(TEMP_MOUNT_POINT + "smzip.ctl") ) + int iErr; + RageFileBasic *pFile = fileDriver.Open( "smzip.ctl", RageFile::READ, iErr ); + if( pFile == NULL ) return true; + IniFile ini; + ini.ReadFile( *pFile ); + int version = 0; ini.GetValue( "SMZIP", "Version", version ); if( version != 1 ) @@ -221,23 +227,11 @@ bool CSMPackageInstallDlg::CheckPackages() for( i = 0; i < (int) Directories.size(); ++i ) { - RString path = cwd+Directories[i]; - char buf[1024]; - memcpy( buf, path, path.size()+1 ); - buf[path.size()+1] = 0; - - SHFILEOPSTRUCT op; - memset(&op, 0, sizeof(op)); - - op.wFunc = FO_DELETE; - op.pFrom = buf; - op.pTo = NULL; - op.fFlags = FOF_NOCONFIRMATION; - if( !SHFileOperation(&op) ) - continue; - - /* Something failed. SHFileOperation displayed the error dialog, so just cancel. */ - return false; + RString sDir = Directories[i]; + if( !DeleteRecursive(sDir) ) // error deleting + { + return false; + } } return true; @@ -262,7 +256,8 @@ void CSMPackageInstallDlg::OnOK() m_comboDir.GetWindowText( s ); sInstallDir = s; } - + + // selected install dir becomes the new default int iSelectedInstallDirIndex = m_comboDir.GetCurSel(); if( iSelectedInstallDirIndex == -1 ) { @@ -272,11 +267,20 @@ void CSMPackageInstallDlg::OnOK() SMPackageUtil::SetDefaultInstallDir( iSelectedInstallDirIndex ); + + // mount the zip + RageFileDriverZip fileDriver; + int iErr; + if( !fileDriver.Open(m_sPackagePath, RageFile::READ, iErr) ) + { + AfxMessageBox( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(), m_sPackagePath), MB_ICONSTOP ); + exit( 1 ); + } + + // Show comment (if any) { - RageFileDriverZip zip; - zip.Load( m_sPackagePath ); - RString sComment = zip.GetGlobalComment(); + RString sComment = fileDriver.GetGlobalComment(); bool DontShowComment; if( sComment != "" && (!SMPackageUtil::GetPref("DontShowComment", DontShowComment) || !DontShowComment) ) { @@ -291,13 +295,13 @@ void CSMPackageInstallDlg::OnOK() } /* Check for installed packages that should be deleted before installing. */ - if( !CheckPackages() ) + if( !CheckPackages(fileDriver) ) return; // cancelled // Unzip the SMzip package into the installation folder vector vs; - GetDirListingRecursive( TEMP_MOUNT_POINT, "*.*", vs ); + GetDirListingRecursive( &fileDriver, "/", "*", vs ); for( unsigned i=0; i& asInstallDirsTo RString sName = ssprintf("%d",i); RegistryAccess::SetRegValue( INSTALLATIONS_KEY, sName, asInstallDirsToWrite[i] ); } - } void SMPackageUtil::GetGameInstallDirs( vector& asInstallDirsOut ) @@ -41,11 +40,10 @@ void SMPackageUtil::GetGameInstallDirs( vector& asInstallDirsOut ) if( !RegistryAccess::GetRegValue(INSTALLATIONS_KEY, sName, sPath) ) continue; - if( sPath == "" ) // read failed + if( sPath == "" ) // blank entry continue; // skip - RString sProgramDir = sPath+"\\Program"; - if( !DoesFileExist(sProgramDir) ) + if( !IsValidInstallDir(sPath) ) continue; // skip asInstallDirsOut.push_back( sPath ); @@ -55,7 +53,7 @@ void SMPackageUtil::GetGameInstallDirs( vector& asInstallDirsOut ) WriteGameInstallDirs( asInstallDirsOut ); } -void SMPackageUtil::AddGameInstallDir( RString sNewInstallDir ) +void SMPackageUtil::AddGameInstallDir( const RString &sNewInstallDir ) { vector asInstallDirs; GetGameInstallDirs( asInstallDirs ); @@ -88,7 +86,7 @@ void SMPackageUtil::SetDefaultInstallDir( int iInstallDirIndex ) WriteGameInstallDirs( asInstallDirs ); } -void SMPackageUtil::SetDefaultInstallDir( RString sInstallDir ) +void SMPackageUtil::SetDefaultInstallDir( const RString &sInstallDir ) { vector asInstallDirs; GetGameInstallDirs( asInstallDirs ); @@ -103,6 +101,11 @@ void SMPackageUtil::SetDefaultInstallDir( RString sInstallDir ) } } +bool SMPackageUtil::IsValidInstallDir( const RString &sInstallDir ) +{ + return DoesOsAbsoluteFileExist( sInstallDir + "/Songs" ); +} + bool SMPackageUtil::GetPref( const RString &name, bool &val ) { return RegistryAccess::GetRegValue( SMPACKAGE_KEY, name, val ); @@ -115,7 +118,7 @@ bool SMPackageUtil::SetPref( const RString &name, bool val ) /* Get a package directory. For most paths, this is the first two components. For * songs and note skins, this is the first three. */ -RString SMPackageUtil::GetPackageDirectory(RString path) +RString SMPackageUtil::GetPackageDirectory(const RString &path) { if( path.find("CVS") != string::npos ) return ""; // skip @@ -137,7 +140,7 @@ RString SMPackageUtil::GetPackageDirectory(RString path) return ret; } -bool SMPackageUtil::IsValidPackageDirectory( RString path ) +bool SMPackageUtil::IsValidPackageDirectory( const RString &path ) { /* Make sure the path contains only second-level directories, and doesn't * contain any ".", "..", "...", etc. dirs. */ @@ -212,6 +215,15 @@ RString SMPackageUtil::GetLanguageCodeFromDisplayString( const RString &sDisplay return s; } +bool SMPackageUtil::DoesOsAbsoluteFileExist( const RString &sOsAbsoluteFile ) +{ +#if defined(WIN32) + DWORD dwAttr = ::GetFileAttributes( sOsAbsoluteFile ); + return bool(dwAttr != (DWORD)-1); +#endif +} + + static const RString TEMP_MOUNT_POINT = "/@package/"; RageFileOsAbsolute::~RageFileOsAbsolute() diff --git a/stepmania/src/smpackage/SmpackageExportDlg.cpp b/stepmania/src/smpackage/SmpackageExportDlg.cpp index 574d7bf56c..b38ad8142d 100644 --- a/stepmania/src/smpackage/SmpackageExportDlg.cpp +++ b/stepmania/src/smpackage/SmpackageExportDlg.cpp @@ -17,6 +17,7 @@ #include "archutils/Win32/SpecialDirs.h" #include "archutils/Win32/DialogUtil.h" #include "LocalizedString.h" +#include "RageFileDriverDirect.h" #include #include @@ -98,14 +99,14 @@ RString ReplaceInvalidFileNameChars( RString sOldFileName ) } static LocalizedString ERROR_ADDING_FILE ( "SmpackageExportDlg", "Error adding file '%s'." ); -static bool ExportPackage( RString sPackageName, const vector& asDirectoriesToExport, RString sComment ) +static bool ExportPackage( const RString &sPackageName, const RString &sSourceInstallDir, const vector& asDirectoriesToExport, const RString &sComment ) { CZipArchive zip; // // Create the package zip file // - const RString sPackagePath = "Desktop/" + sPackageName; + const RString sPackagePath = SpecialDirs::GetDesktopDir() + sPackageName; try { zip.Open( sPackagePath, CZipArchive::zipCreate ); @@ -118,13 +119,23 @@ static bool ExportPackage( RString sPackageName, const vector& asDirect return false; } - zip.SetGlobalComment( sComment ); + /* Find files to add to zip. */ vector asFilePaths; - for( unsigned i=0; i& asDirect ini.SetValue( "SMZIP", "Version", 1 ); set Directories; - for( i=0; i& asDirect try { - zip.AddNewFile( sFilePath, bUseCompression?Z_BEST_COMPRESSION:Z_NO_COMPRESSION, true ); + zip.AddNewFile( sSourceInstallDir+sFilePath, bUseCompression?Z_BEST_COMPRESSION:Z_NO_COMPRESSION, true ); } catch (CException* e) { @@ -229,7 +240,7 @@ void CSmpackageExportDlg::OnButtonExportAsOne() vector asPaths; GetCheckedPaths( asPaths ); - if( asPaths.size() >= 0 ) + if( asPaths.size() == 0 ) { AfxMessageBox( NO_ITEMS_ARE_CHECKED.GetValue() ); return; @@ -254,7 +265,7 @@ void CSmpackageExportDlg::OnButtonExportAsOne() if( !MakeComment(sComment) ) return; // cancelled - if( ExportPackage( sPackageName, asPaths, sComment ) ) + if( ExportPackage( sPackageName, GetCurrentInstallDir(), asPaths, sComment ) ) AfxMessageBox( ssprintf(SUCCESSFULLY_EXPORTED.GetValue(),sPackageName.c_str()) ); } @@ -285,14 +296,14 @@ void CSmpackageExportDlg::OnButtonExportAsIndividual() RString sPackageName; vector asPathBits; - split( sPath, "\\", asPathBits, true ); + split( sPath, "/", asPathBits, true ); sPackageName = asPathBits[ asPathBits.size()-1 ] + ".smzip"; sPackageName = ReplaceInvalidFileNameChars( sPackageName ); vector asPathsToExport; asPathsToExport.push_back( sPath ); - if( ExportPackage( sPackageName, asPathsToExport, sComment ) ) + if( ExportPackage( sPackageName, GetCurrentInstallDir(), asPathsToExport, sComment ) ) asExportedPackages.push_back( sPackageName ); else asFailedPackages.push_back( sPackageName ); @@ -368,11 +379,11 @@ void CSmpackageExportDlg::GetCheckedPaths( vector& aPathsOut ) while( item ) { - sPath = (LPCTSTR)m_tree.GetItemText(item) + '\\' + sPath; + sPath = RString((LPCTSTR)m_tree.GetItemText(item)) + '/' + sPath; item = m_tree.GetParentItem(item); } - TrimRight( sPath, "\\" ); // strip off last slash + TrimRight( sPath, "/" ); // strip off last slash aPathsOut.push_back( sPath ); } @@ -386,7 +397,6 @@ void CSmpackageExportDlg::OnButtonEdit() int nResponse = dlg.DoModal(); if( nResponse == IDOK ) { - SMPackageUtil::WriteGameInstallDirs( dlg.m_vsReturnedInstallDirs ); RefreshInstallationList(); RefreshTree(); } @@ -411,24 +421,27 @@ void CSmpackageExportDlg::OnSelchangeComboDir() RefreshTree(); } +RString CSmpackageExportDlg::GetCurrentInstallDir() +{ + CString s; + m_comboDir.GetWindowText( s ); + RString s2 = s; + if( s2.Right(1) != "/" ) + s2 += "/"; + return s2; +} + void CSmpackageExportDlg::RefreshTree() { m_tree.DeleteAllItems(); - RString sDir; - { - CString s; - m_comboDir.GetWindowText( s ); - sDir = s; - } - - SetCurrentDirectory( sDir ); + RageFileDriverDirect fileDriver( GetCurrentInstallDir() ); // Add announcers { vector as1; HTREEITEM item1 = m_tree.InsertItem( "Announcers" ); - GetDirListing( "Announcers\\*.*", as1, true, false ); + fileDriver.GetDirListing( "Announcers/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Characters" ); - GetDirListing( "Characters\\*.*", as1, true, false ); + fileDriver.GetDirListing( "Characters/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Themes" ); - GetDirListing( "Themes\\*.*", as1, true, false ); + fileDriver.GetDirListing( "Themes/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "BGAnimations" ); - GetDirListing( "BGAnimations\\*.*", as1, true, false ); + fileDriver.GetDirListing( "BGAnimations/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "RandomMovies" ); - GetDirListing( "RandomMovies\\*.avi", as1, false, false ); - GetDirListing( "RandomMovies\\*.mpg", as1, false, false ); - GetDirListing( "RandomMovies\\*.mpeg", as1, false, false ); + fileDriver.GetDirListing( "RandomMovies/*.avi", as1, false, false ); + fileDriver.GetDirListing( "RandomMovies/*.mpg", as1, false, false ); + fileDriver.GetDirListing( "RandomMovies/*.mpeg", as1, false, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Visualizations" ); - GetDirListing( "Visualizations\\*.avi", as1, false, false ); - GetDirListing( "Visualizations\\*.mpg", as1, false, false ); - GetDirListing( "Visualizations\\*.mpeg", as1, false, false ); + fileDriver.GetDirListing( "Visualizations/*.avi", as1, false, false ); + fileDriver.GetDirListing( "Visualizations/*.mpg", as1, false, false ); + fileDriver.GetDirListing( "Visualizations/*.mpeg", as1, false, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Courses" ); - GetDirListing( "Courses\\*.crs", as1, false, false ); + fileDriver.GetDirListing( "Courses/*.crs", as1, false, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "NoteSkins" ); - GetDirListing( "NoteSkins\\*.*", as1, true, false ); + fileDriver.GetDirListing( "NoteSkins/*", as1, true, false ); for( unsigned i=0; i as2; HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 ); - GetDirListing( "NoteSkins\\" + as1[i] + "\\*.*", as2, true, false ); + fileDriver.GetDirListing( "NoteSkins/" + as1[i] + "/*", as2, true, false ); for( unsigned j=0; j as1; HTREEITEM item1 = m_tree.InsertItem( "Songs" ); - GetDirListing( "Songs\\*.*", as1, true, false ); + fileDriver.GetDirListing( "Songs/*", as1, true, false ); for( unsigned i=0; i as2; HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 ); - GetDirListing( "Songs\\" + as1[i] + "\\*.*", as2, true, false ); + fileDriver.GetDirListing( "Songs/" + as1[i] + "/*", as2, true, false ); for( unsigned j=0; j aItems; GetTreeItems( aItems ); for( int i=0; i& aCheckedItemsOut ); void GetCheckedPaths( vector& aCheckedItemsOut ); bool MakeComment( RString &comment ); + RString GetCurrentInstallDir(); // Generated message map functions //{{AFX_MSG(CSmpackageExportDlg) diff --git a/stepmania/src/smpackage/smpackage.cpp b/stepmania/src/smpackage/smpackage.cpp index 46f573d1d4..5ec93a26d6 100644 --- a/stepmania/src/smpackage/smpackage.cpp +++ b/stepmania/src/smpackage/smpackage.cpp @@ -56,65 +56,13 @@ BOOL CSmpackageApp::InitInstance() LOG = new RageLog(); - if( DoesFileExist("Songs") ) // this is a SM program directory + TCHAR szCurrentDirectory[MAX_PATH]; + GetCurrentDirectory( ARRAYSIZE(szCurrentDirectory), szCurrentDirectory ); + if( CAN_INSTALL_PACKAGES && SMPackageUtil::IsValidInstallDir(szCurrentDirectory) ) { - TCHAR szCurrentDirectory[MAX_PATH]; - GetCurrentDirectory( ARRAYSIZE(szCurrentDirectory), szCurrentDirectory ); SMPackageUtil::AddGameInstallDir( szCurrentDirectory ); // add this if it doesn't already exist } - // check if there's a .smzip command line argument - vector arrayCommandLineBits; - split( ::GetCommandLine(), " ", arrayCommandLineBits ); - for( unsigned i=0; iDoesFileExist(sPath) ) - { - AfxMessageBox( ssprintf(THE_FILE_DOES_NOT_EXIST.GetValue(),sPath.c_str()), MB_ICONERROR ); - exit(0); - } - - // We found a zip package. Prompt the user to install it! - CSMPackageInstallDlg dlg( CString(sPath.c_str()) ); - int nResponse = dlg.DoModal(); - if( nResponse == IDOK ) - { - CSmpackageExportDlg dlg; - int nResponse = dlg.DoModal(); - // Since the dialog has been closed, return FALSE so that we exit the - // application, rather than start the application's message pump. - return FALSE; - } - else if (nResponse == IDCANCEL) - { - // the user cancelled. Don't fall through to the Manager. - exit(0); - } - } - } FILEMAN = new RageFileManager( "" ); LUA = new LuaManager(); @@ -133,11 +81,63 @@ BOOL CSmpackageApp::InitInstance() THEME->SwitchThemeAndLanguage( SpecialFiles::BASE_THEME_NAME, sLanguage, bPseudoLocalize ); - // Show the Manager Dialog - MainMenuDlg dlg; - int nResponse = dlg.DoModal(); -// if (nResponse == IDOK) + // check for --machine-profile-stats and launch Stats.xml + for( int i=0; i& asInstallDirsToWrite ); void GetGameInstallDirs( vector& asInstallDirsOut ); - void AddGameInstallDir( RString sNewInstallDir ); + void AddGameInstallDir( const RString &sNewInstallDir ); void SetDefaultInstallDir( int iInstallDirIndex ); - void SetDefaultInstallDir( RString sInstallDir ); + void SetDefaultInstallDir( const RString &sInstallDir ); + bool IsValidInstallDir( const RString &sInstallDir ); bool GetPref( const RString &name, bool &val ); bool SetPref( const RString &name, bool val ); - RString GetPackageDirectory(RString path); - bool IsValidPackageDirectory(RString path); + RString GetPackageDirectory( const RString &path ); + bool IsValidPackageDirectory( const RString &path ); bool LaunchGame(); @@ -23,6 +24,8 @@ namespace SMPackageUtil RString GetLanguageCodeFromDisplayString( const RString &sDisplayString ); bool GetFileContentsOsAbsolute( const RString &sAbsoluteOsFile, RString &sOut ); + + bool DoesOsAbsoluteFileExist( const RString &sOsAbsoluteFile ); } #include "RageFile.h"