[General] Use const string references

This commit is contained in:
momo5502
2018-12-17 14:29:18 +01:00
parent 16a8ee65c9
commit 4fa89722a2
130 changed files with 453 additions and 452 deletions

View File

@ -2,7 +2,7 @@
namespace Utils
{
CSV::CSV(std::string file, bool isFile, bool allowComments)
CSV::CSV(const std::string& file, bool isFile, bool allowComments)
{
this->valid = false;
this->parse(file, isFile, allowComments);
@ -55,7 +55,7 @@ namespace Utils
return "";
}
void CSV::parse(std::string file, bool isFile, bool allowComments)
void CSV::parse(const std::string& file, bool isFile, bool allowComments)
{
std::string buffer;
@ -81,7 +81,7 @@ namespace Utils
}
}
void CSV::parseRow(std::string row, bool allowComments)
void CSV::parseRow(const std::string& row, bool allowComments)
{
bool isString = false;
std::string element;

View File

@ -6,7 +6,7 @@ namespace Utils
{
public:
CSV() { }
CSV(std::string file, bool isFile = true, bool allowComments = true);
CSV(const std::string& file, bool isFile = true, bool allowComments = true);
~CSV();
int getRows();
@ -21,7 +21,7 @@ namespace Utils
bool valid;
std::vector<std::vector<std::string>> dataMap;
void parse(std::string file, bool isFile = true, bool allowComments = true);
void parseRow(std::string row, bool allowComments = true);
void parse(const std::string& file, bool isFile = true, bool allowComments = true);
void parseRow(const std::string& row, bool allowComments = true);
};
}

View File

@ -27,17 +27,17 @@ namespace Utils
std::string Cache::ValidUrl;
std::mutex Cache::CacheMutex;
std::string Cache::GetStaticUrl(std::string path)
std::string Cache::GetStaticUrl(const std::string& path)
{
return Cache::Urls[0] + path;
}
std::string Cache::GetUrl(std::string url, std::string path)
std::string Cache::GetUrl(const std::string& url, const std::string& path)
{
return url + path;
}
std::string Cache::GetFile(std::string path, int timeout, std::string useragent)
std::string Cache::GetFile(const std::string& path, int timeout, const std::string& useragent)
{
std::lock_guard<std::mutex> _(Cache::CacheMutex);

View File

@ -5,14 +5,14 @@ namespace Utils
class Cache
{
public:
static std::string GetStaticUrl(std::string path);
static std::string GetFile(std::string path, int timeout = 5000, std::string useragent = "IW4x");
static std::string GetStaticUrl(const std::string& path);
static std::string GetFile(const std::string& path, int timeout = 5000, const std::string& useragent = "IW4x");
static void Uninitialize();
private:
static std::mutex CacheMutex;
static const char* Urls[];
static std::string ValidUrl;
static std::string GetUrl(std::string url, std::string path);
static std::string GetUrl(const std::string& url, const std::string& path);
};
}

View File

@ -4,7 +4,7 @@ namespace Utils
{
namespace Compression
{
std::string ZLib::Compress(std::string data)
std::string ZLib::Compress(const std::string& data)
{
Utils::Memory::Allocator allocator;
unsigned long length = (data.size() * 2);
@ -19,13 +19,10 @@ namespace Utils
return "";
}
data.clear();
data.append(buffer, length);
return data;
return std::string(buffer, length);
}
std::string ZLib::Decompress(std::string data)
std::string ZLib::Decompress(const std::string& data)
{
z_stream stream;
ZeroMemory(&stream, sizeof(stream));

View File

@ -11,8 +11,8 @@ namespace Utils
class ZLib
{
public:
static std::string Compress(std::string data);
static std::string Decompress(std::string data);
static std::string Compress(const std::string& data);
static std::string Decompress(const std::string& data);
};
};
}

View File

@ -55,7 +55,7 @@ namespace Utils
return key;
}
std::string ECC::SignMessage(Key key, std::string message)
std::string ECC::SignMessage(Key key, const std::string& message)
{
if (!key.isValid()) return "";
@ -69,7 +69,7 @@ namespace Utils
return std::string(reinterpret_cast<char*>(buffer), length);
}
bool ECC::VerifyMessage(Key key, std::string message, std::string signature)
bool ECC::VerifyMessage(Key key, const std::string& message, const std::string& signature)
{
if (!key.isValid()) return false;
@ -97,7 +97,7 @@ namespace Utils
return key;
}
std::string RSA::SignMessage(RSA::Key key, std::string message)
std::string RSA::SignMessage(RSA::Key key, const std::string& message)
{
if (!key.isValid()) return "";
@ -114,7 +114,7 @@ namespace Utils
return std::string(reinterpret_cast<char*>(buffer), length);
}
bool RSA::VerifyMessage(Key key, std::string message, std::string signature)
bool RSA::VerifyMessage(Key key, const std::string& message, const std::string& signature)
{
if (!key.isValid()) return false;
@ -135,7 +135,7 @@ namespace Utils
register_cipher(&des3_desc);
}
std::string DES3::Encrypt(std::string text, std::string iv, std::string key)
std::string DES3::Encrypt(const std::string& text, const std::string& iv, const std::string& key)
{
std::string encData;
encData.resize(text.size());
@ -150,7 +150,7 @@ namespace Utils
return encData;
}
std::string DES3::Decrpyt(std::string data, std::string iv, std::string key)
std::string DES3::Decrpyt(const std::string& data, const std::string& iv, const std::string& key)
{
std::string decData;
decData.resize(data.size());
@ -169,7 +169,7 @@ namespace Utils
#pragma region Tiger
std::string Tiger::Compute(std::string data, bool hex)
std::string Tiger::Compute(const std::string& data, bool hex)
{
return Tiger::Compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
@ -193,7 +193,7 @@ namespace Utils
#pragma region SHA1
std::string SHA1::Compute(std::string data, bool hex)
std::string SHA1::Compute(const std::string& data, bool hex)
{
return SHA1::Compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
@ -217,7 +217,7 @@ namespace Utils
#pragma region SHA256
std::string SHA256::Compute(std::string data, bool hex)
std::string SHA256::Compute(const std::string& data, bool hex)
{
return SHA256::Compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
@ -241,7 +241,7 @@ namespace Utils
#pragma region SHA512
std::string SHA512::Compute(std::string data, bool hex)
std::string SHA512::Compute(const std::string& data, bool hex)
{
return SHA512::Compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
@ -265,7 +265,7 @@ namespace Utils
#pragma region JenkinsOneAtATime
unsigned int JenkinsOneAtATime::Compute(std::string data)
unsigned int JenkinsOneAtATime::Compute(const std::string& data)
{
return JenkinsOneAtATime::Compute(data.data(), data.size());
}

View File

@ -11,8 +11,8 @@ namespace Utils
public:
Token() { this->tokenString.clear(); };
Token(const Token& obj) : tokenString(obj.tokenString) { };
Token(std::string token) : tokenString(token.begin(), token.end()) { };
Token(std::basic_string<uint8_t> token) : tokenString(token.begin(), token.end()) { };
Token(const std::string& token) : tokenString(token.begin(), token.end()) { };
Token(const std::basic_string<uint8_t>& token) : tokenString(token.begin(), token.end()) { };
Token& operator++ ()
{
@ -187,7 +187,7 @@ namespace Utils
return "";
}
void set(std::string pubKeyBuffer)
void set(const std::string& pubKeyBuffer)
{
this->free();
@ -197,7 +197,7 @@ namespace Utils
}
}
void deserialize(std::string key)
void deserialize(const std::string& key)
{
this->free();
@ -240,8 +240,8 @@ namespace Utils
};
static Key GenerateKey(int bits);
static std::string SignMessage(Key key, std::string message);
static bool VerifyMessage(Key key, std::string message, std::string signature);
static std::string SignMessage(Key key, const std::string& message);
static bool VerifyMessage(Key key, const std::string& message, const std::string& signature);
};
class RSA
@ -289,50 +289,50 @@ namespace Utils
};
static Key GenerateKey(int bits);
static std::string SignMessage(Key key, std::string message);
static bool VerifyMessage(Key key, std::string message, std::string signature);
static std::string SignMessage(Key key, const std::string& message);
static bool VerifyMessage(Key key, const std::string& message, const std::string& signature);
};
class DES3
{
public:
static void Initialize();
static std::string Encrypt(std::string text, std::string iv, std::string key);
static std::string Decrpyt(std::string text, std::string iv, std::string key);
static std::string Encrypt(const std::string& text, const std::string& iv, const std::string& key);
static std::string Decrpyt(const std::string& text, const std::string& iv, const std::string& key);
};
class Tiger
{
public:
static std::string Compute(std::string data, bool hex = false);
static std::string Compute(const std::string& data, bool hex = false);
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
};
class SHA1
{
public:
static std::string Compute(std::string data, bool hex = false);
static std::string Compute(const std::string& data, bool hex = false);
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
};
class SHA256
{
public:
static std::string Compute(std::string data, bool hex = false);
static std::string Compute(const std::string& data, bool hex = false);
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
};
class SHA512
{
public:
static std::string Compute(std::string data, bool hex = false);
static std::string Compute(const std::string& data, bool hex = false);
static std::string Compute(const uint8_t* data, size_t length, bool hex = false);
};
class JenkinsOneAtATime
{
public:
static unsigned int Compute(std::string data);
static unsigned int Compute(const std::string& data);
static unsigned int Compute(const char *key, size_t len);
};
}

View File

@ -98,7 +98,7 @@ namespace Utils
}
}
void Entities::parse(std::string buffer)
void Entities::parse(const std::string& buffer)
{
int parseState = 0;
std::string key;

View File

@ -7,7 +7,7 @@ namespace Utils
public:
Entities() {};
Entities(const char* string, size_t lenPlusOne) : Entities(std::string(string, lenPlusOne - 1)) {}
Entities(std::string buffer) : Entities() { this->parse(buffer); };
Entities(const std::string& buffer) : Entities() { this->parse(buffer); };
Entities(const Entities &obj) : entities(obj.entities) {};
std::string build();
@ -27,6 +27,6 @@ namespace Utils
};
std::vector<std::unordered_map<std::string, std::string>> entities;
void parse(std::string buffer);
void parse(const std::string& buffer);
};
}

View File

@ -4,13 +4,13 @@ namespace Utils
{
namespace IO
{
bool FileExists(std::string file)
bool FileExists(const std::string& file)
{
//return std::ifstream(file).good();
return GetFileAttributesA(file.data()) != INVALID_FILE_ATTRIBUTES;
}
bool WriteFile(std::string file, std::string data, bool append)
bool WriteFile(const std::string& file, const std::string& data, bool append)
{
auto pos = file.find_last_of("/\\");
if (pos != std::string::npos)
@ -30,14 +30,14 @@ namespace Utils
return false;
}
std::string ReadFile(std::string file)
std::string ReadFile(const std::string& file)
{
std::string data;
ReadFile(file, &data);
return data;
}
bool ReadFile(std::string file, std::string* data)
bool ReadFile(const std::string& file, std::string* data)
{
if (!data) return false;
data->clear();
@ -63,7 +63,7 @@ namespace Utils
return false;
}
size_t FileSize(std::string file)
size_t FileSize(const std::string& file)
{
if (FileExists(file))
{
@ -79,22 +79,22 @@ namespace Utils
return 0;
}
bool CreateDir(std::string dir)
bool CreateDir(const std::string& dir)
{
return std::experimental::filesystem::create_directories(dir);
}
bool DirectoryExists(std::string directory)
bool DirectoryExists(const std::string& directory)
{
return std::experimental::filesystem::is_directory(directory);
}
bool DirectoryIsEmpty(std::string directory)
bool DirectoryIsEmpty(const std::string& directory)
{
return std::experimental::filesystem::is_empty(directory);
}
std::vector<std::string> ListFiles(std::string dir)
std::vector<std::string> ListFiles(const std::string& dir)
{
std::vector<std::string> files;

View File

@ -4,14 +4,14 @@ namespace Utils
{
namespace IO
{
bool FileExists(std::string file);
bool WriteFile(std::string file, std::string data, bool append = false);
bool ReadFile(std::string file, std::string* data);
std::string ReadFile(std::string file);
size_t FileSize(std::string file);
bool CreateDir(std::string dir);
bool DirectoryExists(std::string file);
bool DirectoryIsEmpty(std::string file);
std::vector<std::string> ListFiles(std::string dir);
bool FileExists(const std::string& file);
bool WriteFile(const std::string& file, const std::string& data, bool append = false);
bool ReadFile(const std::string& file, std::string* data);
std::string ReadFile(const std::string& file);
size_t FileSize(const std::string& file);
bool CreateDir(const std::string& dir);
bool DirectoryExists(const std::string& file);
bool DirectoryIsEmpty(const std::string& file);
std::vector<std::string> ListFiles(const std::string& dir);
}
}

View File

@ -2,12 +2,12 @@
namespace Utils
{
void InfoString::set(std::string key, std::string value)
void InfoString::set(const std::string& key, const std::string& value)
{
this->keyValuePairs[key] = value;
}
std::string InfoString::get(std::string key)
std::string InfoString::get(const std::string& key)
{
if (this->keyValuePairs.find(key) != this->keyValuePairs.end())
{

View File

@ -6,11 +6,11 @@ namespace Utils
{
public:
InfoString() {};
InfoString(std::string buffer) : InfoString() { this->parse(buffer); };
InfoString(const std::string& buffer) : InfoString() { this->parse(buffer); };
InfoString(const InfoString &obj) : keyValuePairs(obj.keyValuePairs) {};
void set(std::string key, std::string value);
std::string get(std::string key);
void set(const std::string& key, const std::string& value);
std::string get(const std::string& key);
std::string build();

View File

@ -2,7 +2,7 @@
namespace Utils
{
Library::Library(std::string buffer, bool _freeOnDestroy) : module(nullptr), freeOnDestroy(_freeOnDestroy)
Library::Library(const std::string& buffer, bool _freeOnDestroy) : module(nullptr), freeOnDestroy(_freeOnDestroy)
{
this->module = LoadLibraryExA(buffer.data(), nullptr, 0);
}

View File

@ -6,14 +6,14 @@ namespace Utils
{
public:
Library() : module(nullptr), freeOnDestroy(false) {};
Library(std::string buffer, bool freeOnDestroy = true);
Library(const std::string& buffer, bool freeOnDestroy = true);
~Library();
bool valid();
HMODULE getModule();
template <typename T>
std::function<T> get(std::string process)
std::function<T> get(const std::string& process)
{
if (!this->valid())
{

View File

@ -19,7 +19,7 @@ namespace Utils
return data;
}
char* Memory::DuplicateString(std::string string)
char* Memory::DuplicateString(const std::string& string)
{
char* newString = Memory::AllocateArray<char>(string.size() + 1);
std::memcpy(newString, string.data(), string.size());

View File

@ -95,7 +95,7 @@ namespace Utils
return (this->pool.empty() && this->refMemory.empty());
}
char* duplicateString(std::string string)
char* duplicateString(const std::string& string)
{
std::lock_guard<std::mutex> _(this->mutex);
@ -142,7 +142,7 @@ namespace Utils
return static_cast<T*>(Allocate(count * sizeof(T)));
}
static char* DuplicateString(std::string string);
static char* DuplicateString(const std::string& string);
static void Free(void* data);
static void Free(const void* data);

View File

@ -191,7 +191,7 @@ namespace Utils
return this->data() + ret;
}
char* Stream::saveString(std::string string)
char* Stream::saveString(const std::string& string)
{
return this->saveString(string.data()/*, string.size()*/);
}
@ -215,7 +215,7 @@ namespace Utils
return this->data() + ret;
}
char* Stream::saveText(std::string string)
char* Stream::saveText(const std::string& string)
{
return this->save(string.data(), string.length());
}

View File

@ -27,7 +27,7 @@ namespace Utils
class Reader
{
public:
Reader(Utils::Memory::Allocator* _allocator, std::string _buffer) : position(0), buffer(_buffer), allocator(_allocator) {}
Reader(Utils::Memory::Allocator* _allocator, const std::string& _buffer) : position(0), buffer(_buffer), allocator(_allocator) {}
std::string readString();
const char* readCString();
@ -104,14 +104,14 @@ namespace Utils
return save(array, sizeof(T), count);
}
char* saveString(std::string string);
char* saveString(const std::string& string);
char* saveString(const char* string);
char* saveString(const char* string, size_t len);
char* saveByte(unsigned char byte, size_t count = 1);
char* saveNull(size_t count = 1);
char* saveMax(size_t count = 1);
char* saveText(std::string string);
char* saveText(const std::string& string);
void align(Alignment align);
bool pushBlock(Game::XFILE_BLOCK_TYPES stream);

View File

@ -35,7 +35,7 @@ namespace Utils
return input;
}
std::string DumpHex(std::string data, std::string separator)
std::string DumpHex(const std::string& data, const std::string& separator)
{
std::string result;
@ -83,7 +83,7 @@ namespace Utils
return result;
}
void Replace(std::string &string, std::string find, std::string replace)
void Replace(std::string &string, const std::string& find, const std::string& replace)
{
size_t nPos = 0;
@ -94,12 +94,12 @@ namespace Utils
}
}
bool StartsWith(std::string haystack, std::string needle)
bool StartsWith(const std::string& haystack, const std::string& needle)
{
return (haystack.size() >= needle.size() && !strncmp(needle.data(), haystack.data(), needle.size()));
}
bool EndsWith(std::string haystack, std::string needle)
bool EndsWith(const std::string& haystack, const std::string& needle)
{
return (haystack.size() >= needle.size() && !strncmp(needle.data(), haystack.data() + (haystack.size() - needle.size()), needle.size()));
}

View File

@ -77,10 +77,10 @@ namespace Utils
int IsSpace(int c);
std::string ToLower(std::string input);
std::string ToUpper(std::string input);
bool EndsWith(std::string haystack, std::string needle);
bool EndsWith(const std::string& haystack, const std::string& needle);
std::vector<std::string> Explode(const std::string& str, char delim);
void Replace(std::string &string, std::string find, std::string replace);
bool StartsWith(std::string haystack, std::string needle);
void Replace(std::string &string, const std::string& find, const std::string& replace);
bool StartsWith(const std::string& haystack, const std::string& needle);
std::string &LTrim(std::string &s);
std::string &RTrim(std::string &s);
std::string &Trim(std::string &s);
@ -88,9 +88,9 @@ namespace Utils
std::string FormatTimeSpan(int milliseconds);
std::string FormatBandwidth(size_t bytes, int milliseconds);
std::string DumpHex(std::string data, std::string separator = " ");
std::string DumpHex(const std::string& data, const std::string& separator = " ");
std::string XOR(std::string str, char value);
std::string XOR(const std::string str, char value);
std::string EncodeBase64(const char* input, const unsigned long inputSize);
std::string EncodeBase64(const std::string& input);

View File

@ -2,7 +2,7 @@
namespace Utils
{
std::string GetMimeType(std::string url)
std::string GetMimeType(const std::string& url)
{
wchar_t* mimeType = nullptr;
FindMimeFromData(nullptr, std::wstring(url.begin(), url.end()).data(), nullptr, 0, nullptr, 0, &mimeType, 0);
@ -16,7 +16,7 @@ namespace Utils
return "application/octet-stream";
}
std::string ParseChallenge(std::string data)
std::string ParseChallenge(const std::string& data)
{
auto pos = data.find_first_of("\n ");
if (pos == std::string::npos) return data;
@ -140,7 +140,7 @@ namespace Utils
std::this_thread::yield();
}
void OpenUrl(std::string url)
void OpenUrl(const std::string& url)
{
SafeShellExecute(nullptr, "open", url.data(), nullptr, nullptr, SW_SHOWNORMAL);
}

View File

@ -7,8 +7,8 @@ typedef NTSTATUS(NTAPI* NtQueryInformationThread_t)(HANDLE ThreadHandle, LONG Th
namespace Utils
{
std::string GetMimeType(std::string url);
std::string ParseChallenge(std::string data);
std::string GetMimeType(const std::string& url);
std::string ParseChallenge(const std::string& data);
void OutputDebugLastError();
std::string GetLastWindowsError();
@ -21,7 +21,7 @@ namespace Utils
void SetEnvironment();
void OpenUrl(std::string url);
void OpenUrl(const std::string& url);
bool HasIntercection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2);

View File

@ -5,12 +5,12 @@ namespace Utils
{
WebIO::WebIO() : WebIO("WebIO") {}
WebIO::WebIO(std::string useragent, std::string url) : WebIO(useragent)
WebIO::WebIO(const std::string& useragent, const std::string& url) : WebIO(useragent)
{
this->setURL(url);
}
WebIO::WebIO(std::string useragent) : cancel(false), timeout(5000), hSession(nullptr) // 5 seconds timeout by default
WebIO::WebIO(const std::string& useragent) : cancel(false), timeout(5000), hSession(nullptr) // 5 seconds timeout by default
{
this->openSession(useragent);
}
@ -24,7 +24,7 @@ namespace Utils
this->closeSession();
}
void WebIO::openSession(std::string useragent)
void WebIO::openSession(const std::string& useragent)
{
this->closeSession();
this->hSession = InternetOpenA(useragent.data(), INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, 0);
@ -35,13 +35,10 @@ namespace Utils
if (this->hSession) InternetCloseHandle(this->hSession);
}
void WebIO::setCredentials(std::string _username, std::string _password)
void WebIO::setCredentials(const std::string& _username, const std::string& _password)
{
this->username.clear();
this->password.clear();
this->username.append(_username.begin(), _username.end());
this->password.append(_password.begin(), _password.end());
this->username = _username;
this->password = _password;
}
void WebIO::setURL(std::string _url)
@ -152,13 +149,13 @@ namespace Utils
return body;
}
std::string WebIO::postFile(std::string _url, std::string data, std::string fieldName, std::string fileName)
std::string WebIO::postFile(const std::string& _url, const std::string& data, const std::string& fieldName, const std::string& fileName)
{
this->setURL(_url);
return this->postFile(data, fieldName, fileName);
}
std::string WebIO::postFile(std::string data, std::string fieldName, std::string fileName)
std::string WebIO::postFile(const std::string& data, std::string fieldName, std::string fileName)
{
WebIO::Params headers;
@ -185,13 +182,13 @@ namespace Utils
return this->execute("POST", body, headers);
}
std::string WebIO::post(std::string _url, std::string body, bool* success)
std::string WebIO::post(const std::string& _url, const std::string& body, bool* success)
{
this->setURL(_url);
return this->post(body, success);
}
std::string WebIO::post(std::string _url, WebIO::Params params, bool* success)
std::string WebIO::post(const std::string& _url, WebIO::Params params, bool* success)
{
this->setURL(_url);
return this->post(params, success);
@ -202,12 +199,12 @@ namespace Utils
return this->post(this->buildPostBody(params), success);
}
std::string WebIO::post(std::string body, bool* success)
std::string WebIO::post(const std::string& body, bool* success)
{
return this->execute("POST", body, WebIO::Params(), success);
}
std::string WebIO::get(std::string _url, bool* success)
std::string WebIO::get(const std::string& _url, bool* success)
{
this->setURL(_url);
return this->get(success);
@ -259,7 +256,7 @@ namespace Utils
return this;
}
std::string WebIO::execute(const char* command, std::string body, WebIO::Params headers, bool* success)
std::string WebIO::execute(const char* command, const std::string& body, WebIO::Params headers, bool* success)
{
if (success) *success = false;
if (!this->openConnection()) return "";
@ -357,7 +354,7 @@ namespace Utils
this->closeConnection();
}
bool WebIO::setDirectory(std::string directory)
bool WebIO::setDirectory(const std::string& directory)
{
return (FtpSetCurrentDirectoryA(this->hConnect, directory.data()) == TRUE);
}
@ -417,13 +414,13 @@ namespace Utils
}
}
bool WebIO::createDirectory(std::string directory)
bool WebIO::createDirectory(const std::string& directory)
{
return (FtpCreateDirectoryA(this->hConnect, directory.data()) == TRUE);
}
// Recursively delete a directory
bool WebIO::deleteDirectory(std::string directory)
bool WebIO::deleteDirectory(const std::string& directory)
{
std::string tempDir;
this->getDirectory(tempDir);
@ -443,12 +440,12 @@ namespace Utils
return (FtpRemoveDirectoryA(this->hConnect, directory.data()) == TRUE);
}
bool WebIO::renameDirectory(std::string directory, std::string newDir)
bool WebIO::renameDirectory(const std::string& directory, const std::string& newDir)
{
return (FtpRenameFileA(this->hConnect, directory.data(), newDir.data()) == TRUE); // According to the internetz, this should work
}
bool WebIO::listElements(std::string directory, std::vector<std::string> &list, bool files)
bool WebIO::listElements(const std::string& directory, std::vector<std::string> &list, bool files)
{
list.clear();
@ -486,37 +483,37 @@ namespace Utils
return result;
}
bool WebIO::listDirectories(std::string directory, std::vector<std::string> &list)
bool WebIO::listDirectories(const std::string& directory, std::vector<std::string> &list)
{
return this->listElements(directory, list, false);
}
bool WebIO::listFiles(std::string directory, std::vector<std::string> &list)
bool WebIO::listFiles(const std::string& directory, std::vector<std::string> &list)
{
return this->listElements(directory, list, true);
}
bool WebIO::uploadFile(std::string file, std::string localfile)
bool WebIO::uploadFile(const std::string& file, const std::string& localfile)
{
return (FtpPutFileA(this->hConnect, localfile.data(), file.data(), FTP_TRANSFER_TYPE_BINARY, NULL) == TRUE);
}
bool WebIO::deleteFile(std::string file)
bool WebIO::deleteFile(const std::string& file)
{
return (FtpDeleteFileA(this->hConnect, file.data()) == TRUE);
}
bool WebIO::renameFile(std::string file, std::string newFile)
bool WebIO::renameFile(const std::string& file, const std::string& newFile)
{
return (FtpRenameFileA(this->hConnect, file.data(), newFile.data()) == TRUE);
}
bool WebIO::downloadFile(std::string file, std::string localfile)
bool WebIO::downloadFile(const std::string& file, const std::string& localfile)
{
return (FtpGetFileA(this->hConnect, file.data(), localfile.data(), FALSE, NULL, FTP_TRANSFER_TYPE_BINARY, 0) == TRUE);
}
bool WebIO::uploadFileData(std::string file, std::string data)
bool WebIO::uploadFileData(const std::string& file, const std::string& data)
{
bool result = false;
this->hFile = FtpOpenFileA(this->hConnect, file.data(), GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
@ -535,7 +532,7 @@ namespace Utils
return result;
}
bool WebIO::downloadFileData(std::string file, std::string &data)
bool WebIO::downloadFileData(const std::string& file, std::string &data)
{
data.clear();

View File

@ -19,23 +19,23 @@ namespace Utils
typedef std::map<std::string, std::string> Params;
WebIO();
WebIO(std::string useragent);
WebIO(std::string useragent, std::string url);
WebIO(const std::string& useragent);
WebIO(const std::string& useragent, const std::string& url);
~WebIO();
void setURL(std::string url);
void setCredentials(std::string username, std::string password);
void setCredentials(const std::string& username, const std::string& password);
std::string postFile(std::string url, std::string data, std::string fieldName, std::string fileName);
std::string postFile(std::string data, std::string fieldName, std::string fileName);
std::string postFile(const std::string& url, const std::string& data, const std::string& fieldName, const std::string& fileName);
std::string postFile(const std::string& data, std::string fieldName, std::string fileName);
std::string post(std::string url, WebIO::Params params, bool* success = nullptr);
std::string post(std::string url, std::string body, bool* success = nullptr);
std::string post(const std::string& url, WebIO::Params params, bool* success = nullptr);
std::string post(const std::string& url, const std::string& body, bool* success = nullptr);
std::string post(WebIO::Params params, bool* success = nullptr);
std::string post(std::string body, bool* success = nullptr);
std::string post(const std::string& body, bool* success = nullptr);
std::string get(std::string url, bool* success = nullptr);
std::string get(const std::string& url, bool* success = nullptr);
std::string get(bool* success = nullptr);
WebIO* setTimeout(DWORD mseconds);
@ -44,23 +44,23 @@ namespace Utils
bool connect();
void disconnect(); // Not necessary
bool setDirectory(std::string directory);
bool setDirectory(const std::string&directory);
bool setRelativeDirectory(std::string directory);
bool getDirectory(std::string &directory);
bool createDirectory(std::string directory);
bool deleteDirectory(std::string directory);
bool renameDirectory(std::string directory, std::string newDir);
bool createDirectory(const std::string& directory);
bool deleteDirectory(const std::string& directory);
bool renameDirectory(const std::string& directory, const std::string& newDir);
bool listDirectories(std::string directory, std::vector<std::string> &list);
bool listFiles(std::string directory, std::vector<std::string> &list);
bool listDirectories(const std::string& directory, std::vector<std::string> &list);
bool listFiles(const std::string& directory, std::vector<std::string> &list);
bool deleteFile(std::string file);
bool renameFile(std::string file, std::string newFile);
bool uploadFile(std::string file, std::string localfile);
bool downloadFile(std::string file, std::string localfile);
bool deleteFile(const std::string& file);
bool renameFile(const std::string& file, const std::string& newFile);
bool uploadFile(const std::string& file, const std::string& localfile);
bool downloadFile(const std::string& file, const std::string& localfile);
bool uploadFileData(std::string file, std::string data);
bool downloadFileData(std::string file, std::string &data);
bool uploadFileData(const std::string& file,const std::string& data);
bool downloadFileData(const std::string& file, std::string &data);
void setProgressCallback(Utils::Slot<void(size_t, size_t)> callback);
void cancelDownload() { this->cancel = true; }
@ -102,11 +102,11 @@ namespace Utils
bool isSecuredConnection();
std::string execute(const char* command, std::string body, WebIO::Params headers = WebIO::Params(), bool* success = nullptr);
std::string execute(const char* command, const std::string& body, WebIO::Params headers = WebIO::Params(), bool* success = nullptr);
bool listElements(std::string directory, std::vector<std::string> &list, bool files);
bool listElements(const std::string& directory, std::vector<std::string> &list, bool files);
void openSession(std::string useragent);
void openSession(const std::string& useragent);
void closeSession();
bool openConnection();