gaim/gaim

Buddy pounce commands now work in non-ASCII paths
oldstatus
2005-05-15, Daniel Atallah
3770305c569c
Parents 1068e9761861
Children 4d99f8de26ba
Buddy pounce commands now work in non-ASCII paths
  • +64 -24
    src/gtkpounce.c
  • --- a/src/gtkpounce.c Sun May 15 14:36:07 2005 -0400
    +++ b/src/gtkpounce.c Sun May 15 14:53:53 2005 -0400
    @@ -1015,44 +1015,84 @@
    if (gaim_pounce_action_is_enabled(pounce, "execute-command"))
    {
    const char *command;
    - char *localecmd;
    - command = gaim_pounce_action_get_attribute(pounce, "execute-command",
    - "command");
    - localecmd = g_locale_from_utf8(command, -1, NULL, NULL, NULL);
    + command = gaim_pounce_action_get_attribute(pounce,
    + "execute-command", "command");
    - if (localecmd != NULL)
    + if (command != NULL)
    {
    #ifndef _WIN32
    - int pid = fork();
    + char *localecmd = g_locale_from_utf8(command, -1, NULL,
    + NULL, NULL);
    - if (pid == 0) {
    - char *args[4];
    + if (localecmd != NULL)
    + {
    + int pid = fork();
    +
    + if (pid == 0) {
    + char *args[4];
    - args[0] = "sh";
    - args[1] = "-c";
    - args[2] = (char *)localecmd;
    - args[3] = NULL;
    + args[0] = "sh";
    + args[1] = "-c";
    + args[2] = (char *)localecmd;
    + args[3] = NULL;
    - execvp(args[0], args);
    + execvp(args[0], args);
    - _exit(0);
    + _exit(0);
    + }
    + g_free(localecmd);
    }
    #else /* !_WIN32 */
    - STARTUPINFO StartInfo;
    - PROCESS_INFORMATION ProcInfo;
    + PROCESS_INFORMATION pi;
    + BOOL retval;
    + gchar *message = NULL;
    +
    + memset(&pi, 0, sizeof(pi));
    +
    + if (G_WIN32_HAVE_WIDECHAR_API ()) {
    + STARTUPINFOW si;
    + wchar_t *wc_cmd = g_utf8_to_utf16(command,
    + -1, NULL, NULL, NULL);
    +
    + memset(&si, 0 , sizeof(si));
    + si.cb = sizeof(si);
    +
    + retval = CreateProcessW(NULL, wc_cmd, NULL,
    + NULL, 0, 0, NULL, NULL,
    + &si, &pi);
    + g_free(wc_cmd);
    + } else {
    + STARTUPINFOA si;
    + char *l_cmd = g_locale_from_utf8(command,
    + -1, NULL, NULL, NULL);
    - memset(&ProcInfo, 0, sizeof(ProcInfo));
    - memset(&StartInfo, 0 , sizeof(StartInfo));
    - StartInfo.cb = sizeof(StartInfo);
    - CreateProcess(NULL, (char *)command, NULL, NULL, 0, 0, NULL,
    - NULL, &StartInfo, &ProcInfo);
    + memset(&si, 0 , sizeof(si));
    + si.cb = sizeof(si);
    +
    + retval = CreateProcessA(NULL, l_cmd, NULL,
    + NULL, 0, 0, NULL, NULL,
    + &si, &pi);
    + g_free(l_cmd);
    + }
    +
    + if (retval) {
    + CloseHandle(pi.hProcess);
    + CloseHandle(pi.hThread);
    + } else {
    + message = g_win32_error_message(GetLastError());
    + }
    +
    gaim_debug_info("pounce",
    - "Pounce execute command called for: %s\n",
    - command);
    + "Pounce execute command called for: "
    + "%s\n%s%s%s",
    + command,
    + retval ? "" : "Error: ",
    + retval ? "" : message,
    + retval ? "" : "\n");
    + g_free(message);
    #endif /* !_WIN32 */
    }
    - g_free(localecmd);
    }
    if (gaim_pounce_action_is_enabled(pounce, "play-sound"))