957 auto s = Director::getInstance()->getWinSize();
958 auto util = FileUtils::getInstance();
962 Label* label =
nullptr;
964 std::string dir =
"中文路径/";
965 std::string filename =
"测试文件.test";
968 auto getMsg = [&act](
bool b,
const std::string& path)-> std::string
971 snprintf((
char *)msg, 512,
"%s for %s path: \"%s\"", b ?
"success" :
"failed", act.c_str(), path.c_str());
972 return std::string(msg);
976 std::string dirPath = util->getWritablePath() + dir;
977 if (!util->isDirectoryExist(dirPath))
979 util->createDirectory(dirPath);
983 bool isExist = util->isDirectoryExist(dirPath);
984 label = Label::createWithSystemFont(getMsg(isExist, dirPath),
"", 12, Size(s.width, 0));
985 label->setPosition(x, y * 4);
986 this->addChild(label);
991 std::string filePath = dirPath + filename;
992 if (! util->isFileExist(filePath))
994 std::string writeDataStr =
" 测试字符串.";
996 writeData.copy((
unsigned char *)writeDataStr.c_str(), writeDataStr.size());
997 util->writeDataToFile(writeData, filePath);
1000 isExist = util->isFileExist(filePath);
1001 label = Label::createWithSystemFont(getMsg(isExist, filePath),
"", 12, Size(s.width, 0));
1002 label->setPosition(x, y * 3);
1003 this->addChild(label);
1009 unsigned char* buffer =
nullptr;
1010 Data readData = util->getDataFromFile(filePath);
1011 buffer = (
unsigned char*)malloc(
sizeof(
unsigned char) * (readData.getSize() + 1));
1012 memcpy(buffer, readData.getBytes(), readData.getSize());
1013 buffer[readData.getSize()] =
'\0';
1015 log(
"The content of file from writable path: %s", buffer);
1019 label = Label::createWithSystemFont(getMsg(util->removeFile(filePath), filePath),
"", 12, Size(s.width, 0));
1020 label->setPosition(x, y * 2);
1021 this->addChild(label);
1025 label = Label::createWithSystemFont(getMsg(util->removeDirectory(dirPath), dirPath),
"", 12, Size(s.width, 0));
1026 label->setPosition(x, y * 1);
1027 this->addChild(label);
virtual void onEnter() override