forked from TheElixZammuto/moonlight-xbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
71 lines (62 loc) · 1.91 KB
/
Copy pathUtils.cpp
File metadata and controls
71 lines (62 loc) · 1.91 KB
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
#pragma once
#include "pch.h"
#include "Utils.hpp"
#define LOG_LINES 64
namespace moonlight_xbox_dx {
namespace Utils {
std::vector<std::wstring> logLines;
bool showLogs = false;
bool showStats = false;
StreamingStats stats;
Platform::String^ StringPrintf(const char* fmt, ...) {
va_list list;
va_start(list, fmt);
char message[2048];
vsprintf_s(message, 2047, fmt, list);
std::string s_str = std::string(message);
std::wstring wid_str = std::wstring(s_str.begin(), s_str.end());
const wchar_t* w_char = wid_str.c_str();
Platform::String^ p_string = ref new Platform::String(w_char);
return p_string;
}
void Log(const char* fmt) {
try {
int len = strlen(fmt) + 1;
wchar_t* stringBuf = (wchar_t*)malloc(sizeof(wchar_t) * len);
if (stringBuf == NULL)return;
mbstowcs(stringBuf, fmt, len);
std::wstring string(stringBuf);
if (logLines.size() == LOG_LINES)logLines.erase(logLines.begin());
logLines.push_back(string);
}
catch (...){
}
}
std::vector<std::wstring> GetLogLines() {
return logLines;
}
//https://stackoverflow.com/a/20707518
Platform::String^ StringFromChars(char* chars)
{
size_t newsize = strlen(chars) + 1;
wchar_t* wcstring = new wchar_t[newsize];
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wcstring, newsize, chars, _TRUNCATE);
Platform::String^ str = ref new Platform::String(wcstring);
delete[] wcstring;
return str;
}
//https://stackoverflow.com/a/43628199
Platform::String^ StringFromStdString(std::string input) {
std::wstring w_str = std::wstring(input.begin(), input.end());
const wchar_t* w_chars = w_str.c_str();
return (ref new Platform::String(w_chars));
}
//https://stackoverflow.com/a/35905753
std::string PlatformStringToStdString(Platform::String ^input) {
std::wstring fooW(input->Begin());
std::string fooA(fooW.begin(), fooW.end());
return fooA;
}
}
}