gwin32fsmonitorutils: coding style fixes

This commit is contained in:
Ignacio Casal Quinteiro
2016-03-01 08:37:14 +01:00
parent 7f60cbb701
commit 007e3c5939

View File

@@ -31,9 +31,9 @@
#define MAX_PATH_LONG 32767 /* Support Paths longer than MAX_PATH (260) characters */ #define MAX_PATH_LONG 32767 /* Support Paths longer than MAX_PATH (260) characters */
static gboolean static gboolean
g_win32_fs_monitor_handle_event (GWin32FSMonitorPrivate *monitor, g_win32_fs_monitor_handle_event (GWin32FSMonitorPrivate *monitor,
gchar *filename, const gchar *filename,
PFILE_NOTIFY_INFORMATION pfni) PFILE_NOTIFY_INFORMATION pfni)
{ {
GFileMonitorEvent fme; GFileMonitorEvent fme;
PFILE_NOTIFY_INFORMATION pfni_next; PFILE_NOTIFY_INFORMATION pfni_next;
@@ -42,67 +42,68 @@ g_win32_fs_monitor_handle_event (GWin32FSMonitorPrivate *monitor,
switch (pfni->Action) switch (pfni->Action)
{ {
case FILE_ACTION_ADDED: case FILE_ACTION_ADDED:
fme = G_FILE_MONITOR_EVENT_CREATED; fme = G_FILE_MONITOR_EVENT_CREATED;
break; break;
case FILE_ACTION_REMOVED: case FILE_ACTION_REMOVED:
fme = G_FILE_MONITOR_EVENT_DELETED; fme = G_FILE_MONITOR_EVENT_DELETED;
break; break;
case FILE_ACTION_MODIFIED: case FILE_ACTION_MODIFIED:
{
gboolean success_attribs = GetFileAttributesExW (monitor->wfullpath_with_long_prefix,
GetFileExInfoStandard,
&attrib_data);
if (monitor->file_attribs != INVALID_FILE_ATTRIBUTES &&
success_attribs &&
attrib_data.dwFileAttributes != monitor->file_attribs)
fme = G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED;
else
fme = G_FILE_MONITOR_EVENT_CHANGED;
monitor->file_attribs = attrib_data.dwFileAttributes;
}
break;
case FILE_ACTION_RENAMED_OLD_NAME:
if (pfni->NextEntryOffset != 0)
{ {
gboolean success_attribs = GetFileAttributesExW (monitor->wfullpath_with_long_prefix, /* If the file was renamed in the same directory, we would get a
GetFileExInfoStandard, * FILE_ACTION_RENAMED_NEW_NAME action in the next FILE_NOTIFY_INFORMATION
&attrib_data); * structure.
*/
glong file_name_len = 0;
if (monitor->file_attribs != INVALID_FILE_ATTRIBUTES && pfni_next = (PFILE_NOTIFY_INFORMATION) ((BYTE*)pfni + pfni->NextEntryOffset);
success_attribs && renamed_file = g_utf16_to_utf8 (pfni_next->FileName, pfni_next->FileNameLength / sizeof(WCHAR), NULL, &file_name_len, NULL);
attrib_data.dwFileAttributes != monitor->file_attribs) if (pfni_next->Action == FILE_ACTION_RENAMED_NEW_NAME)
fme = G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED; fme = G_FILE_MONITOR_EVENT_RENAMED;
else else
fme = G_FILE_MONITOR_EVENT_CHANGED; fme = G_FILE_MONITOR_EVENT_MOVED_OUT;
monitor->file_attribs = attrib_data.dwFileAttributes;
} }
break; else
fme = G_FILE_MONITOR_EVENT_MOVED_OUT;
break;
case FILE_ACTION_RENAMED_OLD_NAME: case FILE_ACTION_RENAMED_NEW_NAME:
if (pfni->NextEntryOffset != 0) if (monitor->pfni_prev != NULL &&
{ monitor->pfni_prev->Action == FILE_ACTION_RENAMED_OLD_NAME)
/* If the file was renamed in the same directory, we would get a {
* FILE_ACTION_RENAMED_NEW_NAME action in the next FILE_NOTIFY_INFORMATION /* don't bother sending events, was already sent (rename) */
* structure. fme = -1;
*/ }
glong file_name_len = 0; else
fme = G_FILE_MONITOR_EVENT_MOVED_IN;
break;
pfni_next = (PFILE_NOTIFY_INFORMATION) ((BYTE*)pfni + pfni->NextEntryOffset); default:
renamed_file = g_utf16_to_utf8 (pfni_next->FileName, pfni_next->FileNameLength / sizeof(WCHAR), NULL, &file_name_len, NULL); /* The possible Windows actions are all above, so shouldn't get here */
if (pfni_next->Action == FILE_ACTION_RENAMED_NEW_NAME) g_assert_not_reached ();
fme = G_FILE_MONITOR_EVENT_RENAMED; break;
else
fme = G_FILE_MONITOR_EVENT_MOVED_OUT;
}
else
fme = G_FILE_MONITOR_EVENT_MOVED_OUT;
break;
case FILE_ACTION_RENAMED_NEW_NAME:
if (monitor->pfni_prev != NULL &&
monitor->pfni_prev->Action == FILE_ACTION_RENAMED_OLD_NAME)
{
/* don't bother sending events, was already sent (rename) */
fme = -1;
}
else
fme = G_FILE_MONITOR_EVENT_MOVED_IN;
break;
default:
/* The possible Windows actions are all above, so shouldn't get here */
g_assert_not_reached ();
break;
} }
if (fme != -1) if (fme != -1)
return g_file_monitor_source_handle_event (monitor->fms, return g_file_monitor_source_handle_event (monitor->fms,
fme, fme,
@@ -147,13 +148,15 @@ g_win32_fs_monitor_callback (DWORD error,
do do
{ {
pfile_notify_walker = (PFILE_NOTIFY_INFORMATION)((BYTE*)monitor->file_notify_buffer + offset); pfile_notify_walker = (PFILE_NOTIFY_INFORMATION)((BYTE *)monitor->file_notify_buffer + offset);
if (pfile_notify_walker->Action > 0) if (pfile_notify_walker->Action > 0)
{ {
glong file_name_len; glong file_name_len;
gchar *changed_file; gchar *changed_file;
changed_file = g_utf16_to_utf8 (pfile_notify_walker->FileName, pfile_notify_walker->FileNameLength / sizeof(WCHAR), NULL, &file_name_len, NULL); changed_file = g_utf16_to_utf8 (pfile_notify_walker->FileName,
pfile_notify_walker->FileNameLength / sizeof(WCHAR),
NULL, &file_name_len, NULL);
if (monitor->isfile) if (monitor->isfile)
{ {
@@ -198,17 +201,17 @@ g_win32_fs_monitor_callback (DWORD error,
switch (alias_state) switch (alias_state)
{ {
case G_WIN32_FILE_MONITOR_NO_ALIAS: case G_WIN32_FILE_MONITOR_NO_ALIAS:
monitored_file = g_strdup (changed_file); monitored_file = g_strdup (changed_file);
break; break;
case G_WIN32_FILE_MONITOR_LONG_FILENAME: case G_WIN32_FILE_MONITOR_LONG_FILENAME:
case G_WIN32_FILE_MONITOR_SHORT_FILENAME: case G_WIN32_FILE_MONITOR_SHORT_FILENAME:
monitored_file_w = wcsrchr (monitor->wfullpath_with_long_prefix, L'\\'); monitored_file_w = wcsrchr (monitor->wfullpath_with_long_prefix, L'\\');
monitored_file = g_utf16_to_utf8 (monitored_file_w + 1, -1, NULL, NULL, NULL); monitored_file = g_utf16_to_utf8 (monitored_file_w + 1, -1, NULL, NULL, NULL);
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
break; break;
} }
g_win32_fs_monitor_handle_event (monitor, monitored_file, pfile_notify_walker); g_win32_fs_monitor_handle_event (monitor, monitored_file, pfile_notify_walker);
@@ -220,6 +223,7 @@ g_win32_fs_monitor_callback (DWORD error,
g_free (changed_file); g_free (changed_file);
} }
monitor->pfni_prev = pfile_notify_walker; monitor->pfni_prev = pfile_notify_walker;
offset += pfile_notify_walker->NextEntryOffset; offset += pfile_notify_walker->NextEntryOffset;
} }