OSDN Git Service

LinGui: fix a mingw build issue
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 14 Apr 2010 16:01:26 +0000 (16:01 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 14 Apr 2010 16:01:26 +0000 (16:01 +0000)
The new multi-instance file locking needs to be ifdef'd for mingw

git-svn-id: svn://localhost/HandBrake/trunk@3221 b64f7644-9d1e-0410-96f1-a4d463321fa5

gtk/src/main.c
gtk/src/presets.c

index fc52e2a..3782efe 100644 (file)
@@ -40,7 +40,6 @@
 #else
 #include <windows.h>
 #include <io.h>
-//#include <pthread/pthread.h>
 #define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
 #endif
 
@@ -521,6 +520,7 @@ bind_presets_tree_model (signal_user_data_t *ud)
 static void
 clean_old_logs()
 {
+#if !defined(_WIN32)
        const gchar *file;
        gchar *config;
 
@@ -543,7 +543,7 @@ clean_old_logs()
                                path = g_strdup_printf("%s/ghb.pid.%d", config, pid);
                                if (g_file_test(path, G_FILE_TEST_EXISTS))
                                {
-                                       fd = g_open(path, O_RDWR);
+                                       fd = open(path, O_RDWR);
                                        if (fd >= 0)
                                        {
                                                lock = lockf(fd, F_TLOCK, 0);
@@ -570,6 +570,60 @@ clean_old_logs()
                g_dir_close(gdir);
        }
        g_free(config);
+#else
+       const gchar *file;
+       gchar *config;
+
+       config = ghb_get_user_config_dir(NULL);
+
+       if (g_file_test(config, G_FILE_TEST_IS_DIR))
+       {
+               GDir *gdir = g_dir_open(config, 0, NULL);
+               file = g_dir_read_name(gdir);
+               while (file)
+               {
+                       if (strncmp(file, "Activity.log.", 13) == 0)
+                       {
+                               gchar *path;
+                               int pid;
+
+                               sscanf(file, "Activity.log.%d", &pid);
+
+#if 0
+                               int fd, lock = 1;
+
+                               path = g_strdup_printf("%s/ghb.pid.%d", config, pid);
+                               if (g_file_test(path, G_FILE_TEST_EXISTS))
+                               {
+                                       fd = open(path, O_RDWR);
+                                       if (fd >= 0)
+                                       {
+                                               lock = lockf(fd, F_TLOCK, 0);
+                                       }
+                                       g_free(path);
+                                       close(fd);
+                                       if (lock == 0)
+                                       {
+                                               path = g_strdup_printf("%s/%s", config, file);
+                                               g_unlink(path);
+                                               g_free(path);
+                                       }
+                               }
+                               else
+#endif
+                               {
+                                       //g_free(path);
+                                       path = g_strdup_printf("%s/%s", config, file);
+                                       g_unlink(path);
+                                       g_free(path);
+                               }
+                       }
+                       file = g_dir_read_name(gdir);
+               }
+               g_dir_close(gdir);
+       }
+       g_free(config);
+#endif
 }
 
 static void
@@ -722,11 +776,6 @@ main (int argc, char *argv[])
        textdomain (GETTEXT_PACKAGE);
 #endif
 
-#ifdef PTW32_STATIC_LIB
-       pthread_win32_process_attach_np();
-       pthread_win32_thread_attach_np();
-#endif
-
        if (!g_thread_supported())
                g_thread_init(NULL);
        context = g_option_context_new ("- Rip and encode DVD or MPEG file");
@@ -921,9 +970,6 @@ main (int argc, char *argv[])
        notify_uninit();
 #endif
        g_free(ud);
-#ifdef PTW32_STATIC_LIB
-       pthread_win32_thread_detach_np();
-       pthread_win32_process_detach_np();
-#endif
+
        return 0;
 }
index 7d7e844..66f69a7 100644 (file)
@@ -1211,7 +1211,6 @@ ghb_find_pid_file()
                        if (strncmp(file, "ghb.pid.", 8) == 0)
                        {
                                gchar *path;
-                               int fd, lock = 1;
                                pid_t my_pid;
                                int pid;
 
@@ -1222,9 +1221,12 @@ ghb_find_pid_file()
                                        file = g_dir_read_name(gdir);
                                        continue;
                                }
-
                                path = g_strdup_printf("%s/%s", config, file);
-                               fd = g_open(path, O_RDWR);
+
+#if !defined(_WIN32)
+                               int fd, lock = 1;
+
+                               fd = open(path, O_RDWR);
                                if (fd >= 0)
                                {
                                        lock = lockf(fd, F_TLOCK, 0);
@@ -1240,6 +1242,13 @@ ghb_find_pid_file()
                                }
                                g_free(path);
                                close(fd);
+#else
+                               g_dir_close(gdir);
+                               g_unlink(path);
+                               g_free(path);
+                               g_free(config);
+                               return pid;
+#endif
                        }
                        file = g_dir_read_name(gdir);
                }