2015-06-27 17:58:44 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#include "Core/FileLoaders/RetryingFileLoader.h"
|
|
|
|
|
|
|
|
// Takes ownership of backend.
|
|
|
|
RetryingFileLoader::RetryingFileLoader(FileLoader *backend)
|
2018-12-27 18:32:47 +00:00
|
|
|
: ProxiedFileLoader(backend) {
|
2015-06-27 17:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RetryingFileLoader::Exists() {
|
2018-12-27 18:32:47 +00:00
|
|
|
if (!ProxiedFileLoader::Exists()) {
|
2015-06-27 17:58:44 +00:00
|
|
|
// Retry once, immediately.
|
2018-12-27 18:32:47 +00:00
|
|
|
return ProxiedFileLoader::Exists();
|
2015-06-27 17:58:44 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-04 07:27:49 +00:00
|
|
|
bool RetryingFileLoader::ExistsFast() {
|
2018-12-27 18:32:47 +00:00
|
|
|
if (!ProxiedFileLoader::ExistsFast()) {
|
2016-07-04 07:27:49 +00:00
|
|
|
// Retry once, immediately.
|
2018-12-27 18:32:47 +00:00
|
|
|
return ProxiedFileLoader::ExistsFast();
|
2016-07-04 07:27:49 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-27 17:58:44 +00:00
|
|
|
bool RetryingFileLoader::IsDirectory() {
|
|
|
|
// Can't tell if it's an error either way.
|
2018-12-27 18:32:47 +00:00
|
|
|
return ProxiedFileLoader::IsDirectory();
|
2015-06-27 17:58:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s64 RetryingFileLoader::FileSize() {
|
2018-12-27 18:32:47 +00:00
|
|
|
s64 filesize = ProxiedFileLoader::FileSize();
|
2015-06-27 17:58:44 +00:00
|
|
|
if (filesize == 0) {
|
2018-12-27 18:32:47 +00:00
|
|
|
return ProxiedFileLoader::FileSize();
|
2015-06-27 17:58:44 +00:00
|
|
|
}
|
|
|
|
return filesize;
|
|
|
|
}
|
|
|
|
|
2016-06-27 06:20:05 +00:00
|
|
|
size_t RetryingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
|
|
|
|
size_t readSize = backend_->ReadAt(absolutePos, bytes, data, flags);
|
2015-06-27 17:58:44 +00:00
|
|
|
|
|
|
|
int retries = 0;
|
|
|
|
while (readSize < bytes && retries < MAX_RETRIES) {
|
|
|
|
u8 *p = (u8 *)data;
|
2016-06-27 06:20:05 +00:00
|
|
|
readSize += backend_->ReadAt(absolutePos + readSize, bytes - readSize, p + readSize, flags);
|
2015-06-27 17:58:44 +00:00
|
|
|
++retries;
|
|
|
|
}
|
|
|
|
|
|
|
|
return readSize;
|
|
|
|
}
|