Skip to content

Instantly share code, notes, and snippets.

@lamlambda
Last active February 15, 2016 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lamlambda/6a5b2175538754d36839 to your computer and use it in GitHub Desktop.
Save lamlambda/6a5b2175538754d36839 to your computer and use it in GitHub Desktop.
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