| Index: native_client_sdk/src/examples/api/file_io/file_io.cc
|
| diff --git a/native_client_sdk/src/examples/api/file_io/file_io.cc b/native_client_sdk/src/examples/api/file_io/file_io.cc
|
| index 9de72f8f6ab8b61615aefd76cb2992b718c35357..d8e27afd0f097a53be88884e70ae45f0626c12b8 100644
|
| --- a/native_client_sdk/src/examples/api/file_io/file_io.cc
|
| +++ b/native_client_sdk/src/examples/api/file_io/file_io.cc
|
| @@ -11,6 +11,7 @@
|
|
|
| #include "ppapi/c/pp_stdint.h"
|
| #include "ppapi/c/ppb_file_io.h"
|
| +#include "ppapi/cpp/directory_entry.h"
|
| #include "ppapi/cpp/file_io.h"
|
| #include "ppapi/cpp/file_ref.h"
|
| #include "ppapi/cpp/file_system.h"
|
| @@ -39,6 +40,7 @@ namespace {
|
| const char* const kLoadPrefix = "ld";
|
| const char* const kSavePrefix = "sv";
|
| const char* const kDeletePrefix = "de";
|
| +const char* const kListPrefix = "ls";
|
| }
|
|
|
| /// The Instance class. One of these exists for each instance of your NaCl
|
| @@ -133,6 +135,13 @@ class FileIoInstance : public pp::Instance {
|
| callback_factory_.NewCallback(&FileIoInstance::Delete, file_name));
|
| return;
|
| }
|
| +
|
| + if (instruction.compare(kListPrefix) == 0) {
|
| + const std::string& dir_name = file_name;
|
| + file_thread_.message_loop().PostWork(
|
| + callback_factory_.NewCallback(&FileIoInstance::List, dir_name));
|
| + return;
|
| + }
|
| }
|
|
|
| void OpenFileSystem(int32_t /* result */) {
|
| @@ -267,6 +276,35 @@ class FileIoInstance : public pp::Instance {
|
| ShowStatusMessage("File deleted");
|
| }
|
|
|
| + void List(int32_t /* result */, const std::string& dir_name) {
|
| + if (!file_system_ready_) {
|
| + ShowErrorMessage("File system is not open", PP_ERROR_FAILED);
|
| + return;
|
| + }
|
| + pp::FileRef ref(file_system_, dir_name.c_str());
|
| +
|
| + // Pass ref along to keep it alive.
|
| + ref.ReadDirectoryEntries(callback_factory_.NewCallbackWithOutput(
|
| + &FileIoInstance::ListCallback, ref));
|
| + }
|
| +
|
| + void ListCallback(int32_t result,
|
| + const std::vector<pp::DirectoryEntry>& entries,
|
| + pp::FileRef /* unused_ref */) {
|
| + if (result != PP_OK) {
|
| + ShowErrorMessage("List failed", result);
|
| + return;
|
| + }
|
| +
|
| + std::string buffer = "File list:";
|
| + for (size_t i = 0; i < entries.size(); ++i) {
|
| + pp::Var name = entries[i].file_ref().GetName();
|
| + if (name.is_string())
|
| + buffer += " " + name.AsString();
|
| + }
|
| + ShowStatusMessage(buffer);
|
| + }
|
| +
|
| /// Encapsulates our simple javascript communication protocol
|
| void ShowErrorMessage(const std::string& message, int32_t result) {
|
| std::stringstream ss;
|
|
|