diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2008-08-13 04:00:00 +0400 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:15:56 +0300 |
commit | 173c07e166fdf6fcd20f18ea73008f1b628945df (patch) | |
tree | 13ebea85cdc4c16ae93714ff0627ee9f91ad7e08 /CPP/7zip/UI/FileManager/RootFolder.cpp | |
parent | 3901bf0ab88106a5b031cba7bc18d60cdebf7eef (diff) |
4.59 beta
Diffstat (limited to 'CPP/7zip/UI/FileManager/RootFolder.cpp')
-rwxr-xr-x | CPP/7zip/UI/FileManager/RootFolder.cpp | 113 |
1 files changed, 81 insertions, 32 deletions
diff --git a/CPP/7zip/UI/FileManager/RootFolder.cpp b/CPP/7zip/UI/FileManager/RootFolder.cpp index 5c8e0e28..3f3c67ef 100755 --- a/CPP/7zip/UI/FileManager/RootFolder.cpp +++ b/CPP/7zip/UI/FileManager/RootFolder.cpp @@ -20,7 +20,7 @@ using namespace NWindows; -static const STATPROPSTG kProperties[] = +static const STATPROPSTG kProperties[] = { { NULL, kpidName, VT_BSTR} }; @@ -28,10 +28,33 @@ static const STATPROPSTG kProperties[] = // static const wchar_t *kMyComputerTitle = L"Computer"; // static const wchar_t *kMyNetworkTitle = L"Network"; -void CRootFolder::Init() +UString RootFolder_GetName_Computer(int &iconIndex) { - _computerName = LangString(IDS_COMPUTER, 0x03020300); - _networkName = LangString(IDS_NETWORK, 0x03020301); + iconIndex = GetIconIndexForCSIDL(CSIDL_DRIVES); + return LangString(IDS_COMPUTER, 0x03020300); +} + +UString RootFolder_GetName_Network(int &iconIndex) +{ + iconIndex = GetIconIndexForCSIDL(CSIDL_NETWORK); + return LangString(IDS_NETWORK, 0x03020301); +} + +UString RootFolder_GetName_Documents(int &iconIndex) +{ + iconIndex = GetIconIndexForCSIDL(CSIDL_PERSONAL); + return LangString(IDS_DOCUMENTS, 0x03020302); ; +} + +const int ROOT_INDEX_COMPUTER = 0; +const int ROOT_INDEX_DOCUMENTS = 1; +const int ROOT_INDEX_NETWORK = 2; + +void CRootFolder::Init() +{ + _names[ROOT_INDEX_COMPUTER] = RootFolder_GetName_Computer(_iconIndices[ROOT_INDEX_COMPUTER]); + _names[ROOT_INDEX_DOCUMENTS] = RootFolder_GetName_Documents(_iconIndices[ROOT_INDEX_DOCUMENTS]); + _names[ROOT_INDEX_NETWORK] = RootFolder_GetName_Network(_iconIndices[ROOT_INDEX_NETWORK]); }; STDMETHODIMP CRootFolder::LoadItems() @@ -42,50 +65,78 @@ STDMETHODIMP CRootFolder::LoadItems() STDMETHODIMP CRootFolder::GetNumberOfItems(UInt32 *numItems) { - *numItems = 2; + *numItems = kNumRootFolderItems; return S_OK; } STDMETHODIMP CRootFolder::GetProperty(UInt32 itemIndex, PROPID propID, PROPVARIANT *value) { - NCOM::CPropVariant propVariant; + NCOM::CPropVariant prop; switch(propID) { - case kpidIsFolder: - propVariant = true; - break; - case kpidName: - if (itemIndex == 0) - propVariant = _computerName; - else if (itemIndex == 1) - propVariant = _networkName; - break; + case kpidIsDir: prop = true; break; + case kpidName: prop = _names[itemIndex]; break; } - propVariant.Detach(value); + prop.Detach(value); return S_OK; } +UString GetMyDocsPath() +{ + UString us; + WCHAR s[MAX_PATH + 1]; + if (SHGetSpecialFolderPathW(0, s, CSIDL_PERSONAL, FALSE)) + us = s; + #ifndef _UNICODE + else + { + CHAR s2[MAX_PATH + 1]; + if (SHGetSpecialFolderPathA(0, s2, CSIDL_PERSONAL, FALSE)) + us = GetUnicodeString(s2); + } + #endif + if (us.Length() > 0 && us[us.Length() - 1] != L'\\') + us += L'\\'; + return us; +} + STDMETHODIMP CRootFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder) { - if (index == 0) + if (index == ROOT_INDEX_COMPUTER) { CFSDrives *fsDrivesSpec = new CFSDrives; CMyComPtr<IFolderFolder> subFolder = fsDrivesSpec; fsDrivesSpec->Init(); *resultFolder = subFolder.Detach(); } - else if (index == 1) + else if (index == ROOT_INDEX_NETWORK) { CNetFolder *netFolderSpec = new CNetFolder; CMyComPtr<IFolderFolder> subFolder = netFolderSpec; - netFolderSpec->Init(0, 0, _networkName + L'\\'); + netFolderSpec->Init(0, 0, _names[ROOT_INDEX_NETWORK] + L'\\'); *resultFolder = subFolder.Detach(); } + else if (index == ROOT_INDEX_DOCUMENTS) + { + UString s = GetMyDocsPath(); + if (!s.IsEmpty()) + { + NFsFolder::CFSFolder *fsFolderSpec = new NFsFolder::CFSFolder; + CMyComPtr<IFolderFolder> subFolder = fsFolderSpec; + RINOK(fsFolderSpec->Init(s, NULL)); + *resultFolder = subFolder.Detach(); + } + } else return E_INVALIDARG; return S_OK; } +static bool AreEqualNames(const UString &name1, const UString &name2) +{ + return (name1 == name2 || name1 == (name2 + UString(L'\\'))); +} + STDMETHODIMP CRootFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder) { *resultFolder = 0; @@ -99,12 +150,15 @@ STDMETHODIMP CRootFolder::BindToFolder(const wchar_t *name, IFolderFolder **resu *resultFolder = rootFolder.Detach(); return S_OK; } - if (name2 == _computerName || - name2 == (_computerName + UString(L'\\'))) - return BindToFolder(UInt32(0), resultFolder); - if (name2 == _networkName || - name2 == (_networkName + UString(L'\\'))) - return BindToFolder(UInt32(1), resultFolder); + for (int i = 0; i < kNumRootFolderItems; i++) + if (AreEqualNames(name2, _names[i])) + return BindToFolder((UInt32)i, resultFolder); + if (AreEqualNames(name2, L"My Documents") || + AreEqualNames(name2, L"Documents")) + return BindToFolder((UInt32)ROOT_INDEX_DOCUMENTS, resultFolder); + if (AreEqualNames(name2, L"My Computer") || + AreEqualNames(name2, L"Computer")) + return BindToFolder((UInt32)ROOT_INDEX_COMPUTER, resultFolder); if (name2 == UString(L'\\')) { CMyComPtr<IFolderFolder> subFolder = this; @@ -157,7 +211,7 @@ STDMETHODIMP CRootFolder::GetNumberOfProperties(UInt32 *numProperties) return S_OK; } -STDMETHODIMP CRootFolder::GetPropertyInfo(UInt32 index, +STDMETHODIMP CRootFolder::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) { if (index >= sizeof(kProperties) / sizeof(kProperties[0])) @@ -183,12 +237,7 @@ STDMETHODIMP CRootFolder::GetFolderProperty(PROPID propID, PROPVARIANT *value) STDMETHODIMP CRootFolder::GetSystemIconIndex(UInt32 index, INT32 *iconIndex) { - int aCSIDL; - if (index == 0) - aCSIDL = CSIDL_DRIVES; - else - aCSIDL = CSIDL_NETWORK; - *iconIndex = GetIconIndexForCSIDL(aCSIDL); + *iconIndex = _iconIndices[index]; return S_OK; } |