1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/volume.cpp
3 // Purpose: wxFSVolume - encapsulates system volume information
4 // Author: William Osborne
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "fsvolume.h"
24 #include "wx/wxprec.h"
40 #include "wx/hashmap.h"
41 #include "wx/dynlib.h"
42 #include "wx/arrimpl.cpp"
44 #include "wx/volume.h"
46 #include "wx/palmos/missing.h"
50 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51 // Dynamic library function defs.
52 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
54 static wxDynamicLibrary s_mprLib
;
56 typedef DWORD (WINAPI
* WNetOpenEnumPtr
)(DWORD
, DWORD
, DWORD
, LPNETRESOURCE
, LPHANDLE
);
57 typedef DWORD (WINAPI
* WNetEnumResourcePtr
)(HANDLE
, LPDWORD
, LPVOID
, LPDWORD
);
58 typedef DWORD (WINAPI
* WNetCloseEnumPtr
)(HANDLE
);
60 static WNetOpenEnumPtr s_pWNetOpenEnum
;
61 static WNetEnumResourcePtr s_pWNetEnumResource
;
62 static WNetCloseEnumPtr s_pWNetCloseEnum
;
64 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
66 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
67 static long s_cancelSearch
= FALSE
;
71 FileInfo(unsigned flag
=0, wxFSVolumeKind type
=wxFS_VOL_OTHER
) :
72 m_flags(flag
), m_type(type
) {}
74 FileInfo(const FileInfo
& other
) { *this = other
; }
75 FileInfo
& operator=(const FileInfo
& other
)
77 m_flags
= other
.m_flags
;
78 m_type
= other
.m_type
;
83 wxFSVolumeKind m_type
;
85 WX_DECLARE_STRING_HASH_MAP(FileInfo
, FileInfoMap
);
86 // Cygwin bug (?) destructor for global s_fileInfo is called twice...
87 static FileInfoMap
& GetFileInfoMap()
89 static FileInfoMap
s_fileInfo(25);
93 #define s_fileInfo (GetFileInfoMap())
95 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
96 // Local helper functions.
97 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99 //=============================================================================
100 // Function: GetBasicFlags
101 // Purpose: Set basic flags, primarily wxFS_VOL_REMOTE and wxFS_VOL_REMOVABLE.
102 // Notes: - Local and mapped drives are mounted by definition. We have no
103 // way to determine mounted status of network drives, so assume that
104 // all drives are mounted, and let the caller decide otherwise.
105 // - Other flags are 'best guess' from type of drive. The system will
106 // not report the file attributes with any degree of accuracy.
107 //=============================================================================
108 static unsigned GetBasicFlags(const wxChar
* filename
)
110 unsigned flags
= wxFS_VOL_MOUNTED
;
115 //=============================================================================
116 // Function: FilteredAdd
117 // Purpose: Add a file to the list if it meets the filter requirement.
118 // Notes: - See GetBasicFlags for remarks about the Mounted flag.
119 //=============================================================================
120 static bool FilteredAdd(wxArrayString
& list
, const wxChar
* filename
,
121 unsigned flagsSet
, unsigned flagsUnset
)
126 //=============================================================================
127 // Function: BuildListFromNN
128 // Purpose: Append or remove items from the list
129 // Notes: - There is no way to find all disconnected NN items, or even to find
130 // all items while determining which are connected and not. So this
131 // function will find either all items or connected items.
132 //=============================================================================
133 static void BuildListFromNN(wxArrayString
& list
, NETRESOURCE
* pResSrc
,
134 unsigned flagsSet
, unsigned flagsUnset
)
138 //=============================================================================
139 // Function: CompareFcn
140 // Purpose: Used to sort the NN list alphabetically, case insensitive.
141 //=============================================================================
142 static int CompareFcn(wxString
* first
, wxString
* second
)
144 return wxStricmp(first
->c_str(), second
->c_str());
147 //=============================================================================
148 // Function: BuildRemoteList
149 // Purpose: Append Network Neighborhood items to the list.
150 // Notes: - Mounted gets transalated into Connected. FilteredAdd is told
151 // to ignore the Mounted flag since we need to handle it in a weird
153 // - The resulting list is sorted alphabetically.
154 //=============================================================================
155 static bool BuildRemoteList(wxArrayString
& list
, NETRESOURCE
* pResSrc
,
156 unsigned flagsSet
, unsigned flagsUnset
)
161 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
163 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
165 //=============================================================================
166 // Function: GetVolumes
167 // Purpose: Generate and return a list of all volumes (drives) available.
169 //=============================================================================
170 wxArrayString
wxFSVolumeBase::GetVolumes(int flagsSet
, int flagsUnset
)
177 //=============================================================================
178 // Function: CancelSearch
179 // Purpose: Instruct an active search to stop.
180 // Notes: - This will only sensibly be called by a thread other than the one
181 // performing the search. This is the only thread-safe function
182 // provided by the class.
183 //=============================================================================
184 void wxFSVolumeBase::CancelSearch()
188 //=============================================================================
189 // Function: constructor
190 // Purpose: default constructor
191 //=============================================================================
192 wxFSVolumeBase::wxFSVolumeBase()
196 //=============================================================================
197 // Function: constructor
198 // Purpose: constructor that calls Create
199 //=============================================================================
200 wxFSVolumeBase::wxFSVolumeBase(const wxString
& name
)
204 //=============================================================================
206 // Purpose: Finds, logs in, etc. to the request volume.
207 //=============================================================================
208 bool wxFSVolumeBase::Create(const wxString
& name
)
213 //=============================================================================
215 // Purpose: returns TRUE if the volume is legal.
216 // Notes: For fixed disks, it must exist. For removable disks, it must also
217 // be present. For Network Shares, it must also be logged in, etc.
218 //=============================================================================
219 bool wxFSVolumeBase::IsOk() const
224 //=============================================================================
226 // Purpose: Return the type of the volume.
227 //=============================================================================
228 wxFSVolumeKind
wxFSVolumeBase::GetKind() const
230 return wxFS_VOL_OTHER
;
233 //=============================================================================
234 // Function: GetFlags
235 // Purpose: Return the caches flags for this volume.
236 // Notes: - Returns -1 if no flags were cached.
237 //=============================================================================
238 int wxFSVolumeBase::GetFlags() const
245 // ============================================================================
247 // ============================================================================
251 void wxFSVolume::InitIcons()
255 //=============================================================================
257 // Purpose: return the requested icon.
258 //=============================================================================
260 wxIcon
wxFSVolume::GetIcon(wxFSIconType type
) const
262 return m_icons
[type
];
267 #endif // wxUSE_FSVOLUME