本文整理汇总了C++中CCFileUtils类的典型用法代码示例。如果您正苦于以下问题:C++ CCFileUtils类的具体用法?C++ CCFileUtils怎么用?C++ CCFileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCFileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applicationDidFinishLaunching
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
// turn on display FPS
pDirector->setDisplayStats(false);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
pEGLView->setDesignResolutionSize(SCREEN_WIDTH, SCREEN_HEIGHT, kResolutionExactFit);
CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
fileUtils->addSearchPath("fonts");
fileUtils->addSearchPath("images");
fileUtils->addSearchPath("sounds");
CCScene* scene = CCScene::create();
GameScene* layer = GameScene::create();
scene->addChild(layer);
pDirector->runWithScene(scene);
return true;
}
示例2: CCMessageBox
void Recipe76::doStep2()
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCMessageBox("iOS Only", "RecipeBook");
return;
#else
std::string zipFilename = "archive.zip";
CCFileUtils* fileUtils = CCFileUtils::sharedFileUtils();
// フルパスを取得
std::string fullPath = fileUtils->fullPathForFilename(zipFilename.c_str());
// 書き込み可能なディレクトリを取得
std::string path = fileUtils->getWritablePath();
std::string unzipdPath = path + "unzipd/";
// zipの展開
unzipFileToDir(fullPath.c_str(), unzipdPath.c_str());
// 展開したzip中のテキストファイル取得
std::string txtPath = unzipdPath + "test-step2.txt";
unsigned long size;
unsigned char* data = fileUtils->getFileData(txtPath.c_str(), "rb", &size);
std::string text;
if (data != NULL) {
text.assign((const char*)data, size);
delete [] data;
}
CCString *msg = CCString::createWithFormat("read from zip file'%s'", text.c_str());
CCLabelTTF *label = (CCLabelTTF*)this->getChildByTag(10);
label->setString(msg->getCString());
#endif
}
示例3: initLuaGlobalVariables
void initLuaGlobalVariables(const std::string& entry)
{
//GLOBAL_ROOT_DIR
CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
CCLuaStack* pStack = pEngine->getLuaStack();
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
using namespace std;
string path = pFileUtils->fullPathForFilename(entry.c_str());
// replace "\" with "/", normalize the path
int pos = string::npos;
while ((pos = path.find_first_of("\\")) != string::npos)
{
path.replace(pos, 1, "/");
}
string script_dir = path.substr(0, path.find_last_of("/"));
string root_dir = script_dir.substr(0, script_dir.find_last_of("/"));
CCLOG("RootDir: %s\nScriptDir: %s \n",root_dir.c_str(), script_dir.c_str());
std::string env = "GLOBAL_ROOT_DIR=\""; env.append(root_dir); env.append("\"");
pEngine->executeString(env.c_str());
env = "__LUA_STARTUP_FILE__=\"";env.append(path);env.append("\"");
pEngine->executeString(env.c_str());
pStack->addSearchPath(script_dir.c_str());
pFileUtils->addSearchPath(root_dir.c_str());
pFileUtils->addSearchPath(script_dir.c_str());
ScutExt::Init(root_dir+"/");
}
示例4: validate
bool ProjectConfig::validate(void)
{
CCFileUtils *utils = CCFileUtils::sharedFileUtils();
if (!utils->isDirectoryExist(m_projectDir)) return false;
if (!utils->isDirectoryExist(getWritableRealPath())) return false;
if (!utils->isFileExist(getScriptFileRealPath())) return false;
return true;
}
示例5: getDatabaseFilePath
NS_CC_PURCHASE_BEGIN
CCString* getDatabaseFilePath(CCString* prefix)
{
CCFileUtils* pUtils = CCFileUtils::sharedFileUtils();
const char* dbPath = prefix->length() == 0 ? DBPATH: CCString::createWithFormat("%s_%s", prefix->getCString(), DBPATH)->getCString();
std::string documentsDir = pUtils->getWriteablePath();
return CCString::createWithFormat("%s%s", documentsDir.c_str(), dbPath);
}
示例6: onExit
void TestSearchPath::onExit()
{
CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();
// reset search path
sharedFileUtils->setSearchPaths(m_defaultSearchPathArray);
sharedFileUtils->setSearchResolutionsOrder(m_defaultResolutionsOrderArray);
FileUtilsDemo::onExit();
}
示例7: Save
void User::Save()
{
CCFileUtils* fileUtils = CCFileUtils::sharedFileUtils();
bugsCatched->writeToFile("BugsCatched.plist");
item->writeToFile("Item.plist");
string writablePath = fileUtils->getWritablePath() + "User.txt";
FILE *fp = fopen(writablePath.c_str(), "w");
string data = name + "\n" + ConvertInt(score) + "\n" + ConvertInt(level);
fputs(data.c_str(), fp);
fclose(fp);
}
示例8: GetFileModifyTime
time_t XFileAssist::GetFileModifyTime(const char szFileName[])
{
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
// 注意有个坑: 安卓下面,fullPathForFilename返回的不见得是fullPath
// 如果根据规则(searchPath + RelativePath + Resolution + FileName),在APK(Zip)包里面找到了这个文件
// 那么返回的就只是一个相对路径(相对于APK的root)
std::string strFullPath = pFileUtils->fullPathForFilename(szFileName);
return XFileHelper::GetFileModifyTime(strFullPath.c_str());
}
示例9: WriteFileData
BOOL XFileAssist::WriteFileData(const char szFileName[], const void* pvData, size_t uDataLen)
{
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::string strWritePath = pFileUtils->getWritablePath();
strWritePath.push_back(DIR_SPRIT);
strWritePath += szFileName;
return XFileHelper::WriteFileData(strWritePath.c_str(), pvData, uDataLen);
}
示例10:
XFileAssist::XFileAssist()
{
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::string strWritePath = pFileUtils->getWritablePath();
std::vector<std::string> pathTable;
pathTable.push_back(strWritePath);
pFileUtils->setSearchPaths(pathTable);
}
示例11: setResourceRootPath
void CCApplication::setResourceRootPath(const std::string& rootResDir)
{
m_resourceRootPath = rootResDir;
if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
{
m_resourceRootPath += '/';
}
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
pFileUtils->setSearchPaths(searchPaths);
}
示例12: onEnter
void TestSearchPath::onEnter()
{
FileUtilsDemo::onEnter();
CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();
string ret;
sharedFileUtils->purgeCachedEntries();
m_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
vector<string> searchPaths = m_defaultSearchPathArray;
string writablePath = sharedFileUtils->getWritablePath();
string fileName = writablePath+"external.txt";
char szBuf[100] = "Hello Cocos2d-x!";
FILE* fp = fopen(fileName.c_str(), "wb");
if (fp)
{
fwrite(szBuf, 1, strlen(szBuf), fp);
fclose(fp);
CCLog("Writing file to writable path succeed.");
}
searchPaths.insert(searchPaths.begin(), writablePath);
searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath1");
searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2");
sharedFileUtils->setSearchPaths(searchPaths);
m_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
vector<string> resolutionsOrder = m_defaultResolutionsOrderArray;
resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad");
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
for( int i=1; i<3; i++) {
CCString *filename = CCString::createWithFormat("file%d.txt", i);
ret = sharedFileUtils->fullPathForFilename(filename->getCString());
CCLog("%s -> %s", filename->getCString(), ret.c_str());
}
// Gets external.txt from writable path
string fullPath = sharedFileUtils->fullPathForFilename("external.txt");
CCLog("\nexternal file path = %s\n", fullPath.c_str());
if (fullPath.length() > 0) {
fp = fopen(fullPath.c_str(), "rb");
if (fp)
{
char szReadBuf[100] = {0};
fread(szReadBuf, 1, strlen(szBuf), fp);
CCLog("The content of file from writable path: %s", szReadBuf);
fclose(fp);
}
}
}
示例13: CCSizeMake
bool AppDelegate::applicationDidFinishLaunching()
{
// As an example, load config file
// XXX: This should be loaded before the Director is initialized,
// XXX: but at this point, the director is already initialized
CCConfiguration::sharedConfiguration()->loadConfigFile("configs/config-example.plist");
// initialize director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
CCSize designSize = CCSizeMake(480, 320);
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
std::vector<std::string> searchPaths;
if (screenSize.height > 320)
{
CCSize resourceSize = CCSizeMake(960, 640);
searchPaths.push_back("hd");
searchPaths.push_back("hd/scenetest");
pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
}
else
{
searchPaths.push_back("scenetest");
}
pFileUtils->setSearchPaths(searchPaths);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);
#else
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
#endif
CCScene * pScene = CCScene::create();
CCLayer * pLayer = new TestController();
pLayer->autorelease();
pScene->addChild(pLayer);
pDirector->runWithScene(pScene);
return true;
}
示例14: while
/**
* 从数据包加载任务
*/
bool
MCTaskManager::loadTasks()
{
bool result = false;
do {
CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
/* 加载任务 */
taskAccessor_ = new MCTaskAccessor;
taskAccessor_->loadTasks(fileUtils->fullPathForFilename(kMCTaskPackageFilepath).c_str());
result = true;
} while (0);
return result;
}
示例15: CCSizeMake
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
CCSize designSize = CCSizeMake(480, 320);
CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
if (screenSize.height > 320)
{
CCSize resourceSize = CCSizeMake(960, 640);
std::vector<std::string> searchPaths;
searchPaths.push_back("hd");
pFileUtils->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
}
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);
// turn on display FPS
// pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
// CCScene *pScene = HelloWorld::scene();
CocosGUIExamplesRegisterScene *pScene = new CocosGUIExamplesRegisterScene();
pScene->autorelease();
// run
pDirector->runWithScene(pScene);
return true;
}