Improved file name checking

The code that checks if a file name is legal was not very good (oops :sweat_smile: ) because it replaced way too many characters. With this patch it only replaces characters that are actually file name illegal (on Windows or on Unix) so it can handle for example Chinese characters fine now.