summaryrefslogtreecommitdiff
path: root/src/lib/ecore_file
diff options
context:
space:
mode:
authorIvan Briano <sachieru@gmail.com>2013-02-17 14:53:25 -0300
committerIvan Briano <sachieru@gmail.com>2013-02-17 14:53:25 -0300
commit61b8e2aefe0d988806c9edd080d86b265b53d647 (patch)
tree20ad42c561e7f378347138f3ed5098ec39090a37 /src/lib/ecore_file
parentd0c0a21240c22dda9f71e1b1b5244fcbef95c0d4 (diff)
More removal of \r
Diffstat (limited to 'src/lib/ecore_file')
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_win32.c612
1 files changed, 306 insertions, 306 deletions
diff --git a/src/lib/ecore_file/ecore_file_monitor_win32.c b/src/lib/ecore_file/ecore_file_monitor_win32.c
index 84ac083cfd..52b876a5a7 100644
--- a/src/lib/ecore_file/ecore_file_monitor_win32.c
+++ b/src/lib/ecore_file/ecore_file_monitor_win32.c
@@ -1,306 +1,306 @@
1/* 1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */ 3 */
4 4
5#ifdef HAVE_CONFIG_H 5#ifdef HAVE_CONFIG_H
6# include <config.h> 6# include <config.h>
7#endif 7#endif
8 8
9# define WIN32_LEAN_AND_MEAN 9# define WIN32_LEAN_AND_MEAN
10# include <windows.h> 10# include <windows.h>
11# undef WIN32_LEAN_AND_MEAN 11# undef WIN32_LEAN_AND_MEAN
12# include <process.h> 12# include <process.h>
13 13
14# include "ecore_file_private.h" 14# include "ecore_file_private.h"
15 15
16 16
17typedef struct _Ecore_File_Monitor_Win32 Ecore_File_Monitor_Win32; 17typedef struct _Ecore_File_Monitor_Win32 Ecore_File_Monitor_Win32;
18typedef struct _Ecore_File_Monitor_Win32_Data Ecore_File_Monitor_Win32_Data; 18typedef struct _Ecore_File_Monitor_Win32_Data Ecore_File_Monitor_Win32_Data;
19 19
20/* 4096 = 256 * sizeof(FILE_NOTIFY_INFORMATION) */ 20/* 4096 = 256 * sizeof(FILE_NOTIFY_INFORMATION) */
21# define ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE 4096 21# define ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE 4096
22# define ECORE_FILE_MONITOR_WIN32(x) ((Ecore_File_Monitor_Win32 *)(x)) 22# define ECORE_FILE_MONITOR_WIN32(x) ((Ecore_File_Monitor_Win32 *)(x))
23 23
24struct _Ecore_File_Monitor_Win32_Data 24struct _Ecore_File_Monitor_Win32_Data
25{ 25{
26 char buffer[ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE]; 26 char buffer[ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE];
27 OVERLAPPED overlapped; 27 OVERLAPPED overlapped;
28 HANDLE handle; 28 HANDLE handle;
29 HANDLE event; 29 HANDLE event;
30 Ecore_File_Monitor *monitor; 30 Ecore_File_Monitor *monitor;
31 Ecore_Win32_Handler *h; 31 Ecore_Win32_Handler *h;
32 DWORD buf_length; 32 DWORD buf_length;
33 int is_dir; 33 int is_dir;
34}; 34};
35 35
36struct _Ecore_File_Monitor_Win32 36struct _Ecore_File_Monitor_Win32
37{ 37{
38 Ecore_File_Monitor monitor; 38 Ecore_File_Monitor monitor;
39 Ecore_File_Monitor_Win32_Data *file; 39 Ecore_File_Monitor_Win32_Data *file;
40 Ecore_File_Monitor_Win32_Data *dir; 40 Ecore_File_Monitor_Win32_Data *dir;
41}; 41};
42 42
43static Ecore_File_Monitor *_monitors = NULL; 43static Ecore_File_Monitor *_monitors = NULL;
44 44
45static Eina_Bool _ecore_file_monitor_win32_cb(void *data, Ecore_Win32_Handler *wh); 45static Eina_Bool _ecore_file_monitor_win32_cb(void *data, Ecore_Win32_Handler *wh);
46 46
47 47
48static Ecore_File_Monitor_Win32_Data * 48static Ecore_File_Monitor_Win32_Data *
49_ecore_file_monitor_win32_data_new(Ecore_File_Monitor *monitor, int type) 49_ecore_file_monitor_win32_data_new(Ecore_File_Monitor *monitor, int type)
50{ 50{
51 Ecore_File_Monitor_Win32_Data *md; 51 Ecore_File_Monitor_Win32_Data *md;
52 DWORD filter; 52 DWORD filter;
53 53
54 md = (Ecore_File_Monitor_Win32_Data *)calloc(1, sizeof(Ecore_File_Monitor_Win32_Data)); 54 md = (Ecore_File_Monitor_Win32_Data *)calloc(1, sizeof(Ecore_File_Monitor_Win32_Data));
55 if (!md) return NULL; 55 if (!md) return NULL;
56 56
57 md->handle = CreateFile(monitor->path, 57 md->handle = CreateFile(monitor->path,
58 FILE_LIST_DIRECTORY, 58 FILE_LIST_DIRECTORY,
59 FILE_SHARE_READ | 59 FILE_SHARE_READ |
60 FILE_SHARE_WRITE, 60 FILE_SHARE_WRITE,
61 NULL, 61 NULL,
62 OPEN_EXISTING, 62 OPEN_EXISTING,
63 FILE_FLAG_BACKUP_SEMANTICS | 63 FILE_FLAG_BACKUP_SEMANTICS |
64 FILE_FLAG_OVERLAPPED, 64 FILE_FLAG_OVERLAPPED,
65 NULL); 65 NULL);
66 if (md->handle == INVALID_HANDLE_VALUE) 66 if (md->handle == INVALID_HANDLE_VALUE)
67 goto free_md; 67 goto free_md;
68 68
69 md->event = CreateEvent(NULL, FALSE, FALSE, NULL); 69 md->event = CreateEvent(NULL, FALSE, FALSE, NULL);
70 if (!md->event) 70 if (!md->event)
71 goto close_handle; 71 goto close_handle;
72 72
73 ZeroMemory (&md->overlapped, sizeof(md->overlapped)); 73 ZeroMemory (&md->overlapped, sizeof(md->overlapped));
74 md->overlapped.hEvent = md->event; 74 md->overlapped.hEvent = md->event;
75 75
76 filter = (type == 0) ? FILE_NOTIFY_CHANGE_FILE_NAME : FILE_NOTIFY_CHANGE_DIR_NAME; 76 filter = (type == 0) ? FILE_NOTIFY_CHANGE_FILE_NAME : FILE_NOTIFY_CHANGE_DIR_NAME;
77 filter |= 77 filter |=
78 FILE_NOTIFY_CHANGE_ATTRIBUTES | 78 FILE_NOTIFY_CHANGE_ATTRIBUTES |
79 FILE_NOTIFY_CHANGE_SIZE | 79 FILE_NOTIFY_CHANGE_SIZE |
80 FILE_NOTIFY_CHANGE_LAST_WRITE | 80 FILE_NOTIFY_CHANGE_LAST_WRITE |
81 FILE_NOTIFY_CHANGE_LAST_ACCESS | 81 FILE_NOTIFY_CHANGE_LAST_ACCESS |
82 FILE_NOTIFY_CHANGE_CREATION | 82 FILE_NOTIFY_CHANGE_CREATION |
83 FILE_NOTIFY_CHANGE_SECURITY; 83 FILE_NOTIFY_CHANGE_SECURITY;
84 84
85 if (!ReadDirectoryChangesW(md->handle, 85 if (!ReadDirectoryChangesW(md->handle,
86 md->buffer, 86 md->buffer,
87 ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE, 87 ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE,
88 FALSE, 88 FALSE,
89 filter, 89 filter,
90 &md->buf_length, 90 &md->buf_length,
91 &md->overlapped, 91 &md->overlapped,
92 NULL)) 92 NULL))
93 goto close_event; 93 goto close_event;
94 94
95 md->h = ecore_main_win32_handler_add(md->event, 95 md->h = ecore_main_win32_handler_add(md->event,
96 _ecore_file_monitor_win32_cb, 96 _ecore_file_monitor_win32_cb,
97 md); 97 md);
98 if (!md->h) 98 if (!md->h)
99 goto close_event; 99 goto close_event;
100 100
101 md->monitor = monitor; 101 md->monitor = monitor;
102 md->is_dir = type; 102 md->is_dir = type;
103 103
104 return md; 104 return md;
105 105
106 close_event: 106 close_event:
107 CloseHandle(md->event); 107 CloseHandle(md->event);
108 close_handle: 108 close_handle:
109 CloseHandle(md->handle); 109 CloseHandle(md->handle);
110 free_md: 110 free_md:
111 free(md); 111 free(md);
112 112
113 return NULL; 113 return NULL;
114} 114}
115 115
116static void 116static void
117_ecore_file_monitor_win32_data_free(Ecore_File_Monitor_Win32_Data *md) 117_ecore_file_monitor_win32_data_free(Ecore_File_Monitor_Win32_Data *md)
118{ 118{
119 if (!md) return; 119 if (!md) return;
120 120
121 CloseHandle(md->event); 121 CloseHandle(md->event);
122 CloseHandle (md->handle); 122 CloseHandle (md->handle);
123 free (md); 123 free (md);
124} 124}
125 125
126static Eina_Bool 126static Eina_Bool
127_ecore_file_monitor_win32_cb(void *data, Ecore_Win32_Handler *wh) 127_ecore_file_monitor_win32_cb(void *data, Ecore_Win32_Handler *wh)
128{ 128{
129 char filename[PATH_MAX]; 129 char filename[PATH_MAX];
130 PFILE_NOTIFY_INFORMATION fni; 130 PFILE_NOTIFY_INFORMATION fni;
131 Ecore_File_Monitor_Win32_Data *md; 131 Ecore_File_Monitor_Win32_Data *md;
132 wchar_t *wname; 132 wchar_t *wname;
133 char *name; 133 char *name;
134 DWORD filter; 134 DWORD filter;
135 DWORD offset; 135 DWORD offset;
136 DWORD buf_length; 136 DWORD buf_length;
137 Ecore_File_Event event = ECORE_FILE_EVENT_NONE; 137 Ecore_File_Event event = ECORE_FILE_EVENT_NONE;
138 138
139 md = (Ecore_File_Monitor_Win32_Data *)data; 139 md = (Ecore_File_Monitor_Win32_Data *)data;
140 140
141 if (!GetOverlappedResult (md->handle, &md->overlapped, &buf_length, TRUE)) 141 if (!GetOverlappedResult (md->handle, &md->overlapped, &buf_length, TRUE))
142 return 1; 142 return 1;
143 143
144 fni = (PFILE_NOTIFY_INFORMATION)md->buffer; 144 fni = (PFILE_NOTIFY_INFORMATION)md->buffer;
145 do { 145 do {
146 if (!fni) 146 if (!fni)
147 break; 147 break;
148 offset = fni->NextEntryOffset; 148 offset = fni->NextEntryOffset;
149 149
150 wname = (wchar_t *)malloc(sizeof(wchar_t) * (fni->FileNameLength + 1)); 150 wname = (wchar_t *)malloc(sizeof(wchar_t) * (fni->FileNameLength + 1));
151 if (!wname) 151 if (!wname)
152 return 0; 152 return 0;
153 153
154 memcpy(wname, fni->FileName, fni->FileNameLength); 154 memcpy(wname, fni->FileName, fni->FileNameLength);
155 wname[fni->FileNameLength]='\0'; 155 wname[fni->FileNameLength]='\0';
156 name = evil_wchar_to_char(wname); 156 name = evil_wchar_to_char(wname);
157 free(wname); 157 free(wname);
158 if (!name) 158 if (!name)
159 return 0; 159 return 0;
160 160
161 _snprintf(filename, PATH_MAX, "%s\\%s", md->monitor->path, name); 161 _snprintf(filename, PATH_MAX, "%s\\%s", md->monitor->path, name);
162 free(name); 162 free(name);
163 163
164 switch (fni->Action) 164 switch (fni->Action)
165 { 165 {
166 case FILE_ACTION_ADDED: 166 case FILE_ACTION_ADDED:
167 if (md->is_dir) 167 if (md->is_dir)
168 event = ECORE_FILE_EVENT_CREATED_DIRECTORY; 168 event = ECORE_FILE_EVENT_CREATED_DIRECTORY;
169 else 169 else
170 event = ECORE_FILE_EVENT_CREATED_FILE; 170 event = ECORE_FILE_EVENT_CREATED_FILE;
171 break; 171 break;
172 case FILE_ACTION_REMOVED: 172 case FILE_ACTION_REMOVED:
173 if (md->is_dir) 173 if (md->is_dir)
174 event = ECORE_FILE_EVENT_DELETED_DIRECTORY; 174 event = ECORE_FILE_EVENT_DELETED_DIRECTORY;
175 else 175 else
176 event = ECORE_FILE_EVENT_DELETED_FILE; 176 event = ECORE_FILE_EVENT_DELETED_FILE;
177 break; 177 break;
178 case FILE_ACTION_MODIFIED: 178 case FILE_ACTION_MODIFIED:
179 if (!md->is_dir) 179 if (!md->is_dir)
180 event = ECORE_FILE_EVENT_MODIFIED; 180 event = ECORE_FILE_EVENT_MODIFIED;
181 break; 181 break;
182 case FILE_ACTION_RENAMED_OLD_NAME: 182 case FILE_ACTION_RENAMED_OLD_NAME:
183 if (md->is_dir) 183 if (md->is_dir)
184 event = ECORE_FILE_EVENT_DELETED_DIRECTORY; 184 event = ECORE_FILE_EVENT_DELETED_DIRECTORY;
185 else 185 else
186 event = ECORE_FILE_EVENT_DELETED_FILE; 186 event = ECORE_FILE_EVENT_DELETED_FILE;
187 break; 187 break;
188 case FILE_ACTION_RENAMED_NEW_NAME: 188 case FILE_ACTION_RENAMED_NEW_NAME:
189 if (md->is_dir) 189 if (md->is_dir)
190 event = ECORE_FILE_EVENT_CREATED_DIRECTORY; 190 event = ECORE_FILE_EVENT_CREATED_DIRECTORY;
191 else 191 else
192 event = ECORE_FILE_EVENT_CREATED_FILE; 192 event = ECORE_FILE_EVENT_CREATED_FILE;
193 break; 193 break;
194 default: 194 default:
195 fprintf(stderr, "unknown event\n"); 195 fprintf(stderr, "unknown event\n");
196 event = ECORE_FILE_EVENT_NONE; 196 event = ECORE_FILE_EVENT_NONE;
197 break; 197 break;
198 } 198 }
199 if (event != ECORE_FILE_EVENT_NONE) 199 if (event != ECORE_FILE_EVENT_NONE)
200 md->monitor->func(md->monitor->data, md->monitor, event, filename); 200 md->monitor->func(md->monitor->data, md->monitor, event, filename);
201 201
202 fni = (PFILE_NOTIFY_INFORMATION)((LPBYTE)fni + offset); 202 fni = (PFILE_NOTIFY_INFORMATION)((LPBYTE)fni + offset);
203 } while (offset); 203 } while (offset);
204 204
205 filter = (md->is_dir == 0) ? FILE_NOTIFY_CHANGE_FILE_NAME : FILE_NOTIFY_CHANGE_DIR_NAME; 205 filter = (md->is_dir == 0) ? FILE_NOTIFY_CHANGE_FILE_NAME : FILE_NOTIFY_CHANGE_DIR_NAME;
206 filter |= 206 filter |=
207 FILE_NOTIFY_CHANGE_ATTRIBUTES | 207 FILE_NOTIFY_CHANGE_ATTRIBUTES |
208 FILE_NOTIFY_CHANGE_SIZE | 208 FILE_NOTIFY_CHANGE_SIZE |
209 FILE_NOTIFY_CHANGE_LAST_WRITE | 209 FILE_NOTIFY_CHANGE_LAST_WRITE |
210 FILE_NOTIFY_CHANGE_LAST_ACCESS | 210 FILE_NOTIFY_CHANGE_LAST_ACCESS |
211 FILE_NOTIFY_CHANGE_CREATION | 211 FILE_NOTIFY_CHANGE_CREATION |
212 FILE_NOTIFY_CHANGE_SECURITY; 212 FILE_NOTIFY_CHANGE_SECURITY;
213 213
214 ReadDirectoryChangesW(md->handle, 214 ReadDirectoryChangesW(md->handle,
215 md->buffer, 215 md->buffer,
216 ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE, 216 ECORE_FILE_MONITOR_WIN32_BUFFER_SIZE,
217 FALSE, 217 FALSE,
218 filter, 218 filter,
219 &md->buf_length, 219 &md->buf_length,
220 &md->overlapped, 220 &md->overlapped,
221 NULL); 221 NULL);
222 return 1; 222 return 1;
223} 223}
224 224
225int 225int
226ecore_file_monitor_backend_init(void) 226ecore_file_monitor_backend_init(void)
227{ 227{
228 return 1; 228 return 1;
229} 229}
230 230
231int 231int
232ecore_file_monitor_backend_shutdown(void) 232ecore_file_monitor_backend_shutdown(void)
233{ 233{
234 return 1; 234 return 1;
235} 235}
236 236
237Ecore_File_Monitor * 237Ecore_File_Monitor *
238ecore_file_monitor_backend_add(const char *path, 238ecore_file_monitor_backend_add(const char *path,
239 void (*func) (void *data, Ecore_File_Monitor *em, 239 void (*func) (void *data, Ecore_File_Monitor *em,
240 Ecore_File_Event event, 240 Ecore_File_Event event,
241 const char *path), 241 const char *path),
242 void *data) 242 void *data)
243{ 243{
244 Ecore_File_Monitor_Win32 *m; 244 Ecore_File_Monitor_Win32 *m;
245 Ecore_File_Monitor *em; 245 Ecore_File_Monitor *em;
246 size_t len; 246 size_t len;
247 247
248 if (!path || (*path == '\0')) return NULL; 248 if (!path || (*path == '\0')) return NULL;
249 if (!ecore_file_exists(path) || !ecore_file_is_dir(path)) 249 if (!ecore_file_exists(path) || !ecore_file_is_dir(path))
250 return NULL; 250 return NULL;
251 if (!func) return NULL; 251 if (!func) return NULL;
252 252
253 em = (Ecore_File_Monitor *)calloc(1, sizeof(Ecore_File_Monitor_Win32)); 253 em = (Ecore_File_Monitor *)calloc(1, sizeof(Ecore_File_Monitor_Win32));
254 if (!em) return NULL; 254 if (!em) return NULL;
255 255
256 em->func = func; 256 em->func = func;
257 em->data = data; 257 em->data = data;
258 258
259 em->path = strdup(path); 259 em->path = strdup(path);
260 if (!em->path) 260 if (!em->path)
261 { 261 {
262 free(em); 262 free(em);
263 return NULL; 263 return NULL;
264 } 264 }
265 len = strlen(em->path); 265 len = strlen(em->path);
266 if (em->path[len - 1] == '/' || em->path[len - 1] == '\\') 266 if (em->path[len - 1] == '/' || em->path[len - 1] == '\\')
267 em->path[len - 1] = '\0'; 267 em->path[len - 1] = '\0';
268 268
269 m = ECORE_FILE_MONITOR_WIN32(em); 269 m = ECORE_FILE_MONITOR_WIN32(em);
270 270
271 m->file = _ecore_file_monitor_win32_data_new(em, 0); 271 m->file = _ecore_file_monitor_win32_data_new(em, 0);
272 if (!m->file) 272 if (!m->file)
273 { 273 {
274 free(em->path); 274 free(em->path);
275 free(em); 275 free(em);
276 return NULL; 276 return NULL;
277 } 277 }
278 278
279 m->dir = _ecore_file_monitor_win32_data_new(em, 1); 279 m->dir = _ecore_file_monitor_win32_data_new(em, 1);
280 if (!m->dir) 280 if (!m->dir)
281 { 281 {
282 _ecore_file_monitor_win32_data_free(m->file); 282 _ecore_file_monitor_win32_data_free(m->file);
283 free(em->path); 283 free(em->path);
284 free(em); 284 free(em);
285 return NULL; 285 return NULL;
286 } 286 }
287 287
288 _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); 288 _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em)));
289 289
290 return em; 290 return em;
291} 291}
292 292
293void 293void
294ecore_file_monitor_backend_del(Ecore_File_Monitor *em) 294ecore_file_monitor_backend_del(Ecore_File_Monitor *em)
295{ 295{
296 Ecore_File_Monitor_Win32 *m; 296 Ecore_File_Monitor_Win32 *m;
297 297
298 if (!em) 298 if (!em)
299 return; 299 return;
300 300
301 m = ECORE_FILE_MONITOR_WIN32(em); 301 m = ECORE_FILE_MONITOR_WIN32(em);
302 _ecore_file_monitor_win32_data_free(m->dir); 302 _ecore_file_monitor_win32_data_free(m->dir);
303 _ecore_file_monitor_win32_data_free(m->file); 303 _ecore_file_monitor_win32_data_free(m->file);
304 free(em->path); 304 free(em->path);
305 free(em); 305 free(em);
306} 306}