mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Initial work on StorageFolderBrowser
This commit is contained in:
parent
4bad28046b
commit
7ca186fe93
@ -10,7 +10,7 @@ using namespace Concurrency;
|
||||
using namespace Windows::Storage;
|
||||
using namespace Windows::Storage::Streams;
|
||||
|
||||
std::mutex initMutex;
|
||||
static std::mutex initMutex;
|
||||
|
||||
StorageFileLoader::StorageFileLoader(Windows::Storage::StorageFile ^file) {
|
||||
file_ = file;
|
||||
|
101
UWP/StorageFolderBrowser.cpp
Normal file
101
UWP/StorageFolderBrowser.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include "pch.h"
|
||||
#include "ppltasks.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "thread/threadutil.h"
|
||||
|
||||
#include "StorageFolderBrowser.h"
|
||||
#include "UWPUtil.h"
|
||||
|
||||
using namespace Concurrency;
|
||||
using namespace Windows::Storage;
|
||||
using namespace Windows::Storage::Streams;
|
||||
|
||||
static std::mutex initMutex;
|
||||
|
||||
StorageFolderBrowser::StorageFolderBrowser(Windows::Storage::StorageFolder ^folder) : folder_(folder) {
|
||||
thread_.reset(new std::thread([this]() { this->threadfunc(); }));
|
||||
|
||||
path_ = FromPlatformString(folder->Path);
|
||||
displayName_ = FromPlatformString(folder->DisplayName);
|
||||
}
|
||||
|
||||
void StorageFolderBrowser::threadfunc() {
|
||||
setCurrentThreadName("StorageFileLoader");
|
||||
|
||||
initMutex.lock();
|
||||
|
||||
/*
|
||||
auto opentask = create_task(folder_->GetItemsAsync()->OpenReadAsync()).then([this](IRandomAccessStreamWithContentType ^stream) {
|
||||
stream_ = stream;
|
||||
active_ = true;
|
||||
});
|
||||
|
||||
try {
|
||||
opentask.wait();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
operationFailed_ = true;
|
||||
// TODO: What do we do?
|
||||
const char *what = e.what();
|
||||
ILOG("%s", what);
|
||||
}
|
||||
catch (Platform::COMException ^e) {
|
||||
|
||||
}
|
||||
|
||||
auto sizetask = create_task(file_->GetBasicPropertiesAsync()).then([this](Windows::Storage::FileProperties::BasicProperties ^props) {
|
||||
size_ = props->Size;
|
||||
});
|
||||
try {
|
||||
sizetask.wait();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
const char *what = e.what();
|
||||
ILOG("%s", what);
|
||||
}
|
||||
catch (Platform::COMException ^e) {
|
||||
std::string what = FromPlatformString(e->ToString());
|
||||
ILOG("%s", what.c_str());
|
||||
}
|
||||
*/
|
||||
initMutex.unlock();
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
while (active_) {
|
||||
if (!operationRequested_) {
|
||||
cond_.wait(lock);
|
||||
}
|
||||
if (operationRequested_) {
|
||||
switch (operation_.type) {
|
||||
case OpType::LIST_DIRECTORY: {
|
||||
|
||||
/*
|
||||
Streams::Buffer ^buf = ref new Streams::Buffer(operation_.size);
|
||||
operationFailed_ = false;
|
||||
stream_->Seek(operation_.offset);
|
||||
auto task = create_task(stream_->ReadAsync(buf, operation_.size, Streams::InputStreamOptions::None));
|
||||
Streams::IBuffer ^output = nullptr;
|
||||
try {
|
||||
task.wait();
|
||||
output = task.get();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
operationFailed_ = true;
|
||||
const char *what = e.what();
|
||||
ILOG("%s", what);
|
||||
}
|
||||
operationRequested_ = false;
|
||||
std::unique_lock<std::mutex> lock(mutexResponse_);
|
||||
response_.buffer = output;
|
||||
responseAvailable_ = true;
|
||||
condResponse_.notify_one();
|
||||
break;*/
|
||||
}
|
||||
default:
|
||||
operationRequested_ = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
70
UWP/StorageFolderBrowser.h
Normal file
70
UWP/StorageFolderBrowser.h
Normal file
@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Core/Loaders.h"
|
||||
|
||||
// This thing is a terrible abomination that wraps asynchronous file access behind a synchronous interface,
|
||||
// completely defeating MS' design goals for StorageFile. But hey, you gotta do what you gotta do.
|
||||
// This opens a stream attached to the passed-in file. Multiple of these can be created against one StorageFile.
|
||||
|
||||
class StorageFolderBrowser {
|
||||
public:
|
||||
StorageFolderBrowser(Windows::Storage::StorageFolder ^folder);
|
||||
~StorageFolderBrowser();
|
||||
|
||||
std::string Path() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
std::string DisplayName() const {
|
||||
return displayName_;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void threadfunc();
|
||||
|
||||
enum class OpType {
|
||||
NONE,
|
||||
LIST_DIRECTORY,
|
||||
CHANGE_FOLDER,
|
||||
};
|
||||
|
||||
struct Operation {
|
||||
OpType type;
|
||||
};
|
||||
|
||||
struct Response {
|
||||
};
|
||||
|
||||
std::string path_;
|
||||
std::string displayName_;
|
||||
|
||||
bool active_ = false;
|
||||
std::unique_ptr<std::thread> thread_;
|
||||
|
||||
Windows::Storage::StorageFolder ^folder_;
|
||||
|
||||
bool operationRequested_ = false;
|
||||
Operation operation_{ OpType::NONE };
|
||||
std::condition_variable cond_;
|
||||
std::mutex mutex_;
|
||||
|
||||
bool operationFailed_ = false;
|
||||
|
||||
bool responseAvailable_ = false;
|
||||
Response response_;
|
||||
std::condition_variable condResponse_;
|
||||
std::mutex mutexResponse_;
|
||||
|
||||
int64_t seekPos_ = 0;
|
||||
};
|
@ -377,6 +377,7 @@ copy AssetsGold\*.* Assets /Y</Command>
|
||||
<ClInclude Include="Common\DirectXHelper.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="StorageFileLoader.h" />
|
||||
<ClInclude Include="StorageFolderBrowser.h" />
|
||||
<ClInclude Include="UWPHost.h" />
|
||||
<ClInclude Include="UWPUtil.h" />
|
||||
<ClInclude Include="XAudioSoundStream.h" />
|
||||
@ -410,6 +411,7 @@ copy AssetsGold\*.* Assets /Y</Command>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='UWP Gold|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="StorageFileLoader.cpp" />
|
||||
<ClCompile Include="StorageFolderBrowser.cpp" />
|
||||
<ClCompile Include="UWPHost.cpp" />
|
||||
<ClCompile Include="XAudioSoundStream.cpp" />
|
||||
</ItemGroup>
|
||||
|
@ -49,6 +49,7 @@
|
||||
<ClCompile Include="StorageFileLoader.cpp" />
|
||||
<ClCompile Include="UWPHost.cpp" />
|
||||
<ClCompile Include="..\Windows\XinputDevice.cpp" />
|
||||
<ClCompile Include="StorageFolderBrowser.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="App.h" />
|
||||
@ -61,6 +62,7 @@
|
||||
<ClInclude Include="UWPHost.h" />
|
||||
<ClInclude Include="..\Windows\XinputDevice.h" />
|
||||
<ClInclude Include="UWPUtil.h" />
|
||||
<ClInclude Include="StorageFolderBrowser.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="Assets\StoreLogo.png">
|
||||
|
Loading…
Reference in New Issue
Block a user