@@ -66,23 +66,13 @@ CON_COMMAND_F(sar_download_file, "sar_download_file <url> <filepath> [directory]
6666 }
6767
6868 std::string filepath = args[2 ];
69- std::string gamedir = " " ;
69+ std::string gamedir = args. ArgC () > 3 ? args[ 3 ] : " " ;
7070
71- auto paths = fileSystem->GetSearchPaths ();
72- if (args.ArgC () > 3 && args[3 ][0 ]) {
73- for (auto path : paths) {
74- if (strstr (path.c_str (), args[3 ]) == NULL ) continue ;
75- gamedir = path;
76- break ;
77- }
78- }
79- if (gamedir == " " ) {
80- gamedir = std::string (engine->GetGameDirectory ()) + " /" ;
81- for (auto path : paths) {
82- if (!std::ifstream (path + filepath).good ()) continue ;
83- gamedir = path;
84- break ;
85- }
71+ auto result = fileSystem->FindFileSomewhere (filepath, gamedir);
72+ if (result.has_value ()) {
73+ filepath = result.value ();
74+ } else {
75+ filepath = std::string (engine->GetGameDirectory ()) + " /" + filepath;
8676 }
8777
8878 CURL *curl = curl_easy_init ();
@@ -102,13 +92,13 @@ CON_COMMAND_F(sar_download_file, "sar_download_file <url> <filepath> [directory]
10292 if (res == CURLE_OK) {
10393
10494 // Create any intermediate directories
105- std::string dirpath = gamedir + filepath;
95+ std::string dirpath = filepath;
10696 std::replace (dirpath.begin (), dirpath.end (), ' \\ ' , ' /' );
10797 dirpath = dirpath.substr (0 , dirpath.rfind (' /' ));
10898 std::filesystem::create_directories (dirpath);
10999
110- std::filesystem::remove (gamedir + filepath);
111- std::filesystem::copy (temp, gamedir + filepath); // for some reason moving the file doesn't work
100+ std::filesystem::remove (filepath);
101+ std::filesystem::copy (temp, filepath); // for some reason moving the file doesn't work
112102
113103 } else {
114104 console->Print (" An error occurred\n " );
0 commit comments