diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonMessages.ml ./src/daemon/common/commonMessages.ml
--- ./src/daemon/common/commonMessages.ml	2005-06-20 20:50:01.000000000 +0200
+++ ./src/daemon/common/commonMessages.ml	2005-07-07 00:16:58.000000000 +0200
@@ -29,7 +29,7 @@
 let message_file_name = try
     Sys.getenv "MLDONKEY_MESSAGES"
   with _ ->
-      Filename.concat CommonOptions.config_dir "messages.ini"
+      Filename.concat CommonOptions.home_dir "messages.ini"
     
       (* 
 let _ =
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/daemon/common/commonOptions.ml ./src/daemon/common/commonOptions.ml
--- ./src/daemon/common/commonOptions.ml	2005-07-05 14:26:40.000000000 +0200
+++ ./src/daemon/common/commonOptions.ml	2005-07-07 00:17:24.000000000 +0200
@@ -28,28 +28,31 @@
   
 let bin_dir = Filename.dirname Sys.argv.(0)
 
-let home_dir = (try Sys.getenv "HOME" with _ -> ".")
-
 let hidden_dir_prefix =
   if Autoconf.system = "windows" then "" else "."
 
-let config_dir_basename = hidden_dir_prefix ^ "mldonkey" 
+let config_dir_basename = hidden_dir_prefix ^ "mldonkey"
   
-let config_dir = Filename.concat home_dir config_dir_basename
+let home_dir =
+  match Autoconf.system with
+  | "windows" -> Filename.concat (try Sys.getenv "APPDATA" with _ -> ".") config_dir_basename
+  | "linux" | "freebsd" | "openbsd" | "solaris" | "darwin" ->
+       Filename.concat (try Sys.getenv "HOME" with _ -> ".") config_dir_basename
+  | _ -> "."
   
-let installer_ini = create_options_file (Filename.concat config_dir
+let installer_ini = create_options_file (Filename.concat home_dir
       "installer.ini")
   
 let installer_section = file_section installer_ini [] ""
   
 let mldonkey_directory = 
   define_option installer_section ["mldonkey_directory"] 
-    "The directory where mldonkey's option files are" string_option "."
+    "The directory where mldonkey's option files are" string_option home_dir
 
 let _ =
   (try Options.load installer_ini with _ -> ())
   
-let (file_basedir, home_basedir) = 
+let (file_basedir_pre, home_basedir) = 
   try
     if (String2.starts_with 
           (Filename.basename Sys.argv.(0))  "mlgui")
@@ -58,9 +61,8 @@
     try
       Unix.chdir chroot_dir;
       let new_passwd = Filename.concat chroot_dir "/etc/passwd" in
-      if not (Sys.file_exists new_passwd) then begin
-          lprintf "No /etc/passwd in your chroot directory\n create one if you want to use 'run_as_user' option\n"
-        end;
+      if not (Sys.file_exists new_passwd) then
+	lprintf "No /etc/passwd in your chroot directory\n create one if you want to use 'run_as_user' option\n";
       MlUnix.chroot chroot_dir;
       lprintf "mldonkey is now running in %s\n"  chroot_dir;
         ".", "."
@@ -73,11 +75,28 @@
       (
         try
           let s = Sys.getenv "MLDONKEY_DIR" in
-          if s = "" then "." else s
+          if s = "" then !!mldonkey_directory else s
         with _ ->
             !!mldonkey_directory
       ), home_dir
 
+let file_basedir =
+(* Creating dirs does work differently on Windows than Unix.
+   Dirs like c:\b are split down by unix2.safe_mkdir to "c".
+   This function splits the directory name into the drive name
+   and chdir to it before creating directories.
+   Non-absolute paths in $MLDONKEY_DIR do not work as well *)
+  if Sys.file_exists (Filename.concat (Sys.getcwd ()) "downloads.ini") then
+    (Sys.getcwd ())
+  else
+    if Autoconf.system = "windows" then
+      match String2.split file_basedir_pre ':' with
+      | drive :: directory :: _ ->
+          Unix.chdir (drive ^ ":\\");
+          directory
+      | _ -> lprintf "Please provide an absolute path in MLDONKEY_DIR like d:\\mldonkey, exiting...\n"; exit 2
+    else file_basedir_pre
+
 let _ =
   (try
      Unix2.safe_mkdir file_basedir
@@ -87,7 +106,6 @@
      exit 2);
   Unix2.can_write_to_directory file_basedir;
   Unix.chdir file_basedir;
-
   if Sys.file_exists "mlnet.pid" then
     begin
       lprintf "\n\n\nPID file mlnet.pid exists in %s\n"
@@ -98,14 +116,13 @@
       lprintf "this directory delete mlnet.pid and restart the core.\n";
       exit 2
     end;
-
-  lprintf "The .ini-files are saved in %s\n" file_basedir;
+  lprintf "\nMLDonkey is working in %s\n\n" file_basedir;
 
   let filename =
         try
       Sys.getenv "MLDONKEY_STRINGS"
     with _ ->
-        Filename.concat config_dir "mlnet_strings"
+        Filename.concat home_dir "mlnet_strings"
   in
   Unix2.safe_mkdir (Filename.dirname filename);
   Unix2.can_write_to_directory (Filename.dirname filename);
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/gui/gui_cdget.ml ./src/gtk/gui/gui_cdget.ml
--- ./src/gtk/gui/gui_cdget.ml	2004-03-07 10:37:37.000000000 +0100
+++ ./src/gtk/gui/gui_cdget.ml	2005-07-07 00:16:17.000000000 +0200
@@ -42,7 +42,7 @@
 module M = Gui_messages
 
 
-let mldonkey_cache = Filename.concat CommonOptions.config_dir "cache" 
+let mldonkey_cache = Filename.concat CommonOptions.home_dir "cache" 
   
 let file_from_url url = 
   try
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/gui/gui_messages.ml ./src/gtk/gui/gui_messages.ml
--- ./src/gtk/gui/gui_messages.ml	2004-02-02 20:55:20.000000000 +0100
+++ ./src/gtk/gui/gui_messages.ml	2005-07-07 00:16:34.000000000 +0200
@@ -26,7 +26,7 @@
 let message_file_name = try
     Sys.getenv "MLDONKEY_GUI_MESSAGES"
   with _ -> 
-      Filename.concat CommonOptions.config_dir "gui_messages.ini"
+      Filename.concat CommonOptions.home_dir "gui_messages.ini"
 
       (*
 let _ =
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/gui/gui_options.ml ./src/gtk/gui/gui_options.ml
--- ./src/gtk/gui/gui_options.ml	2004-01-14 23:54:17.000000000 +0100
+++ ./src/gtk/gui/gui_options.ml	2005-07-07 00:16:47.000000000 +0200
@@ -31,9 +31,9 @@
 module M = Gui_messages
 module C = Gui_columns
 
-let _ = Unix2.safe_mkdir CommonOptions.config_dir
+let _ = Unix2.safe_mkdir CommonOptions.home_dir
 let mldonkey_gui_ini = create_options_file 
-    (Filename.concat CommonOptions.config_dir "mldonkey_gui.ini")
+    (Filename.concat CommonOptions.home_dir "mldonkey_gui.ini")
   
 module KeyOption = struct
     
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/gui2/gui2_options.ml ./src/gtk/gui2/gui2_options.ml
--- ./src/gtk/gui2/gui2_options.ml	2003-12-02 18:04:41.000000000 +0100
+++ ./src/gtk/gui2/gui2_options.ml	2005-07-07 00:16:09.000000000 +0200
@@ -30,7 +30,7 @@
 module M = Gui2_messages
 
 let mldonkey_gui_ini = create_options_file 
-    (Filename.concat CommonOptions.config_dir "mldonkey_gui2.ini")
+    (Filename.concat CommonOptions.home_dir "mldonkey_gui2.ini")
   
 module KeyOption = struct
     
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/newgui/gui_installer.ml ./src/gtk/newgui/gui_installer.ml
--- ./src/gtk/newgui/gui_installer.ml	2004-03-07 10:34:25.000000000 +0100
+++ ./src/gtk/newgui/gui_installer.ml	2005-07-07 00:15:13.000000000 +0200
@@ -36,17 +36,8 @@
 
   
   
-let _ = Unix2.safe_mkdir CommonOptions.config_dir
-let installer_name = Filename.concat CommonOptions.config_dir "installer.ini"
-
-  (*
-let installer_ini = create_options_file installer_name
-  
-let mldonkey_directory = 
-  define_option CommonOptions.installer_section ["mldonkey_directory"] 
-    "The directory where mldonkey's option files are" string_option
-  config_dir
-    *)
+let _ = Unix2.safe_mkdir CommonOptions.home_dir
+let installer_name = Filename.concat CommonOptions.home_dir "installer.ini"
 
 let _ =
   (try Options.load CommonOptions.installer_ini with _ -> ())
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/newgui/gui_main.ml ./src/gtk/newgui/gui_main.ml
--- ./src/gtk/newgui/gui_main.ml	2004-11-01 12:23:00.000000000 +0100
+++ ./src/gtk/newgui/gui_main.ml	2005-07-07 00:15:19.000000000 +0200
@@ -35,7 +35,7 @@
 (*module Gui_rooms = Gui_rooms2*)
 let chmod_config () =
   let base_config = 
-    (Filename.concat CommonOptions.config_dir "mldonkey_newgui.ini")
+    (Filename.concat CommonOptions.home_dir "mldonkey_newgui.ini")
   in
   let save_config =
     base_config^".old"
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/newgui/gui_messages.ml ./src/gtk/newgui/gui_messages.ml
--- ./src/gtk/newgui/gui_messages.ml	2004-05-03 10:22:25.000000000 +0200
+++ ./src/gtk/newgui/gui_messages.ml	2005-07-07 00:15:31.000000000 +0200
@@ -27,7 +27,7 @@
     Sys.getenv "MLDONKEY_GUI_MESSAGES"
   with _ -> 
       let filename = 
-        Filename.concat CommonOptions.config_dir "newgui_messages.ini"
+        Filename.concat CommonOptions.home_dir "newgui_messages.ini"
       in
       Unix2.safe_mkdir (Filename.dirname filename);
       filename
@@ -880,7 +880,7 @@
 (** Messages and string constants. *)
 
 let chat_config_file = 
-  Filename.concat CommonOptions.config_dir "chat.ini"
+  Filename.concat CommonOptions.home_dir "chat.ini"
 
 (** {2 Command line messages} *)
 
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/newgui/gui_options.ml ./src/gtk/newgui/gui_options.ml
--- ./src/gtk/newgui/gui_options.ml	2005-03-02 20:28:14.000000000 +0100
+++ ./src/gtk/newgui/gui_options.ml	2005-07-07 00:15:41.000000000 +0200
@@ -43,10 +43,10 @@
 module M = Gui_messages
 module C = Gui_columns
 
-let _ = Unix2.safe_mkdir CommonOptions.config_dir
+let _ = Unix2.safe_mkdir CommonOptions.home_dir
   
 let mldonkey_gui_ini = create_options_file 
-    (Filename.concat CommonOptions.config_dir "mldonkey_newgui.ini")
+    (Filename.concat CommonOptions.home_dir "mldonkey_newgui.ini")
   
 module KeyOption = struct
     
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk/progress/gui_progress_main.ml ./src/gtk/progress/gui_progress_main.ml
--- ./src/gtk/progress/gui_progress_main.ml	2004-03-18 00:42:32.000000000 +0100
+++ ./src/gtk/progress/gui_progress_main.ml	2005-07-07 00:14:50.000000000 +0200
@@ -36,7 +36,7 @@
 (*module Gui_rooms = Gui_rooms2*)
 let chmod_config () =
   let base_config = 
-    (Filename.concat CommonOptions.config_dir "mldonkey_gui.ini")
+    (Filename.concat CommonOptions.home_dir "mldonkey_gui.ini")
   in
   let save_config =
     base_config^".old"
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk2/gui/gui_installer.ml ./src/gtk2/gui/gui_installer.ml
--- ./src/gtk2/gui/gui_installer.ml	2005-03-02 20:45:12.000000000 +0100
+++ ./src/gtk2/gui/gui_installer.ml	2005-07-07 00:14:32.000000000 +0200
@@ -36,17 +36,8 @@
 
   
   
-let _ = Unix2.safe_mkdir CommonOptions.config_dir
-let installer_name = Filename.concat CommonOptions.config_dir "installer.ini"
-
-  (*
-let installer_ini = create_options_file installer_name
-  
-let mldonkey_directory = 
-  define_option CommonOptions.installer_section ["mldonkey_directory"] 
-    "The directory where mldonkey's option files are" string_option
-  config_dir
-    *)
+let _ = Unix2.safe_mkdir CommonOptions.home_dir
+let installer_name = Filename.concat CommonOptions.home_dir "installer.ini"
 
 let _ =
   (try Options.load CommonOptions.installer_ini with _ -> ())
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk2/gui/guiMain.ml ./src/gtk2/gui/guiMain.ml
--- ./src/gtk2/gui/guiMain.ml	2005-05-02 14:57:59.000000000 +0200
+++ ./src/gtk2/gui/guiMain.ml	2005-07-07 00:13:35.000000000 +0200
@@ -47,7 +47,7 @@
 
 let chmod_config () =
   let base_config = 
-    (Filename.concat CommonOptions.config_dir "mlgui.ini")
+    (Filename.concat CommonOptions.home_dir "mlgui.ini")
   in
   let save_config =
     base_config ^ ".old"
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk2/gui/guiMessages.ml ./src/gtk2/gui/guiMessages.ml
--- ./src/gtk2/gui/guiMessages.ml	2005-04-26 13:02:21.000000000 +0200
+++ ./src/gtk2/gui/guiMessages.ml	2005-07-07 00:13:48.000000000 +0200
@@ -23,7 +23,7 @@
 open Options
 open Gettext
 
-let filename = Filename.concat CommonOptions.config_dir "mlnet_strings"
+let filename = Filename.concat CommonOptions.home_dir "mlnet_strings"
 
 let _s x = (* lprintf "searching string %s\n" x; *) GuiUtf8.simple_utf8_of (_s "GuiMessages" x)
 
@@ -966,7 +966,7 @@
 (* Messages and string constants. *)
 
 let chat_config_file = 
-  Filename.concat CommonOptions.config_dir "chat.ini"
+  Filename.concat CommonOptions.home "chat.ini"
 
 (* {2 Command line messages} *)
 
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk2/gui/guiOptions.ml ./src/gtk2/gui/guiOptions.ml
--- ./src/gtk2/gui/guiOptions.ml	2005-04-26 13:02:21.000000000 +0200
+++ ./src/gtk2/gui/guiOptions.ml	2005-07-07 00:14:07.000000000 +0200
@@ -40,10 +40,10 @@
 module M = GuiMessages
 module C = GuiColumns
 
-let _ = Unix2.safe_mkdir CommonOptions.config_dir
+let _ = Unix2.safe_mkdir CommonOptions.home_dir
   
 let gui_ini = create_options_file 
-    (Filename.concat CommonOptions.config_dir "mlgui.ini")
+    (Filename.concat CommonOptions.home_dir "mlgui.ini")
 
 
 
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/gtk2/gui/guiStarter.ml ./src/gtk2/gui/guiStarter.ml
--- ./src/gtk2/gui/guiStarter.ml	2005-03-02 20:45:11.000000000 +0100
+++ ./src/gtk2/gui/guiStarter.ml	2005-07-07 00:14:13.000000000 +0200
@@ -10,7 +10,7 @@
     Sys.getenv "MLDONKEY_GUI_MESSAGES"
   with _ -> 
       let filename = 
-        Filename.concat CommonOptions.config_dir "gtk2gui_messages.ini"
+        Filename.concat CommonOptions.home_dir "gtk2gui_messages.ini"
       in
       Unix2.safe_mkdir (Filename.dirname filename);
       filename
diff -x CVS -x Root -x Repository -x Tag -x Entries -x Entries.Log -x .svn -x '*.rej' -x '*.orig' -x .cvsignore -N -r -u ./src/im/imOptions.ml ./src/im/imOptions.ml
--- ./src/im/imOptions.ml	2005-03-02 21:37:09.000000000 +0100
+++ ./src/im/imOptions.ml	2005-07-07 00:13:29.000000000 +0200
@@ -51,7 +51,7 @@
   end
 
 let accounts_ini = create_options_file
-    (Filename.concat  CommonOptions.config_dir "mldonkey_im.ini")
+    (Filename.concat  CommonOptions.home_dir "mldonkey_im.ini")
 let accounts_section = file_section accounts_ini [] ""
   
 let accounts = 
