| 872 | } |
| 873 | |
| 874 | bool Core::loadScriptFile(color_ostream &out, std::filesystem::path fname, bool silent) |
| 875 | { |
| 876 | if(!silent) { |
| 877 | INFO(script,out) << "Running script: " << fname << std::endl; |
| 878 | std::cerr << "Running script: " << fname << std::endl; |
| 879 | } |
| 880 | |
| 881 | auto pathlist = {getHackPath(), getHackPath().parent_path(), std::filesystem::current_path()}; |
| 882 | |
| 883 | std::filesystem::path path; |
| 884 | |
| 885 | for (auto& p : pathlist) |
| 886 | { |
| 887 | auto candidate = fname.is_relative() ? p / fname : fname; |
| 888 | if (std::filesystem::exists(candidate)) |
| 889 | { |
| 890 | path = candidate; |
| 891 | break; |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | std::ifstream script{ path }; |
| 896 | if ( !script ) |
| 897 | { |
| 898 | if(!silent) |
| 899 | out.printerr("Error loading script: {}\n", fname); |
| 900 | return false; |
| 901 | } |
| 902 | std::string command; |
| 903 | while(script.good()) { |
| 904 | std::string temp; |
| 905 | getline(script,temp); |
| 906 | bool doMore = false; |
| 907 | if ( temp.length() > 0 ) { |
| 908 | if ( temp[0] == '#' ) |
| 909 | continue; |
| 910 | if ( temp[temp.length()-1] == '\r' ) |
| 911 | temp = temp.substr(0,temp.length()-1); |
| 912 | if ( temp.length() > 0 ) { |
| 913 | if ( temp[temp.length()-1] == '\\' ) { |
| 914 | temp = temp.substr(0,temp.length()-1); |
| 915 | doMore = true; |
| 916 | } |
| 917 | } |
| 918 | } |
| 919 | command = command + temp; |
| 920 | if ( (!doMore || !script.good()) && !command.empty() ) { |
| 921 | runCommand(out, command); |
| 922 | command = ""; |
| 923 | } |
| 924 | } |
| 925 | return true; |
| 926 | } |
| 927 | |
| 928 | static void run_dfhack_init(color_ostream &out, Core *core) |
| 929 | { |
no test coverage detected