The problem with the previous code - which used mp.get_user_path, is that it returns a path even with --no-config, and even if the file doesn't exist. This is why we tested the "config" property, and also used mp.utils.file_info to check that the file exists. mp.find_config_file doesn't return a path with no-cofig and doesn't return a path if the file doesn't exists. It's simpler and better.
Showing the changes to player/javascript (1 of 1 file). Show all
Unified · Split
| @@ -771,14 +771,10 @@ g.mp_event_loop = function mp_event_loop() { · 770 unmodified lines | ||
| 771 | 771 | |
| 772 | 772 | |
| 773 | 773 | // let the user extend us, e.g. by adding items to mp.module_paths |
| 774 | −if (mp.get_property_bool("config")) { // --no-config disables custom init | |
| 775 | − // file_info doesn't expand meta-paths (other file functions do) | |
| 776 | − var file_info = mp.utils.file_info, user_path = mp.utils.get_user_path; | |
| 777 | − | |
| 778 | − if (file_info(user_path("~~/init.js"))) | |
| 779 | − require("~~/init"); | |
| 780 | − else if (file_info(user_path("~~/.init.js"))) | |
| 781 | − mp.msg.warn("Config file ~~/.init.js is ignored. Use ~~/init.js"); | |
| 782 | −} | |
| 774 | +var initjs = mp.find_config_file("init.js"); // ~~/init.js | |
| 775 | +if (initjs) | |
| 776 | + require(initjs.slice(0, -3)); // remove ".js" | |
| 777 | +else if ((initjs = mp.find_config_file(".init.js"))) | |
| 778 | + mp.msg.warn("Use init.js instead of .init.js (ignoring " + initjs + ")"); | |
| 783 | 779 | |
| 784 | 780 | })(this) |