如何在Windows Phone 8中从安装位置复制文件到隔离存储

How to Copy Files from Installed location to Isolated Storage in Windows Phone 8

本文关键字:复制 位置 文件 存储 隔离 安装 Windows Phone      更新时间:2023-10-16

我正在使用cocos2dx为WP8开发一个应用程序。我无法找到一个复制功能,可以帮助我将文件从安装位置复制到隔离存储。有人知道怎么做吗?请帮助

看一下来自Microsoft的"Marble Game"示例-它包含了许多说明性的代码片段。例如,这是加载数据的小编辑(异步):

    concurrency::task<Platform::Array<byte>^> ReadDataAsync(
        _In_ Windows::Storage::StorageFolder^ location,
        _In_ Platform::String^ filename
        )
    {
        return concurrency::task<Windows::Storage::StorageFile^>(location->GetFileAsync(filename)).then([=](Windows::Storage::StorageFile^ file)
        {
            return file->OpenReadAsync();
        }).then([=](Windows::Storage::Streams::IRandomAccessStreamWithContentType^ stream)
        {
            uint32 fileSize = static_cast<uint32>(stream->Size);
            auto reader = ref new Windows::Storage::Streams::DataReader(stream);
            return concurrency::task<uint32>(reader->LoadAsync(fileSize)).then([=](uint32 count)
            {
                auto fileData = ref new Platform::Array<byte>(fileSize);
                reader->ReadBytes(fileData);
                return fileData;
            });
        });
    }

如何使用(假设项目中包含了my_data.xml,并且"Content=True")

        PCWSTR XML_FILE = L"my_data.xml"; // pay attention this is wide string
        auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
        auto file = ref new Platform::String(XML_FILE);
        concurrency::task<Platform::Array<byte>^> data_task = ReadDataAsync(folder, file);
        concurrency::task_status res = data_task.wait();
        Platform::Array<byte>^ data_buf = data_task.get();

现在您有了一个数据缓冲区,可以根据需要随意使用它或保存到隔离存储