From b72442a0362a266990b5a8f7431ec708de1ff006 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 18 Aug 2020 23:33:25 +0200 Subject: WIP: FIX p2p --- src/Cache.cpp | 6 +++--- src/Process.cpp | 23 ++++++----------------- 2 files changed, 9 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/Cache.cpp b/src/Cache.cpp index bb87857..eecc790 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -351,9 +351,9 @@ namespace dchat string downloadLimitBytesStr = to_string(downloadLimitBytes); - std::string cmdUtf8 = "curl -L --silent -o '"; - cmdUtf8 += escapeCommand(filepath.string()); - cmdUtf8 += "' --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url '" + escapeCommand(url) + "'"; + std::string cmdUtf8 = "curl -L --silent -o "; + cmdUtf8 += escapeCommandArg(filepath.string()); + cmdUtf8 += " --max-filesize " + downloadLimitBytesStr + " --range 0-" + downloadLimitBytesStr + " --url " + escapeCommandArg(url); Process::string_type cmd = toNativeString(cmdUtf8); // TODO: Use this instead of curl on windows: certutil.exe -urlcache -split -f "https://url/to/file" path/and/name/to/save/as/file Process *process = new Process(cmd, toNativeString(""), nullptr, nullptr, false); diff --git a/src/Process.cpp b/src/Process.cpp index d82da42..29eb5fc 100644 --- a/src/Process.cpp +++ b/src/Process.cpp @@ -2,32 +2,21 @@ namespace dchat { - std::string escapeCommand(const std::string &cmd) + std::string escapeCommandArg(const std::string &cmd) { std::string result; result.reserve(cmd.size()); - bool escape = false; + result += "'"; for(char c : cmd) { - if(c == '\\') - escape = !escape; + if(c == '\'') + result += "\"'\""; // "'" else - { - if(escape) - result += "\\"; - - if(c == '"') - result += "\\\""; // \" - else if(c == '\'') - result += "\\'"; // \' - else - result += c; - - escape = false; - } + result += c; } + result += "'"; return result; } } \ No newline at end of file -- cgit v1.2.3