本文整理汇总了C++中FileUtils类的典型用法代码示例。如果您正苦于以下问题:C++ FileUtils类的具体用法?C++ FileUtils怎么用?C++ FileUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadPlayerData
void CDataManager::LoadPlayerData()
{
FileUtils* Utils = FileUtils::sharedFileUtils();
string fString = FileUtils::sharedFileUtils()->getWritablePath() + "player_data.json";
string szData;
ssize_t fileSize;
const char* stream = (char*)Utils->getFileData(fString, "rb", &fileSize);
if (stream == NULL)
{
m_PlayerData.m_szName = "Guest";
m_PlayerData.m_nStage1Count = 0;
m_PlayerData.m_nStage2Count = 0;
m_PlayerData.m_nStage3Count = 0;
}
else
{
string data = string((const char*)stream, fileSize);
CC_SAFE_DELETE_ARRAY(stream);
//Document doc;
/*if (doc.Parse<0>(data.c_str()).HasParseError())
CCLOG(doc.GetParseError());*/
/*else
{
m_PlayerData.m_szName = doc["PlayerName"].GetString();
m_PlayerData.m_nStage1Count = doc["Stage1"].GetInt();
m_PlayerData.m_nStage2Count = doc["Stage2"].GetInt();
m_PlayerData.m_nStage3Count = doc["Stage3"].GetInt();
}*/
}
}
示例2: printFileUtils
static void printFileUtils(int fd)
{
FileUtils* fu = FileUtils::getInstance();
mydprintf(fd, "\nSearch Paths:\n");
auto list = fu->getSearchPaths();
for( const auto &item : list) {
mydprintf(fd, "%s\n", item.c_str());
}
mydprintf(fd, "\nResolution Order:\n");
list = fu->getSearchResolutionsOrder();
for( const auto &item : list) {
mydprintf(fd, "%s\n", item.c_str());
}
mydprintf(fd, "\nWriteble Path:\n");
mydprintf(fd, "%s\n", fu->getWritablePath().c_str());
mydprintf(fd, "\nFull Path Cache:\n");
auto cache = fu->getFullPathCache();
for( const auto &item : cache) {
mydprintf(fd, "%s -> %s\n", item.first.c_str(), item.second.c_str());
}
}
示例3: LoadResource
void ActorManager::LoadResource(const vector<Name>& resNameList)
{
//1.打开文件
FileUtils* fin = FileUtils::getInstance();
Data data = fin->getDataFromFile("data/Actor.json");
CCASSERT(!data.isNull(), "[Actor.json] Lost!");
//2.载入json
string str = string((char*)data.getBytes(), data.getSize());
rapidjson::Document root;
root.Parse<0>(str.c_str());
CCASSERT(root.IsObject() && root.HasMember("actordata"), "illegal [Actor.json]");
//3.读取json数据
int Size = root["actordata"].Size();
for (int i = 0; i < Size; i++) {
string name = root["actordata"][i]["name"].GetString();
if (std::find(resNameList.begin(), resNameList.end(), name) != resNameList.end())
{
ActorData d;
d.defaultanimate=root["actordata"][i]["defaultanimate"].GetString();
int size = root["actordata"][i]["actioncount"].GetInt();
CCASSERT(size != 0, "framecount must NOT equal 0");
for (int j = 0; j < size; j++) {
d.maps[root["actordata"][i]["actionName"][j].GetString()] = root["actordata"][i]["animateName"][j].GetString();
}
m_actordata[name] = d;
}
}
}
示例4: LoadResponsesForTraining_new
void AnnHelper::LoadResponsesForTraining_new(std::vector<std::string> _files, cv::Mat& _response)
{
FileUtils futils;
MathUtils mathUtils;
MatUtils matutils;
Mat responses;
for (string filename : _files)
{
//获取图片信息文件路径
string fileinfo = filename.substr(0, filename.find_last_of('\\'));//目录
fileinfo += "\\training_data_new.txt";
//读取结果矩阵
vector<string> matNames;
vector<string> matStrs;
futils.ReadMatFile(matStrs, matNames, fileinfo);
assert(matStrs.size() > 0);
int bcodeIndex = 0;//数值矩阵
int bitIndex = 0;//位数矩阵
for (int i = 0; i < matNames.size(); i++)
{
if (matNames[i] == "code")
{
bcodeIndex = i;
}
if (matNames[i] == "bit")
{
bitIndex = i;
}
}
string bcode = "";
Mat decCodeMat = matutils.ToMat(matStrs[bcodeIndex]);
Mat bitMat = matutils.ToMat(matStrs[bitIndex]);
assert(decCodeMat.cols == bitMat.cols);
int bitNum=0;
int bit = 0;
for (int i = 0; i < decCodeMat.cols; i++)
{
bitNum = decCodeMat.at<float>(0, i);
bit = bitMat.at<float>(0, i);
bcode += mathUtils.ConvertToBinary(bitNum, bit);
}
stringstream ss;
Mat resMat(1, bcode.length(), CV_32F);
for (int i = 0; i < resMat.cols; i++)
{
ss << bcode[i];
float ib = 0.;
ss >> ib;
resMat.at<float>(0, i) = ib;
ss.clear();
}
matutils.AddMatRow(responses, resMat, responses);
}
_response = responses;
}
示例5: onExit
void TestUnicodePath::onExit()
{
FileUtils *sharedFileUtils = FileUtils::getInstance();
sharedFileUtils->purgeCachedEntries();
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
FileUtilsDemo::onExit();
}
示例6: CCAssert
int LuaStack::executeScriptFile(const char* filename)
{
CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");
static const std::string BYTECODE_FILE_EXT = ".luac";
static const std::string NOT_BYTECODE_FILE_EXT = ".lua";
std::string buf(filename);
//
// remove .lua or .luac
//
size_t pos = buf.rfind(BYTECODE_FILE_EXT);
if (pos != std::string::npos)
{
buf = buf.substr(0, pos);
}
else
{
pos = buf.rfind(NOT_BYTECODE_FILE_EXT);
if (pos == buf.length() - NOT_BYTECODE_FILE_EXT.length())
{
buf = buf.substr(0, pos);
}
}
FileUtils *utils = FileUtils::getInstance();
//
// 1. check .lua suffix
// 2. check .luac suffix
//
std::string tmpfilename = buf + NOT_BYTECODE_FILE_EXT;
if (utils->isFileExist(tmpfilename))
{
buf = tmpfilename;
}
else
{
tmpfilename = buf + BYTECODE_FILE_EXT;
if (utils->isFileExist(tmpfilename))
{
buf = tmpfilename;
}
}
std::string fullPath = utils->fullPathForFilename(buf);
Data data = utils->getDataFromFile(fullPath);
int rn = 0;
if (!data.isNull())
{
if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0)
{
rn = executeFunction(0);
}
}
return rn;
}
示例7: setResourceRootPath
void Application::setResourceRootPath(const std::string& rootResDir)
{
_resourceRootPath = rootResDir;
if (_resourceRootPath[_resourceRootPath.length() - 1] != '/')
{
_resourceRootPath += '/';
}
FileUtils* pFileUtils = FileUtils::getInstance();
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
searchPaths.insert(searchPaths.begin(), _resourceRootPath);
pFileUtils->setSearchPaths(searchPaths);
}
示例8: initResourcePath
void AppDelegate::initResourcePath()
{
FileUtils* sharedFileUtils = FileUtils::getInstance();
std::string strBasePath = sharedFileUtils->getWritablePath();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)|| (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
sharedFileUtils->addSearchPath("res/");
#else
sharedFileUtils->addSearchPath("../../res/");
#endif
sharedFileUtils->addSearchPath(strBasePath + "upd/", true);
}
示例9: FileUtils_createFile
static jboolean FileUtils_createFile(JNIEnv* env,jobject thiz,jstring filePath)
{
FileUtils* fileUtils = (FileUtils*)env->GetIntField(thiz,fileUtilsFieldID);
if(fileUtils == NULL)
return -1;
const jchar* jFilePath = env->GetStringChars(filePath,NULL);
jsize j_size = env->GetStringLength(filePath);
char* s_filePath = UTF16toUTF8((jchar*)jFilePath,(size_t*)&j_size);
bool ret = fileUtils->createFile(s_filePath);
env->ReleaseStringChars(filePath,jFilePath);
free(s_filePath);
return ret;
}
示例10: touch_file
void touch_file(bool single)
{
FileUtils file;
int ret = file.open("test1.txt", O_WRONLY | O_TRUNC | O_CREAT, 0644);
ASSERT_NE(ret, 0);
vector<string> v;
gen_file(v, single);
for (size_t i = 0;i < v.size();i++) {
file.write(v[i].c_str(), v[i].size());
}
file.close();
}
示例11: FileUtils
bool AdjustBMParam::saveParameters(){
FileUtils* fileUtils = new FileUtils();
QString fileName = fileUtils->saveFile();
int preFilterSz = this->ui->preFilterSz->value();
int preFilterCap = this->ui->preFilterCap->value();
int sadWndSz = this->ui->SADWndSz->value();
int minDisp = this->ui->minDisp->value();
int numDisp = 16*(this->ui->numDisp->value());
int texture = this->ui->textureth->value();
int uniquness = this->ui->uniq->value();
int spkWndSz = this->ui->speckleWndSz->value();
int spkRange = this->ui->specklerange->value();
if(sadWndSz%2==0)
sadWndSz++;
if(sadWndSz<5)
sadWndSz = 5;
if(preFilterSz%2==0)
preFilterSz++;
if(preFilterSz<5)
preFilterSz = 5;
CvFileStorage* fstorage = cvOpenFileStorage(fileName.toLocal8Bit().data(), NULL, CV_STORAGE_WRITE);
if(fstorage == NULL){
fprintf(stderr,"ERROR: File storage NULL!\n");
return false;
}
cvWriteInt(fstorage, "preFilterSize", preFilterSz);
cvWriteInt(fstorage, "preFilterCap", preFilterCap);
cvWriteInt(fstorage, "sadWindowSize", sadWndSz);
cvWriteInt(fstorage, "minDisp", minDisp);
cvWriteInt(fstorage, "numDisp", numDisp);
cvWriteInt(fstorage, "textureThreshold", texture);
cvWriteInt(fstorage, "uniquness", uniquness);
cvWriteInt(fstorage, "spkWindowSize", spkWndSz);
cvWriteInt(fstorage,"spkRange", spkRange);
cvReleaseFileStorage(&fstorage);
delete fileUtils;
return true;
}
示例12: main
int main(int argc, char *argv[])
{
FileUtils tools;
std::string root(argv[1]);
if(argc != 2)
{
std::cerr << "Usage: file_utils <root_directory>\n";
return 1;
}
// Find all duplicate files start at root directory
tools.FindDups(root);
}
示例13: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
FileUtils *fu = FileUtils::getInstance();
ValueMap vm = fu->getValueMapFromFile("data.plist");
log("%s",vm["name"].asString().c_str());
return true;
}
示例14: CCAssert
int LuaStack::executeScriptFile(const char* filename)
{
CCAssert(filename, "CCLuaStack::executeScriptFile() - invalid filename");
FileUtils *utils = FileUtils::getInstance();
std::string fullPath = utils->fullPathForFilename(filename);
Data data = utils->getDataFromFile(fullPath);
int rn = 0;
if (!data.isNull()) {
if (luaLoadBuffer(_state, (const char*)data.getBytes(), (int)data.getSize(), fullPath.c_str()) == 0) {
rn = executeFunction(0);
}
}
return rn;
}
示例15: if
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("Bomberman", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
glview = GLViewImpl::create("Bomberman");
#endif
director->setOpenGLView(glview);
}
// turn on display FPS
director->setDisplayStats(false);
// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);
// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
auto frameSize = glview->getFrameSize();
// if the frame's height is larger than the height of medium size.
if (frameSize.height > mediumResolutionSize.height)
{
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
}
// if the frame's height is larger than the height of small size.
else if (frameSize.height > smallResolutionSize.height)
{
director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
}
// if the frame's height is smaller than the height of medium size.
else
{
director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
}
register_all_packages();
FileUtils* fileUtils = FileUtils::getInstance();
fileUtils->addSearchPath("res");
// create a scene. it's an autorelease object
auto scene = GameStartScene::createScene();
// run
director->runWithScene(scene);
CCLOG("Animation Interval = %f", director->getAnimationInterval());
return true;
}