Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Tools.cpp
Go to the documentation of this file.
1#include "Tools.h"
2
3#include "PluginManager/PluginManager.h"
4
5namespace ArkApi::Tools
6{
8 {
9 char buffer[MAX_PATH];
10 GetModuleFileNameA(nullptr, buffer, MAX_PATH);
11
12 const std::string::size_type pos = std::string(buffer).find_last_of("\\/");
13
14 return std::string(buffer).substr(0, pos);
15 }
16
17 std::wstring ConvertToWideStr(const std::string& text)
18 {
19 const size_t size = text.size();
20
21 std::wstring wstr;
22 if (size > 0)
23 {
24 wstr.resize(size);
25
26 size_t converted_chars;
27 mbstowcs_s(&converted_chars, wstr.data(), size + 1, text.c_str(), _TRUNCATE);
28 }
29
30 return wstr;
31 }
32
33 std::string ConvertToAnsiStr(const std::wstring& text)
34 {
35 const size_t length = text.size();
36
37 std::string str(length, '\0');
38 std::use_facet<std::ctype<wchar_t>>(std::locale()).narrow(text.c_str(), text.c_str() + length, '?', str.data());
39
40 return str;
41 }
42
43 std::string Utf8Encode(const std::wstring& wstr)
44 {
45 if (wstr.empty())
46 return std::string();
47
48 const int size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr);
49
50 std::string str(size_needed, 0);
51 WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), str.data(), size_needed, nullptr, nullptr);
52
53 return str;
54 }
55
56 std::wstring Utf8Decode(const std::string& str)
57 {
58 if (str.empty())
59 return std::wstring();
60
61 const int size_needed = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), nullptr, 0);
62
63 std::wstring wstr(size_needed, 0);
64 MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), wstr.data(), size_needed);
65
66 return wstr;
67 }
68
69 bool IsPluginLoaded(const std::string& plugin_name)
70 {
71 return PluginManager::Get().IsPluginLoaded(plugin_name);
72 }
73
75 {
76 return API_VERSION;
77 }
78}
ARK_API std::string GetCurrentDir()
Definition Tools.cpp:7
std::string GetApiVer()
Definition Tools.cpp:74