Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
sqlite cocos2dx
bool Title::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
std::string path = "";
path.append(FileUtils::getInstance()->getWritablePath());
path.append("quiz.db");
// コピー先に保存
std::string filePathTo = path;
// コピー元からファイルパス取得
std::string filePathFrom = FileUtils::getInstance()->fullPathForFilename("quiz.db");
if(!FileUtils::getInstance()->isFileExist(filePathTo.c_str())) {
// 存在しなければassetsにあるDBをコピー
Data sqlData = FileUtils::getInstance()->getDataFromFile(filePathFrom.c_str());
FILE *fp = fopen(filePathTo.c_str(), "wb");
if (!fp) {
return true;
}
fwrite(sqlData.getBytes(), sqlData.getSize(), 1, fp);
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment