static void MainRig_Startup(const StartupConfig& cfg, VariantFunctions& serv) { std::string appNameString = cfg._applicationName; std::string logCfgString = cfg._logConfigFile; serv.Add<std::string()>( Fn_GetAppName, [appNameString](){ return appNameString; }); serv.Add<std::string()>( Fn_LogCfg, [logCfgString](){ return logCfgString; }); srand(std::random_device().operator()()); auto guidGen = std::make_shared<std::mt19937_64>(std::random_device().operator()()); serv.Add<uint64()>( Fn_GuidGen, [guidGen](){ return (*guidGen)(); }); // // We need to initialize logging output. // The "int" directory stands for "intermediate." We cache processed // models and textures in this directory // But it's also a convenient place for log files (since it's excluded from // git and it contains only temporary data). // Note that we overwrite the log file every time, destroying previous data. // CreateDirectoryRecursive("int"); if (cfg._setWorkingDir) SetWorkingDirectory(); }
BOOL CreateDirectoryRecursive(const char* dir) { char str[MAX_PATH]; if (DirectoryExists(dir)) return TRUE; else { lstrcpy(str,dir); CutDirString(str); *GetFileTitleEx(str)=0; CreateDirectoryRecursive(str); return CreateDirectory(dir,NULL); } }
static void SerializeToFile( RenderCore::ColladaConversion::NascentModel& model, RenderCore::ColladaConversion::OCModelSerializeFunction fn, const char destinationFilename[], const ConsoleRig::LibVersionDesc& versionInfo) { auto chunks = (model.*fn)(); // (create the directory if we need to) CreateDirectoryRecursive(MakeFileNameSplitter(destinationFilename).DriveAndPath()); BasicFile outputFile(destinationFilename, "wb"); BuildChunkFile(outputFile, chunks, versionInfo, [](const ColladaConversion::NascentChunk& c) { return c._hdr._type != ChunkType_Metrics; }); }
BOOL CProjectNewDialog::CreateDirectoryRecursive(LPCTSTR lpszDirectory) { if (lpszDirectory == NULL) return FALSE; if (lpszDirectory[0] == _T('\0')) return FALSE; if (CPathTool::IsDirectory(lpszDirectory)) return TRUE; CString strParent = CPathTool::GetParentDirectory(lpszDirectory); if (!CPathTool::IsDirectory(strParent)) { if (!CreateDirectoryRecursive(strParent)) return FALSE; } return CreateDirectory(lpszDirectory, NULL); }
bool FileUtilities::Copy(const String &sFrom, const String &sTo, bool bCreateMissingDirectories) { int iNumberOfTries = 0; const int iMaxNumberOfTries = 5; if (bCreateMissingDirectories) { String sToPath = sTo.Mid(0, sTo.ReverseFind(_T("\\"))); CreateDirectoryRecursive(sToPath); } const int maxRecursions = 10000; for (int i = 0; i < maxRecursions; i++) { // Use classic api to copy the file if (::CopyFile(sFrom, sTo, FALSE) != 0) { //Copy OK return true; } iNumberOfTries ++; // We failed to delete the file. if (iNumberOfTries >= iMaxNumberOfTries) { // We still couldn't copy the file. Lets give up and report in windows event log and hMailServer application log int iLastError = ::GetLastError(); String sErrorMessage; sErrorMessage.Format(_T("Could not copy the file %s to %s. Tried 5 times without success. Windows eror code: %d (%s)"), sFrom, sTo, iLastError, Dictionary::GetWindowsErrorDescription(iLastError)); ErrorManager::Instance()->ReportError(ErrorManager::High, 5048, "File::Copy", sErrorMessage); return false; } // Some other process must have locked the file. Sleep(1000); } assert(0); // if we get here, something is really strange... return false; }
bool DialogInstall::ExtractCurrentFile(const std::wstring& fileName) { // Some archives don't explicity list directories, so create them recursively if (!CreateDirectoryRecursive(fileName)) { return false; } if (fileName.back() == L'\\') { // Nothing left to do return true; } if (unzOpenCurrentFile(m_PackageUnzFile) != UNZ_OK) { return false; } HANDLE hFile = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) { return false; } int read; do { BYTE buffer[16384]; DWORD written; read = unzReadCurrentFile(m_PackageUnzFile, buffer, 16384); if (read < 0 || !WriteFile(hFile, (LPCVOID)buffer, read, &written, nullptr) || read != written) { read = UNZ_ERRNO; break; } } while (read != UNZ_EOF); CloseHandle(hFile); return unzCloseCurrentFile(m_PackageUnzFile) == UNZ_OK && read == UNZ_EOF; }
BOOL EnsureDirPresence(const char* fname) { char dir[MAX_PATH],str[MAX_PATH+100]; lstrcpy(dir,fname); *GetFileTitleEx(dir)=0; if (!DirectoryExists(dir)) { wsprintf(str,"Directory %s does not exist.\nWould you like to create it?",dir); switch (MessageBox(GetFocus(),str,szAppName,MB_YESNOCANCEL | MB_ICONQUESTION)) { case IDYES: return CreateDirectoryRecursive(dir); case IDNO: default: // ??? return FALSE; case IDCANCEL: SetCancelAllFlag(); return FALSE; } } else return TRUE; }
void CProjectNewDialog::Create() { UpdateData(); // retrieve selected element CProjectTemplateItem *pItem = NULL; int nItem = GetSelectedItem(); if (nItem >= 0 && nItem < m_wndTemplateList.GetItemCount()) pItem = reinterpret_cast<CProjectTemplateItem*>(m_wndTemplateList.GetItemData(nItem)); // retrieve and modify project CLaTeXProject *pProject = theApp.GetProject(); ASSERT(pProject); if (!pProject) return; pProject->SetPathName(CPathTool::Cat(m_strProjectPath, m_strProjectName + _T(".tcp"))); pProject->SetMainPath(CPathTool::Cat(m_strProjectPath, m_strProjectName + _T(".tex"))); pProject->SetRunBibTex(m_bUseBibTex); pProject->SetRunMakeIndex(m_bUseMakeIndex); // create path to the project if (!CreateDirectoryRecursive(pProject->GetWorkingDirectory())) { //Show error msg with path and system error message TCHAR systemError[200]; ::FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language systemError, 200, NULL ); CString errMsg; errMsg.Format(STE_PROJECTDIR_CREATE_ERR, pProject->GetWorkingDirectory(), systemError); AfxMessageBox(errMsg, MB_ICONSTOP | MB_OK); return; } pProject->Save(pProject->GetPathName()); // set carriage return CString strCrlf; switch (m_nFileFormat) { case DOSStyleEOLMode: strCrlf = _T("\r\n"); break; case UnixStyleEOLMode: strCrlf = _T("\n"); break; case MacStyleEOLMode: strCrlf = _T("\r"); break; default: ASSERT(FALSE); strCrlf = _T("\r\n"); } // initialize project if (pItem) { BOOL bResult = pItem->InitProject(theApp.GetProject(), strCrlf); if (bResult) { //open new main file theApp.OpenLatexDocument(theApp.GetProject()->GetMainPath(), FALSE, -1, FALSE, false); CTemplateDialog::EndDialog(IDOK); } else CTemplateDialog::EndDialog(IDCANCEL); } }
LRESULT CALLBACK AFPluginsOptionsProc(HWND hwnd, UINT umsg, WPARAM wparm, LPARAM lparm) { char str[MAX_PATH+256],dir[MAX_PATH]; char lpszTitle[]="Select audio file plug-in directory:"; int index; PluginNode *pnode; AFPlugin *plugin; LPNMHDR lpnmhdr; BROWSEINFO bi; LPITEMIDLIST lpidl; switch (umsg) { case WM_INITDIALOG: SetDlgItemText(hwnd,ID_PLUGINDIR,"Audio file plug-in &directory (takes effect on startup)"); SetDlgItemText(hwnd,ID_PLUGINLIST,"Audio file &plug-ins"); pnode=afFirstPlugin; while (pnode!=NULL) { wsprintf(str,"%s %s (%s)",AFNODE(pnode)->Description,AFNODE(pnode)->Version,pnode->pluginFileName); index=(int)SendDlgItemMessage(hwnd,ID_PLUGINS,LB_ADDSTRING,0,(LPARAM)str); SendDlgItemMessage(hwnd,ID_PLUGINS,LB_SETITEMDATA,(WPARAM)index,(LPARAM)(AFNODE(pnode))); pnode=pnode->next; } SetCheckBox(hwnd,ID_PLUGINALLOW,opAllowMultipleAFPlugins); CorrectDirString(afPluginDir); SetDlgItemText(hwnd,ID_DIR,afPluginDir); CheckCurAFSel(hwnd); DisableApply(hwnd); return TRUE; case WM_NOTIFY: lpnmhdr=(LPNMHDR)lparm; switch (lpnmhdr->code) { case PSN_APPLY: TrackPropPage(hwnd,3); opAllowMultipleAFPlugins=GetCheckBox(hwnd,ID_PLUGINALLOW); GetDlgItemText(hwnd,ID_DIR,afPluginDir,sizeof(afPluginDir)); CorrectDirString(afPluginDir); DisableApply(hwnd); SetWindowLong(hwnd,DWL_MSGRESULT,PSNRET_NOERROR); break; case PSN_RESET: DisableApply(hwnd); TrackPropPage(hwnd,3); break; default: break; } break; case WM_COMMAND: switch (LOWORD(wparm)) { case ID_DIR: GetDlgItemText(hwnd,ID_DIR,dir,sizeof(dir)); if (!DirectoryExists(dir)) CreateDirectoryRecursive(dir); bi.hwndOwner=hwnd; bi.pidlRoot=NULL; bi.pszDisplayName=dir; bi.lpszTitle=lpszTitle; bi.ulFlags=BIF_RETURNONLYFSDIRS; bi.lpfn=BrowseProc; if (dir[lstrlen(dir)-1]=='\\') dir[lstrlen(dir)-1]=0; bi.lParam=(LPARAM)dir; if ((lpidl=SHBrowseForFolder(&bi))!=NULL) { SHGetPathFromIDList(lpidl,dir); CorrectDirString(dir); SetDlgItemText(hwnd,ID_DIR,dir); EnableApply(hwnd); } break; case ID_PLUGINS: switch (HIWORD(wparm)) { case LBN_DBLCLK: CheckCurAFSel(hwnd); plugin=(AFPlugin*)GetCurPlugin(hwnd); if ((plugin!=NULL) && (plugin->Config!=NULL)) plugin->Config(hwnd); break; case LBN_KILLFOCUS: case LBN_SETFOCUS: case LBN_SELCANCEL: case LBN_SELCHANGE: CheckCurAFSel(hwnd); break; default: break; } break; case ID_PLUGINCONFIG: plugin=(AFPlugin*)GetCurPlugin(hwnd); if ((plugin!=NULL) && (plugin->Config!=NULL)) plugin->Config(hwnd); break; case ID_PLUGINABOUT: plugin=(AFPlugin*)GetCurPlugin(hwnd); if ((plugin!=NULL) && (plugin->About!=NULL)) plugin->About(hwnd); break; case ID_PLUGINALLOW: EnableApply(hwnd); break; default: break; } break; default: break; } return FALSE; }