This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Utility.h
89 lines (76 loc) · 2.9 KB
/
Utility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef MODIO_UTILITY_H
#define MODIO_UTILITY_H
#ifdef __linux__
#define MODIO_LINUX_DETECTED
#endif
#ifdef __APPLE__
#define MODIO_OSX_DETECTED
#endif
#ifdef __MACH__
#define MODIO_OSX_DETECTED
#endif
#ifdef _WIN32
#define MODIO_WINDOWS_DETECTED
#endif
#ifdef _WIN64
#define MODIO_WINDOWS_DETECTED
#endif
#if defined(PLATFORM_WINDOWS) || defined(PLATFORM_MAC) || defined(PLATFORM_WINDOWS)
# define MODIO_UE4_DETECTED
#endif
#ifndef PATH_MAX
#define PATH_MAX 260
#endif
#include "dependencies/nlohmann/json.hpp" // for json, basic_json<>::...
#include "c/ModioC.h"
namespace modio
{
// String methods
std::string MODIO_DLL toString(i32 number);
std::string MODIO_DLL toString(u32 number);
std::string MODIO_DLL toString(double number);
std::string MODIO_DLL toString(bool boolean);
std::string replaceSubstrings(const std::string &str, const std::string &from, const std::string &to);
std::string addSlashIfNeeded(const std::string &directory_path);
std::string getFilename(std::string file_path);
std::string getFileExtension(std::string path);
// Log methods
void writeLogLine(const std::string &text, u32 debug_level);
void clearLog();
// Time methods
u32 getCurrentTimeSeconds();
double getCurrentTimeMillis();
std::string CP437ToUTF8(const std::string& string);
// Json methods
bool hasKey(nlohmann::json json_object, const std::string &key);
nlohmann::json toJson(const std::string &json_str);
nlohmann::json openJson(const std::string &file_path);
void writeJson(const std::string &file_path, nlohmann::json json_object);
// Filesystem methods
std::string getModIODirectory();
std::vector<std::string> getFilenames(const std::string &directory);
std::vector<std::string> getDirectoryNames(const std::string &root_directory);
bool isDirectory(const std::string& directory);
bool directoryExists(const std::string& path);
bool fileExists(const std::string &directory);
std::string getDirectoryPath(const std::string &filename);
bool createDirectory(const std::string& directory);
bool removeDirectory(const std::string &directory);
void removeFile(const std::string &filename);
double getFileSize(const std::string &file_path);
/**
* Creates the paths up to the file/folder. So if it's a folder name, ensure that you have a slash at end of the path
*
* Example: Sending in /home/cool_username/a/b creates the folder /home/cool_username/a as it expects that b is a file
* Example: Sending in /home/cool_username/a/b.txt creates the folder /home/cool_username/a as b is a file
* Example: Sending in /home/cool_username/a/b/ creates the folder /home/cool_username/a/b
*/
bool createPath(const std::string &strPathAndFile);
std::vector<std::string> getHeaders();
std::vector<std::string> getHeadersNoToken();
std::vector<std::string> getUrlEncodedHeaders();
std::string base64Encode(unsigned char const* bytes_to_encode, unsigned int in_len);
std::string getMyDocumentsPath();
std::string randomString(u32 length);
} // namespace modio
#endif