forked from a1928370421/Bongobs-Cat-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pal.cpp
142 lines (121 loc) · 3.14 KB
/
Pal.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "Pal.hpp"
#include <iostream>
#include <fstream>
#include <Model/CubismMoc.hpp>
#include "Define.hpp"
#include <Windows.h>
#include <io.h>
#include <codecvt>
#include <filesystem>
using std::endl;
using namespace Csm;
using namespace std;
using namespace Define;
csmByte* Pal::LoadFileAsBytes(const string filePath, csmSizeInt* outSize)
{
//filePath;//
const char* path = filePath.c_str();
#if _WIN64
//fix open wchar file path
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
wchar_t *wstr = new wchar_t[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wstr, wchars_num);
int size = 0;
struct _stat64 statBuf;
if (_wstat64(wstr, &statBuf) == 0)
{
size = statBuf.st_size;
} else {
size = 0;
}
*outSize = size;
#else
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
wchar_t *wstr = new wchar_t[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, path, -1, wstr, wchars_num);
int size = 0;
struct _stat32 statBuf;
if (_wstat32(wstr, &statBuf) == 0) {
size = statBuf.st_size;
} else {
size = 0;
}
#endif // X64
std::fstream file;
char* buf = new char[size];
file.open(wstr, std::ios::in | std::ios::binary);
if (!file.is_open())
{
return NULL;
}
file.read(buf, size);
file.close();
delete [] wstr;
return reinterpret_cast<csmByte*>(buf);
}
void Pal::ReleaseBytes(csmByte* byteData)
{
delete[] byteData;
}
void Pal::PrintLog(const csmChar *format, ...)
{
va_list args;
csmChar buf[256];
va_start(args, format);
vsnprintf_s(buf, sizeof(buf), format, args); // 標準出力でレンダリング
#ifdef CSM_DEBUG_MEMORY_LEAKING
// メモリリークチェック時は大量の標準出力がはしり重いのでprintfを利用する
std::printf(buf);
#else
std::cerr << buf << std::endl;
#endif
va_end(args);
}
void Pal::PrintMessage(const csmChar* message)
{
PrintLog("%s", message);
}
bool Pal::IsFileExist(const Csm::csmChar *csDir)
{
bool re;
int wchars_num = MultiByteToWideChar(CP_UTF8, 0, csDir, -1, NULL, 0);
wchar_t *wstr = new wchar_t[wchars_num];
MultiByteToWideChar(CP_UTF8, 0, csDir, -1, wstr, wchars_num);
int size = 0;
struct _stat64 statBuf;
if (_wstat64(wstr, &statBuf) == 0) {
re = true;
} else {
re = false;
}
delete[] wstr;
return re;
}
int Pal::GetAllDirName(const Csm::csmChar *csDir, Csm::csmChar **Files)
{
return 0;
}
const char *Pal::GetModelName(const char *filePath)
{
string _filepath = filePath;
_filepath += "/*.model3.json";
struct _finddata_t fileInfo;
long long findResult = _findfirst(_filepath.c_str(), &fileInfo);
if (findResult == -1) {
_findclose(findResult);
return "";
}
_findclose(findResult);
string _filename = fileInfo.name;
char *buf = new char[_filename.size()+1];
buf[_filename.size()] = 0x00;
memcpy(buf, _filename.c_str(), _filename.size());
return buf;
}
void Pal::GetDesktopResolution(int &horizontal, int &vertical) {
RECT desktop;
const HWND hDesktop = GetDesktopWindow();
GetWindowRect(hDesktop, &desktop);
horizontal = desktop.right;
vertical = desktop.bottom;
}