diff -a -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/commonFile.ml ./src/daemon/common/commonFile.ml
--- ./src/daemon/common/commonFile.ml	2005-12-14 22:17:46.000000000 +0100
+++ ./src/daemon/common/commonFile.ml	2006-01-02 19:02:23.000000000 +0100
@@ -252,8 +252,20 @@
   
 let set_file_best_name file name =
   let file = as_file_impl file in
-  let name = String2.replace name '/' "::" in
-  file.impl_file_best_name <- name
+  let old_name = file.impl_file_best_name in
+  let real_name = Filename2.name_check name "" in
+  if real_name = "" then
+    lprintf_nl () "can not rename file \"%s\" to \"%s\""
+      file.impl_file_best_name real_name
+  else begin
+    file.impl_file_best_name <- real_name;
+    if name <> real_name then
+      lprintf_nl () "wanted new name \"%s\" changed to \"%s\" due to system limitations"
+        (String.escaped name) (String.escaped file.impl_file_best_name);
+    if !verbose && old_name <> file.impl_file_best_name then
+      lprintf_nl () "best_name of \"%s\" changed to \"%s\""
+        (String.escaped old_name) (String.escaped file.impl_file_best_name)
+  end
 
 let set_file_format (file : file) format =
   let file = as_file_impl file in
diff -a -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/driver/driverCommands.ml ./src/daemon/driver/driverCommands.ml
--- ./src/daemon/driver/driverCommands.ml	2006-01-01 20:25:42.000000000 +0100
+++ ./src/daemon/driver/driverCommands.ml	2006-01-02 18:35:31.000000000 +0100
@@ -1992,9 +1992,7 @@
 \\<td class=downloaded width=100%%\\>\\</td\\>
 \\<td nowrap class=\\\"fbig pr\\\"\\>\\<a onclick=\\\"javascript: {
                    var getdir = prompt('Input: <priority#> <directory> (surround dir with quotes if necessary)','0 /home/mldonkey/share')
-                   var reg = new RegExp (' ', 'gi') ;
-                   var outstr = getdir.replace(reg, '+');
-                   parent.fstatus.location.href='submit?q=share+' + encodeURI(outstr);
+                   parent.fstatus.location.href='submit?q=share+' + encodeURIComponent(getdir);
                    setTimeout('window.location.reload()',1000);
                     }\\\"\\>Add Share\\</a\\>
 \\</td\\>
@@ -2662,8 +2660,8 @@
         try
           let file = file_find num in
           set_file_best_name file new_name;
-          Printf.sprintf (_b "Download %d renamed to %s") num new_name
-        with _ -> Printf.sprintf (_b "No file number %d") num
+          Printf.sprintf (_b "Download %d renamed to %s") num (file_best_name file)
+        with e -> Printf.sprintf (_b "No file number %d, error %s") num (Printexc2.to_string e)
     ), "<num> \"<new name>\" :\t\tchange name of download <num> to <new name>";
 
     "dllink", Arg_multiple (fun args o ->
diff -a -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/networks/donkey/donkeyGlobals.ml ./src/networks/donkey/donkeyGlobals.ml
--- ./src/networks/donkey/donkeyGlobals.ml	2006-01-01 20:27:07.000000000 +0100
+++ ./src/networks/donkey/donkeyGlobals.ml	2006-01-02 13:23:15.000000000 +0100
@@ -277,9 +277,7 @@
       match impl.impl_file_probable_name with
         None -> ()
       | Some best_name ->
-          let best_name = String2.replace best_name '/' "::" in
-          set_file_best_name file best_name;
-          if !verbose then lprintf_nl () "BEST NAME now IS %s" best_name;
+          set_file_best_name file best_name
     with Not_found -> ()
 
 let new_file file_diskname file_state md4 file_size filenames writable =
diff -a -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/networks/donkey/donkeyInteractive.ml ./src/networks/donkey/donkeyInteractive.ml
--- ./src/networks/donkey/donkeyInteractive.ml	2006-01-01 20:27:07.000000000 +0100
+++ ./src/networks/donkey/donkeyInteractive.ml	2006-01-02 20:18:17.000000000 +0100
@@ -547,6 +547,13 @@
       else
         let md4 = if String.length md4 > 32 then
           String.sub md4 0 32 else md4 in
+	let name =
+	  let name2 = Filename2.name_check name "" in
+	    if name2 = "" then
+	      Printf.sprintf "urn_ed2k_%s" md4
+	    else
+	      name2
+	in
           begin try
             let file = query_download [name] (Int64.of_string size)
               (Md4.of_string md4) None None None false;
@@ -790,9 +797,7 @@
 \\<!--
 function submitRenameForm(i) {
 var formID = document.getElementById(\\\"renameForm\\\" + i)
-var regExp = new RegExp (' ', 'gi') ;
-var renameTextOut = formID.newName.value.replace(regExp, '+');
-parent.fstatus.location.href='submit?q=rename+'+i+'+\\\"'+encodeURI(renameTextOut)+'\\\"';
+parent.fstatus.location.href='submit?q=rename+'+i+'+\\\"'+encodeURIComponent(formID.newName.value)+'\\\"';
 }
 //--\\>
 \\</script\\>";
@@ -1279,9 +1284,7 @@
 \\<!--
 function submitRenameForm(i) {
 var formID = document.getElementById(\\\"renameForm\\\" + i)
-var regExp = new RegExp (' ', 'gi') ;
-var renameTextOut = formID.newName.value.replace(regExp, '+');
-parent.fstatus.location.href='submit?q=rename+%d+\\\"'+encodeURI(renameTextOut)+'\\\"';
+parent.fstatus.location.href='submit?q=rename+%d+\\\"'+encodeURIComponent(formID.newName.value)+'\\\"';
 }
 //--\\>
 \\</script\\>" (file_num file)
diff -a -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/utils/cdk/filename2.ml ./src/utils/cdk/filename2.ml
--- ./src/utils/cdk/filename2.ml	2005-10-17 17:25:46.000000000 +0200
+++ ./src/utils/cdk/filename2.ml	2006-01-02 18:59:09.000000000 +0100
@@ -150,6 +150,43 @@
   done;
   s
 
+let name_check name fs =
+  let windows name =
+    if Autoconf.windows then
+      let new_name = ref name in
+      let rec remove_leading name = (* filename can not start with a '.' *)
+        match String.sub name 0 1 with
+	| "." -> new_name := String.sub name 1 ((String.length name) - 1)
+	| _ -> raise Exit
+      in
+      let rec remove_trailing name = (* filename can not end with '.' or space *)
+        match String.sub name ((String.length name) - 1) 1 with
+	| "." | " " -> new_name := String.sub name 0 ((String.length name) - 1)
+	| _ -> raise Exit
+      in
+      (try while true do remove_leading !new_name done with _ -> ());
+      (try while true do remove_trailing !new_name done with _ -> ());
+      (* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/creating__deleting__and_maintaining_files.asp
+         filter: '*', '?', '|', ':' *)
+      let name = Str.global_replace (Str.regexp "\\*\\|\\?\\||\\|:\\|\"") "_" !new_name in
+      name
+    else
+      name
+  in
+  let macosx name =
+  (* ':' is directory seperator on Mac OS X: http://www.comentum.com/File-Systems-HFS-FAT-UFS.html *)
+    if Autoconf.system = "macosx" then
+      let name = String2.replace name ':' "_" in
+      name
+    else
+      name
+  in
+  (* filter: '/', '\', '<', '>', '"' *)
+  let name = Str.global_replace (Str.regexp "/\\|\\\\|<\\|>") "_" name in
+  let name = macosx name in
+  let name = windows name in
+  name
+
 let temp_directory () =
   match Sys.os_type with
     "Unix" | "Cygwin" ->
diff -a -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/utils/cdk/filename2.mli ./src/utils/cdk/filename2.mli
--- ./src/utils/cdk/filename2.mli	2005-10-17 17:25:46.000000000 +0200
+++ ./src/utils/cdk/filename2.mli	2006-01-02 14:05:03.000000000 +0100
@@ -63,5 +63,8 @@
   
 val escaped : string -> string
 
+(* remove invalid chars in a filename, depending on the filesystem *)
+val name_check : string -> string -> string
+
 val temp_directory : unit -> string
   
\ Kein Zeilenumbruch am Dateiende.
diff -a -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/utils/cdk/string2.mli ./src/utils/cdk/string2.mli
--- ./src/utils/cdk/string2.mli	2004-08-19 09:56:55.000000000 +0200
+++ ./src/utils/cdk/string2.mli	2006-01-02 14:45:42.000000000 +0100
@@ -103,7 +103,3 @@
   
 val map : (char -> 'a) -> string -> 'a array
 val iteri: (int -> char -> unit) -> string -> unit
-  
-
-val init : int -> (int -> char) -> string
-  
\ Kein Zeilenumbruch am Dateiende.
