【问题标题】:How to Copy Files from Installed location to Isolated Storage in Windows Phone 8如何将文件从安装位置复制到 Windows Phone 8 中的独立存储
【发布时间】:2014-03-20 11:01:16
【问题描述】:

我正在使用 cocos2dx 为 WP8 开发一个应用程序。我找不到帮助我将文件从已安装位置复制到独立存储的复制功能。有谁知道如何做到这一点。请帮忙

【问题讨论】:

标签: c++ windows-phone-8 cocos2d-x


【解决方案1】:

看看来自 Microsoft 的 "Marble Game" 示例 - 它包含许多说明性代码 sn-ps。例如,这是加载数据(异步)的小修改:

    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();

现在您有了一个数据缓冲区,可以根据需要随意使用或保存到独立存储中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多