Index: /trunk/Common/log.c
===================================================================
--- /trunk/Common/log.c	(revision 252)
+++ /trunk/Common/log.c	(revision 253)
@@ -3,4 +3,5 @@
 #include "cm_log.h"
 
+#include "../config.h"
 #include "cm_string.h"
 
@@ -26,8 +27,13 @@
 #define LOGNAME_LENGTH 12
 
+#ifdef BUILD_GUI_VALID
+void AddLog(const char* str);
+#endif
+
 void cm_force_log(const char* log) {
 	time_t t = time(NULL);
 	struct tm* tm = localtime(&t);
 	char date[513];
+	char* str;
 	strftime(date, 512, "%a %b %d %H:%M:%S %Z %Y", tm);
 #ifdef _PSP
@@ -35,8 +41,14 @@
 #elif defined(__PPU__)
 	tt_printf("[%s] %s\n", date, log);
+#elif defined(BUILD_GUI_VALID)
+	str = malloc(strlen(date) + strlen(log) + 3 + 1);
+	str[strlen(date) + strlen(log) + 3] = 0;
+	sprintf(str, "[%s] %s", date, log);
+	AddLog(str);
+	free(str);
 #else
 	fprintf(logfile, "[%s] %s\n", date, log);
+	fflush(logfile);
 #endif
-	fflush(logfile);
 }
 
Index: /trunk/Platform/watcom.mk
===================================================================
--- /trunk/Platform/watcom.mk	(revision 252)
+++ /trunk/Platform/watcom.mk	(revision 253)
@@ -14,3 +14,4 @@
 LIBSUF = .dll
 OBJ = obj
-SERVADD = wrc -bt=nt -i=$(WATCOM)/h/nt tewi.rc tewi.exe && wrc -bt=nt -i=$(WATCOM)/h/nt gui.rc tewi.exe
+REQOBJS = concat.rc
+SERVADD = wrc -bt=nt -i=$(WATCOM)/h/nt concat.rc tewi.exe
Index: /trunk/Server/Makefile
===================================================================
--- /trunk/Server/Makefile	(revision 252)
+++ /trunk/Server/Makefile	(revision 253)
@@ -46,21 +46,23 @@
 	$(CC) $(CFLAGS) $(EXTCFLAGS) -c -o $@ $<
 
-tewi.res: tewi.rc ../Binary/tewi.ico
-	$(WINDRES) tewi.rc -O coff -o $@
+tewi.res: concat.rc ../Binary/tewi.ico
+	$(WINDRES) concat.rc -O coff -o $@
 
-tewi_bcc.res: tewi.rc ../Binary/tewi.ico
-	brc32 -r -fo$@ tewi.rc
+tewi_bcc.res: concat.rc ../Binary/tewi.ico
+	brc32 -r -fo$@ concat.rc
 
-gui.res: gui.rc gui.h
-	$(WINDRES) gui.rc -O coff -o $@
+gui.res: concat.rc gui.h
+	$(WINDRES) concat.rc -O coff -o $@
 
-gui_bcc.res: gui.rc gui.h
-	brc32 -r -fo$@ gui.rc
+gui_bcc.res: concat.rc gui.h
+	brc32 -r -fo$@ concat.rc
 
-vc6.res: tewi.rc gui.rc
-	cat tewi.rc gui.rc > concat.rc
+vc6.res: concat.rc
 	rc /fo$@ concat.rc
 	rm -f concat.rc
 
+concat.rc: tewi.rc gui.rc
+	cat tewi.rc gui.rc > concat.rc
+
 clean:
 	rm -f *.o tewi *.exe *.res *.elf *.sfo *.pbp *.self *.pkg *.obj concat.rc
Index: /trunk/Server/config.c
===================================================================
--- /trunk/Server/config.c	(revision 252)
+++ /trunk/Server/config.c	(revision 253)
@@ -132,4 +132,5 @@
 	int ifbr = 0;
 	int ignore = -1;
+	int portcount;
 	FILE* f;
 	cm_log("Config", "Reading %s", path);
@@ -488,5 +489,10 @@
 		free(line);
 		fclose(f);
-		return stop;
+		for(portcount = 0; config.ports[portcount] != -1; portcount++);
+		if(portcount == 0){
+			return 1;
+		}else{
+			return stop;
+		}
 	} else {
 		cm_log("Config", "Could not open the file");
Index: /trunk/Server/gui.c
===================================================================
--- /trunk/Server/gui.c	(revision 252)
+++ /trunk/Server/gui.c	(revision 253)
@@ -4,6 +4,11 @@
 
 #include "gui.h"
-
+#include "tw_server.h"
+
+#include <cm_log.h>
+
+#include <stdio.h>
 #include <windows.h>
+#include <process.h>
 #include <commctrl.h>
 
@@ -15,13 +20,16 @@
 HWND button_about;
 HWND status;
+HFONT monospace;
 BOOL tewi_alive;
 BOOL was_starting;
 BOOL exiting;
+BOOL idle;
+extern FILE* logfile;
+extern int running;
 
 #define WINWIDTH(rc) (rc.right - rc.left)
 #define WINHEIGHT(rc) (rc.bottom - rc.top)
 
-#define DIALOG_X(n) (HIWORD(GetDialogBaseUnits()) * n)
-#define DIALOG_Y(n) (LOWORD(GetDialogBaseUnits()) * n)
+int startup(int argc, char** argv);
 
 void ShowBitmapSize(HWND hWnd, HDC hdc, const char* name, int x, int y, int w, int h){
@@ -45,4 +53,23 @@
 }
 
+int max = 0;
+void AddLog(const char* str){
+	HDC hdc;
+	PAINTSTRUCT ps;
+	SIZE sz;
+
+	SendMessage(logarea, LB_ADDSTRING, 0, (LPARAM)str);
+
+	hdc = CreateCompatibleDC(NULL);
+	SelectObject(hdc, monospace);
+	GetTextExtentPoint32(hdc, str, strlen(str), &sz);
+	DeleteDC(hdc);
+	
+	if(max < sz.cx){
+		max = sz.cx;
+		SendMessage(logarea, LB_SETHORIZONTALEXTENT, max, 0);
+	}
+}
+
 LRESULT CALLBACK VersionDialog(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp){
 	if(msg == WM_COMMAND){
@@ -63,5 +90,5 @@
 		HDC dc = (HDC)wp;
 		SetBkMode(dc, TRANSPARENT);
-		return GetSysColorBrush(COLOR_MENU);
+		return (LRESULT)GetSysColorBrush(COLOR_MENU);
 	}else{
 		return FALSE;
@@ -70,10 +97,33 @@
 }
 
+void tewi_thread(void* ptr){
+	int st = startup(0, NULL);
+	was_starting = TRUE;
+	if(st == -1){
+		tewi_alive = TRUE;
+		idle = FALSE;
+	}else{
+		cm_force_log("Config error");
+		idle = FALSE;
+		_endthread();
+	}
+	running = 1;
+	tw_server_loop();
+	tewi_alive = FALSE;
+	was_starting = TRUE;
+	idle = FALSE;
+	_endthread();
+}
+
 void StartTewi(void){
-	was_starting = TRUE;
+	EnableWindow(button_start, FALSE);
+	EnableWindow(button_stop, FALSE);
+	_beginthread(tewi_thread, 0, NULL);
 }
 
 void StopTewi(void){
-	was_starting = TRUE;
+	EnableWindow(button_start, FALSE);
+	EnableWindow(button_stop, FALSE);
+	running = 0;
 }
 
@@ -119,4 +169,6 @@
 		InitCommonControls();
 
+		monospace = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
+
 		status = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM, NULL, hWnd, GUI_STATUS);
 		SendMessage(status, SB_SIMPLE, 0, 0);
@@ -129,9 +181,13 @@
 		button_about = CreateWindow("BUTTON", "&About", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, 20 * 2, 100, 20, hWnd, (HMENU)GUI_BUTTON_ABOUT, hInst, NULL);
 		button_about = CreateWindow("BUTTON", "E&xit", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, WINWIDTH(rc) - 100, WINHEIGHT(rc) - WINHEIGHT(src) - 20, 100, 20, hWnd, (HMENU)GUI_BUTTON_EXIT, hInst, NULL);
-		logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL);
+		logarea = CreateWindow("LISTBOX", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOSEL, 0, 40, WINWIDTH(rc) - 100, WINHEIGHT(rc) - 40 - WINHEIGHT(src), hWnd, (HMENU)GUI_LOG, hInst, NULL);
+
+		SendMessage(logarea, WM_SETFONT, (WPARAM)monospace, TRUE);
+
 		SetTimer(hWnd, TIMER_WATCH_TEWI, 100, NULL);
 	}else if(msg == WM_TIMER){
 		if(wp == TIMER_WATCH_TEWI){
-			if(tewi_alive){
+			if(idle){
+			}else if(tewi_alive){
 				if(was_starting){
 					was_starting = FALSE;
@@ -140,4 +196,5 @@
 				EnableWindow(button_start, FALSE);
 				EnableWindow(button_stop, TRUE);
+				idle = TRUE;
 			}else{
 				if(was_starting){
@@ -151,4 +208,5 @@
 					SendMessage(hWnd, WM_CLOSE, 0, 0);
 				}
+				idle = TRUE;
 			}
 		}
@@ -172,5 +230,6 @@
 
 BOOL InitApp(void){
-	WNDCLASS wc;
+	WNDCLASSEX wc;
+	wc.cbSize = sizeof(WNDCLASSEX);
 	wc.style = CS_HREDRAW | CS_VREDRAW;
 	wc.lpfnWndProc = WndProc;
@@ -183,5 +242,6 @@
 	wc.lpszMenuName = NULL;
 	wc.lpszClassName = "tewihttpd";
-	return RegisterClass(&wc);
+	wc.hIconSm = LoadIcon(hInst, "TEWI");
+	return RegisterClassEx(&wc);
 }
 
@@ -191,5 +251,5 @@
 	HWND hDeskWnd = GetDesktopWindow();
 	GetWindowRect(hDeskWnd, &deskrc);
-	hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 200, NULL, 0, hInst, NULL);
+	hWnd = CreateWindow("tewihttpd", "Tewi HTTPd", (WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME) ^ WS_MAXIMIZEBOX, 0, 0, 600, 400, NULL, 0, hInst, NULL);
 
 	if(!hWnd){
@@ -210,4 +270,6 @@
 	was_starting = FALSE;
 	exiting = FALSE;
+	idle = TRUE;
+	logfile = stderr;
 	if(!InitApp()){
 		return FALSE;
Index: /trunk/Server/main.c
===================================================================
--- /trunk/Server/main.c	(revision 252)
+++ /trunk/Server/main.c	(revision 253)
@@ -527,5 +527,5 @@
 #endif
 
-#if !defined(BUILD_GUI) || !(defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__))
+#if !defined(BUILD_GUI_VALID)
 int main(int argc, char** argv) {
 	int st;
@@ -797,5 +797,5 @@
 	signal(SIGCHLD, SIG_IGN);
 	signal(SIGPIPE, SIG_IGN);
-#else
+#elif !defined(BUILD_GUI)
 	SetConsoleTitle(tw_server);
 #endif
Index: /trunk/Server/server.c
===================================================================
--- /trunk/Server/server.c	(revision 252)
+++ /trunk/Server/server.c	(revision 253)
@@ -1050,3 +1050,7 @@
 		}
 	}
-}
+	for(i = 0; i < sockcount; i++){
+		close_socket(sockets[i]);
+	}
+	cm_force_log("Server is down");
+}
Index: /trunk/config.h.tmpl
===================================================================
--- /trunk/config.h.tmpl	(revision 252)
+++ /trunk/config.h.tmpl	(revision 253)
@@ -18,4 +18,8 @@
 #ifdef NO_SSL
 #define SSL void
+#endif
+
+#if (defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)) && defined(USE_POLL)
+#define BUILD_GUI_VALID
 #endif
 
Index: /trunk/make-installer.sh
===================================================================
--- /trunk/make-installer.sh	(revision 252)
+++ /trunk/make-installer.sh	(revision 253)
@@ -24,5 +24,5 @@
 ../Tool/genconf "C:/Tewi" modules dll > ../generated.conf
 ../Tool/itworks > ../itworks.html
-makensis /inputcharset utf8 -DVERSION=$VERSION -DONLY_EXEC install.nsi
+makensis -DVERSION=$VERSION -DONLY_EXEC install.nsi
 cp install.exe ../install.exe
 cd ..
