diff -ruN xchat-2.6.4.orig/src/common/thread.c xchat-2.6.4/src/common/thread.c --- xchat-2.6.4.orig/src/common/thread.c Thu Jan 1 02:00:00 1970 +++ xchat-2.6.4/src/common/thread.c Wed Jun 21 18:30:04 2006 @@ -0,0 +1,111 @@ +#include +#include + +#define USE_PTHREAD + +#ifdef WIN32 + +#include +#define pthread_t DWORD +#define pipe(a) _pipe(a,4096,_O_BINARY) + +#else +#ifdef USE_PTHREAD + +#include + +#else + +#include +#include +#include +#define pthread_t int + +#endif +#endif + + +typedef struct +{ + pthread_t threadid; + int pipe_fd[2]; +} thread; + +thread * +thread_new (void) +{ + thread *th; + + th = calloc (1, sizeof (*th)); + if (!th) + return NULL; + + if (pipe (th->pipe_fd) == -1) + { + free (th); + return NULL; + } + +#ifdef __EMX__ /* os/2 */ + setmode (pipe_fd[0], O_BINARY); + setmode (pipe_fd[1], O_BINARY); +#endif + + return th; +} + +int +thread_start (thread *th, void *(*start_routine)(void *), void *arg) +{ + pthread_t id; + +#ifdef WIN32 + CloseHandle (CreateThread (NULL, 0, + (LPTHREAD_START_ROUTINE)start_routine, + arg, 0, (DWORD *)&id)); +#else +#ifdef USE_PTHREAD + if (pthread_create (&id, NULL, start_routine, arg) != 0) + return 0; +#else + switch (id = fork ()) + { + case -1: + return 0; + case 0: + /* this is the child */ + setuid (getuid ()); + start_routine (arg); + _exit (0); + } +#endif +#endif + + th->threadid = id; + + return 1; +} + +/*void +thread_kill (thread *th) +{ +#ifdef WIN32 + PostThreadMessage (th->threadid, WM_QUIT, 0, 0); +#else +#ifdef USE_PTHREAD + pthread_cancel (th->threadid); + pthread_join (th->threadid, (void *)&th); +#else + kill (th->threadid, SIGKILL); + waitpid (th->threadid, NULL, 0); +#endif +#endif +} + +void +thread_free (thread *th) +{ + close (th->pipe_fd[0]); + close (th->pipe_fd[1]); + free (th); +}*/ diff -ruN xchat-2.6.4.orig/src/fe-gtk/gtkutil.c xchat-2.6.4/src/fe-gtk/gtkutil.c --- xchat-2.6.4.orig/src/fe-gtk/gtkutil.c Tue Jun 6 04:35:02 2006 +++ xchat-2.6.4/src/fe-gtk/gtkutil.c Wed Jun 21 18:34:44 2006 @@ -50,6 +50,10 @@ #include "../common/fe.h" #include "gtkutil.h" #include "pixmaps.h" +#ifdef WIN32 +#include "../common/fe.h" +#include "../common/thread.c" +#endif /* gtkutil.c, just some gtk wrappers */ @@ -62,6 +66,13 @@ void *userdata; filereqcallback callback; int flags; /* FRF_* flags */ + + #ifdef WIN32 + int multiple; + thread *th; + char *title; /* native locale */ + char *filter; + #endif }; static char last_dir[256] = ""; @@ -180,6 +191,198 @@ } } +#ifdef WIN32 + +static int +win32_openfile (char *file_buf, int file_buf_len, char *title_text, char *filter, + int multiple) +{ + OPENFILENAME o; + + memset (&o, 0, sizeof (o)); + + o.lStructSize = sizeof (o); + o.lpstrFilter = filter; + o.lpstrFile = file_buf; + o.nMaxFile = file_buf_len; + o.lpstrTitle = title_text; + o.Flags = 0x02000000 | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | + OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_LONGNAMES | OFN_NONETWORKBUTTON; + if (multiple) + o.Flags |= OFN_ALLOWMULTISELECT; + + return GetOpenFileName (&o); +} + +static int +win32_savefile (char *file_buf, int file_buf_len, char *title_text, char *filter, + int multiple) +{ + OPENFILENAME o; + + memset (&o, 0, sizeof (o)); + + o.lStructSize = sizeof (o); + o.lpstrFilter = filter; + o.lpstrFile = file_buf; + o.nMaxFile = file_buf_len; + o.lpstrTitle = title_text; + o.Flags = 0x02000000 | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | + OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_LONGNAMES | OFN_NONETWORKBUTTON; + if (multiple) + o.Flags |= OFN_ALLOWMULTISELECT; + + return GetSaveFileName (&o); +} + +static void * +win32_thread (struct file_req *freq) +{ + char buf[1024 + 32]; + char file[1024]; + + memset (file, 0, sizeof (file)); + safe_strcpy (file, last_dir, sizeof (file)); + + if (win32_openfile (file, sizeof (file), freq->title, freq->filter, freq->multiple)) + { + if (freq->multiple) + { + char *f = file; + + if (f[strlen (f) + 1] == 0) /* only selected one file */ + { + snprintf (buf, sizeof (buf), "1\n%s\n", file); + write (freq->th->pipe_fd[1], buf, strlen (buf)); + } else + { + f += strlen (f) + 1; /* skip first, it's only the dir */ + while (f[0]) + { + snprintf (buf, sizeof (buf), "1\n%s\\%s\n", /*dir!*/file, f); + write (freq->th->pipe_fd[1], buf, strlen (buf)); + f += strlen (f) + 1; + } + } + + } else + { + snprintf (buf, sizeof (buf), "1\n%s\n", file); + write (freq->th->pipe_fd[1], buf, strlen (buf)); + } + } + + write (freq->th->pipe_fd[1], "0\n", 2); + Sleep (2000); + + return NULL; +} + +static void * +win32_thread2 (struct file_req *freq) +{ + char buf[1024 + 32]; + char file[1024]; + + memset (file, 0, sizeof (file)); + safe_strcpy (file, last_dir, sizeof (file)); + + if (win32_savefile (file, sizeof (file), freq->title, freq->filter, freq->multiple)) + { + if (freq->multiple) + { + char *f = file; + + if (f[strlen (f) + 1] == 0) /* only selected one file */ + { + snprintf (buf, sizeof (buf), "1\n%s\n", file); + write (freq->th->pipe_fd[1], buf, strlen (buf)); + } else + { + f += strlen (f) + 1; /* skip first, it's only the dir */ + while (f[0]) + { + snprintf (buf, sizeof (buf), "1\n%s\\%s\n", /*dir!*/file, f); + write (freq->th->pipe_fd[1], buf, strlen (buf)); + f += strlen (f) + 1; + } + } + + } else + { + snprintf (buf, sizeof (buf), "1\n%s\n", file); + write (freq->th->pipe_fd[1], buf, strlen (buf)); + } + } + + write (freq->th->pipe_fd[1], "0\n", 2); + Sleep (2000); + + return NULL; +} + +static int +waitline2 (GIOChannel *source, char *buf, int bufsize) +{ + int i = 0; + int len; + + while (1) + { + if (g_io_channel_read (source, &buf[i], 1, &len) != G_IO_ERROR_NONE) + return -1; + if (buf[i] == '\n' || bufsize == i + 1) + { + buf[i] = 0; + return i; + } + i++; + } +} + +static gboolean +win32_close_pipe (int fd) +{ + close (fd); + return 0; +} + +static gboolean +win32_read_thread (GIOChannel *source, GIOCondition cond, struct file_req *freq) +{ + char buf[512]; + char *file; + + waitline2 (source, buf, sizeof buf); + + switch (buf[0]) + { + case '0': /* filedialog has closed */ + freq->callback (freq->userdata, NULL); + break; + + case '1': /* got a filename! */ + waitline2 (source, buf, sizeof buf); + file = g_filename_to_utf8 (buf, -1, 0, 0, 0); + freq->callback (freq->userdata, file); + g_free (file); + return TRUE; + } + + /* it doesn't work to close them here, because of the weird + way giowin32 works. We must _return_ before closing them */ + g_timeout_add(3000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[0]); + g_timeout_add(2000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[1]); + + g_free (freq->title); + free (freq->th); + free (freq); + + return FALSE; +} + +#endif + void gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, int flags) @@ -187,6 +390,53 @@ struct file_req *freq; GtkWidget *dialog; extern char *get_xdir_fs (void); + + if (!(flags & FRF_WRITE)) + { + freq = malloc (sizeof (struct file_req)); + freq->th = thread_new (); + freq->flags = 0; + freq->multiple = (flags & FRF_MULTIPLE); + freq->callback = callback; + freq->userdata = userdata; + freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0); + if (!filter) + freq->filter = "All files\000*.*\000" + "EXE files\000*.EXE\000" + "MP3 files\000*.MP3\000" + "MPEG files\000*.MPG;*.MPEG\000" + "RAR files\000*.RAR\000" + "ZIP files\000*.ZIP\000"; + else + freq->filter = filter; + + thread_start (freq->th, win32_thread, freq); + fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq); + + return; + + } + + else { + freq = malloc (sizeof (struct file_req)); + freq->th = thread_new (); + freq->flags = 0; + freq->multiple = (flags & FRF_MULTIPLE); + freq->callback = callback; + freq->userdata = userdata; + freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0); + if (!filter) + freq->filter = "Text files\000*.TXT\000" + "All files\000*.*\000"; + else + freq->filter = filter; + + thread_start (freq->th, win32_thread2, freq); + fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq); + + return; + } +#endif if (flags & FRF_WRITE) { diff -ruN xchat-2.6.4.orig/src/fe-gtk/makefile.msc xchat-2.6.4/src/fe-gtk/makefile.msc --- xchat-2.6.4.orig/src/fe-gtk/makefile.msc Sun Jun 27 08:44:12 2004 +++ xchat-2.6.4/src/fe-gtk/makefile.msc Wed Jun 21 18:30:04 2006 @@ -13,13 +13,14 @@ $(CC) $(CFLAGS) $(GLIB) $(GTK) /c $< $(PROG): $(FEGTK_OBJECTS) $(COMLIB) xchat-icon.obj - $(LINK) /out:$(PROG) /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup $(LDFLAGS) $(FEGTK_OBJECTS) $(COMLIB) xchat-icon.obj + $(LINK) /out:$(PROG) /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup xchat-icon.obj $(LDFLAGS) $(FEGTK_OBJECTS) $(COMLIB) @dir $(PROG) xchat.rc: echo XC_ICON ICON "../../xchat.ico" > xchat.rc + echo 1 24 "xchat.exe.manifest" >> xchat.rc -xchat.res: xchat.rc ../../xchat.ico +xchat.res: xchat.rc xchat.exe.manifest ../../xchat.ico rc /r xchat.rc xchat-icon.obj: xchat.res diff -ruN xchat-2.6.4.orig/src/fe-gtk/plugingui.c xchat-2.6.4/src/fe-gtk/plugingui.c --- xchat-2.6.4.orig/src/fe-gtk/plugingui.c Thu Oct 20 06:37:04 2005 +++ xchat-2.6.4/src/fe-gtk/plugingui.c Wed Jun 21 18:30:04 2006 @@ -149,7 +149,9 @@ plugingui_load (void) { gtkutil_file_req (_("Select a Plugin or Script to load"), plugingui_load_cb, - current_sess, NULL, FRF_ADDFOLDER); + current_sess, + "Plugins and Scripts\000" "*.dll;*.pl;*.tcl;*.py\000" + "All files\000" "*.*\000", 0); } static void diff -ruN xchat-2.6.4.orig/src/fe-gtk/xchat.exe.manifest xchat-2.6.4/src/fe-gtk/xchat.exe.manifest --- xchat-2.6.4.orig/src/fe-gtk/xchat.exe.manifest Thu Jan 1 02:00:00 1970 +++ xchat-2.6.4/src/fe-gtk/xchat.exe.manifest Wed Jun 21 18:30:04 2006 @@ -0,0 +1,16 @@ + + + +IRC Client + +