Assorted cleanup, UWP memory map fixes. PSPFlower runs in both 32-bit and 64-bit.

This commit is contained in:
Henrik Rydgard
2017-03-23 10:02:28 +01:00
committed by Henrik Rydgård
parent c0f6a24a21
commit ff2b6b3fca
31 changed files with 258 additions and 138 deletions
+46 -9
View File
@@ -8,11 +8,17 @@ using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
StorageFileLoader::StorageFileLoader(Windows::Storage::StorageFile ^file) {
create_task(file->OpenReadAsync()).then([this](IRandomAccessStreamWithContentType ^stream) {
file_ = file;
auto opentask = create_task(file->OpenReadAsync());
opentask.then([this](IRandomAccessStreamWithContentType ^stream) {
stream_ = stream;
active_ = true;
thread_ = std::thread([this]() { this->threadfunc(); });
});
auto attrtask = create_task(file->GetBasicPropertiesAsync());
attrtask.then([this](Windows::Storage::FileProperties::BasicProperties ^props) {
size_ = props->Size;
});
}
StorageFileLoader::~StorageFileLoader() {
@@ -54,28 +60,63 @@ bool StorageFileLoader::ExistsFast() {
}
bool StorageFileLoader::IsDirectory() {
return false;
return (file_->Attributes & Windows::Storage::FileAttributes::Directory) != Windows::Storage::FileAttributes::Normal;
}
s64 StorageFileLoader::FileSize() {
return 0;
if (size_ == -1)
__debugbreak(); // crude race condition detection
return size_;
}
std::string StorageFileLoader::Path() const { return ""; }
std::string StorageFileLoader::Path() const {
return "";
}
std::string StorageFileLoader::Extension() { return ""; }
std::string StorageFileLoader::Extension() {
return "";
}
void StorageFileLoader::EnsureOpen() {
while (size_ == -1)
Sleep(100);
}
// Note that multithreaded use could wreak havoc with this...
void StorageFileLoader::Seek(s64 absolutePos) {
EnsureOpen();
seekPos_ = absolutePos;
}
size_t StorageFileLoader::Read(size_t bytes, size_t count, void *data, Flags flags) {
EnsureOpen();
{
std::unique_lock<std::mutex> lock(mutex_);
operations_.push(Operation{ OpType::READ, seekPos_, (int64_t)(bytes * count) });
cond_.notify_one();
}
// OK, now wait for response...
{
std::unique_lock<std::mutex> responseLock(mutexResponse_);
condResponse_.wait(responseLock);
Operation resp = responses_.front();
responses_.pop();
DataReader ^rd = DataReader::FromBuffer(resp.buffer);
Platform::Array<uint8_t> ^bytearray = ref new Platform::Array<uint8_t>(resp.buffer->Length);
rd->ReadBytes(bytearray);
memcpy(data, bytearray->Data, bytes * count);
return 0;
}
}
size_t StorageFileLoader::ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags) {
EnsureOpen();
{
std::unique_lock<std::mutex> lock(mutex_);
operations_.push(Operation{ OpType::READ, absolutePos, (int64_t)(bytes * count) });
cond_.notify_one();
}
// OK, now wait for response...
{
std::unique_lock<std::mutex> responseLock(mutexResponse_);
condResponse_.wait(responseLock);
@@ -85,7 +126,3 @@ size_t StorageFileLoader::Read(size_t bytes, size_t count, void *data, Flags fla
return 0;
}
}
size_t StorageFileLoader::ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags) {
return 0;
}