[easytag/wip/mingw-fixes: 2/2] Use g_spawn_async() on Windows



commit dc7c4432f79ee7d8d9b071aeddab1a8be062e88f
Author: David King <amigadave amigadave com>
Date:   Fri Feb 7 17:03:27 2014 +0000

    Use g_spawn_async() on Windows
    
    Remove Windows-specific code to spawn processes. Bundle the GLib spawn
    helper in the Windows installer.

 TODO                           |    1 -
 easytag-win32-installer.nsi.in |    1 +
 src/browser.c                  |   67 ----------------------------------------
 src/misc.c                     |   58 ----------------------------------
 4 files changed, 1 insertions(+), 126 deletions(-)
---
diff --git a/TODO b/TODO
index 16e1389..5469d28 100644
--- a/TODO
+++ b/TODO
@@ -13,7 +13,6 @@ General tidying
 * Port file I/O to use GFile from GIO
 ** Additionally, make I/O asynchronous
 ** Always use the GLib encoding for filenames (convert for display)
-* Use g_spawn_async() or g_app_info_launch() to spawn processes
 * Instantiate windows on first use, not at startup
 * GObjectification
 * Avoid using gtk_events_pending(), use asynchronous operations instead
diff --git a/easytag-win32-installer.nsi.in b/easytag-win32-installer.nsi.in
index f4b493a..f28171a 100644
--- a/easytag-win32-installer.nsi.in
+++ b/easytag-win32-installer.nsi.in
@@ -199,6 +199,7 @@ Section "Core ${PRODUCT_NAME} Files" SecProgram
   File "${PREFIX}/bin/libvorbis-0.dll"
   File "${PREFIX}/bin/libvorbisfile-3.dll"
   File "${PREFIX}/bin/libwavpack-1.dll"
+  File "${PREFIX}/bin/gspawn-win32-helper.exe"
   File "${PREFIX}/bin/pango-querymodules.exe"
   File "${PREFIX}/bin/zlib1.dll"
 
diff --git a/src/browser.c b/src/browser.c
index 4556645..cf14e7b 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -4224,19 +4224,11 @@ Run_Program_With_Selected_Files (GtkWidget *combobox)
 static gboolean
 Run_Program (const gchar *program_name, GList *args_list)
 {
-#ifdef G_OS_WIN32
-    GList              *filelist;
-    gchar              *argv_join;
-    gchar              *full_command;
-    STARTUPINFO         siStartupInfo;
-    PROCESS_INFORMATION piProcessInfo;
-#else /* !G_OS_WIN32 */
     gchar **argv_user;
     gint    argv_user_number;
     gchar  *msg;
     GPid pid;
     GError *error = NULL;
-#endif /* !G_OS_WIN32 */
     gchar **argv;
     gint    argv_index = 0;
     GList *l;
@@ -4279,64 +4271,6 @@ Run_Program (const gchar *program_name, GList *args_list)
         return FALSE;
     }
 
-
-    /* TODO: Replace with g_spawn_async()? */
-#ifdef G_OS_WIN32
-    filelist = args_list;
-
-    // See documentation : http://c.developpez.com/faq/vc/?page=ProcessThread and 
http://www.answers.com/topic/createprocess
-    ZeroMemory(&siStartupInfo, sizeof(siStartupInfo));
-    siStartupInfo.cb = sizeof(siStartupInfo);
-    ZeroMemory(&piProcessInfo, sizeof(piProcessInfo));
-
-    argv = g_new0(gchar *,g_list_length(filelist) + 2); // "+2" for 1rst arg 'foo' and last arg 'NULL'
-    //argv[argv_index++] = "foo";
-
-    // Load files as arguments
-    for (l = filelist; l != NULL; l = g_list_next (l))
-    {
-        /* TODO: Use g_shell_quote() instead. */
-        // We must enclose filename between " because of possible (probable!) spaces in filenames"
-        argv[argv_index++] = g_strconcat ("\"", (gchar *)l->data, "\"", NULL);
-    }
-    argv[argv_index] = NULL; // Ends the list of arguments
-
-    // Make a command line with all arguments (joins strings together to form one long string separated by a 
space)
-    argv_join = g_strjoinv(" ", argv);
-    // Build the full command to pass to CreateProcess (FIX ME : it will ignore args of program)
-    full_command = g_strconcat("\"",program_path,"\" ",argv_join,NULL);
-
-    //if (CreateProcess(program_path, // Here it doesn't seem to load all the selected files
-    //                  argv_join,
-    if (CreateProcess(NULL,
-                      full_command,
-                      NULL,
-                      NULL,
-                      FALSE,
-                      CREATE_DEFAULT_ERROR_MODE,
-                      NULL,
-                      NULL,
-                      &siStartupInfo,
-                      &piProcessInfo) == FALSE)
-    {
-        gchar *error;
-
-        error = g_win32_error_message (GetLastError ());
-        Log_Print (LOG_ERROR, _("Cannot execute ā€˜%sā€™ (%s)"), program_name,
-                   error);
-        g_free (error);
-    }
-
-    // Free allocated parameters (for each filename)
-    for (argv_index = 1; argv[argv_index]; argv_index++)
-        g_free(argv[argv_index]);
-
-    g_free(argv_join);
-    g_free(full_command);
-    g_free(program_path);
-
-#else /* !G_OS_WIN32 */
-
     g_free(program_path); // Freed as never used
 
     argv_user = g_strsplit(program_name," ",0); // the string may contains arguments, space is the delimiter
@@ -4378,7 +4312,6 @@ Run_Program (const gchar *program_name, GList *args_list)
     }
 
     g_strfreev (argv_user);
-#endif /* !G_OS_WIN32 */
 
     return TRUE;
 }
diff --git a/src/misc.c b/src/misc.c
index 83107d6..f258f7d 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -759,16 +759,10 @@ Run_Audio_Player_Using_File_List (GList *etfilelist)
     ET_File *etfile;
     gchar   *filename;
     gchar   *program_path;
-#ifdef G_OS_WIN32
-    gchar              *argv_join;
-    STARTUPINFO         siStartupInfo;
-    PROCESS_INFORMATION piProcessInfo;
-#else /* !G_OS_WIN32 */
     GPid pid;
     gchar **argv_user;
     gint    argv_user_number;
     GError *error = NULL;
-#endif /* !G_OS_WIN32 */
 
     g_return_if_fail (etfilelist != NULL);
 
@@ -798,57 +792,6 @@ Run_Audio_Player_Using_File_List (GList *etfilelist)
     }
     g_free(program_path);
 
-    /* TODO: Replace with g_spawn_async()? */
-#ifdef G_OS_WIN32
-    // See documentation : http://c.developpez.com/faq/vc/?page=ProcessThread and 
http://www.answers.com/topic/createprocess
-    ZeroMemory(&siStartupInfo, sizeof(siStartupInfo));
-    siStartupInfo.cb = sizeof(siStartupInfo);
-    ZeroMemory(&piProcessInfo, sizeof(piProcessInfo));
-
-    argv = g_new0(gchar *,g_list_length(etfilelist) + 2); // "+2" for 1rst arg 'foo' and last arg 'NULL'
-    argv[argv_index++] = "foo";
-
-    // Load files as arguments
-    for (l = etfilelist; l != NULL; l = g_list_next (l))
-    {
-        etfile = (ET_File *)l->data;
-        filename = ((File_Name *)etfile->FileNameCur->data)->value;
-        //filename_utf8 = ((File_Name *)etfile->FileNameCur->data)->value_utf8;
-        /* TODO: Use g_shell_quote() instead. */
-        // We must enclose filename between quotes, because of possible (probable!) spaces in filenames"
-        argv[argv_index++] = g_strconcat("\"", filename, "\"", NULL);
-    }
-    argv[argv_index] = NULL; // Ends the list of arguments
-
-    // Make a command line with all arguments (joins strings together to form one long string separated by a 
space)
-    argv_join = g_strjoinv(" ", argv);
-
-    if (CreateProcess(AUDIO_FILE_PLAYER,
-                      argv_join,
-                      NULL,
-                      NULL,
-                      FALSE,
-                      CREATE_DEFAULT_ERROR_MODE,
-                      NULL,
-                      NULL,
-                      &siStartupInfo,
-                      &piProcessInfo) == FALSE)
-    {
-        gchar *error;
-
-        error = g_win32_error_message (GetLastError ());
-        Log_Print (LOG_ERROR, _("Cannot execute ā€˜%sā€™ (%s)"), AUDIO_FILE_PLAYER,
-                   error);
-        g_free (error);
-    }
-
-    // Free allocated parameters (for each filename)
-    for (argv_index = 1; argv[argv_index]; argv_index++)
-        g_free(argv[argv_index]);
-
-    g_free(argv_join);
-
-#else /* !G_OS_WIN32 */
     argv_user = g_strsplit(AUDIO_FILE_PLAYER," ",0); // the string may contains arguments, space is the 
delimiter
     // Number of arguments into 'argv_user'
     for (argv_user_number=0;argv_user[argv_user_number];argv_user_number++);
@@ -894,7 +837,6 @@ Run_Audio_Player_Using_File_List (GList *etfilelist)
     }
 
     g_strfreev (argv_user);
-#endif /* !G_OS_WIN32 */
 
     g_free(argv);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]