在Windows Phone 8 cocos2d-x中写入权限

时间:2014-09-23 12:31:45

标签: windows-phone-8 cocos2d-x

我在cocos2d-x中有一个应用程序,用户在文本文件中添加数据,可以随时删除内容

创建文本文件getWritablepath函数用于创建文件

std::string path = CCFileUtils::sharedFileUtils()->getWritablePath() + "demo.txt";
FILE* file = fopen(path.c_str(), "a+");

要删除内容..除了删除的内容之外,用户想要的所有内容都会复制到临时文件中,并删除orignal文件并重命名临时文件

std::string path_temp = CCFileUtils::sharedFileUtils()->getWritablePath() + "temp1.txt";
FILE* file_temp = fopen(path_temp.c_str(), "a+");
const char* break1 = "~";


for (int i=0;i< array1->count(); i++) {
    CCString *string=(CCString *)array1->objectAtIndex(i);
    const char* tmp1 = string->getCString();
    file = fopen(path_temp.c_str(), "a+");
    ifstream is;

    is.open (path_temp.c_str(), ios::binary| ios::ate );
    int length = is.tellg();
    is.close();
    cout<<"size by new"<<length;

    if(tmp2!=tmp1){

        if(length==0){

            fputs(tmp1, file_temp);
            fclose(file_temp);
        }
        else
        {
            fputs(break1,file_temp);
            fputs(tmp1, file_temp);
               fclose(file_temp);
        }


    }
}
array1->removeObjectAtIndex(tag);
remove(path.c_str());                       // This particular function remove rename   gives error as write permission denied
rename(path_temp.c_str(), path.c_str());

以上逻辑在android和ios中正常工作

删除,重命名在Windows中不起作用,因为写入权限被拒绝。 应用程序数据存储在Windows Phone的独立存储中。

0 个答案:

没有答案