Changed the retry function in PithosClient to use the TPL
[pithos-ms-client] / trunk / Pithos.Core / NativeMethods.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Runtime.InteropServices;
5 using System.Text;
6
7 namespace Pithos.Core
8 {
9     #region Enums & Structs
10
11     #region enum HChangeNotifyEventID
12     /// <summary>
13     /// Describes the event that has occurred. 
14     /// Typically, only one event is specified at a time. 
15     /// If more than one event is specified, the values contained 
16     /// in the <i>dwItem1</i> and <i>dwItem2</i> 
17     /// parameters must be the same, respectively, for all specified events. 
18     /// This parameter can be one or more of the following values. 
19     /// </summary>
20     /// <remarks>
21     /// <para><b>Windows NT/2000/XP:</b> <i>dwItem2</i> contains the index 
22     /// in the system image list that has changed. 
23     /// <i>dwItem1</i> is not used and should be <see langword="null"/>.</para>
24     /// <para><b>Windows 95/98:</b> <i>dwItem1</i> contains the index 
25     /// in the system image list that has changed. 
26     /// <i>dwItem2</i> is not used and should be <see langword="null"/>.</para>
27     /// </remarks>
28     [Flags]
29     enum HChangeNotifyEventID
30     {
31         /// <summary>
32         /// All events have occurred. 
33         /// </summary>
34         SHCNE_ALLEVENTS = 0x7FFFFFFF,
35
36         /// <summary>
37         /// A file type association has changed. <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> 
38         /// must be specified in the <i>uFlags</i> parameter. 
39         /// <i>dwItem1</i> and <i>dwItem2</i> are not used and must be <see langword="null"/>. 
40         /// </summary>
41         SHCNE_ASSOCCHANGED = 0x08000000,
42
43         /// <summary>
44         /// The attributes of an item or folder have changed. 
45         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
46         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
47         /// <i>dwItem1</i> contains the item or folder that has changed. 
48         /// <i>dwItem2</i> is not used and should be <see langword="null"/>.
49         /// </summary>
50         SHCNE_ATTRIBUTES = 0x00000800,
51
52         /// <summary>
53         /// A nonfolder item has been created. 
54         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
55         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
56         /// <i>dwItem1</i> contains the item that was created. 
57         /// <i>dwItem2</i> is not used and should be <see langword="null"/>.
58         /// </summary>
59         SHCNE_CREATE = 0x00000002,
60
61         /// <summary>
62         /// A nonfolder item has been deleted. 
63         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
64         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
65         /// <i>dwItem1</i> contains the item that was deleted. 
66         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
67         /// </summary>
68         SHCNE_DELETE = 0x00000004,
69
70         /// <summary>
71         /// A drive has been added. 
72         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
73         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
74         /// <i>dwItem1</i> contains the root of the drive that was added. 
75         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
76         /// </summary>
77         SHCNE_DRIVEADD = 0x00000100,
78
79         /// <summary>
80         /// A drive has been added and the Shell should create a new window for the drive. 
81         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
82         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
83         /// <i>dwItem1</i> contains the root of the drive that was added. 
84         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
85         /// </summary>
86         SHCNE_DRIVEADDGUI = 0x00010000,
87
88         /// <summary>
89         /// A drive has been removed. <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
90         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
91         /// <i>dwItem1</i> contains the root of the drive that was removed.
92         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
93         /// </summary>
94         SHCNE_DRIVEREMOVED = 0x00000080,
95
96         /// <summary>
97         /// Not currently used. 
98         /// </summary>
99         SHCNE_EXTENDED_EVENT = 0x04000000,
100
101         /// <summary>
102         /// The amount of free space on a drive has changed. 
103         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
104         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
105         /// <i>dwItem1</i> contains the root of the drive on which the free space changed.
106         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
107         /// </summary>
108         SHCNE_FREESPACE = 0x00040000,
109
110         /// <summary>
111         /// Storage media has been inserted into a drive. 
112         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
113         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
114         /// <i>dwItem1</i> contains the root of the drive that contains the new media. 
115         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
116         /// </summary>
117         SHCNE_MEDIAINSERTED = 0x00000020,
118
119         /// <summary>
120         /// Storage media has been removed from a drive. 
121         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
122         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
123         /// <i>dwItem1</i> contains the root of the drive from which the media was removed. 
124         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
125         /// </summary>
126         SHCNE_MEDIAREMOVED = 0x00000040,
127
128         /// <summary>
129         /// A folder has been created. <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> 
130         /// or <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
131         /// <i>dwItem1</i> contains the folder that was created. 
132         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
133         /// </summary>
134         SHCNE_MKDIR = 0x00000008,
135
136         /// <summary>
137         /// A folder on the local computer is being shared via the network. 
138         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
139         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
140         /// <i>dwItem1</i> contains the folder that is being shared. 
141         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
142         /// </summary>
143         SHCNE_NETSHARE = 0x00000200,
144
145         /// <summary>
146         /// A folder on the local computer is no longer being shared via the network. 
147         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
148         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
149         /// <i>dwItem1</i> contains the folder that is no longer being shared. 
150         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
151         /// </summary>
152         SHCNE_NETUNSHARE = 0x00000400,
153
154         /// <summary>
155         /// The name of a folder has changed. 
156         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
157         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
158         /// <i>dwItem1</i> contains the previous pointer to an item identifier list (PIDL) or name of the folder. 
159         /// <i>dwItem2</i> contains the new PIDL or name of the folder. 
160         /// </summary>
161         SHCNE_RENAMEFOLDER = 0x00020000,
162
163         /// <summary>
164         /// The name of a nonfolder item has changed. 
165         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
166         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
167         /// <i>dwItem1</i> contains the previous PIDL or name of the item. 
168         /// <i>dwItem2</i> contains the new PIDL or name of the item. 
169         /// </summary>
170         SHCNE_RENAMEITEM = 0x00000001,
171
172         /// <summary>
173         /// A folder has been removed. 
174         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
175         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
176         /// <i>dwItem1</i> contains the folder that was removed. 
177         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
178         /// </summary>
179         SHCNE_RMDIR = 0x00000010,
180
181         /// <summary>
182         /// The computer has disconnected from a server. 
183         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
184         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
185         /// <i>dwItem1</i> contains the server from which the computer was disconnected. 
186         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
187         /// </summary>
188         SHCNE_SERVERDISCONNECT = 0x00004000,
189
190         /// <summary>
191         /// The contents of an existing folder have changed, 
192         /// but the folder still exists and has not been renamed. 
193         /// <see cref="HChangeNotifyFlags.SHCNF_IDLIST"/> or 
194         /// <see cref="HChangeNotifyFlags.SHCNF_PATH"/> must be specified in <i>uFlags</i>. 
195         /// <i>dwItem1</i> contains the folder that has changed. 
196         /// <i>dwItem2</i> is not used and should be <see langword="null"/>. 
197         /// If a folder has been created, deleted, or renamed, use SHCNE_MKDIR, SHCNE_RMDIR, or 
198         /// SHCNE_RENAMEFOLDER, respectively, instead. 
199         /// </summary>
200         SHCNE_UPDATEDIR = 0x00001000,
201
202         SHCNE_UPDATEITEM = 0x00002000,
203
204         /// <summary>
205         /// An image in the system image list has changed. 
206         /// <see cref="HChangeNotifyFlags.SHCNF_DWORD"/> must be specified in <i>uFlags</i>. 
207         /// </summary>
208         SHCNE_UPDATEIMAGE = 0x00008000,
209
210     }
211     #endregion // enum HChangeNotifyEventID
212
213     #region public enum HChangeNotifyFlags
214     /// <summary>
215     /// Flags that indicate the meaning of the <i>dwItem1</i> and <i>dwItem2</i> parameters. 
216     /// The uFlags parameter must be one of the following values.
217     /// </summary>
218     [Flags]
219     public enum HChangeNotifyFlags
220     {
221         /// <summary>
222         /// The <i>dwItem1</i> and <i>dwItem2</i> parameters are DWORD values. 
223         /// </summary>
224         SHCNF_DWORD = 0x0003,
225         /// <summary>
226         /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of ITEMIDLIST structures that 
227         /// represent the item(s) affected by the change. 
228         /// Each ITEMIDLIST must be relative to the desktop folder. 
229         /// </summary>
230         SHCNF_IDLIST = 0x0000,
231         /// <summary>
232         /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings of 
233         /// maximum length MAX_PATH that contain the full path names 
234         /// of the items affected by the change. 
235         /// </summary>
236         SHCNF_PATHA = 0x0001,
237         /// <summary>
238         /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings of 
239         /// maximum length MAX_PATH that contain the full path names 
240         /// of the items affected by the change. 
241         /// </summary>
242         SHCNF_PATHW = 0x0005,
243         /// <summary>
244         /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings that 
245         /// represent the friendly names of the printer(s) affected by the change. 
246         /// </summary>
247         SHCNF_PRINTERA = 0x0002,
248         /// <summary>
249         /// <i>dwItem1</i> and <i>dwItem2</i> are the addresses of null-terminated strings that 
250         /// represent the friendly names of the printer(s) affected by the change. 
251         /// </summary>
252         SHCNF_PRINTERW = 0x0006,
253         /// <summary>
254         /// The function should not return until the notification 
255         /// has been delivered to all affected components. 
256         /// As this flag modifies other data-type flags, it cannot by used by itself.
257         /// </summary>
258         SHCNF_FLUSH = 0x1000,
259         /// <summary>
260         /// The function should begin delivering notifications to all affected components 
261         /// but should return as soon as the notification process has begun. 
262         /// As this flag modifies other data-type flags, it cannot by used by itself.
263         /// </summary>
264         SHCNF_FLUSHNOWAIT = 0x2000
265     }
266     #endregion // enum HChangeNotifyFlags
267
268
269     #endregion
270
271
272     internal static class NativeMethods
273     {
274         [DllImport("shell32.dll")]
275         public static extern void SHChangeNotify(HChangeNotifyEventID wEventId,
276                                            HChangeNotifyFlags uFlags,
277                                            IntPtr dwItem1,
278                                            IntPtr dwItem2);
279
280     }
281 }