// SmpackageExportDlg.cpp : implementation file #define CO_EXIST_WITH_MFC #include "global.h" #include "stdafx.h" #include "smpackage.h" #include "SmpackageExportDlg.h" #include "RageUtil.h" #include "ZipArchive\ZipArchive.h" #include "EnterName.h" #include "EnterComment.h" #include "smpackageUtil.h" #include "EditInsallations.h" #include "IniFile.h" #include "RageFileDriverMemory.h" #include "archutils/Win32/SpecialDirs.h" #include "archutils/Win32/DialogUtil.h" #include "LocalizedString.h" #include "RageFileDriverDirect.h" #include "arch/Dialog/Dialog.h" #include #include #include #include ".\smpackageexportdlg.h" using namespace std; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSmpackageExportDlg dialog CSmpackageExportDlg::CSmpackageExportDlg(CWnd* pParent /*=NULL*/) : CDialog(CSmpackageExportDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSmpackageExportDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CSmpackageExportDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSmpackageExportDlg) DDX_Control(pDX, IDC_COMBO_DIR, m_comboDir); DDX_Control(pDX, IDC_BUTTON_EXPORT_AS_INDIVIDUAL, m_buttonExportAsIndividual); DDX_Control(pDX, IDC_BUTTON_EXPORT_AS_ONE, m_buttonExportAsOne); DDX_Control(pDX, IDC_TREE, m_tree); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSmpackageExportDlg, CDialog) //{{AFX_MSG_MAP(CSmpackageExportDlg) ON_BN_CLICKED(IDC_BUTTON_EXPORT_AS_ONE, OnButtonExportAsOne) ON_BN_CLICKED(IDC_BUTTON_EXPORT_AS_INDIVIDUAL, OnButtonExportAsIndividual) ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay) ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit) ON_CBN_SELCHANGE(IDC_COMBO_DIR, OnSelchangeComboDir) ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen) //}}AFX_MSG_MAP ON_WM_CTLCOLOR() END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSmpackageExportDlg message handlers BOOL CSmpackageExportDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here DialogUtil::LocalizeDialogAndContents( *this ); RefreshInstallationList(); RefreshTree(); return TRUE; // return TRUE unless you set the focus to a control } RString ReplaceInvalidFileNameChars( RString sOldFileName ) { RString sNewFileName = sOldFileName; const char charsToReplace[] = { ' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=', '[', ']', '{', '}', '|', ':', '\"', '\\', '<', '>', ',', '?', '/' }; for( int i=0; i& asDirectoriesToExport, const RString &sComment ) { CZipArchive zip; // // Create the package zip file // const RString sPackagePath = SpecialDirs::GetDesktopDir() + sPackageName; try { zip.Open( sPackagePath, CZipArchive::zipCreate ); } catch( CException* e ) { e->ReportError(); zip.Close(); e->Delete(); return false; } zip.SetGlobalComment( sComment ); /* Find files to add to zip. */ vector asFilePaths; { RageFileDriverDirect fileDriver( sSourceInstallDir ); for( unsigned i=0; i Directories; for( unsigned i=0; i::const_iterator it; int num = 0; for( it = Directories.begin(); it != Directories.end(); ++it ) ini.SetValue( "Packages", ssprintf("%i", num++), *it ); ini.SetValue( "Packages", "NumPackages", num ); RageFileObjMem f; ini.WriteFile( f ); RString buf = f.GetString(); CZipMemFile control; control.Write( buf.GetBuffer(0), buf.size() ); control.Seek( 0, CZipAbstractFile::begin ); zip.AddNewFile( control, "smzip.ctl" ); } // // Add files to zip // for( unsigned j=0; jDelete(); return false; } } zip.Close(); return true; } bool CSmpackageExportDlg::MakeComment( RString &comment ) { bool DontAskForComment; if( SMPackageUtil::GetPref("DontAskForComment", DontAskForComment) && DontAskForComment ) { comment = ""; return true; } EnterComment commentDlg; int nResponse = commentDlg.DoModal(); if( nResponse != IDOK ) return false; // cancelled comment = commentDlg.m_sEnteredComment; if( commentDlg.m_bDontAsk ) SMPackageUtil::SetPref( "DontAskForComment", true ); return true; } static LocalizedString NO_ITEMS_ARE_CHECKED ( "CSmpackageExportDlg", "No items are checked." ); static LocalizedString SUCCESSFULLY_EXPORTED( "CSmpackageExportDlg", "Successfully exported package '%s' to your Desktop." ); void CSmpackageExportDlg::OnButtonExportAsOne() { vector asPaths; GetCheckedPaths( asPaths ); if( asPaths.size() == 0 ) { Dialog::OK( NO_ITEMS_ARE_CHECKED.GetValue() ); return; } else if( asPaths.size() == 1 ) { OnButtonExportAsIndividual(); return; } // Generate a package name RString sPackageName; EnterName nameDlg; int nResponse = nameDlg.DoModal(); if( nResponse != IDOK ) return; // cancelled sPackageName = nameDlg.m_sEnteredName; sPackageName = ReplaceInvalidFileNameChars( sPackageName+".smzip" ); // Generate a comment RString sComment; if( !MakeComment(sComment) ) return; // cancelled if( ExportPackage( sPackageName, GetCurrentInstallDir(), asPaths, sComment ) ) Dialog::OK( ssprintf(SUCCESSFULLY_EXPORTED.GetValue(),sPackageName.c_str()) ); } static LocalizedString THE_FOLLOWING_PACKAGES_WERE_EXPORTED ("CSmpackageExportDlg","The following packages were exported to your Desktop:"); static LocalizedString THE_FOLLOWING_PACKAGES_FAILED ("CSmpackageExportDlg","The following packages failed to export:"); void CSmpackageExportDlg::OnButtonExportAsIndividual() { vector asPaths; GetCheckedPaths( asPaths ); if( asPaths.size() == 0 ) { Dialog::OK( NO_ITEMS_ARE_CHECKED.GetValue() ); return; } // Generate a comment RString sComment; if( !MakeComment(sComment) ) return; // cancelled vector asExportedPackages; vector asFailedPackages; for( unsigned i=0; i asPathsToExport; asPathsToExport.push_back( sPath ); if( ExportPackage( sPackageName, GetCurrentInstallDir(), asPathsToExport, sComment ) ) asExportedPackages.push_back( sPackageName ); else asFailedPackages.push_back( sPackageName ); } RString sMessage; if( asExportedPackages.size() > 0 ) sMessage += THE_FOLLOWING_PACKAGES_WERE_EXPORTED.GetValue()+"\n\n"+join( "\n", asExportedPackages ); if( asFailedPackages.size() > 0 ) { if( !sMessage.empty() ) sMessage += "\n\n"; sMessage += THE_FOLLOWING_PACKAGES_FAILED.GetValue()+"\n\n"+join( "\n", asFailedPackages ); } Dialog::OK( sMessage ); } void CSmpackageExportDlg::OnButtonPlay() { // TODO: Add your control notification handler code here SMPackageUtil::LaunchGame(); exit(0); } void CSmpackageExportDlg::GetTreeItems( CArray& aItemsOut ) { CArray aRootsToExplore; // add all top-level roots HTREEITEM item = m_tree.GetRootItem(); while( item != NULL ) { aRootsToExplore.Add( item ); item = m_tree.GetNextSiblingItem( item ); } while( aRootsToExplore.GetSize() > 0 ) { HTREEITEM item = aRootsToExplore[0]; aRootsToExplore.RemoveAt( 0 ); aItemsOut.Add( item ); HTREEITEM child = m_tree.GetChildItem( item ); while( child != NULL ) { aRootsToExplore.Add( child ); child = m_tree.GetNextSiblingItem( child ); } } } void CSmpackageExportDlg::GetCheckedTreeItems( CArray& aCheckedItemsOut ) { CArray aItems; GetTreeItems( aItems ); for( int i=0; i& aPathsOut ) { CArray aItems; GetCheckedTreeItems( aItems ); for( int i=0; i asInstallDirs; SMPackageUtil::GetGameInstallDirs( asInstallDirs ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Announcers" ); fileDriver.GetDirListing( "Announcers/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Characters" ); fileDriver.GetDirListing( "Characters/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "Themes" ); fileDriver.GetDirListing( "Themes/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "BGAnimations" ); fileDriver.GetDirListing( "BGAnimations/*", as1, true, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "RandomMovies" ); fileDriver.GetDirListing( "RandomMovies/*.ogv", 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" ); fileDriver.GetDirListing( "Visualizations/*.ogv", 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" ); fileDriver.GetDirListing( "Courses/*.crs", as1, false, false ); for( unsigned i=0; i as1; HTREEITEM item1 = m_tree.InsertItem( "NoteSkins" ); fileDriver.GetDirListing( "NoteSkins/*", as1, true, false ); for( unsigned i=0; i as2; HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 ); fileDriver.GetDirListing( "NoteSkins/" + as1[i] + "/*", as2, true, false ); for( unsigned j=0; j as1; HTREEITEM item1 = m_tree.InsertItem( "Songs" ); fileDriver.GetDirListing( "Songs/*", as1, true, false ); for( unsigned i=0; i as2; HTREEITEM item2 = m_tree.InsertItem( as1[i], item1 ); fileDriver.GetDirListing( "Songs/" + as1[i] + "/*", as2, true, false ); for( unsigned j=0; j aItems; GetTreeItems( aItems ); for( int i=0; i