Last active
February 15, 2016 10:31
-
-
Save lamlambda/6a5b2175538754d36839 to your computer and use it in GitHub Desktop.
sqlite cocos2dx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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