예제 #1
0
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
}
예제 #2
0
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);
}
예제 #3
0
파일: FileAssist.cpp 프로젝트: StevenFm/bbt
XFileAssist::XFileAssist()
{
    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    
    std::string strWritePath = pFileUtils->getWritablePath();
    
    std::vector<std::string> pathTable;
    
    pathTable.push_back(strWritePath);
    
    pFileUtils->setSearchPaths(pathTable);
}
예제 #4
0
파일: FileAssist.cpp 프로젝트: StevenFm/bbt
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);
}
예제 #5
0
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);
        }
    }
}
예제 #6
0
void SQLHelper::init()
{
    int result;
    //Check database if exist
    CCFileUtils *fileUtils = CCFileUtils::sharedFileUtils();
    _dbPath = fileUtils->getWritablePath();
    _dbPath.append("TrivialJokoa.db");
    std::ifstream f(_dbPath.c_str());
    
    if(!f)
    {
        //Database not exist
        result = sqlite3_open(_dbPath.c_str(),&_db);
        createDB();
    } else {
        CCLOG("DB EXIST");
        result = sqlite3_open(_dbPath.c_str(),&_db);
    }
    
    if (result != SQLITE_OK)
        CCLOG("OPENING WRONG, %d", result);

}
예제 #7
0
    void AppDelegate::initGameView() {

        // initialize director
        CCDirector *pDirector = CCDirector::sharedDirector();
        pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
        pDirector->setProjection(kCCDirectorProjection2D);


        CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
        if(!isPortraitApp) {
            screenSize = CCSizeMake(screenSize.height, screenSize.width);
        }

        std::vector<std::string> resDirOrders;
        std::string res;
        TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();


        if (platform == kTargetIphone || platform == kTargetIpad)
        {
            std::vector<std::string> searchPaths = CCFileUtils::sharedFileUtils()->getSearchPaths();
            searchPaths.insert(searchPaths.begin(), "Published files iOS");
            searchPaths.insert(searchPaths.begin(), getCCBDirectoryPath());

            CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
            if (screenSize.height > 1136)
            {
                res = "iPad";
                setResolutionSizes(true, true, isPortraitApp);
                resDirOrders.push_back("resources-ipadhd");
                resDirOrders.push_back("resources-ipad");
                resDirOrders.push_back("resources-iphonehd");
                isIPhone = false;
                isRetina = true;
                cocos2d::extension::CCBReader::setResolutionScale(2);
            } else if(screenSize.height > 1024) {
                res = "iPhone";
                setResolutionSizes(false, true, isPortraitApp);
                resDirOrders.push_back("resources-iphonehd");
                resDirOrders.push_back("resources-iphone");
                isIPhone = true;
                isRetina = true;
            }
            else if (screenSize.height > 960)
            {
                res = "iPad";
                setResolutionSizes(true, false, isPortraitApp);
                resDirOrders.push_back("resources-ipad");
                resDirOrders.push_back("resources-iphonehd");
                isIPhone = false;
                isRetina = false;
                cocos2d::extension::CCBReader::setResolutionScale(2);

            }
            else if (screenSize.height > 480)
            {
                res = "iPhone";
                setResolutionSizes(false, true, isPortraitApp);
                resDirOrders.push_back("resources-iphonehd");
                resDirOrders.push_back("resources-iphone");
                isIPhone = true;
                isRetina = true;
            }
            else
            {
                res = "iPhone";
                setResolutionSizes(false, false, isPortraitApp);
                resDirOrders.push_back("resources-iphone");
                isIPhone = true;
                isRetina = false;
            }

        }
        else if (platform == kTargetAndroid || platform == kTargetWindows)
        {
            int dpi = -1;
            dpi = CCDevice::getDPI();

            if(dpi > 300) { // retina
                if (screenSize.height > 1920) {
                    res = "xlarge";
                    setResolutionSizes(true, true, isPortraitApp);
                    resDirOrders.push_back("resources-xlarge");
                    resDirOrders.push_back("resources-large");
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                } else {
                    res = "large";
                    setResolutionSizes(false, true, isPortraitApp);
                    resDirOrders.push_back("resources-large");
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                }
            } else { // non retina
                if (screenSize.height > 960)
                {
                    res = "large";
                    setResolutionSizes(true, false, isPortraitApp);
                    resDirOrders.push_back("resources-large");
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                    cocos2d::extension::CCBReader::setResolutionScale(2);
                }
                else if (screenSize.height > 768)
                {
                    res = "medium";
                    setResolutionSizes(true, false, isPortraitApp);
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                }
                else if (screenSize.height > 480)
                {
                    res = "small";
                    setResolutionSizes(false, false, isPortraitApp);
                    resDirOrders.push_back("resources-small");
                }
                else
                {
                    setResolutionSizes(false, false, isPortraitApp);
                    res = "xsmall";
                    resDirOrders.push_back("resources-xsmall");
                }

            }
        }

        CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
        pFileUtils->setSearchResolutionsOrder(resDirOrders);

        std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
        searchPaths.insert(searchPaths.begin(), pFileUtils->getWritablePath());
        pFileUtils->setSearchPaths(searchPaths);

        PlayerStatus::setDeviceResolution(res);
        // 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);
    }