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 "WizardSheet.h"
00026 #include "WizardSharePage.h"
00027 #include "Library.h"
00028 #include "LibraryFolders.h"
00029 #include "SharedFolder.h"
00030 #include "DlgFolderScan.h"
00031 #include "ShellIcons.h"
00032 #include "Skin.h"
00033 #include "DlgHelp.h"
00034
00035 #ifdef _DEBUG
00036 #define new DEBUG_NEW
00037 #undef THIS_FILE
00038 static char THIS_FILE[] = __FILE__;
00039 #endif
00040
00041 IMPLEMENT_DYNCREATE(CWizardSharePage, CWizardPage)
00042
00043 BEGIN_MESSAGE_MAP(CWizardSharePage, CWizardPage)
00044
00045 ON_NOTIFY(LVN_ITEMCHANGED, IDC_SHARE_FOLDERS, OnItemChangedShareFolders)
00046 ON_BN_CLICKED(IDC_SHARE_ADD, OnShareAdd)
00047 ON_BN_CLICKED(IDC_SHARE_REMOVE, OnShareRemove)
00048
00049 END_MESSAGE_MAP()
00050
00051
00053
00054
00055 CWizardSharePage::CWizardSharePage() : CWizardPage(CWizardSharePage::IDD)
00056 {
00057
00058
00059 }
00060
00061 CWizardSharePage::~CWizardSharePage()
00062 {
00063 }
00064
00065 void CWizardSharePage::DoDataExchange(CDataExchange* pDX)
00066 {
00067 CPropertyPage::DoDataExchange(pDX);
00068
00069 DDX_Control(pDX, IDC_SHARE_FOLDERS, m_wndList);
00070 DDX_Control(pDX, IDC_SHARE_REMOVE, m_wndRemove);
00071
00072 }
00073
00075
00076
00077 BOOL CWizardSharePage::OnInitDialog()
00078 {
00079 CPropertyPage::OnInitDialog();
00080
00081 Skin.Apply( _T("CWizardSharePage"), this );
00082
00083 CBitmap bmBase;
00084 bmBase.LoadBitmap( IDB_FOLDERS );
00085
00086 CRect rc;
00087 m_wndList.GetClientRect( &rc );
00088 m_wndList.InsertColumn( 0, _T("Folder"), LVCFMT_LEFT, rc.Width() - GetSystemMetrics( SM_CXVSCROLL ) );
00089 m_wndList.SetImageList( ShellIcons.GetObject( 16 ), LVSIL_SMALL );
00090 m_wndList.EnableToolTips( TRUE );
00091
00092 {
00093 CQuickLock oLock( Library.m_pSection );
00094
00095 for ( POSITION pos = LibraryFolders.GetFolderIterator() ; pos ; )
00096 {
00097 CLibraryFolder* pFolder = LibraryFolders.GetNextFolder( pos );
00098
00099 m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, m_wndList.GetItemCount(),
00100 pFolder->m_sPath, 0, 0, SHI_FOLDER_OPEN, 0 );
00101 }
00102
00103 CreateDirectory( Settings.Downloads.CompletePath, NULL );
00104 AddPhysicalFolder( Settings.Downloads.CompletePath );
00105
00106 CreateDirectory( Settings.Downloads.CollectionPath, NULL );
00107 AddPhysicalFolder( Settings.Downloads.CollectionPath );
00108
00109 AddPhysicalFolder( _T("C:\\Program Files\\Piolet\\My Shared Folder") );
00110 AddPhysicalFolder( _T("C:\\Program Files\\eMule\\Incoming") );
00111 AddPhysicalFolder( _T("C:\\Program Files\\eDonkey2000\\incoming") );
00112 AddPhysicalFolder( _T("C:\\Program Files\\Ares\\My Shared Folder") );
00113 AddPhysicalFolder( _T("C:\\Program Files\\morpheus\\My Shared Folder") );
00114
00115
00116 AddRegistryFolder( HKEY_CURRENT_USER, _T("Software\\Kazaa\\Transfer"), _T("DlDir0") );
00117 AddRegistryFolder( HKEY_CURRENT_USER, _T("Software\\Xolox"), _T("completedir") );
00118 AddRegistryFolder( HKEY_CURRENT_USER, _T("Software\\Xolox"), _T("sharedir") );
00119 }
00120
00121 return TRUE;
00122 }
00123
00124 BOOL CWizardSharePage::OnSetActive()
00125 {
00126 SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
00127 return CWizardPage::OnSetActive();
00128 }
00129
00130 void CWizardSharePage::AddPhysicalFolder(LPCTSTR pszFolder)
00131 {
00132 DWORD nFlags = GetFileAttributes( pszFolder );
00133
00134 if ( nFlags == 0xFFFFFFFF ) return;
00135 if ( ( nFlags & FILE_ATTRIBUTE_DIRECTORY ) == 0 ) return;
00136
00137 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00138 {
00139 if ( m_wndList.GetItemText( nItem, 0 ).CompareNoCase( pszFolder ) == 0 ) return;
00140 }
00141
00142 m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, m_wndList.GetItemCount(),
00143 pszFolder, 0, 0, SHI_FOLDER_OPEN, 0 );
00144 }
00145
00146 void CWizardSharePage::AddRegistryFolder(HKEY hRoot, LPCTSTR pszKey, LPCTSTR pszValue)
00147 {
00148 TCHAR szFolder[MAX_PATH];
00149 DWORD dwType, dwFolder;
00150 HKEY hKey = NULL;
00151
00152 if ( RegOpenKeyEx( hRoot, pszKey, 0, KEY_READ, &hKey ) != ERROR_SUCCESS ) return;
00153
00154 dwType = REG_SZ;
00155 dwFolder = MAX_PATH - 1;
00156
00157 if ( RegQueryValueEx( hKey, pszValue, NULL, &dwType, (LPBYTE)szFolder, &dwFolder )
00158 != ERROR_SUCCESS || dwType != REG_SZ )
00159 {
00160 RegCloseKey( hKey );
00161 return;
00162 }
00163
00164 RegCloseKey( hKey );
00165
00166 szFolder[ dwFolder ] = 0;
00167
00168 AddPhysicalFolder( szFolder );
00169 }
00170
00171 void CWizardSharePage::OnItemChangedShareFolders(NMHDR* pNMHDR, LRESULT* pResult)
00172 {
00173 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
00174 m_wndRemove.EnableWindow( m_wndList.GetSelectedCount() > 0 );
00175 *pResult = 0;
00176 }
00177
00178 void CWizardSharePage::OnShareAdd()
00179 {
00180
00181 TCHAR szPath[MAX_PATH];
00182 LPITEMIDLIST pPath;
00183 LPMALLOC pMalloc;
00184 BROWSEINFO pBI;
00185
00186 ZeroMemory( &pBI, sizeof(pBI) );
00187 pBI.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
00188 pBI.pszDisplayName = szPath;
00189 pBI.lpszTitle = _T("Select folder to share:");
00190 pBI.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
00191
00192 pPath = SHBrowseForFolder( &pBI );
00193
00194 if ( pPath == NULL ) return;
00195
00196 SHGetPathFromIDList( pPath, szPath );
00197 SHGetMalloc( &pMalloc );
00198 pMalloc->Free( pPath );
00199
00200 CString strPathLC( szPath );
00201 CharLower( strPathLC.GetBuffer() );
00202 strPathLC.ReleaseBuffer();
00203
00204
00205
00206 CString strWindowsLC, strProgramsLC;
00207 PTSTR pszWindowsPath, pszProgramsPath;
00208
00209 pszWindowsPath = strWindowsLC.GetBuffer( MAX_PATH + 1 );
00210 pszProgramsPath = strProgramsLC.GetBuffer( MAX_PATH + 1 );
00211
00212 if ( HINSTANCE hShell = LoadLibrary( _T("shfolder.dll") ) )
00213 {
00214 HRESULT (WINAPI *pfnSHGetFolderPath)(HWND, int, HANDLE, DWORD, LPWSTR);
00215 (FARPROC&)pfnSHGetFolderPath = GetProcAddress( hShell, "SHGetFolderPathW" );
00216 if ( pfnSHGetFolderPath != NULL )
00217 {
00218 (*pfnSHGetFolderPath)(NULL, CSIDL_WINDOWS, NULL, NULL, pszWindowsPath);
00219 (*pfnSHGetFolderPath)(NULL, CSIDL_PROGRAM_FILES, NULL, NULL, pszProgramsPath);
00220 }
00221 FreeLibrary( hShell );
00222 }
00223 CharLower( pszWindowsPath );
00224 CharLower( pszProgramsPath );
00225
00226 strWindowsLC.ReleaseBuffer();
00227 strProgramsLC.ReleaseBuffer();
00228
00229 if ( strWindowsLC.IsEmpty() ) strWindowsLC = _T("c:\\windows");
00230 if ( strProgramsLC.IsEmpty() ) strProgramsLC = _T("c:\\program files");
00231
00232
00233
00234 CString strIncompletePathLC = Settings.Downloads.IncompletePath;
00235 CharLower( strIncompletePathLC.GetBuffer() );
00236 strIncompletePathLC.ReleaseBuffer();
00237
00238 CString strGeneralPathLC = Settings.General.Path;
00239 CharLower( strGeneralPathLC.GetBuffer() );
00240 strGeneralPathLC.ReleaseBuffer();
00241
00242 CString strUserPathLC = Settings.General.UserPath;
00243 CharLower( strUserPathLC.GetBuffer() );
00244 strUserPathLC.ReleaseBuffer();
00245
00246
00247
00248 if ( strPathLC == _T( "" ) ||
00249 strPathLC == strWindowsLC.Left( 3 ) ||
00250 strPathLC == strProgramsLC ||
00251 strPathLC == strWindowsLC ||
00252 strPathLC == strGeneralPathLC ||
00253 strPathLC == strGeneralPathLC + _T("\\data") ||
00254 strPathLC == strUserPathLC ||
00255 strPathLC == strUserPathLC + _T("\\data") ||
00256 strPathLC == strIncompletePathLC )
00257 {
00258 CHelpDlg::Show( _T("ShareHelp.BadShare") );
00259 return;
00260 }
00261
00262 BOOL bForceAdd = FALSE;
00263
00264 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00265 {
00266 BOOL bSubFolder = FALSE;
00267 CString strOldLC( m_wndList.GetItemText( nItem, 0 ) );
00268 CharLower( strOldLC.GetBuffer() );
00269 strOldLC.ReleaseBuffer();
00270
00271 if ( strPathLC == strOldLC )
00272 {
00273
00274 }
00275 else if ( strPathLC.GetLength() > strOldLC.GetLength() )
00276 {
00277 if ( strPathLC.Left( strOldLC.GetLength() + 1 ) != strOldLC + '\\' )
00278 continue;
00279 }
00280 else if ( strPathLC.GetLength() < strOldLC.GetLength() )
00281 {
00282 bSubFolder = TRUE;
00283 if ( strOldLC.Left( strPathLC.GetLength() + 1 ) != strPathLC + '\\' )
00284 continue;
00285 }
00286 else
00287 {
00288 continue;
00289 }
00290
00291 if ( bSubFolder )
00292 {
00293 CString strFormat, strMessage;
00294 LoadString( strFormat, IDS_LIBRARY_SUBFOLDER_IN_LIBRARY );
00295 strMessage.Format( strFormat, (LPCTSTR)szPath );
00296
00297 if ( bForceAdd || AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDYES )
00298 {
00299
00300 bForceAdd = TRUE;
00301
00302 m_wndList.DeleteItem( nItem );
00303 nItem--;
00304 }
00305 else
00306 {
00307 return;
00308 }
00309 }
00310 else
00311 {
00312 CString strFormat, strMessage;
00313 Skin.LoadString( strFormat, IDS_WIZARD_SHARE_ALREADY );
00314 strMessage.Format( strFormat, (LPCTSTR)strOldLC );
00315 AfxMessageBox( strMessage, MB_ICONINFORMATION );
00316
00317 return;
00318 }
00319 }
00320
00321
00322 m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, m_wndList.GetItemCount(),
00323 szPath, 0, 0, SHI_FOLDER_OPEN, 0 );
00324 }
00325
00326 void CWizardSharePage::OnShareRemove()
00327 {
00328 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00329 {
00330 if ( m_wndList.GetItemState( nItem, LVIS_SELECTED ) )
00331 {
00332 m_wndList.DeleteItem( nItem-- );
00333 }
00334 }
00335 }
00336
00337 LRESULT CWizardSharePage::OnWizardNext()
00338 {
00339 CWaitCursor pCursor;
00340
00341 if ( m_wndList.GetItemCount() == 0 )
00342 {
00343 CString strMessage;
00344 Skin.LoadString( strMessage, IDS_WIZARD_SHARE_CONFIRM );
00345 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) == IDNO )
00346 return -1;
00347 }
00348
00349 {
00350 CQuickLock oLock( Library.m_pSection );
00351
00352 for ( POSITION pos = LibraryFolders.GetFolderIterator() ; pos ; )
00353 {
00354 CLibraryFolder* pFolder = LibraryFolders.GetNextFolder( pos );
00355
00356 int nItem = 0;
00357 for ( ; nItem < m_wndList.GetItemCount() ; nItem++ )
00358 {
00359 CString strFolder = m_wndList.GetItemText( nItem, 0 );
00360 if ( strFolder.CompareNoCase( pFolder->m_sPath ) == 0 ) break;
00361 }
00362
00363 if ( nItem >= m_wndList.GetItemCount() )
00364 {
00365 LibraryFolders.RemoveFolder( pFolder );
00366 }
00367 }
00368
00369 for ( int nItem = 0 ; nItem < m_wndList.GetItemCount() ; nItem++ )
00370 {
00371 LibraryFolders.AddFolder( m_wndList.GetItemText( nItem, 0 ) );
00372 }
00373 }
00374
00375 CFolderScanDlg dlgScan;
00376 dlgScan.DoModal();
00377
00378 return 0;
00379 }