00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Library.h"
00026 #include "LibraryFolders.h"
00027 #include "LibraryBuilder.h"
00028 #include "CollectionFile.h"
00029 #include "SharedFile.h"
00030 #include "WndLibrary.h"
00031 #include "SharedFolder.h"
00032
00033 #ifdef _DEBUG
00034 #define new DEBUG_NEW
00035 #undef THIS_FILE
00036 static char THIS_FILE[] = __FILE__;
00037 #endif
00038
00039 IMPLEMENT_SERIAL(CLibraryWnd, CPanelWnd, 0)
00040
00041 BEGIN_MESSAGE_MAP(CLibraryWnd, CPanelWnd)
00042
00043 ON_WM_CREATE()
00044 ON_WM_DESTROY()
00045 ON_WM_SIZE()
00046 ON_WM_MDIACTIVATE()
00047 ON_WM_TIMER()
00048
00049 END_MESSAGE_MAP()
00050
00051
00052
00054
00055
00056 CLibraryWnd::CLibraryWnd() : CPanelWnd( TRUE, FALSE )
00057 {
00058 Create( IDR_LIBRARYFRAME );
00059 }
00060
00061 CLibraryWnd::~CLibraryWnd()
00062 {
00063 }
00064
00066
00067
00068 BOOL CLibraryWnd::Display(CLibraryFile* pFile)
00069 {
00070 return m_wndFrame.Display( pFile );
00071 }
00072
00073 BOOL CLibraryWnd::Display(CAlbumFolder* pFolder)
00074 {
00075 return m_wndFrame.Display( pFolder );
00076 }
00077
00079
00080
00081 int CLibraryWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00082 {
00083 if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00084
00085 m_tLast = 0;
00086
00087 m_wndFrame.Create( this );
00088
00089 LoadState();
00090
00091 return 0;
00092 }
00093
00094 void CLibraryWnd::OnDestroy()
00095 {
00096 SaveState();
00097 CPanelWnd::OnDestroy();
00098 }
00099
00100 BOOL CLibraryWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00101 {
00102 if ( m_wndFrame.m_hWnd )
00103 {
00104 if ( m_wndFrame.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00105 }
00106
00107 return CPanelWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00108 }
00109
00110 void CLibraryWnd::OnSize(UINT nType, int cx, int cy)
00111 {
00112 CPanelWnd::OnSize( nType, cx, cy );
00113 if ( m_wndFrame.m_hWnd ) m_wndFrame.SetWindowPos( NULL, 0, 0, cx, cy, SWP_NOZORDER );
00114 }
00115
00116 void CLibraryWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
00117 {
00118 CPanelWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
00119
00120 if ( bActivate )
00121 {
00122 m_wndFrame.Update();
00123 m_wndFrame.SetFocus();
00124 }
00125 }
00126
00127 void CLibraryWnd::OnTimer(UINT nIDEvent)
00128 {
00129 DWORD tNow = GetTickCount();
00130
00131 if ( nIDEvent == 1 )
00132 {
00133 if ( IsPartiallyVisible() )
00134 {
00135 CWaitCursor pCursor;
00136 m_wndFrame.Update( FALSE );
00137 m_tLast = tNow;
00138 }
00139 }
00140 else if ( tNow - m_tLast > 30000 )
00141 {
00142 m_wndFrame.Update( FALSE );
00143 m_tLast = tNow;
00144 }
00145 }
00146
00147 void CLibraryWnd::OnSkinChange()
00148 {
00149 CPanelWnd::OnSkinChange();
00150 m_wndFrame.OnSkinChange();
00151 }
00152
00154
00155
00156 HRESULT CLibraryWnd::GetGenericView(IGenericView** ppView)
00157 {
00158 if ( m_wndFrame.m_hWnd == NULL ) return S_FALSE;
00159 CLibraryList* pList = m_wndFrame.GetViewSelection();
00160 *ppView = (IGenericView*)pList->GetInterface( IID_IGenericView, TRUE );
00161 return S_OK;
00162 }
00163
00164 BOOL CLibraryWnd::OnCollection(LPCTSTR pszPath)
00165 {
00166 CAlbumFolder* pFolder = NULL;
00167 CString strFormat, strMessage;
00168 CCollectionFile pCollection;
00169 CLibraryFolder* pLibFolder;
00170
00171 if ( pCollection.Open( pszPath ) )
00172 {
00173
00174
00175 CreateDirectory( Settings.Downloads.CollectionPath, NULL );
00176
00177 pLibFolder = LibraryFolders.AddFolder( Settings.Downloads.CollectionPath );
00178
00179 pLibFolder = LibraryFolders.GetFolder( Settings.Downloads.CollectionPath );
00180 if( pLibFolder != NULL ) pLibFolder->Scan();
00181
00182 CSingleLock oLock( &Library.m_pSection, TRUE );
00183 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( pszPath, FALSE, TRUE ) )
00184 {
00185
00186
00187 LibraryFolders.MountCollection( &pFile->m_pSHA1, &pCollection );
00188 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00189 oLock.Unlock();
00190 }
00191 else
00192 {
00193 oLock.Unlock();
00194
00195 CString strSource( pszPath ), strTarget;
00196
00197 int nName = strSource.ReverseFind( '\\' );
00198 if ( nName >= 0 )
00199 {
00200 strTarget = Settings.Downloads.CollectionPath + strSource.Mid( nName );
00201 LibraryBuilder.RequestPriority( strTarget );
00202 }
00203
00204 oLock.Lock();
00205 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, FALSE, TRUE ) )
00206 {
00207
00208
00209 LibraryFolders.MountCollection( &pFile->m_pSHA1, &pCollection );
00210 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00211 oLock.Unlock();
00212 }
00213 else
00214 {
00215 oLock.Unlock();
00216
00217 if ( strTarget.GetLength() > 0 && CopyFile( strSource, strTarget, TRUE ) )
00218 {
00219
00220
00221 if( pLibFolder != NULL ) pLibFolder->Scan();
00222
00223 LoadString( strFormat, IDS_LIBRARY_COLLECTION_INSTALLED );
00224 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle() );
00225 AfxMessageBox( strMessage, MB_ICONINFORMATION );
00226 oLock.Lock();
00227 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, FALSE, TRUE ) )
00228 {
00229 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00230 }
00231 oLock.Unlock();
00232 }
00233 else
00234 {
00235 if( GetLastError() == ERROR_FILE_EXISTS )
00236 {
00237
00238
00239
00240
00241
00242
00243
00244 LoadString( strFormat, IDS_LIBRARY_COLLECTION_INSTALLED );
00245 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle() );
00246 AfxMessageBox( strMessage , MB_ICONINFORMATION );
00247
00248 oLock.Lock();
00249 if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( strTarget, FALSE, TRUE ) )
00250 {
00251
00252 LibraryFolders.MountCollection( &pFile->m_pSHA1, &pCollection );
00253 pFolder = LibraryFolders.GetCollection( &pFile->m_pSHA1 );
00254 oLock.Unlock();
00255 }
00256 else
00257 {
00258
00259 oLock.Unlock();
00260 LoadString( strFormat, IDS_LIBRARY_COLLECTION_CANT_INSTALL );
00261 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle(), (LPCTSTR)Settings.Downloads.CollectionPath );
00262 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00263 }
00264 }
00265 else
00266 {
00267 LoadString( strFormat, IDS_LIBRARY_COLLECTION_CANT_INSTALL );
00268 strMessage.Format( strFormat, (LPCTSTR)pCollection.GetTitle(), (LPCTSTR)Settings.Downloads.CollectionPath );
00269 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00270 }
00271 }
00272 }
00273 }
00274 }
00275 else
00276 {
00277 LoadString( strFormat, IDS_LIBRARY_COLLECTION_INVALID );
00278 strMessage.Format( strFormat, pszPath );
00279 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00280 }
00281
00282 if ( pFolder != NULL ) Display( pFolder );
00283 return ( pFolder != NULL );
00284 }
00285
00286
00287
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354