fix file extracting

fix preferences reading
This commit is contained in:
Chris Danford
2006-01-24 07:26:27 +00:00
parent 044a0d6208
commit 1424fe42a1
2 changed files with 78 additions and 76 deletions
+65 -51
View File
@@ -17,6 +17,7 @@
#include "RageFileDriverZip.h" #include "RageFileDriverZip.h"
#include "archutils/Win32/DialogUtil.h" #include "archutils/Win32/DialogUtil.h"
#include "LocalizedString.h" #include "LocalizedString.h"
#include "RageLog.h"
#ifdef _DEBUG #ifdef _DEBUG
#define new DEBUG_NEW #define new DEBUG_NEW
@@ -91,14 +92,14 @@ BOOL CSMPackageInstallDlg::OnInitDialog()
if( !file.Open(m_sPackagePath) ) if( !file.Open(m_sPackagePath) )
{ {
MessageBox( ssprintf(COULD_NOT_OPEN_FILE.GetValue(),m_sPackagePath.c_str()) ); MessageBox( ssprintf(COULD_NOT_OPEN_FILE.GetValue(),m_sPackagePath.c_str()) );
return FALSE; exit(1); // better way to abort?
} }
RageFileDriverZip zip; RageFileDriverZip zip;
if( zip.Load(&file) ); if( !zip.Load(&file) )
{ {
MessageBox( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(),m_sPackagePath.c_str()) ); MessageBox( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(),m_sPackagePath.c_str()) );
return FALSE; exit(1); // better way to abort?
} }
// //
@@ -110,7 +111,7 @@ BOOL CSMPackageInstallDlg::OnInitDialog()
"\t%s\r\n" "\t%s\r\n"
"\r\n" + "\r\n" +
THIS_PACKAGE_CONTAINS.GetValue()+"\r\n", THIS_PACKAGE_CONTAINS.GetValue()+"\r\n",
m_sPackagePath m_sPackagePath.c_str()
); );
CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE1); CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE1);
pEdit1->SetWindowText( sMessage1 ); pEdit1->SetWindowText( sMessage1 );
@@ -121,7 +122,7 @@ BOOL CSMPackageInstallDlg::OnInitDialog()
// //
{ {
vector<RString> vs; vector<RString> vs;
GetDirListingRecursive( &zip, "", "*", vs ); GetDirListingRecursive( &zip, "/", "*", vs );
CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2); CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2);
RString sText = "\t" + join( "\r\n\t", vs ); RString sText = "\t" + join( "\r\n\t", vs );
pEdit2->SetWindowText( sText ); pEdit2->SetWindowText( sText );
@@ -242,10 +243,12 @@ static bool CheckPackages( RageFileDriverZip &fileDriver )
return true; return true;
} }
static LocalizedString NO_INSTALLATIONS ("CSMPackageInstallDlg", "No Installations found. Exiting."); static LocalizedString NO_INSTALLATIONS ("CSMPackageInstallDlg", "No Installations found. Exiting.");
static LocalizedString INSTALLING_PLEASE_WAIT ("CSMPackageInstallDlg", "Installing '%s'. Please wait..."); static LocalizedString INSTALLING_PLEASE_WAIT ("CSMPackageInstallDlg", "Installing '%s'. Please wait...");
static LocalizedString ERROR_COPYING_FILE ("CSMPackageInstallDlg", "Error copying file '%s'"); static LocalizedString ERROR_OPENING_SOURCE_FILE ("CSMPackageInstallDlg", "Error opening source file '%s': %s");
static LocalizedString PACKAGE_INSTALLED_SUCCESSFULLY ("CSMPackageInstallDlg","Package installed successfully!"); static LocalizedString ERROR_OPENING_DESTINATION_FILE ("CSMPackageInstallDlg", "Error opening destination file '%s': %s");
static LocalizedString ERROR_COPYING_FILE ("CSMPackageInstallDlg", "Error copying file '%s': %s");
static LocalizedString PACKAGE_INSTALLED_SUCCESSFULLY ("CSMPackageInstallDlg","Package installed successfully!");
void CSMPackageInstallDlg::OnOK() void CSMPackageInstallDlg::OnOK()
{ {
// TODO: Add extra validation here // TODO: Add extra validation here
@@ -274,18 +277,23 @@ void CSMPackageInstallDlg::OnOK()
// mount the zip // mount the zip
RageFileDriverZip fileDriver; RageFileOsAbsolute file;
int iErr; if( !file.Open(m_sPackagePath) )
if( !fileDriver.Open(m_sPackagePath, RageFile::READ, iErr) )
{ {
AfxMessageBox( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(), m_sPackagePath), MB_ICONSTOP ); MessageBox( ssprintf(COULD_NOT_OPEN_FILE.GetValue(),m_sPackagePath.c_str()) );
exit( 1 ); exit(1); // better way to abort?
} }
RageFileDriverZip zip;
if( !zip.Load(&file) )
{
MessageBox( ssprintf(IS_NOT_A_VALID_ZIP.GetValue(),m_sPackagePath.c_str()) );
exit(1); // better way to abort?
}
// Show comment (if any) // Show comment (if any)
{ {
RString sComment = fileDriver.GetGlobalComment(); RString sComment = zip.GetGlobalComment();
bool DontShowComment; bool DontShowComment;
if( sComment != "" && (!SMPackageUtil::GetPref("DontShowComment", DontShowComment) || !DontShowComment) ) if( sComment != "" && (!SMPackageUtil::GetPref("DontShowComment", DontShowComment) || !DontShowComment) )
{ {
@@ -300,18 +308,18 @@ void CSMPackageInstallDlg::OnOK()
} }
/* Check for installed packages that should be deleted before installing. */ /* Check for installed packages that should be deleted before installing. */
if( !CheckPackages(fileDriver) ) if( !CheckPackages(zip) )
return; // cancelled return; // cancelled
// Unzip the SMzip package into the installation folder // Unzip the SMzip package into the installation folder
vector<RString> vs; vector<RString> vs;
GetDirListingRecursive( &fileDriver, "/", "*", vs ); GetDirListingRecursive( &zip, "/", "*", vs );
for( unsigned i=0; i<vs.size(); i++ ) for( unsigned i=0; i<vs.size(); i++ )
{ {
// Throw some text up so the user has something to look at during the long pause. // Throw some text up so the user has something to look at during the long pause.
CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE1); CEdit* pEdit1 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE1);
pEdit1->SetWindowText( ssprintf(INSTALLING_PLEASE_WAIT.GetValue(), m_sPackagePath) ); pEdit1->SetWindowText( ssprintf(INSTALLING_PLEASE_WAIT.GetValue(), m_sPackagePath.c_str()) );
CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2); CEdit* pEdit2 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE2);
pEdit2->SetWindowText( "" ); pEdit2->SetWindowText( "" );
CEdit* pEdit3 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE3); CEdit* pEdit3 = (CEdit*)GetDlgItem(IDC_EDIT_MESSAGE3);
@@ -337,49 +345,55 @@ retry_unzip:
// Extract the files // Extract the files
const RString sFile = vs[i]; const RString sFile = vs[i];
LOG->Trace( "Extracting: "+sFile );
// skip extracting "thumbs.db" files // skip extracting "thumbs.db" files
if( Basename(sFile).CompareNoCase("thumbs.db") == 0 ) if( Basename(sFile).CompareNoCase("thumbs.db") == 0 )
continue; continue;
bool bSuccess = true;
RString sError; RString sError;
int iErr;
RageFileBasic *pFileFrom = fileDriver.Open( sFile, RageFile::READ, iErr );
if( pFileFrom == NULL )
{ {
bSuccess = false; int iErr;
} RageFileBasic *pFileFrom = zip.Open( sFile, RageFile::READ, iErr );
if( pFileFrom == NULL )
RageFile fileTo;
if( !fileTo.Open(sFile, RageFile::WRITE) )
{
bSuccess = false;
sError = fileTo.GetError();
}
if( bSuccess )
{
bSuccess = FileCopy(*pFileFrom, fileTo, sError);
}
if( !bSuccess )
{
RString sError = ssprintf( ERROR_COPYING_FILE.GetValue(), sFile.c_str() );
switch( MessageBox( sError, NULL, MB_ABORTRETRYIGNORE|MB_ICONEXCLAMATION ) )
{ {
case IDABORT: sError = ssprintf( ERROR_OPENING_SOURCE_FILE.GetValue(), sFile.c_str(), ssprintf("%d",iErr).c_str() );
exit(1); goto show_error;
break; }
case IDRETRY:
goto retry_unzip; RageFile fileTo;
break; if( !fileTo.Open(sFile, RageFile::WRITE) )
case IDIGNORE: {
// do nothing sError = ssprintf( ERROR_OPENING_DESTINATION_FILE.GetValue(), sFile.c_str(), fileTo.GetError().c_str() );
break; goto show_error;
}
RString sErr;
if( !FileCopy(*pFileFrom, fileTo, sErr) )
{
sError = ssprintf( ERROR_COPYING_FILE.GetValue(), sFile.c_str(), sErr.c_str() );
goto show_error;
} }
} }
goto done_with_file;
show_error:
switch( MessageBox( sError, NULL, MB_ABORTRETRYIGNORE|MB_ICONEXCLAMATION ) )
{
case IDABORT:
exit(1); // better way to exit?
break;
case IDRETRY:
goto retry_unzip;
break;
case IDIGNORE:
// do nothing
break;
}
done_with_file:
pProgress1->StepIt(); //increase the progress bar of 1 step pProgress1->StepIt(); //increase the progress bar of 1 step
} }
+13 -25
View File
@@ -73,13 +73,19 @@ BOOL CSmpackageApp::InitInstance()
IniFile ini; IniFile ini;
RString sLanguage; RString sLanguage;
bool bPseudoLocalize = false; bool bPseudoLocalize = false;
bool bShowLogOutput = false;
bool bLogToDisk = false;
if( ini.ReadFile(SpecialFiles::PREFERENCES_INI_PATH) ) if( ini.ReadFile(SpecialFiles::PREFERENCES_INI_PATH) )
{ {
ini.GetValue( "Preferences", "Language", sLanguage ); ini.GetValue( "Options", "Language", sLanguage );
ini.GetValue( "PseudoLocalize", "Language", bPseudoLocalize ); ini.GetValue( "Options", "PseudoLocalize", bPseudoLocalize );
ini.GetValue( "Options", "ShowLogOutput", bShowLogOutput );
ini.GetValue( "Options", "LogToDisk", bLogToDisk );
} }
THEME->SwitchThemeAndLanguage( SpecialFiles::BASE_THEME_NAME, sLanguage, bPseudoLocalize ); THEME->SwitchThemeAndLanguage( SpecialFiles::BASE_THEME_NAME, sLanguage, bPseudoLocalize );
LOG->SetShowLogOutput( bShowLogOutput );
LOG->SetLogToDisk( bLogToDisk );
LOG->SetInfoToDisk( true );
// check for --machine-profile-stats and launch Stats.xml // check for --machine-profile-stats and launch Stats.xml
@@ -92,7 +98,7 @@ BOOL CSmpackageApp::InitInstance()
RString sFile = sPersonalDir + PRODUCT_ID +"/Save/MachineProfile/Stats.xml"; RString sFile = sPersonalDir + PRODUCT_ID +"/Save/MachineProfile/Stats.xml";
if( NULL == ::ShellExecute( NULL, "open", sFile, "", "", SW_SHOWNORMAL ) ) if( NULL == ::ShellExecute( NULL, "open", sFile, "", "", SW_SHOWNORMAL ) )
AfxMessageBox( ssprintf(FAILED_TO_OPEN.GetValue(),sFile.c_str(),GetLastErrorString().c_str()) ); AfxMessageBox( ssprintf(FAILED_TO_OPEN.GetValue(),sFile.c_str(),GetLastErrorString().c_str()) );
goto command_line_handled; exit(1); // better way to quit?
} }
} }
@@ -106,30 +112,13 @@ BOOL CSmpackageApp::InitInstance()
sPathLower.MakeLower(); sPathLower.MakeLower();
// test to see if this is a smzip file // test to see if this is a smzip file
if( sPathLower.Right(3) == "zip" ) if( sPathLower.Right(3).CompareNoCase("zip")==0 )
{ {
if( !SMPackageUtil::DoesOsAbsoluteFileExist(sPath) )
{
AfxMessageBox( ssprintf(THE_FILE_DOES_NOT_EXIST.GetValue(),sPath.c_str()), MB_ICONERROR );
goto command_line_handled;
}
// We found a zip package. Prompt the user to install it! // We found a zip package. Prompt the user to install it!
CSMPackageInstallDlg dlg( sPath ); CSMPackageInstallDlg dlg( sPath );
int nResponse = dlg.DoModal(); int nResponse = dlg.DoModal();
if( nResponse == IDOK ) if( nResponse == IDCANCEL )
{ exit(1); // better way to exit?
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.
goto command_line_handled;
}
else if (nResponse == IDCANCEL)
{
// the user cancelled. Don't fall through to the Manager.
goto command_line_handled;
}
} }
} }
@@ -137,7 +126,6 @@ BOOL CSmpackageApp::InitInstance()
MainMenuDlg dlg; MainMenuDlg dlg;
int nResponse = dlg.DoModal(); int nResponse = dlg.DoModal();
} }
command_line_handled:
SAFE_DELETE( THEME ); SAFE_DELETE( THEME );
SAFE_DELETE( LUA ); SAFE_DELETE( LUA );