Path: blob/master/RSDKv5/RSDK/User/Dummy/DummyStorage.cpp
1168 views
#if RETRO_REV021int32 DummyUserStorage::TryAuth()2{3if (authStatus == STATUS_CONTINUE) {4std::string str = __FILE__;5str += ": TryAuth() # WARNING TryAuth() when auth currently in progress. \r\n";6PrintLog(PRINT_NORMAL, str.c_str());7}89if (!authStatus) {10authStatus = STATUS_CONTINUE;11authTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_AUTH_TIME", 0));12}13return authStatus;14}15int32 DummyUserStorage::TryInitStorage()16{17if (storageStatus == STATUS_CONTINUE) {18std::string str = __FILE__;19str += ": TryInitStorage() # WARNING TryInitStorage() when auth currently in progress. \r\n";20PrintLog(PRINT_NORMAL, str.c_str());21}22else {23storageStatus = STATUS_CONTINUE;24storageInitTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_INIT_TIME", 0));25}26return storageStatus;27}28bool32 DummyUserStorage::GetUsername(String *name)29{30#if !RETRO_USE_ORIGINAL_CODE31if (strlen(customSettings.username) > 0)32InitString(name, customSettings.username, 0);33else34InitString(name, "IntegerGeorge802", 0);35#else36InitString(name, "IntegerGeorge802", 0);37#endif38return true;39}40void DummyUserStorage::ClearPrerollErrors()41{42if (authStatus != STATUS_OK)43authStatus = STATUS_NONE;4445authTime = 0;46if (storageStatus != STATUS_OK)47storageStatus = STATUS_NONE;48}4950void DummyUserStorage::ProcessFileLoadTime()51{52for (int32 f = fileList.Count() - 1; f >= 0; --f) {53DummyFileInfo *file = fileList.At(f);54if (!file)55continue;5657if (!file->storageTime) {58int32 status = 0;59bool32 success = false;60switch (file->type) {61case 1:62success = LoadUserFile(file->path, file->fileBuffer, file->fileSize);63status = STATUS_NOTFOUND;6465if (file->fileSize >= 4) {66uint8 *bufTest = (uint8 *)file->fileBuffer;67// quick and dirty zlib check68if (bufTest[0] == 0x78 && (bufTest[1] == 0x01 || bufTest[1] == 0x9C)) {69uint8 *cBuffer = NULL;70AllocateStorage((void **)&cBuffer, file->fileSize, DATASET_TMP, false);71memcpy(cBuffer, file->fileBuffer, file->fileSize);7273Uncompress(&cBuffer, file->fileSize, (uint8 **)&file->fileBuffer, file->fileSize);7475RemoveStorageEntry((void **)&cBuffer);76}77}78break;7980case 2:81success = SaveUserFile(file->path, file->fileBuffer, file->fileSize);82status = STATUS_ERROR;8384if (file->compressed)85RemoveStorageEntry((void **)&file->fileBuffer);86break;8788case 3:89success = DeleteUserFile(file->path);90status = STATUS_ERROR;91break;92}9394if (success)95status = STATUS_OK;9697if (file->callback)98file->callback(status);99100fileList.Remove(f);101}102else {103--file->storageTime;104}105}106}107108bool32 DummyUserStorage::TryLoadUserFile(const char *filename, void *buffer, uint32 size, void (*callback)(int32 status))109{110bool32 success = false;111memset(buffer, 0, size);112113if (!noSaveActive) {114DummyFileInfo *file = fileList.Append();115file->callback = callback;116memset(file->path, 0, sizeof(file->path));117file->fileBuffer = buffer;118file->fileSize = size;119file->type = 1;120strncpy(file->path, filename, sizeof(file->path));121file->storageTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_LOAD_TIME", 0));122123success = true;124}125else {126std::string str = __FILE__;127str += ": TryLoadUserFile() # TryLoadUserFile(";128str += filename;129str += ", ...) failing due to noSave \r\n";130PrintLog(PRINT_NORMAL, str.c_str());131132if (callback)133callback(STATUS_ERROR);134}135136return success;137}138bool32 DummyUserStorage::TrySaveUserFile(const char *filename, void *buffer, uint32 size, void (*callback)(int32 status), bool32 compressed)139{140bool32 success = false;141if (!noSaveActive) {142DummyFileInfo *file = fileList.Append();143file->callback = callback;144memset(file->path, 0, sizeof(file->path));145file->type = 2;146strncpy(file->path, filename, sizeof(file->path));147file->storageTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_SAVE_TIME", 0));148149if (compressed) {150AllocateStorage((void **)&file->fileBuffer, size, DATASET_TMP, false);151152uLongf clen = size;153compress((Bytef *)file->fileBuffer, &clen, (Bytef *)buffer, (uLong)size);154file->fileSize = (int32)clen;155file->compressed = true;156}157else {158file->fileBuffer = buffer;159file->fileSize = size;160}161162success = true;163}164else {165std::string str = __FILE__;166str += ": TrySaveUserFile() # TrySaveUserFile(";167str += filename;168str += ", ...) failing due to noSave \r\n";169PrintLog(PRINT_NORMAL, str.c_str());170171if (callback)172callback(STATUS_ERROR);173}174175return success;176}177bool32 DummyUserStorage::TryDeleteUserFile(const char *filename, void (*callback)(int32 status))178{179if (!noSaveActive) {180DummyFileInfo *file = fileList.Append();181file->callback = callback;182memset(file->path, 0, sizeof(file->path));183file->fileBuffer = NULL;184file->fileSize = 0;185file->type = 3;186strncpy(file->path, filename, sizeof(file->path));187file->storageTime = GetAPIValue(GetAPIValueID("SYSTEM_USERSTORAGE_STORAGE_DELETE_TIME", 0));188}189else {190std::string str = __FILE__;191str += ": TryDeleteUserFile() # TryDeleteUserFile(";192str += filename;193str += ", ...) failing due to noSave \r\n";194PrintLog(PRINT_NORMAL, str.c_str());195196if (callback)197callback(STATUS_ERROR);198}199200return true;201}202#endif203204205