]> git.saurik.com Git - wxWidgets.git/blame - src/msw/volume.cpp
Test using wxString::ToCDouble() in wxAny.
[wxWidgets.git] / src / msw / volume.cpp
CommitLineData
7183fd72
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/volume.cpp
3// Purpose: wxFSVolume - encapsulates system volume information
4// Author: George Policello
5// Modified by:
6// Created: 28 Jan 02
7// RCS-ID: $Id$
8// Copyright: (c) 2002 George Policello
65571936 9// Licence: wxWindows licence
7183fd72
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
7183fd72
VZ
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
05815ab3
VZ
26#if wxUSE_FSVOLUME
27
7212d155
PC
28#include "wx/volume.h"
29
7183fd72 30#ifndef WX_PRECOMP
df5168c4
MB
31 #if wxUSE_GUI
32 #include "wx/icon.h"
33 #endif
05815ab3 34 #include "wx/intl.h"
86e4f8ad 35 #include "wx/log.h"
df69528b 36 #include "wx/hashmap.h"
a368dde5 37 #include "wx/filefn.h"
7183fd72
VZ
38#endif // WX_PRECOMP
39
40#include "wx/dir.h"
7183fd72
VZ
41#include "wx/dynlib.h"
42#include "wx/arrimpl.cpp"
43
8ba51e73
VZ
44// some compilers require including <windows.h> before <shellapi.h> so do it
45// even if this is not necessary with most of them
46#include "wx/msw/wrapwin.h"
eaeeb91e 47#include <shellapi.h>
a6c7a0f8 48#include <shlobj.h>
7212d155 49#include "wx/msw/missing.h"
eaeeb91e 50
ec67cff1 51#if wxUSE_BASE
7cfdeaad 52
7183fd72
VZ
53//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54// Dynamic library function defs.
55//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
64c288fa 57#if wxUSE_DYNLIB_CLASS
7183fd72 58static wxDynamicLibrary s_mprLib;
64c288fa 59#endif
7183fd72
VZ
60
61typedef DWORD (WINAPI* WNetOpenEnumPtr)(DWORD, DWORD, DWORD, LPNETRESOURCE, LPHANDLE);
62typedef DWORD (WINAPI* WNetEnumResourcePtr)(HANDLE, LPDWORD, LPVOID, LPDWORD);
63typedef DWORD (WINAPI* WNetCloseEnumPtr)(HANDLE);
64
65static WNetOpenEnumPtr s_pWNetOpenEnum;
66static WNetEnumResourcePtr s_pWNetEnumResource;
67static WNetCloseEnumPtr s_pWNetCloseEnum;
68
69//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
70// Globals/Statics
71//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
72static long s_cancelSearch = FALSE;
73
17ebae65 74struct FileInfo
7183fd72
VZ
75{
76 FileInfo(unsigned flag=0, wxFSVolumeKind type=wxFS_VOL_OTHER) :
77 m_flags(flag), m_type(type) {}
51fdd3da
VZ
78
79 FileInfo(const FileInfo& other) { *this = other; }
80 FileInfo& operator=(const FileInfo& other)
81 {
82 m_flags = other.m_flags;
83 m_type = other.m_type;
84 return *this;
85 }
86
7183fd72
VZ
87 unsigned m_flags;
88 wxFSVolumeKind m_type;
89};
90WX_DECLARE_STRING_HASH_MAP(FileInfo, FileInfoMap);
17ebae65
MB
91// Cygwin bug (?) destructor for global s_fileInfo is called twice...
92static FileInfoMap& GetFileInfoMap()
93{
94 static FileInfoMap s_fileInfo(25);
95
96 return s_fileInfo;
97}
98#define s_fileInfo (GetFileInfoMap())
7183fd72 99
7183fd72
VZ
100//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
101// Local helper functions.
102//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
103
104//=============================================================================
105// Function: GetBasicFlags
106// Purpose: Set basic flags, primarily wxFS_VOL_REMOTE and wxFS_VOL_REMOVABLE.
107// Notes: - Local and mapped drives are mounted by definition. We have no
108// way to determine mounted status of network drives, so assume that
109// all drives are mounted, and let the caller decide otherwise.
110// - Other flags are 'best guess' from type of drive. The system will
111// not report the file attributes with any degree of accuracy.
112//=============================================================================
4d90b8de 113static unsigned GetBasicFlags(const wxChar* filename)
7183fd72
VZ
114{
115 unsigned flags = wxFS_VOL_MOUNTED;
116
117 //----------------------------------
118 // 'Best Guess' based on drive type.
119 //----------------------------------
120 wxFSVolumeKind type;
121 switch(GetDriveType(filename))
122 {
123 case DRIVE_FIXED:
124 type = wxFS_VOL_DISK;
125 break;
126
127 case DRIVE_REMOVABLE:
128 flags |= wxFS_VOL_REMOVABLE;
129 type = wxFS_VOL_FLOPPY;
130 break;
131
132 case DRIVE_CDROM:
133 flags |= wxFS_VOL_REMOVABLE | wxFS_VOL_READONLY;
134 type = wxFS_VOL_CDROM;
135 break;
136
137 case DRIVE_REMOTE:
138 flags |= wxFS_VOL_REMOTE;
139 type = wxFS_VOL_NETWORK;
140 break;
141
142 case DRIVE_NO_ROOT_DIR:
143 flags &= ~wxFS_VOL_MOUNTED;
144 type = wxFS_VOL_OTHER;
145 break;
146
147 default:
148 type = wxFS_VOL_OTHER;
149 break;
150 }
151
152 //-----------------------------------------------------------------------
90e572f1 153 // The following most likely will not modify anything not set above,
7183fd72
VZ
154 // and will not work at all for network shares or empty CD ROM drives.
155 // But it is a good check if the Win API ever gets better about reporting
156 // this information.
157 //-----------------------------------------------------------------------
158 SHFILEINFO fi;
ab63e6ae 159 long rc = SHGetFileInfo(filename, 0, &fi, sizeof(fi), SHGFI_ATTRIBUTES);
7183fd72
VZ
160 if (!rc)
161 {
ab63e6ae
VZ
162 // this error is not fatal, so don't show a message to the user about
163 // it, otherwise it would appear every time a generic directory picker
164 // dialog is used and there is a connected network drive
9a83f860 165 wxLogLastError(wxT("SHGetFileInfo"));
7183fd72
VZ
166 }
167 else
168 {
169 if (fi.dwAttributes & SFGAO_READONLY)
170 flags |= wxFS_VOL_READONLY;
171 if (fi.dwAttributes & SFGAO_REMOVABLE)
172 flags |= wxFS_VOL_REMOVABLE;
173 }
174
175 //------------------
176 // Flags are cached.
177 //------------------
178 s_fileInfo[filename] = FileInfo(flags, type);
179
180 return flags;
181} // GetBasicFlags
182
183//=============================================================================
184// Function: FilteredAdd
185// Purpose: Add a file to the list if it meets the filter requirement.
186// Notes: - See GetBasicFlags for remarks about the Mounted flag.
187//=============================================================================
27d2dbbc 188static bool FilteredAdd(wxArrayString& list, const wxChar* filename,
4d90b8de 189 unsigned flagsSet, unsigned flagsUnset)
7183fd72 190{
27d2dbbc 191 bool accept = true;
7183fd72
VZ
192 unsigned flags = GetBasicFlags(filename);
193
194 if (flagsSet & wxFS_VOL_MOUNTED && !(flags & wxFS_VOL_MOUNTED))
27d2dbbc 195 accept = false;
7183fd72 196 else if (flagsUnset & wxFS_VOL_MOUNTED && (flags & wxFS_VOL_MOUNTED))
27d2dbbc 197 accept = false;
7183fd72 198 else if (flagsSet & wxFS_VOL_REMOVABLE && !(flags & wxFS_VOL_REMOVABLE))
27d2dbbc 199 accept = false;
7183fd72 200 else if (flagsUnset & wxFS_VOL_REMOVABLE && (flags & wxFS_VOL_REMOVABLE))
27d2dbbc 201 accept = false;
7183fd72 202 else if (flagsSet & wxFS_VOL_READONLY && !(flags & wxFS_VOL_READONLY))
27d2dbbc 203 accept = false;
7183fd72 204 else if (flagsUnset & wxFS_VOL_READONLY && (flags & wxFS_VOL_READONLY))
27d2dbbc 205 accept = false;
7183fd72 206 else if (flagsSet & wxFS_VOL_REMOTE && !(flags & wxFS_VOL_REMOTE))
27d2dbbc 207 accept = false;
7183fd72 208 else if (flagsUnset & wxFS_VOL_REMOTE && (flags & wxFS_VOL_REMOTE))
27d2dbbc 209 accept = false;
7183fd72
VZ
210
211 // Add to the list if passed the filter.
212 if (accept)
213 list.Add(filename);
214
215 return accept;
216} // FilteredAdd
217
218//=============================================================================
219// Function: BuildListFromNN
220// Purpose: Append or remove items from the list
221// Notes: - There is no way to find all disconnected NN items, or even to find
222// all items while determining which are connected and not. So this
223// function will find either all items or connected items.
224//=============================================================================
27d2dbbc 225static void BuildListFromNN(wxArrayString& list, NETRESOURCE* pResSrc,
4d90b8de 226 unsigned flagsSet, unsigned flagsUnset)
7183fd72
VZ
227{
228 HANDLE hEnum;
229 int rc;
230
231 //-----------------------------------------------
232 // Scope may be all drives or all mounted drives.
233 //-----------------------------------------------
234 unsigned scope = RESOURCE_GLOBALNET;
235 if (flagsSet & wxFS_VOL_MOUNTED)
236 scope = RESOURCE_CONNECTED;
237
238 //----------------------------------------------------------------------
239 // Enumerate all items, adding only non-containers (ie. network shares).
240 // Containers cause a recursive call to this function for their own
241 // enumeration.
242 //----------------------------------------------------------------------
243 if (rc = s_pWNetOpenEnum(scope, RESOURCETYPE_DISK, 0, pResSrc, &hEnum), rc == NO_ERROR)
244 {
4aebbc59
MB
245 DWORD count = 1;
246 DWORD size = 256;
7183fd72
VZ
247 NETRESOURCE* pRes = (NETRESOURCE*)malloc(size);
248 memset(pRes, 0, sizeof(NETRESOURCE));
249 while (rc = s_pWNetEnumResource(hEnum, &count, pRes, &size), rc == NO_ERROR || rc == ERROR_MORE_DATA)
250 {
251 if (s_cancelSearch)
252 break;
253
254 if (rc == ERROR_MORE_DATA)
255 {
256 pRes = (NETRESOURCE*)realloc(pRes, size);
257 count = 1;
258 }
259 else if (count == 1)
260 {
261 // Enumerate the container.
262 if (pRes->dwUsage & RESOURCEUSAGE_CONTAINER)
263 {
264 BuildListFromNN(list, pRes, flagsSet, flagsUnset);
265 }
266
267 // Add the network share.
268 else
269 {
270 wxString filename(pRes->lpRemoteName);
271
1d243ee0
VZ
272 // if the drive is unavailable, FilteredAdd() can hang for
273 // a long time and, moreover, its failure appears to be not
274 // cached so this will happen every time we use it, so try
275 // a much quicker wxDirExists() test (which still hangs but
276 // for much shorter time) for locally mapped drives first
277 // to try to avoid this
278 if ( pRes->lpLocalName &&
279 *pRes->lpLocalName &&
280 !wxDirExists(pRes->lpLocalName) )
281 continue;
282
df69528b 283 if (!filename.empty())
7183fd72
VZ
284 {
285 if (filename.Last() != '\\')
286 filename.Append('\\');
287
288 // The filter function will not know mounted from unmounted, and neither do we unless
289 // we are iterating using RESOURCE_CONNECTED, in which case they all are mounted.
290 // Volumes on disconnected servers, however, will correctly show as unmounted.
b2b6da49 291 FilteredAdd(list, filename.t_str(), flagsSet, flagsUnset&~wxFS_VOL_MOUNTED);
7183fd72
VZ
292 if (scope == RESOURCE_GLOBALNET)
293 s_fileInfo[filename].m_flags &= ~wxFS_VOL_MOUNTED;
294 }
295 }
296 }
297 else if (count == 0)
298 break;
299 }
300 free(pRes);
301 s_pWNetCloseEnum(hEnum);
302 }
303} // BuildListFromNN
304
305//=============================================================================
306// Function: CompareFcn
307// Purpose: Used to sort the NN list alphabetically, case insensitive.
308//=============================================================================
99f161bd 309static int CompareFcn(const wxString& first, const wxString& second)
7183fd72 310{
99f161bd 311 return wxStricmp(first.c_str(), second.c_str());
7183fd72
VZ
312} // CompareFcn
313
314//=============================================================================
315// Function: BuildRemoteList
316// Purpose: Append Network Neighborhood items to the list.
317// Notes: - Mounted gets transalated into Connected. FilteredAdd is told
318// to ignore the Mounted flag since we need to handle it in a weird
319// way manually.
320// - The resulting list is sorted alphabetically.
321//=============================================================================
27d2dbbc 322static bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc,
4d90b8de 323 unsigned flagsSet, unsigned flagsUnset)
7183fd72
VZ
324{
325 // NN query depends on dynamically loaded library.
326 if (!s_pWNetOpenEnum || !s_pWNetEnumResource || !s_pWNetCloseEnum)
327 {
328 wxLogError(_("Failed to load mpr.dll."));
27d2dbbc 329 return false;
7183fd72
VZ
330 }
331
332 // Don't waste time doing the work if the flags conflict.
333 if (flagsSet & wxFS_VOL_MOUNTED && flagsUnset & wxFS_VOL_MOUNTED)
27d2dbbc 334 return false;
7183fd72
VZ
335
336 //----------------------------------------------
337 // Generate the list according to the flags set.
338 //----------------------------------------------
339 BuildListFromNN(list, pResSrc, flagsSet, flagsUnset);
340 list.Sort(CompareFcn);
341
342 //-------------------------------------------------------------------------
343 // If mounted only is requested, then we only need one simple pass.
344 // Otherwise, we need to build a list of all NN volumes and then apply the
345 // list of mounted drives to it.
346 //-------------------------------------------------------------------------
347 if (!(flagsSet & wxFS_VOL_MOUNTED))
348 {
349 // generate.
350 wxArrayString mounted;
351 BuildListFromNN(mounted, pResSrc, flagsSet | wxFS_VOL_MOUNTED, flagsUnset & ~wxFS_VOL_MOUNTED);
352 mounted.Sort(CompareFcn);
353
354 // apply list from bottom to top to preserve indexes if removing items.
4a559093
WS
355 ssize_t iList = list.GetCount()-1;
356 for (ssize_t iMounted = mounted.GetCount()-1; iMounted >= 0 && iList >= 0; iMounted--)
7183fd72
VZ
357 {
358 int compare;
359 wxString all(list[iList]);
360 wxString mount(mounted[iMounted]);
361
27d2dbbc 362 while (compare =
4d90b8de
VS
363 wxStricmp(list[iList].c_str(), mounted[iMounted].c_str()),
364 compare > 0 && iList >= 0)
7183fd72
VZ
365 {
366 iList--;
367 all = list[iList];
368 }
369
370
371 if (compare == 0)
372 {
373 // Found the element. Remove it or mark it mounted.
374 if (flagsUnset & wxFS_VOL_MOUNTED)
ba8c1601 375 list.RemoveAt(iList);
7183fd72
VZ
376 else
377 s_fileInfo[list[iList]].m_flags |= wxFS_VOL_MOUNTED;
378
379 }
380
381 iList--;
382 }
383 }
384
27d2dbbc 385 return true;
7183fd72
VZ
386} // BuildRemoteList
387
388//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
389// wxFSVolume
390//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
391
392//=============================================================================
393// Function: GetVolumes
394// Purpose: Generate and return a list of all volumes (drives) available.
395// Notes:
396//=============================================================================
e2478fde 397wxArrayString wxFSVolumeBase::GetVolumes(int flagsSet, int flagsUnset)
7183fd72 398{
27d2dbbc 399 ::InterlockedExchange(&s_cancelSearch, FALSE); // reset
7183fd72 400
64c288fa 401#if wxUSE_DYNLIB_CLASS
9a83f860 402 if (!s_mprLib.IsLoaded() && s_mprLib.Load(wxT("mpr.dll")))
7183fd72
VZ
403 {
404#ifdef UNICODE
9a83f860
VZ
405 s_pWNetOpenEnum = (WNetOpenEnumPtr)s_mprLib.GetSymbol(wxT("WNetOpenEnumW"));
406 s_pWNetEnumResource = (WNetEnumResourcePtr)s_mprLib.GetSymbol(wxT("WNetEnumResourceW"));
7183fd72 407#else
9a83f860
VZ
408 s_pWNetOpenEnum = (WNetOpenEnumPtr)s_mprLib.GetSymbol(wxT("WNetOpenEnumA"));
409 s_pWNetEnumResource = (WNetEnumResourcePtr)s_mprLib.GetSymbol(wxT("WNetEnumResourceA"));
7183fd72 410#endif
9a83f860 411 s_pWNetCloseEnum = (WNetCloseEnumPtr)s_mprLib.GetSymbol(wxT("WNetCloseEnum"));
7183fd72 412 }
64c288fa 413#endif
7183fd72
VZ
414
415 wxArrayString list;
416
417 //-------------------------------
418 // Local and mapped drives first.
419 //-------------------------------
420 // Allocate the required space for the API call.
95dc6a2b 421 const DWORD chars = GetLogicalDriveStrings(0, NULL);
7183fd72
VZ
422 TCHAR* buf = new TCHAR[chars+1];
423
424 // Get the list of drives.
999836aa 425 GetLogicalDriveStrings(chars, buf);
7183fd72
VZ
426
427 // Parse the list into an array, applying appropriate filters.
428 TCHAR *pVol;
429 pVol = buf;
430 while (*pVol)
431 {
432 FilteredAdd(list, pVol, flagsSet, flagsUnset);
67fade33 433 pVol = pVol + wxStrlen(pVol) + 1;
7183fd72
VZ
434 }
435
436 // Cleanup.
437 delete[] buf;
438
439 //---------------------------
440 // Network Neighborhood next.
441 //---------------------------
442
443 // not exclude remote and not removable
444 if (!(flagsUnset & wxFS_VOL_REMOTE) &&
445 !(flagsSet & wxFS_VOL_REMOVABLE)
446 )
447 {
448 // The returned list will be sorted alphabetically. We don't pass
449 // our in since we don't want to change to order of the local drives.
450 wxArrayString nn;
451 if (BuildRemoteList(nn, 0, flagsSet, flagsUnset))
452 {
89c98653 453 for (size_t idx = 0; idx < nn.GetCount(); idx++)
7183fd72
VZ
454 list.Add(nn[idx]);
455 }
456 }
457
458 return list;
459} // GetVolumes
460
461//=============================================================================
462// Function: CancelSearch
463// Purpose: Instruct an active search to stop.
464// Notes: - This will only sensibly be called by a thread other than the one
465// performing the search. This is the only thread-safe function
466// provided by the class.
467//=============================================================================
e2478fde 468void wxFSVolumeBase::CancelSearch()
7183fd72 469{
27d2dbbc 470 ::InterlockedExchange(&s_cancelSearch, TRUE);
7183fd72
VZ
471} // CancelSearch
472
473//=============================================================================
474// Function: constructor
475// Purpose: default constructor
476//=============================================================================
e2478fde 477wxFSVolumeBase::wxFSVolumeBase()
7183fd72 478{
27d2dbbc 479 m_isOk = false;
7183fd72
VZ
480} // wxVolume
481
482//=============================================================================
483// Function: constructor
484// Purpose: constructor that calls Create
485//=============================================================================
e2478fde 486wxFSVolumeBase::wxFSVolumeBase(const wxString& name)
7183fd72
VZ
487{
488 Create(name);
489} // wxVolume
490
491//=============================================================================
492// Function: Create
493// Purpose: Finds, logs in, etc. to the request volume.
494//=============================================================================
e2478fde 495bool wxFSVolumeBase::Create(const wxString& name)
7183fd72
VZ
496{
497 // assume fail.
27d2dbbc 498 m_isOk = false;
7183fd72
VZ
499
500 // supplied.
501 m_volName = name;
502
503 // Display name.
504 SHFILEINFO fi;
b2b6da49 505 long rc = SHGetFileInfo(m_volName.t_str(), 0, &fi, sizeof(fi), SHGFI_DISPLAYNAME);
7183fd72
VZ
506 if (!rc)
507 {
4d90b8de 508 wxLogError(_("Cannot read typename from '%s'!"), m_volName.c_str());
daa35097 509 return false;
7183fd72
VZ
510 }
511 m_dispName = fi.szDisplayName;
512
7183fd72 513 // all tests passed.
daa35097
VZ
514 m_isOk = true;
515 return true;
7183fd72
VZ
516} // Create
517
518//=============================================================================
519// Function: IsOk
27d2dbbc 520// Purpose: returns true if the volume is legal.
7183fd72
VZ
521// Notes: For fixed disks, it must exist. For removable disks, it must also
522// be present. For Network Shares, it must also be logged in, etc.
523//=============================================================================
e2478fde 524bool wxFSVolumeBase::IsOk() const
7183fd72
VZ
525{
526 return m_isOk;
527} // IsOk
528
529//=============================================================================
530// Function: GetKind
531// Purpose: Return the type of the volume.
532//=============================================================================
e2478fde 533wxFSVolumeKind wxFSVolumeBase::GetKind() const
7183fd72
VZ
534{
535 if (!m_isOk)
536 return wxFS_VOL_OTHER;
537
538 FileInfoMap::iterator itr = s_fileInfo.find(m_volName);
539 if (itr == s_fileInfo.end())
540 return wxFS_VOL_OTHER;
541
542 return itr->second.m_type;
543}
544
545//=============================================================================
546// Function: GetFlags
547// Purpose: Return the caches flags for this volume.
548// Notes: - Returns -1 if no flags were cached.
549//=============================================================================
e2478fde 550int wxFSVolumeBase::GetFlags() const
7183fd72
VZ
551{
552 if (!m_isOk)
553 return -1;
554
555 FileInfoMap::iterator itr = s_fileInfo.find(m_volName);
556 if (itr == s_fileInfo.end())
557 return -1;
558
559 return itr->second.m_flags;
560} // GetFlags
561
ec67cff1 562#endif // wxUSE_BASE
e2478fde
VZ
563
564// ============================================================================
565// wxFSVolume
566// ============================================================================
567
0e7fa3a6 568#if wxUSE_GUI
7183fd72 569
e2478fde
VZ
570void wxFSVolume::InitIcons()
571{
572 m_icons.Alloc(wxFS_VOL_ICO_MAX);
573 wxIcon null;
574 for (int idx = 0; idx < wxFS_VOL_ICO_MAX; idx++)
575 m_icons.Add(null);
576}
577
7183fd72
VZ
578//=============================================================================
579// Function: GetIcon
580// Purpose: return the requested icon.
581//=============================================================================
e2478fde 582
7183fd72
VZ
583wxIcon wxFSVolume::GetIcon(wxFSIconType type) const
584{
e2478fde 585 wxCHECK_MSG( type >= 0 && (size_t)type < m_icons.GetCount(), wxNullIcon,
9a83f860 586 wxT("wxFSIconType::GetIcon(): invalid icon index") );
7183fd72 587
95fbc738 588#ifdef __WXMSW__
7183fd72
VZ
589 // Load on demand.
590 if (m_icons[type].IsNull())
591 {
e2478fde 592 UINT flags = SHGFI_ICON;
7183fd72
VZ
593 switch (type)
594 {
595 case wxFS_VOL_ICO_SMALL:
e2478fde 596 flags |= SHGFI_SMALLICON;
7183fd72
VZ
597 break;
598
599 case wxFS_VOL_ICO_LARGE:
e2478fde 600 flags |= SHGFI_SHELLICONSIZE;
7183fd72
VZ
601 break;
602
603 case wxFS_VOL_ICO_SEL_SMALL:
e2478fde 604 flags |= SHGFI_SMALLICON | SHGFI_OPENICON;
7183fd72
VZ
605 break;
606
607 case wxFS_VOL_ICO_SEL_LARGE:
e2478fde 608 flags |= SHGFI_SHELLICONSIZE | SHGFI_OPENICON;
7183fd72 609 break;
27d2dbbc 610
4d90b8de 611 case wxFS_VOL_ICO_MAX:
9a83f860 612 wxFAIL_MSG(wxT("wxFS_VOL_ICO_MAX is not valid icon type"));
4d90b8de 613 break;
7183fd72
VZ
614 }
615
616 SHFILEINFO fi;
017dc06b 617 long rc = SHGetFileInfo(m_volName.t_str(), 0, &fi, sizeof(fi), flags);
7183fd72
VZ
618 m_icons[type].SetHICON((WXHICON)fi.hIcon);
619 if (!rc || !fi.hIcon)
43b2d5e7 620 {
4d90b8de 621 wxLogError(_("Cannot load icon from '%s'."), m_volName.c_str());
43b2d5e7 622 }
7183fd72
VZ
623 }
624
625 return m_icons[type];
95fbc738
VZ
626#else
627 wxFAIL_MSG(wxS("Can't convert HICON to wxIcon in this port."));
628 return wxNullIcon;
629#endif
7183fd72
VZ
630} // GetIcon
631
632#endif // wxUSE_GUI
633
05815ab3 634#endif // wxUSE_FSVOLUME