void ExtractMapsFromMpq(uint32 build) { char mpq_filename[1024]; char output_filename[1024]; char mpq_map_name[1024]; printf("Extracting maps...\n"); uint32 map_count = ReadMapDBC(); ReadAreaTableDBC(); ReadLiquidTypeTableDBC(); std::string path = output_path; path += "/maps/"; CreateDir(path); printf("Convert map files\n"); for (uint32 z = 0; z < map_count; ++z) { printf("Extract %s (%d/%u) \n", map_ids[z].name, z+1, map_count); // Loadup map grid data sprintf(mpq_map_name, "World\\Maps\\%s\\%s.wdt", map_ids[z].name, map_ids[z].name); WDT_file wdt; if (!wdt.loadFile(WorldMpq, mpq_map_name, false)) continue; for (uint32 y = 0; y < WDT_MAP_SIZE; ++y) { for (uint32 x = 0; x < WDT_MAP_SIZE; ++x) { if (!(wdt.main->adt_list[y][x].flag & 0x1)) continue; sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y); sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x); ConvertADT(mpq_filename, output_filename, y, x, build); } // draw progress bar printf("Processing........................%d%%\r", (100 * (y+1)) / WDT_MAP_SIZE); } } printf("\n"); delete [] areas; delete [] map_ids; }
int CreateDirInPathAndBackToCurrentDir(char* dirName, char* path, char* currentDir) { if(-1 == ChangeDirectory(path)) return -1; if (0 != access(dirName, F_OK)) { if (ENOENT == errno) { // if file does not exist if(-1 == CreateDir(dirName)) return -1; } if (ENOTDIR == errno) { fprintf(stderr, "Not a directory!\n"); return -1; } } if(-1 == ChangeDirectory(currentDir)) return -1; return 0; }
bool TForm1::MakeBackup() { UnicodeString dir = ExtractFileDir(m_strFileName) + "\\backups"; if (!DirectoryExists(dir) && !CreateDir(dir)) { return false; } UnicodeString newfilename = ExtractFileName(m_strFileName); newfilename.Delete(newfilename.Length() - ExtractFileExt(m_strFileName).Length() + 1, ExtractFileExt(m_strFileName).Length()); newfilename = dir + L"\\" + newfilename + " (" + TDateTime::CurrentDateTime().FormatString("yyyy-mm-dd hh_nn") + ")" + ExtractFileExt(m_strFileName); Log->Lines->Add("Сохраняю резервную копию файла в " + newfilename); bool bResult = CopyFile(m_strFileName.c_str(),newfilename.c_str(),false); return bResult; }
static void CreateDir(const char *pPath) { if(!pPath || *pPath == 0) return; // strip trailing '/' ((char*)pPath)[MFString_Length(pPath)-1] = 0; // the path is empty if(*pPath == 0) return; CreateDir(MFStr_GetFilePath(pPath)); CreateDirectory(pPath, NULL); }
void RequestTests::Test_PdbImport() { bool bExec = false; CMtClient client("127.0.0.1", 50); std::string sErrorMsg; int nServerRetCode = -1; std::string sServerResponse; std::ostringstream stCommand; std::wstring sPdbName; std::wstring sSymDir; std::wstring sOutFile; int nCreateDir = -1; sPdbName = Utils::GetTestDataFolder(); sPdbName += L"CrashRpt.pdb"; // Create symbol store dir sSymDir = Utils::GetTestDataFolder(); sSymDir += L"sym"; RmDir(sSymDir, false); nCreateDir = CreateDir(sSymDir); TEST_ASSERT_MSG(nCreateDir==0, "Error creating directory '%s'", strconv::w2a(sSymDir).c_str()); sOutFile = sSymDir; #ifdef _WIN32 sOutFile += L"\\CrashRpt.pdb.txt"; #else sOutFile += L"/CrashRpt.pdb.txt"; #endif // Format command stCommand << "dumper --import-pdb \"" << strconv::w2utf8(sPdbName) << "\" \"" << strconv::w2utf8(sSymDir) << "\" \"" << strconv::w2utf8(sOutFile) << "\"\n"; // Execute daemon status command - assume success bExec = client.ExecuteRequest(stCommand.str().c_str(), nServerRetCode, sServerResponse, sErrorMsg); TEST_ASSERT_MSG(bExec, sErrorMsg.c_str()); TEST_ASSERT_MSG(nServerRetCode==0, "Invalid ret code %d, msg = %s", nServerRetCode, sServerResponse.c_str()); __TEST_CLEANUP__; // Delete sym directory RmDir(sSymDir, false); }
void ConfigManager::InitPaths() { #ifdef __WINDOWS__ ConfigManager::config_folder = GetPortableConfigDir(); #else ConfigManager::config_folder = wxStandardPathsBase::Get().GetUserDataDir(); #endif ConfigManager::home_folder = wxStandardPathsBase::Get().GetUserConfigDir(); ConfigManager::app_path = ::DetermineExecutablePath(); wxString res_path = ::DetermineResourcesPath(); // if non-empty, the app has overriden it (e.g. "--prefix" was passed in the command line) if (data_path_global.IsEmpty()) { if(platform::windows) ConfigManager::data_path_global = app_path + _T("/share/codeblocks"); else if(platform::macosx) ConfigManager::data_path_global = res_path + _T("/share/codeblocks"); else ConfigManager::data_path_global = wxStandardPathsBase::Get().GetDataDir(); } #ifdef CB_AUTOCONF if (plugin_path_global.IsEmpty()) { if(platform::windows || platform::macosx) ConfigManager::plugin_path_global = data_path_global; else { ConfigManager::plugin_path_global = wxStandardPathsBase::Get().GetPluginsDir() + _T("/plugins"); // first assume, we use standard-paths if(!wxDirExists(ConfigManager::plugin_path_global) && wxIsPlatform64Bit()) { // if standard-path does not exist and we are on 64-bit system, use lib64 instead ConfigManager::plugin_path_global = ((const wxStandardPaths&)wxStandardPaths::Get()).GetInstallPrefix() + _T("/lib64/codeblocks/plugins"); } } } #endif ConfigManager::data_path_user = ConfigManager::relo ? data_path_global : config_folder + _T("/share/codeblocks"); CreateDirRecursively(ConfigManager::config_folder); CreateDirRecursively(ConfigManager::data_path_user + _T("/plugins/")); CreateDir(ConfigManager::data_path_user + _T("/scripts/")); ConfigManager::temp_folder = wxStandardPathsBase::Get().GetTempDir(); };
QString CNeoCore::GetTempDir(bool bCreate) { QString Path = Cfg()->GetString("Content/Temp"); if(Path.isEmpty()) { if(Cfg()->IsPortable()) Path = Cfg()->GetAppDir(); else QDir::homePath() + "/Downloads/NeoLoader"; Path += "/Temp/"; } if(Path.right(1) != "/") Path.append("/"); if(bCreate) CreateDir(Path); return Path; }
bool CreateAllDirs(std::string path) { std::vector<std::string> tocreate; std::string basepath = path; while(!PathExists(basepath)) { tocreate.push_back(basepath); basepath = RemoveLastPathComponent(basepath); if(basepath.empty()) break; } for(int i=tocreate.size()-1;i>=0;i--) if(!CreateDir(tocreate[i])) return false; return true; }
bool plFileUtils::EnsureFilePathExists( const wchar_t *filename ) { hsWStringTokenizer izer( filename, L"\\/" ); bool lastWorked = false; wchar_t token[ kFolderIterator_MaxPath ]; while( izer.Next( token, arrsize( token ) ) && izer.HasMoreTokens() ) { // Want the full path from the start of the string lastWorked = CreateDir( izer.fString ); izer.RestoreLastTerminator(); } return lastWorked; }
/****************************************************************** * my_mkdir / my_rmdir * * Create/Delete directories. Return AROS host error codes for * AmigaOS guest CreateDir/DeleteFile calls. ******************************************************************/ int my_mkdir (const TCHAR *name) { BPTR lock; DebOut("name: %s\n", name); lock=CreateDir(name); if(lock) { UnLock(lock); /* CreateDir returns a lock, which we don't need */ return 0; } SetLastError(IoErr()); DebOut("return -1 (%d)\n", IoErr()); return -1; }
int MFFileNative_Open(MFFile *pFile, MFOpenData *pOpenData) { MFCALLSTACK; MFDebug_Assert(pOpenData->cbSize == sizeof(MFOpenDataNative), "Incorrect size for MFOpenDataNative structure. Invalid pOpenData."); MFOpenDataNative *pNative = (MFOpenDataNative*)pOpenData; DWORD access = ((pOpenData->openFlags&MFOF_Read) ? GENERIC_READ : NULL) | ((pOpenData->openFlags&MFOF_Write) ? GENERIC_WRITE : NULL); MFDebug_Assert(access, "Neither MFOF_Read nor MFOF_Write specified."); const char *pFilename = pNative->pFilename; #if defined(MF_XBOX) || defined(MF_X360) pFilename = FixXBoxFilename(pFilename); #endif if(pOpenData->openFlags & MFOF_CreateDirectory) CreateDir(MFStr_GetFilePath(pFilename)); DWORD create = (pOpenData->openFlags & MFOF_Read) ? ((pOpenData->openFlags & MFOF_Write) ? OPEN_ALWAYS : OPEN_EXISTING) : CREATE_ALWAYS; pFile->pFilesysData = CreateFile(pFilename, access, FILE_SHARE_READ, NULL, create, NULL, NULL); if(pFile->pFilesysData == INVALID_HANDLE_VALUE) { // MFDebug_Warn(3, MFStr("Failed to open file '%s'.", pNative->pFilename)); pFile->pFilesysData = 0; return -1; } pFile->createFlags = pOpenData->openFlags; pFile->offset = 0; DWORD excess; uint32 fileSize = GetFileSize(pFile->pFilesysData, &excess); MFDebug_Assert(excess == 0, "Fuji does not support files larger than 4,294,967,295 bytes."); pFile->length = fileSize; #if defined(_DEBUG) MFString_Copy(pFile->fileIdentifier, pNative->pFilename); #endif return 0; }
bool CreateAllDirs(std::string path) { size_t pos; std::vector<std::string> tocreate; std::string basepath = path; while(!PathExists(basepath)) { tocreate.push_back(basepath); pos = basepath.rfind('/'); if(pos == std::string::npos) return false; basepath = basepath.substr(0,pos); } for(int i=tocreate.size()-1;i>=0;i--) CreateDir(tocreate[i]); return true; }
static void SalvageDir(char *iname, char *oname) { dirhandle in, out; afs_int32 myFid[3], parentFid[3]; OpenDir(iname, &in); if (afs_dir_Lookup(&in, ".", myFid) || afs_dir_Lookup(&in, "..", parentFid)) { printf("Lookup of \".\" and/or \"..\" failed: "); printf("%d %d %d %d\n", myFid[1], myFid[2], parentFid[1], parentFid[2]); printf("Directory cannnot be salvaged\n"); } CreateDir(oname, &out); DirSalvage(&in, &out, myFid[1], myFid[2], parentFid[1], parentFid[2]); DFlush(); }
bool DataMgr::SaveToFile(const char *fileName) { const char * _file = NULL; if (fileName) { _file = fileName; m_save_file = fileName; } else _file = m_save_file.c_str(); FILE*file = fopen(_file,"wb"); if (!file){ CreateDir(_file); file = fopen(_file, "wb"); if (!file){ CCLog("SaveStr(%s) Failed", _file); return false; } } StringMap::iterator it = m_StringMap.begin(),itEnd = m_StringMap.end(); std::string temp; for(;it != itEnd;++it) { size_t len = it->first.size(); size_t size = strlen(SAVE_TAG); size_t pos = it->first.find(SAVE_TAG); if (len >= size && pos == len-size) { temp = it->first; temp += "="; temp += it->second; temp += "\n"; std::string decryptedstr = GetDecryptedStr(temp.c_str(),temp.size()); fwrite(decryptedstr.c_str(),1,(int)decryptedstr.size(),file); } } fclose(file); return true; }
void ExtractCameraFiles() { printf("Extracting camera files...\n"); DBCFile camdbc("DBFilesClient\\CinematicCamera.dbc"); if (!camdbc.open()) { printf("Unable to open CinematicCamera.dbc. Camera extract aborted.\n"); return; } // get camera file list from DBC std::vector<std::string> camerafiles; size_t cam_count = camdbc.getRecordCount(); for (uint32 i = 0; i < cam_count; ++i) { std::string camFile(camdbc.getRecord(i).getString(1)); size_t loc = camFile.find(".mdx"); if (loc != std::string::npos) camFile.replace(loc, 4, ".m2"); camerafiles.push_back(std::string(camFile)); } std::string path = output_path; path += "/Cameras/"; CreateDir(path); // extract M2s uint32 count = 0; for (std::string thisFile : camerafiles) { std::string filename = path; filename += (thisFile.c_str() + strlen("Cameras\\")); if (FileExists(filename.c_str())) continue; if (ExtractFile(thisFile.c_str(), filename)) ++count; } printf("Extracted %u camera files\n", count); }
bool CreateDirRec(const char *dir) { if(IsDirectory(dir)) return true; bool result = true; StringList li; StrSplit(dir, "/\\", li, false); std::string d; d.reserve(strlen(dir)); bool last; for(StringList::iterator it = li.begin(); it != li.end(); ++it) { d += *it; last = CreateDir(d.c_str()); result = last && result; d += '/'; } return result || last; }
void Cross::CreatePlatformConfigDir(std::string& in) { #ifdef WIN32 W32_ConfDir(in,true); in += "\\DOSBox"; mkdir(in.c_str()); #elif defined(MACOSX) in = "~/Library/Preferences/"; ResolveHomedir(in); //Don't create it. Assume it exists #elif defined(HW_RVL) in = std::string(appDrive) + "/DOSBox"; CreateDir(in); #else in = "~/.dosbox"; ResolveHomedir(in); mkdir(in.c_str(),0700); #endif in += CROSS_FILESPLIT; }
int ReadBuild(int locale) { Log sLog; // include build info file also std::string filename = std::string("component.wow-")+langs[locale]+".txt"; //sLog.Write("Read %s file... ", filename.c_str()); CreateDir("./dbc/"); ExtractFileToHardDrive(localeMPQ[0], filename.c_str(), (std::string("./dbc/") + filename).c_str()); std::string text; std::string temp; std::ifstream fichier((std::string("./dbc/") + filename).c_str(), std::ios::in); if(!fichier) assert(false && "Error when loading component.wow-..."); while(fichier) { fichier >> temp; text += temp; } size_t pos = text.find("version=\""); size_t pos1 = pos + strlen("version=\""); size_t pos2 = text.find("\"",pos1); if (pos == text.npos || pos2 == text.npos || pos1 >= pos2) { sLog.Write("Fatal error: Invalid %s file format!", filename.c_str()); exit(1); } std::string build_str = text.substr(pos1,pos2-pos1); int build = atoi(build_str.c_str()); if (build <= 0) { sLog.Write("Fatal error: Invalid %s file format!", filename.c_str()); exit(1); } return build; }
bool ForceDirectories(const UnicodeString & Dir) { bool Result = true; if (Dir.IsEmpty()) { return false; } UnicodeString Dir2 = ExcludeTrailingBackslash(Dir); if ((Dir2.Length() < 3) || DirectoryExists(Dir2)) { return Result; } if (ExtractFilePath(Dir2).IsEmpty()) { return ::CreateDir(Dir2); } Result = ForceDirectories(ExtractFilePath(Dir2)) && CreateDir(Dir2); return Result; }
/* * Creates peudo DEV:DFx files. */ void initpseudodevices(void) { ULONG lock; int i; pseudo_dev_created = 0; pseudo_dev_assigned = 0; for(i=0;i<4;++i) dfx_done[i]=0; /* check if dev: already exists */ set_req(0);lock = Lock(amiga_dev_path,SHARED_LOCK);set_req(1); if(!lock) { char name[80]; set_req(0);lock = Lock(pseudo_dev_path,SHARED_LOCK);set_req(1); if(!lock) { /* create it */ lock = CreateDir(pseudo_dev_path); if(!lock) goto fail; UnLock(lock);lock = Lock(pseudo_dev_path,SHARED_LOCK); pseudo_dev_created = 1; } strcpy(name,amiga_dev_path); if(*name && name[strlen(name)-1]==':') name[strlen(name)-1]='\0'; if(!AssignLock(name,lock)) {UnLock(lock);goto fail;} /* the lock is the assign now */ pseudo_dev_assigned = 1; } else UnLock(lock); /* Create the dev:DFi entry */ for(i=0;i<4;++i) if(device_exists("trackdisk.device",i)) { ULONG fd; char name[80]; sprintf(name,"%sDF%d",amiga_dev_path,i); fd = Open(name,MODE_NEWFILE); if(fd) {Close(fd);dfx_done[i]=1;} } return; fail: fprintf(stderr,"Failed to create pseudo dev: entry!\n"); }
void TDebug::OpenNewFile() { if (f) CloseCurFile(); if (!DirectoryExists("log")) CreateDir("log"); static int log_id = 1; while (log_id < 1000) { char file_name[32]; sprintf(file_name,"log\\log.%03d", log_id); f = fopen(file_name, "r+"); if (f) { fclose(f); log_id++; continue; } f = fopen(file_name,"a+"); break; } }
std::string FileUpload::getLocalIconPath() { std::string Ret = ns::NsPlatformHelper::getExternalRootPath(); if (Ret.empty()) { CCLOG("getLocalIconPath, getExternalRootPath() fail"); return ""; } Ret += "/"; Ret += FileUpload::GetFileTypeDir(UploadFileType_Icon); if (!CreateDir(Ret)) { CCLOG("getLocalIconPath, CreateDir fail - %s", Ret.c_str()); return ""; } Ret += "/"; return Ret; }
void DepthOptimizer::RefineAllDepthMaps(){ LoadDataEx(); for (int k = 0; k < ParamParser::imgdirs.size(); ++k){ char fn[128]; CreateDir(ParamParser::imgdirs[k] + "DATA/Refine/"); std::vector<double> dsp; int n = cameras[k].size(); for (int i = 0; i < n; ++i){ sprintf_s(fn, "%sDATA/Render/_depth%d.raw", ParamParser::imgdirs[k].c_str(), i); LoadDepth(fn, dsp, cameras[k][i].W(), cameras[k][i].H()); RefineDepthMap(k, i, dsp); sprintf_s(fn, "%sDATA/Refine/_depth%d.jpg", ParamParser::imgdirs[k].c_str(), i); RenderDepthMap(fn, dsp, cameras[k][i].W(), cameras[k][i].H()); sprintf_s(fn, "%sDATA/Refine/_depth%d.raw", ParamParser::imgdirs[k].c_str(), i); SaveDepth(fn, dsp); } } }
void ExtractMapsFromMpq() { char mpq_filename[1024]; char output_filename[1024]; printf("Extracting maps...\n"); uint32 map_count = ReadMapDBC(); ReadAreaTableDBC(); ReadLiquidTypeTableDBC(); unsigned int total = map_count * ADT_RES * ADT_RES; unsigned int done = 0; std::string path = output_path; path += "/maps/"; CreateDir(path); for(uint32 x = 0; x < ADT_RES; ++x) { for(uint32 y = 0; y < ADT_RES; ++y) { for(uint32 z = 0; z < map_count; ++z) { sprintf(mpq_filename, "World\\Maps\\%s\\%s_%u_%u.adt", map_ids[z].name, map_ids[z].name, x, y); sprintf(output_filename, "%s/maps/%03u%02u%02u.map", output_path, map_ids[z].id, y, x); ConvertADT(mpq_filename, output_filename); done++; } // draw progress bar printf("Processing........................%d%%\r", (100 * done) / total); } } delete [] areas; delete [] map_ids; }
bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents) { plFileName fdir = dir; if (fdir.GetFileName().IsEmpty()) { hsDebugMessage("WARNING: CreateDir called with useless trailing slash", 0); fdir = fdir.StripFileName(); } if (checkParents) { plFileName parent = fdir.StripFileName(); if (parent.IsValid() && !plFileInfo(parent).Exists() && !CreateDir(parent, true)) return false; } if (plFileInfo(fdir).Exists()) return true; #if HS_BUILD_FOR_WIN32 return CreateDirectoryW(fdir.AsString().ToWchar(), nullptr); #else return (mkdir(fdir.AsString().c_str(), 0755) == 0); #endif }
//若是不存在上级文件夹则自动创建 bool zs_ut_s::CreateRecursionDir(std::string path) { if (path.length() == 0) return true; std::string sub; char lastchar=0; //预处理 FixPath(path); std::string::size_type pos = path.find('/'); while (pos != std::string::npos) { std::string cur = path.substr(0, pos-0); if (cur.length() > 0 && !IsDirectory(cur)) { if (!CreateDir(cur)) { return false; } } pos = path.find('/', pos+1); } return true; }
int FileExist(const char *comname,ST_OptLogCfgData *cfg) { DIR *dir; struct dirent *dirent; if (!comname || !(*comname) || !cfg) { return -1; } if (access(cfg->rcdpath,F_OK)) { if (CreateDir(cfg->rcdpath)<0) { Debug_print("create directory %s for Record file failed",cfg->rcdpath); return -1; } } dir = opendir(cfg->rcdpath); if (!dir) { perror("open directory failed"); return -1; } while((dirent=readdir(dir))!=NULL) { if(strstr(dirent->d_name,comname)) { Debug_print("get dirent name :%s\n",dirent->d_name); pthread_mutex_lock(&gendata.pathmutex); snprintf(gendata.path,PATHLEN,"%s/%s",cfg->rcdpath,dirent->d_name); pthread_mutex_unlock(&gendata.pathmutex); closedir(dir); return 1; } } closedir(dir); return 0; }
bool CStaticsFile::CreateDir(std::string &path) { struct stat buf; if(stat(path.c_str(), &buf) ==0) { if(S_ISDIR(buf.st_mode)) { return true; } else { return false; } } else { char *str = strdup(path.c_str()); std::string cdir=dirname(str); free(str); if(CreateDir(cdir)) { if(mkdir(path.c_str(),0755)==0) { return true; } else { return false; } } else { return false; } } return false; }
QByteArray QFileIOService::ExecuteRDSCommand(QRDSServer &rdsserver, quint8 command, const QMap<QString, QString> &map) { QByteArray ret; switch (command) { case QBrowseDirCommand: return BrowseDir(rdsserver, map); break; case QFileReadCommand: return FileRead(rdsserver, map); break; case QFileWriteCommand: return FileWrite(rdsserver, map); break; case QFileRenameCommand: return FileRename(rdsserver, map); break; case QFileRemoveFileCommand: return FileRemove(rdsserver, map, true); break; case QFileRemoveDirectoryCommand: return FileRemove(rdsserver, map, false); break; case QFileExistCommand: return Existence(rdsserver, map); break; case QFileCreateDirCommand: return CreateDir(rdsserver, map); break; case QFileGetRootDirCommand: return GetRootDir(rdsserver); break; } return ret; }
// 保存日志 void CLog::Save(LPCTSTR folder) { if (m_logDocument.p == NULL) return; // 取日志HTML CComDispatchDriver documentDisp(m_logDocument); // document.documentElement.outerHTML _variant_t res; if (FAILED(documentDisp.GetPropertyByName(OLESTR("documentElement"), res.GetAddress()))) return; CComDispatchDriver documentElementDisp((IDispatch*)res); if (FAILED(documentElementDisp.GetPropertyByName(OLESTR("outerHTML"), res.GetAddress()))) return; CString strHtml = (LPCTSTR)(_bstr_t)res; // 另一种取网页HTML方法,末尾有四个乱码? /*CComPtr<IPersistStreamInit> psi; document->QueryInterface(&psi); HGLOBAL html = GlobalAlloc(GMEM_MOVEABLE, 5 * 1024 * 1024); IStream *stream; CreateStreamOnHGlobal(html, TRUE, &stream); psi->Save(stream, FALSE); CString strHtml = (LPCTSTR)GlobalLock(html); strHtml += _T("</body></html>"); GlobalUnlock(html); stream->Release();*/ // 保存 CreateDir(folder); CString path; path.Format(_T("%s\\%d-%02d-%02d %02d:%02d:%02d.html"), folder, m_logStartTime.wYear, m_logStartTime.wMonth, m_logStartTime.wDay, m_logStartTime.wHour, m_logStartTime.wMinute, m_logStartTime.wSecond); WriteString(strHtml, path); }