Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/User/Dummy/DummyStorage.cpp
1168 views
1
#if RETRO_REV02
2
int32 DummyUserStorage::TryAuth()
3
{
4
if (authStatus == STATUS_CONTINUE) {
5
std::string str = __FILE__;
6
str += ": TryAuth() # WARNING TryAuth() when auth currently in progress. \r\n";
7
PrintLog(PRINT_NORMAL, str.c_str());
8
}
9
10
if (!authStatus) {
11
authStatus = STATUS_CONTINUE;
12
authTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_AUTH_TIME", 0));
13
}
14
return authStatus;
15
}
16
int32 DummyUserStorage::TryInitStorage()
17
{
18
if (storageStatus == STATUS_CONTINUE) {
19
std::string str = __FILE__;
20
str += ": TryInitStorage() # WARNING TryInitStorage() when auth currently in progress. \r\n";
21
PrintLog(PRINT_NORMAL, str.c_str());
22
}
23
else {
24
storageStatus = STATUS_CONTINUE;
25
storageInitTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_INIT_TIME", 0));
26
}
27
return storageStatus;
28
}
29
bool32 DummyUserStorage::GetUsername(String *name)
30
{
31
#if !RETRO_USE_ORIGINAL_CODE
32
if (strlen(customSettings.username) > 0)
33
InitString(name, customSettings.username, 0);
34
else
35
InitString(name, "IntegerGeorge802", 0);
36
#else
37
InitString(name, "IntegerGeorge802", 0);
38
#endif
39
return true;
40
}
41
void DummyUserStorage::ClearPrerollErrors()
42
{
43
if (authStatus != STATUS_OK)
44
authStatus = STATUS_NONE;
45
46
authTime = 0;
47
if (storageStatus != STATUS_OK)
48
storageStatus = STATUS_NONE;
49
}
50
51
void DummyUserStorage::ProcessFileLoadTime()
52
{
53
for (int32 f = fileList.Count() - 1; f >= 0; --f) {
54
DummyFileInfo *file = fileList.At(f);
55
if (!file)
56
continue;
57
58
if (!file->storageTime) {
59
int32 status = 0;
60
bool32 success = false;
61
switch (file->type) {
62
case 1:
63
success = LoadUserFile(file->path, file->fileBuffer, file->fileSize);
64
status = STATUS_NOTFOUND;
65
66
if (file->fileSize >= 4) {
67
uint8 *bufTest = (uint8 *)file->fileBuffer;
68
// quick and dirty zlib check
69
if (bufTest[0] == 0x78 && (bufTest[1] == 0x01 || bufTest[1] == 0x9C)) {
70
uint8 *cBuffer = NULL;
71
AllocateStorage((void **)&cBuffer, file->fileSize, DATASET_TMP, false);
72
memcpy(cBuffer, file->fileBuffer, file->fileSize);
73
74
Uncompress(&cBuffer, file->fileSize, (uint8 **)&file->fileBuffer, file->fileSize);
75
76
RemoveStorageEntry((void **)&cBuffer);
77
}
78
}
79
break;
80
81
case 2:
82
success = SaveUserFile(file->path, file->fileBuffer, file->fileSize);
83
status = STATUS_ERROR;
84
85
if (file->compressed)
86
RemoveStorageEntry((void **)&file->fileBuffer);
87
break;
88
89
case 3:
90
success = DeleteUserFile(file->path);
91
status = STATUS_ERROR;
92
break;
93
}
94
95
if (success)
96
status = STATUS_OK;
97
98
if (file->callback)
99
file->callback(status);
100
101
fileList.Remove(f);
102
}
103
else {
104
--file->storageTime;
105
}
106
}
107
}
108
109
bool32 DummyUserStorage::TryLoadUserFile(const char *filename, void *buffer, uint32 size, void (*callback)(int32 status))
110
{
111
bool32 success = false;
112
memset(buffer, 0, size);
113
114
if (!noSaveActive) {
115
DummyFileInfo *file = fileList.Append();
116
file->callback = callback;
117
memset(file->path, 0, sizeof(file->path));
118
file->fileBuffer = buffer;
119
file->fileSize = size;
120
file->type = 1;
121
strncpy(file->path, filename, sizeof(file->path));
122
file->storageTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_LOAD_TIME", 0));
123
124
success = true;
125
}
126
else {
127
std::string str = __FILE__;
128
str += ": TryLoadUserFile() # TryLoadUserFile(";
129
str += filename;
130
str += ", ...) failing due to noSave \r\n";
131
PrintLog(PRINT_NORMAL, str.c_str());
132
133
if (callback)
134
callback(STATUS_ERROR);
135
}
136
137
return success;
138
}
139
bool32 DummyUserStorage::TrySaveUserFile(const char *filename, void *buffer, uint32 size, void (*callback)(int32 status), bool32 compressed)
140
{
141
bool32 success = false;
142
if (!noSaveActive) {
143
DummyFileInfo *file = fileList.Append();
144
file->callback = callback;
145
memset(file->path, 0, sizeof(file->path));
146
file->type = 2;
147
strncpy(file->path, filename, sizeof(file->path));
148
file->storageTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_SAVE_TIME", 0));
149
150
if (compressed) {
151
AllocateStorage((void **)&file->fileBuffer, size, DATASET_TMP, false);
152
153
uLongf clen = size;
154
compress((Bytef *)file->fileBuffer, &clen, (Bytef *)buffer, (uLong)size);
155
file->fileSize = (int32)clen;
156
file->compressed = true;
157
}
158
else {
159
file->fileBuffer = buffer;
160
file->fileSize = size;
161
}
162
163
success = true;
164
}
165
else {
166
std::string str = __FILE__;
167
str += ": TrySaveUserFile() # TrySaveUserFile(";
168
str += filename;
169
str += ", ...) failing due to noSave \r\n";
170
PrintLog(PRINT_NORMAL, str.c_str());
171
172
if (callback)
173
callback(STATUS_ERROR);
174
}
175
176
return success;
177
}
178
bool32 DummyUserStorage::TryDeleteUserFile(const char *filename, void (*callback)(int32 status))
179
{
180
if (!noSaveActive) {
181
DummyFileInfo *file = fileList.Append();
182
file->callback = callback;
183
memset(file->path, 0, sizeof(file->path));
184
file->fileBuffer = NULL;
185
file->fileSize = 0;
186
file->type = 3;
187
strncpy(file->path, filename, sizeof(file->path));
188
file->storageTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_DELETE_TIME", 0));
189
}
190
else {
191
std::string str = __FILE__;
192
str += ": TryDeleteUserFile() # TryDeleteUserFile(";
193
str += filename;
194
str += ", ...) failing due to noSave \r\n";
195
PrintLog(PRINT_NORMAL, str.c_str());
196
197
if (callback)
198
callback(STATUS_ERROR);
199
}
200
201
return true;
202
}
203
#endif
204
205