std::string GetRootPathFromKeyCore() { string path= GetRootPathByKey(KEY_PATH_CORE); if(path.empty()) path= GetRootPath(); return path; }
/* retrives the pathe dependen om the input file name */ void getPath(TCHAR* out, LPTSTR in) { if (_tcslen(in) == 2 && in[1] == _T(':')) GetRootPath(in,out,MAX_PATH); else GetFullPathName (in, MAX_PATH, out, NULL); }
BOOL Util::Init() { // CString strPath=_T(""); /* strPath=GetRootPath(); if(strPath.IsEmpty()) throw MSException("RootPath is empty"); strcpy(strRootPath,(LPCSTR)strPath);*/ /* strPath.Format("%s\\MonitorManager\\ResLibrary.dll",g_strRootPath); m_hResLibrary=::LoadLibrary(strPath); if(m_hResLibrary==NULL) throw MSException("Load ResLibrary.dll failed");*/ CString strPath=""; strPath.Format("%s\\fcgi-bin\\MonitorScheduleWeb.dll",GetRootPath()); HMODULE m_hWebDll=::LoadLibrary(strPath); if(m_hWebDll==NULL) throw MSException("Load MonitorScheduleWeb.dll failed"); sendmsg = (SendMsg)::GetProcAddress(m_hWebDll, "SendMsg"); if(sendmsg == NULL) { puts(" 获取dll函数失败, Failed to GetProcAddress: MonitorScheduleWeb.dll 's SendMsg; "); } return TRUE; }
bool Util::SendMsgToWsServer(string szId, string szText) { bool bRet = true; string errorMsg = ""; if(sendmsg == NULL) { //Init(); char buf[1024]={0}; sprintf(buf,"%s/fcgi-bin/MonitorScheduleWeb.dll",GetRootPath().getText()); //strPath = ".\\MonitorScheduleWeb.dll"; //puts(strPath); HMODULE m_hWebDll=::LoadLibrary(buf); if(m_hWebDll==NULL) throw MSException("Load MonitorScheduleWeb.dll failed"); sendmsg = (SendMsg)::GetProcAddress(m_hWebDll, "SendMsg"); if(sendmsg == NULL) { puts(" 获取dll函数失败, Failed to GetProcAddress: MonitorScheduleWeb.dll 's SendMsg; "); } sprintf(buf,"%s/fcgi-bin/WebECC.ini",GetRootPath().getText()); INIFile inf=LoadIni(buf); szServer=GetIniSetting(inf,"WebECC","WebService",""); szPort=GetIniSetting(inf,"WebECC","WebPort",""); //puts(szServer.c_str()); //puts(szPort.c_str()); } bRet = sendmsg(szId, szText, szServer, szPort, errorMsg); if(bRet) { puts("sendmsg sucess\n"); } else { puts("sendmsg failed\n"); puts(errorMsg.c_str()); } return bRet; }
/* * CD / CHDIR * */ INT cmd_chdir (LPTSTR param) { TCHAR szCurrent[MAX_PATH]; BOOL bChangeDrive = FALSE; /* Filter out special cases first */ /* Print Help */ if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_CD_HELP); return 0; } /* Remove " */ StripQuotes(param); /* Set Error Level to Success */ nErrorLevel = 0; /* Print Current Directory on a disk */ if (_tcslen(param) == 2 && param[1] == _T(':')) { if (GetRootPath(param, szCurrent, MAX_PATH)) { error_invalid_drive(); return 1; } ConOutPuts(szCurrent); return 0; } /* Get Current Directory */ GetCurrentDirectory(MAX_PATH, szCurrent); if (param[0] == _T('\0')) { ConOutPuts(szCurrent); return 0; } /* Input String Contains /D Switch */ if (!_tcsncicmp(param, _T("/D"), 2)) { bChangeDrive = TRUE; param += 2; while (_istspace(*param)) param++; } if (!SetRootPath(bChangeDrive ? NULL : szCurrent, param)) return 1; return 0; }
const CString GetFileName( const TCHAR* Filter ) { CString RootPath = GetRootPath(); CFileDialog Dlg( TRUE, NULL, "Ё║╬╟нд╪Ч", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR, Filter ); Dlg.m_ofn.lpstrInitialDir = RootPath; Dlg.DoModal(); CString Filename = Dlg.GetPathName(); Filename.MakeLower(); return Filename; }
ITradeTable* CTradeTables::GetItemsFull(CXML xPath, int iIndex /* = -1 */) { TiXmlNode* pNode = m_pXMLParser->SelectSingleNode(GetRootPath(), xPath, iIndex); if (pNode) { CTradeTable* pNodeData = new CTradeTable(); pNodeData->SetXMLParser(m_pXMLParser); pNodeData->SetRoot(pNode); return pNodeData; } else return NULL; }
void CGEPYManager::InitDll() { if ( m_bInit ) return; try { char filePath[255]; filesystem->RelativePathToFullPath(GetRootPath(), "MOD", filePath, sizeof(filePath) ); Py_SetPythonHome(filePath); RegisterPythonModules(); Py_Initialize(); main_module = bp::import("__main__"); main_namespace = main_module.attr("__dict__"); main_module.attr("true") = true; main_module.attr("false") = false; try { ExecFile("IORedirect.py"); } catch (...) { HandlePythonException(); } #if defined (WINGDBG) && (DEBUG) try { Exec("import wingdbstub"); } catch (...) { Warning("Failed to import python debugger\n"); HandlePythonException(); } #endif m_bInit = true; } catch (...) { HandlePythonException(); Warning("Failed to load python. :(\n"); } }
CString Util::GetSVMQAddress() { char buf[1024]={0}; // strcpy(buf,"siteview.ini"); sprintf(buf,"%s/MonitorManager/siteview.ini",GetRootPath().getText()); INIFile inf=LoadIni(buf); std::string name=GetIniSetting(inf,"InstallPath","SVMQAddress",""); if(name.empty()) return "127.0.0.1"; else return name.c_str(); }
void Util::EventLog(CString strError) { CString strPath; strPath=GetRootPath(); strPath+="/temp/msevent.log"; ThreadFile tf(strPath); strError+="\r\n"; CTime stime=CTime::GetCurrentTimeEx(); CString strlog; strlog.Format("%s\t%s",stime.Format().c_str(),strError.getText()); char *pstr=strlog.getText(); tf.append(pstr,(ccxx_size_t)strlen(pstr)); /* CString strTemp=_T(""), strFile=_T(""); strFile.Format("%s\\MonitorManager\\meevent.log",g_strRootPath); CTime time=CTime::GetCurrentTime(); strTemp=time.Format("%Y-%m-%d %H:%M:%S"); strTemp+="\t"+strError+"\r\n"; #ifndef DEBUG_T FILE *fp=::fopen(strFile,"a+"); if(fp==NULL) { printf("���ʧ�\n"); return ; } ::fputs(strTemp,fp); ::fclose(fp); #else printf("%s",strTemp); #endif */ return ; }
void GetDirectory (LPTSTR wholepath, LPTSTR directory, BOOL CheckExisting) { /* returns only directory part of path with backslash */ /* TODO: make code unc aware */ /* Is there a better alternative to this? */ LPTSTR last; if (CheckExisting && IsExistingDirectory(wholepath)) { _tcscpy(directory, wholepath); } else if ((last = _tcsrchr(wholepath,_T('\\'))) != NULL) { _tcsncpy(directory, wholepath, last - wholepath + 1); directory[last - wholepath + 1] = 0; } else { GetRootPath(wholepath,directory, MAX_PATH); } }
static CString LegalizePath(const CString &strPath) { CString strOriginPath = strPath; CString strData(strOriginPath); CString strFolderPath; CString strDstPath; while (1) { strFolderPath = GetRootPath(strData); if (strFolderPath == _T("..")) strDstPath = GetParsentFolder(strDstPath); else strDstPath.Append(strFolderPath); PathAddBackslash(strDstPath); strData = strData.Mid(strFolderPath.GetLength()); strData.TrimLeft(L"\\"); if (strData.IsEmpty()) break; } return strDstPath; }
INT CommandDelete (LPTSTR param) { /*cmd is the command that was given, in this case it will always be "del" or "delete" param is whatever is given after the command*/ LPTSTR *arg = NULL; INT args; INT i; INT nEvalArgs = 0; /* nunber of evaluated arguments */ DWORD dwFlags = 0; DWORD dwAttrFlags = 0; DWORD dwFiles = 0; LONG ch; TCHAR szOrginalArg[MAX_PATH]; /*checks the first two chars of param to see if it is /? this however allows the following command to not show help "del frog.txt /?" */ if (!StringsLoaded) { LoadStrings(); } if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_DEL_HELP1); return 0; } nErrorLevel = 0; arg = split (param, &args, FALSE); if (args == 0) { /* only command given */ error_req_param_missing (); freep (arg); return 1; } /* check for options anywhere in command line */ for (i = 0; i < args; i++) { if (*arg[i] == _T('/')) { /*found a command, but check to make sure it has something after it*/ if (_tcslen (arg[i]) >= 2) { ch = _totupper (arg[i][1]); if (ch == _T('N')) { dwFlags |= DEL_NOTHING; } else if (ch == _T('P')) { dwFlags |= DEL_PROMPT; } else if (ch == _T('Q')) { dwFlags |= DEL_QUIET; } else if (ch == _T('F')) { dwFlags |= DEL_FORCE; } else if (ch == _T('S')) { dwFlags |= DEL_SUBDIR; } else if (ch == _T('T')) { dwFlags |= DEL_TOTAL; } else if (ch == _T('W')) { dwFlags |= DEL_WIPE; } else if (ch == _T('Y')) { dwFlags |= DEL_YES; } else if (ch == _T('A')) { dwFlags |= DEL_ATTRIBUTES; /*the proper syntax for /A has a min of 4 chars i.e. /A:R or /A:-H */ if (_tcslen (arg[i]) < 4) { error_invalid_parameter_format(arg[i]); return 0; } ch = _totupper (arg[i][3]); if (_tcslen (arg[i]) == 4) { if(ch == _T('A')) { dwAttrFlags |= ATTR_ARCHIVE; } if(ch == _T('H')) { dwAttrFlags |= ATTR_HIDDEN; } if(ch == _T('S')) { dwAttrFlags |= ATTR_SYSTEM; } if(ch == _T('R')) { dwAttrFlags |= ATTR_READ_ONLY; } } if (_tcslen (arg[i]) == 5) { if(ch == _T('-')) { ch = _totupper (arg[i][4]); if(ch == _T('A')) { dwAttrFlags |= ATTR_N_ARCHIVE; } if(ch == _T('H')) { dwAttrFlags |= ATTR_N_HIDDEN; } if(ch == _T('S')) { dwAttrFlags |= ATTR_N_SYSTEM; } if(ch == _T('R')) { dwAttrFlags |= ATTR_N_READ_ONLY; } } } } } nEvalArgs++; } } /* there are only options on the command line --> error!!! there is the same number of args as there is flags, so none of the args were filenames*/ if (args == nEvalArgs) { error_req_param_missing (); freep (arg); return 1; } /* keep quiet within batch files */ if (bc != NULL) dwFlags |= DEL_QUIET; /* check for filenames anywhere in command line */ for (i = 0; i < args && !(dwFiles & 0x80000000); i++) { /*this checks to see if it isnt a flag, if it isnt, we assume it is a file name*/ if((*arg[i] == _T('/')) || (*arg[i] == _T('-'))) continue; /* We want to make a copies of the argument */ if(_tcslen(arg[i]) == 2 && arg[i][1] == _T(':')) { /* Check for C: D: ... */ GetRootPath(arg[i],szOrginalArg,MAX_PATH); } else { _tcscpy(szOrginalArg,arg[i]); } dwFiles += ProcessDirectory(szOrginalArg, &dwFlags, dwAttrFlags); } freep (arg); /*Based on MS cmd, we only tell what files are being deleted when /S is used */ if (dwFlags & DEL_TOTAL) { dwFiles &= 0x7fffffff; if (dwFiles < 2) { ConOutResPrintf(STRING_DEL_HELP3, dwFiles); } else { ConOutResPrintf(STRING_DEL_HELP4, dwFiles); } } return 0; }
bool nuiFileTree::SetPath(const nglPath& rPath) { mPath = rPath; nglPath path(rPath); path.MakeRelativeTo(GetRootPath()); std::vector<nglString> tokens; path.GetPathName().Tokenize(tokens, _T('/')); nuiTreeNodePtr pNode = mpTreeView->GetTree(); if (!tokens.empty()) { // Find start node: nuiTreeNodePtr pRes = NULL; for (uint32 i = 0; i < pNode->GetChildrenCount() && !pRes; i++) { nuiTreeNodePtr pBNode = (nuiTreeNodePtr)pNode->GetChild(i); bool old = pBNode->IsOpened(); nglPath p(pBNode->GetProperty(_T("Path"))); if (p.GetNodeName() == tokens.at(0)) pRes = pBNode; else { if (!old) pBNode->Open(true); for (uint32 j = 0; j < pBNode->GetChildrenCount() && !pRes; j++) { nuiTreeNodePtr pBNode2 = (nuiTreeNodePtr)pBNode->GetChild(j); nglPath p(pBNode2->GetProperty(_T("Path"))); if (p.GetNodeName() == tokens.at(0)) pRes = pBNode2; } if (!pRes && !old) pBNode->Open(false); } } if (!pRes) return false; pNode = pRes; } else { pNode = (nuiTreeNodePtr)pNode->GetChild(0); } pNode->Select(false); nuiColumnTreeView* pColTreeView = dynamic_cast<nuiColumnTreeView*>(mpTreeView); for (uint i = 0; i < tokens.size(); i++) { pNode->OpenAllChildren(false); pNode->SelectAllChildren(false); std::vector<nuiTreePtr> children; pNode->GetChildren(children); for (uint j = 0; j< children.size(); j++) { nuiFileSelectorNode* pBNode = dynamic_cast<nuiFileSelectorNode*>(children.at(j)); if (pBNode) { nglPath p(pBNode->GetProperty(_T("Path"))); if (p.GetNodeName() == tokens.at(i)) { pNode = pBNode; break; } } } if (pNode == mpTreeView->GetSelectedNode()) // Have we found the next node? return false; // No next node found: bail out... nuiTreeNodePtr pParent = pNode; while (pParent) { if (!pParent->IsEmpty()) pParent->Open(true); if (pColTreeView) pParent->Select(true); pParent = static_cast<nuiTreeNodePtr>(pParent->GetParent()); } if (pColTreeView) mpTreeView->Select(pNode, true); if (pNode->IsEmpty()) // Bail out if the last node is a leaf { PathChanged(); mpTreeView->SelectionChanged(); mpTreeView->SetLayout(mpTreeView->GetIdealRect()); return false; } } PathChanged(); mpTreeView->SelectionChanged(); mpTreeView->SetLayout(mpTreeView->GetIdealRect()); // Update infos and change the edit line: nglPathInfo info; rPath.GetInfo(info); mpTreeView->SetHotRect(mpTreeView->GetHotRect()); return true; }
INT cmd_replace (LPTSTR param) { LPTSTR *arg; INT argc, i,filesReplaced = 0, nFiles, srcIndex = -1, destIndex = -1; DWORD dwFlags = 0; TCHAR szDestPath[MAX_PATH], szSrcPath[MAX_PATH], tmpSrcPath[MAX_PATH]; BOOL doMore = TRUE; /* Help wanted? */ if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_REPLACE_HELP1); return 0; } /* Divide the argument in to an array of c-strings */ arg = split (param, &argc, FALSE, FALSE); nFiles = argc; /* Read options */ for (i = 0; i < argc; i++) { if (arg[i][0] == _T('/')) { if (_tcslen(arg[i]) == 2) { switch (_totupper(arg[i][1])) { case _T('A'): dwFlags |= REPLACE_ADD; break; case _T('P'): dwFlags |= REPLACE_CONFIRM; break; case _T('R'): dwFlags |= REPLACE_READ_ONLY; break; case _T('S'): dwFlags |= REPLACE_SUBDIR; break; case _T('W'): dwFlags |= REPLACE_DISK; break; case _T('U'): dwFlags |= REPLACE_UPDATE; break; default: invalid_switch(arg[i]); return 0; } } else { invalid_switch(arg[i]); freep(arg); return 0; } nFiles--; } else { if (srcIndex == -1) { srcIndex = i; } else if (destIndex == -1) { destIndex = i; } else { invalid_switch(arg[i]); freep(arg); return 0; } } } /* See so that at least source is there */ if (nFiles < 1) { ConOutResPaging(TRUE,STRING_REPLACE_HELP2); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } /* Check so that not both update and add switch is added and subdir */ if ((dwFlags & REPLACE_UPDATE || dwFlags & REPLACE_SUBDIR) && (dwFlags & REPLACE_ADD)) { ConOutResPaging(TRUE,STRING_REPLACE_ERROR4); ConOutResPaging(TRUE,STRING_REPLACE_HELP7); freep(arg); return 1; } /* If we have a destination get the full path */ if (destIndex != -1) { if (_tcslen(arg[destIndex]) == 2 && arg[destIndex][1] == ':') GetRootPath(arg[destIndex],szDestPath,MAX_PATH); else { /* Check for wildcards in destination directory */ if (_tcschr (arg[destIndex], _T('*')) != NULL || _tcschr (arg[destIndex], _T('?')) != NULL) { ConOutResPrintf(STRING_REPLACE_ERROR2,arg[destIndex]); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } getPath(szDestPath, arg[destIndex]); /* Make sure that destination exists */ if (!IsExistingDirectory(szDestPath)) { ConOutResPrintf(STRING_REPLACE_ERROR2, szDestPath); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } } } else { /* Dest is current dir */ GetCurrentDirectory(MAX_PATH,szDestPath); } /* Get the full source path */ if (!(_tcslen(arg[srcIndex]) == 2 && arg[srcIndex][1] == ':')) getPath(szSrcPath, arg[srcIndex]); else _tcscpy(szSrcPath,arg[srcIndex]); /* Source does not have wildcards */ if (_tcschr (arg[srcIndex], _T('*')) == NULL && _tcschr (arg[srcIndex], _T('?')) == NULL) { /* Check so that source is not a directory, because that is not allowed */ if (IsExistingDirectory(szSrcPath)) { ConOutResPrintf(STRING_REPLACE_ERROR6, szSrcPath); ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } /* Check if the file exists */ if (!IsExistingFile(szSrcPath)) { ConOutResPaging(TRUE,STRING_REPLACE_HELP3); freep(arg); return 1; } } /* /w switch is set so wait for any key to be pressed */ if (dwFlags & REPLACE_DISK) { msg_pause(); cgetchar(); } /* Add an extra \ to the destination path if needed */ if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\')) _tcscat(szDestPath, _T("\\")); /* Save source path */ _tcscpy(tmpSrcPath,szSrcPath); /* Replace in dest dir */ filesReplaced += recReplace(dwFlags, tmpSrcPath, szDestPath, &doMore); /* If subdir switch is set replace in the subdirs to */ if (dwFlags & REPLACE_SUBDIR && doMore) { filesReplaced += recFindSubDirs(dwFlags, szSrcPath, szDestPath, &doMore); } /* If source == dest write no more */ if (filesReplaced != -1) { /* No files replaced */ if (filesReplaced==0) { /* Add switch dependent output */ if (dwFlags & REPLACE_ADD) ConOutResPaging(TRUE,STRING_REPLACE_HELP7); else ConOutResPaging(TRUE,STRING_REPLACE_HELP3); } /* Some files replaced */ else { /* Add switch dependent output */ if (dwFlags & REPLACE_ADD) ConOutResPrintf(STRING_REPLACE_HELP8, filesReplaced); else ConOutResPrintf(STRING_REPLACE_HELP4, filesReplaced); } } /* Return memory */ freep(arg); return 1; }
CResourceCompilerHelper::ERcCallResult CResourceCompilerHelper::CallResourceCompiler( const TCHAR* szFileName, const TCHAR* szAdditionalSettings, IResourceCompilerListener* listener, bool bMayShowWindow, bool bUseQuota, CResourceCompilerHelper::ERcExePath rcExePath, bool bSilent, bool bNoUserDialog, const TCHAR *szWorkingDirectory) { // make command for execution TCHAR szRemoteCmdLine[MAX_PATH*3]; if (!szAdditionalSettings) { szAdditionalSettings = _T(""); } tstring path; switch (rcExePath) { case eRcExePath_registry: path = GetRootPath(true); break; case eRcExePath_settingsManager: path = GetRootPath(false); break; case eRcExePath_currentFolder: path = _T("."); break; default: return eRcCallResult_notFound; } if (path.empty()) { path = _T("."); } TCHAR szRemoteDirectory[512]; _stprintf_s(szRemoteDirectory, _T("%s/Bin32/rc"), path.c_str()); const TCHAR* const szHideCustom = ((g_pSettingsManager->GetValue<tstring>(_T("HideCustom"))==_T("true")) || bNoUserDialog) ? _T("") : _T(" /userdialogcustom=0"); if (!szFileName) { _stprintf_s(szRemoteCmdLine, _T("%s/rc.exe /userdialog=0 %s"), szRemoteDirectory, szAdditionalSettings); } else { const TCHAR* const szFormat = bUseQuota ? _T("%s/rc.exe \"%s\" %s %s %s") : _T("%s/rc.exe %s %s %s %s"); const TCHAR* const szUserDialog = bNoUserDialog ? _T("/userdialog=0") : _T("/userdialog=1"); _stprintf_s(szRemoteCmdLine, szFormat, szRemoteDirectory, szFileName, szUserDialog, szAdditionalSettings, szHideCustom); } // Create a pipe to read the stdout of the RC. SECURITY_ATTRIBUTES saAttr; std::memset(&saAttr, 0, sizeof(saAttr)); saAttr.bInheritHandle = TRUE; saAttr.lpSecurityDescriptor = 0; HANDLE hChildStdOutRd, hChildStdOutWr; CreatePipe(&hChildStdOutRd, &hChildStdOutWr, &saAttr, 0); SetHandleInformation(hChildStdOutRd, HANDLE_FLAG_INHERIT, 0); // Need to do this according to MSDN HANDLE hChildStdInRd, hChildStdInWr; CreatePipe(&hChildStdInRd, &hChildStdInWr, &saAttr, 0); SetHandleInformation(hChildStdInWr, HANDLE_FLAG_INHERIT, 0); // Need to do this according to MSDN STARTUPINFO si; ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.dwX = 100; si.dwY = 100; si.hStdError = hChildStdOutWr; si.hStdOutput = hChildStdOutWr; si.hStdInput = hChildStdInRd; si.dwFlags = STARTF_USEPOSITION | STARTF_USESTDHANDLES; PROCESS_INFORMATION pi; ZeroMemory(&pi, sizeof(pi)); if (!CreateProcess( NULL, // No module name (use command line). szRemoteCmdLine, // Command line. NULL, // Process handle not inheritable. NULL, // Thread handle not inheritable. TRUE, // Set handle inheritance to TRUE. bMayShowWindow && (g_pSettingsManager->GetValue<tstring>(_T("ShowWindow"))==_T("true"))?0:CREATE_NO_WINDOW, // creation flags. NULL, // Use parent's environment block. szWorkingDirectory?szWorkingDirectory:szRemoteDirectory, // Set starting directory. &si, // Pointer to STARTUPINFO structure. &pi )) // Pointer to PROCESS_INFORMATION structure. { TCHAR szMessage[65535] = _T(""); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, szMessage, 65354, NULL); GetCurrentDirectory(65534, szMessage); if (!bSilent) { MessageBox(0,_T("ResourceCompiler was not found.\n\nPlease verify CryENGINE RootPath."),_T("Error"),MB_ICONERROR|MB_OK); } return eRcCallResult_notFound; } // Close the pipe that writes to the child process, since we don't actually have any input for it. CloseHandle(hChildStdInWr); // Read all the output from the child process. CloseHandle(hChildStdOutWr); ResourceCompilerLineHandler lineHandler(listener); LineStreamBuffer lineBuffer(&lineHandler, &ResourceCompilerLineHandler::HandleLine); for (;;) { char buffer[2048]; DWORD bytesRead; if (!ReadFile(hChildStdOutRd, buffer, sizeof(buffer), &bytesRead, NULL) || (bytesRead == 0)) { break; } lineBuffer.HandleText(buffer, bytesRead); } // Wait until child process exits. WaitForSingleObject(pi.hProcess, INFINITE); bool ok = true; { DWORD exitCode = 1; if ((GetExitCodeProcess(pi.hProcess, &exitCode) == 0) || (exitCode != 0)) { ok = false; } } // Close process and thread handles. CloseHandle(pi.hProcess); CloseHandle(pi.hThread); return ok ? eRcCallResult_success : eRcCallResult_error; }
INT cmd_copy(LPTSTR param) { LPTSTR *arg; INT argc, i, nFiles, nOverwrite = 0, nSrc = -1, nDes = -1; /* this is the path up to the folder of the src and dest ie C:\windows\ */ TCHAR szDestPath[MAX_PATH]; TCHAR szSrcPath[MAX_PATH]; DWORD dwFlags = 0; /* If this is the type of copy where we are adding files */ BOOL bAppend = FALSE; WIN32_FIND_DATA findBuffer; HANDLE hFile = NULL; BOOL bTouch = FALSE; /* Used when something like "copy c*.exe d*.exe" during the process of figuring out the new name */ /* Pointer to keep track of how far through the append input(file1+file2+file3) we are */ TCHAR * appendPointer = _T("\0"); /* The full path to src and dest. This has drive letter, folders, and filename */ TCHAR tmpDestPath[MAX_PATH]; TCHAR tmpSrcPath[MAX_PATH]; /* A bool on weather or not the destination name will be taking from the input */ BOOL bSrcName = FALSE; /* Seems like a waste but it is a pointer used to copy from input to PreserveName */ TCHAR * UseThisName; /* for CMDCOPY env */ TCHAR *evar; int size; TCHAR * szTouch; BOOL bHasWildcard, bDone = FALSE, bMoreFiles = FALSE; BOOL bMultipleSource = FALSE, bMultipleDest = FALSE; /* Show help/usage info */ if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE, STRING_COPY_HELP2); return 0; } nErrorLevel = 0; /* Get the envor value if it exists */ evar = cmd_alloc(512 * sizeof(TCHAR)); if (evar == NULL) size = 0; else size = GetEnvironmentVariable (_T("COPYCMD"), evar, 512); if (size > 512) { TCHAR *old_evar = evar; evar = cmd_realloc(evar,size * sizeof(TCHAR) ); if (evar!=NULL) size = GetEnvironmentVariable (_T("COPYCMD"), evar, size); else { size=0; evar = old_evar; } } /* check see if we did get any env variable */ if (size != 0) { int t = 0; /* scan and set the flags */ for (t = 0; t < size; t++) { if (_tcsncicmp(_T("/A"),&evar[t],2) == 0) { dwFlags |=COPY_ASCII; t++; } else if (_tcsncicmp(_T("/B"),&evar[t],2) == 0) { dwFlags |= COPY_BINARY; t++; } else if (_tcsncicmp(_T("/D"),&evar[t],2) == 0) { dwFlags |= COPY_DECRYPT; t++; } else if (_tcsncicmp(_T("/V"),&evar[t],2) == 0) { dwFlags |= COPY_VERIFY; t++; } else if (_tcsncicmp(_T("/N"),&evar[t],2) == 0) { dwFlags |= COPY_SHORTNAME; t++; } else if (_tcsncicmp(_T("/Y"),&evar[t],2) == 0) { dwFlags |= COPY_NO_PROMPT; t++; } else if (_tcsncicmp(_T("/-Y"),&evar[t],3) == 0) { dwFlags |= COPY_PROMPT; t+=2; } else if (_tcsncicmp(_T("/Z"),&evar[t],2) == 0) { dwFlags |= COPY_PROMPT; t++; } } } cmd_free(evar); /* Split the user input into array */ arg = split(param, &argc, FALSE, TRUE); nFiles = argc; /* Read switches and count files */ for (i = 0; i < argc; i++) { if (*arg[i] == _T('/')) { if (_tcslen(arg[i]) >= 2) { switch (_totupper(arg[i][1])) { case _T('A'): dwFlags |= COPY_ASCII; break; case _T('B'): dwFlags |= COPY_BINARY; break; case _T('D'): dwFlags |= COPY_DECRYPT; break; case _T('V'): dwFlags |= COPY_VERIFY; break; case _T('N'): dwFlags |= COPY_SHORTNAME; break; case _T('Y'): dwFlags |= COPY_NO_PROMPT; dwFlags &= ~COPY_PROMPT; break; case _T('-'): if (_tcslen(arg[i]) >= 3) if (_totupper(arg[i][2]) == _T('Y')) { dwFlags &= ~COPY_NO_PROMPT; dwFlags |= COPY_PROMPT; } break; case _T('Z'): dwFlags |= COPY_RESTART; break; default: /* Invalid switch */ ConOutResPrintf(STRING_ERROR_INVALID_SWITCH, _totupper(arg[i][1])); nErrorLevel = 1; freep (arg); return 1; break; } } /* If it was a switch, subtract from total arguments */ nFiles--; } else { /* If it isn't a switch then it is the source or destination */ if (nSrc == -1) { nSrc = i; } else if (*arg[i] == _T('+')) { /* Next file should be appended */ bMoreFiles = TRUE; nFiles -= 1; } else if (bMoreFiles) { /* Add this file to the source string this way we can do all checks directly on source string later on */ TCHAR * ptr; int length = (_tcslen(arg[nSrc]) + _tcslen(arg[i]) + 2) * sizeof(TCHAR); ptr = cmd_alloc(length); if (ptr) { _tcscpy(ptr, arg[nSrc]); _tcscat(ptr, _T("|")); _tcscat(ptr, arg[i]); cmd_free(arg[nSrc]); arg[nSrc] = ptr; nFiles -= 1; } bMoreFiles = FALSE; } else if (nDes == -1) { nDes = i; } } } /* keep quiet within batch files */ if (bc != NULL) { dwFlags |= COPY_NO_PROMPT; dwFlags &= ~COPY_PROMPT; } if (nFiles < 1) { /* There are not enough files, there has to be at least 1 */ ConOutResPuts(STRING_ERROR_REQ_PARAM_MISSING); freep(arg); return 1; } if (nFiles > 2) { /* There are too many file names in command */ ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS,_T("")); nErrorLevel = 1; freep(arg); return 1; } if ((_tcschr(arg[nSrc], _T('|')) != NULL) || (_tcschr(arg[nSrc], _T('*')) != NULL) || (_tcschr(arg[nSrc], _T('?')) != NULL) || IsExistingDirectory(arg[nSrc])) { bMultipleSource = TRUE; } /* Reusing the number of files variable */ nFiles = 0; /* Check if no destination argument is passed */ if (nDes == -1) { /* If no destination was entered then just use the current directory as the destination */ GetCurrentDirectory(MAX_PATH, szDestPath); } else { /* Check if the destination is 'x:' */ if ((arg[nDes][1] == _T(':')) && (arg[nDes][2] == _T('\0'))) { GetRootPath(arg[nDes], szDestPath, MAX_PATH); } else { /* If the user entered two file names then form the full string path */ GetFullPathName(arg[nDes], MAX_PATH, szDestPath, NULL); } /* Make sure there is an ending slash to the path if the dest is a folder */ if ((_tcschr(szDestPath, _T('*')) == NULL) && IsExistingDirectory(szDestPath)) { bMultipleDest = TRUE; if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\')) _tcscat(szDestPath, _T("\\")); } /* Check if the destination uses wildcards */ if ((_tcschr(arg[nDes], _T('*')) != NULL) || (_tcschr(arg[nDes], _T('?')) != NULL)) { bMultipleDest = TRUE; } } if (nDes != -1) /* you can only append files when there is a destination */ { if (bMultipleSource && !bMultipleDest) { /* We have multiple source files, but not multiple destination files. This means we are appending the soruce files. */ bAppend = TRUE; if (_tcschr(arg[nSrc], _T('|')) != NULL) appendPointer = arg[nSrc]; } } /* Save the name the user entered */ UseThisName = _tcsrchr(szDestPath,_T('\\')); if (UseThisName) { /* Split the name from the path */ *UseThisName++ = _T('\0'); /* Check if the dest path ends with '\*' or '\' */ if (((UseThisName[0] == _T('*')) && (UseThisName[1] == _T('\0'))) || (UseThisName[0] == _T('\0'))) { /* In this case we will be using the same name as the source file for the destination file because destination is a folder */ bSrcName = TRUE; UseThisName = NULL; } } else { /* Something's seriously wrong! */ UseThisName = szDestPath; } do { /* Get the full string of the path to the source file */ if (_tcschr(arg[nSrc], _T('|')) != NULL) { /* Reset the source path */ szSrcPath[0] = _T('\0'); /* Loop through the source file name and copy all the chars one at a time until it gets too + */ while(TRUE) { if (appendPointer[0] == _T('|')) { /* Skip the | and go to the next file name */ appendPointer++; break; } else if (appendPointer[0] == _T('\0')) { bDone = TRUE; break; } _tcsncat(szSrcPath, appendPointer, 1); appendPointer++; } if (_tcschr(arg[nSrc], _T(',')) != NULL) { /* Only time there is a , in the source is when they are using touch Cant have a destination and can only have on ,, at the end of the string Cant have more then one file name */ szTouch = _tcsstr(arg[nSrc], _T("|")); if (_tcsncmp(szTouch,_T("|,,\0"), 4) || (nDes != -1)) { ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT,arg[nSrc]); nErrorLevel = 1; freep (arg); return 1; } bTouch = TRUE; bDone = TRUE; } } else { bDone = TRUE; _tcscpy(szSrcPath, arg[nSrc]); } /* "x:" is not a valid source path format. */ if ((szSrcPath[1] == _T(':')) && (szSrcPath[2] == _T('\0'))) { ConOutPrintf(_T("%s\n"), szSrcPath); ConOutFormatMessage(ERROR_FILE_NOT_FOUND, szSrcPath); nErrorLevel = 1; break; } /* From this point on, we can assume that the shortest path is 3 letters long and that would be [DriveLetter]:\ */ /* Check if the path has a wildcard */ bHasWildcard = (_tcschr(szSrcPath, _T('*')) != NULL); /* If there is no * in the path name and it is a folder then we will need to add a wildcard to the pathname so FindFirstFile comes up with all the files in that folder */ if (!bHasWildcard && IsExistingDirectory(szSrcPath)) { /* If it doesnt have a \ at the end already then on needs to be added */ if (szSrcPath[_tcslen(szSrcPath) - 1] != _T('\\')) _tcscat(szSrcPath, _T("\\")); _tcscat(szSrcPath, _T("*")); bHasWildcard = TRUE; } /* If the path ends with '\' add a wildcard at the end */ if (szSrcPath[_tcslen(szSrcPath) - 1] == _T('\\')) { _tcscat(szSrcPath, _T("*")); bHasWildcard = TRUE; } /* Get a list of all the files */ hFile = FindFirstFile(szSrcPath, &findBuffer); /* If it couldnt open the file handle, print out the error */ if (hFile == INVALID_HANDLE_VALUE) { /* only print source name when more then one file */ if (bMultipleSource) ConOutPrintf(_T("%s\n"), szSrcPath); ConOutFormatMessage(GetLastError(), szSrcPath); freep(arg); nErrorLevel = 1; return 1; } /* Strip the paths back to the folder they are in */ for (i = (_tcslen(szSrcPath) - 1); i > -1; i--) if (szSrcPath[i] != _T('\\')) szSrcPath[i] = _T('\0'); else break; do { /* Check Breaker */ if (CheckCtrlBreak(BREAK_INPUT)) { FindClose(hFile); freep(arg); return 1; } /* Set the override to yes each new file */ nOverwrite = 1; /* Ignore the . and .. files */ if (!_tcscmp(findBuffer.cFileName, _T(".")) || !_tcscmp(findBuffer.cFileName, _T("..")) || findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } /* Copy the base folder over to a tmp string */ _tcscpy(tmpDestPath, szDestPath); _tcscat(tmpDestPath, _T("\\")); /* Can't put a file into a folder that isn't there */ if (_tcscmp(tmpDestPath, _T("\\\\.\\")) && !IsExistingDirectory(tmpDestPath)) { FindClose(hFile); ConOutFormatMessage(GetLastError(), szSrcPath); freep(arg); nErrorLevel = 1; return 1; } /* Copy over the destination path name */ if (bSrcName) _tcscat(tmpDestPath, findBuffer.cFileName); else { /* If there is no wildcard you can use the name the user entered */ if ((_tcschr(UseThisName, _T('*')) == NULL) && (_tcschr(UseThisName, _T('?')) == NULL)) { _tcscat(tmpDestPath, UseThisName); } else { TCHAR DoneFile[MAX_PATH]; BuildFileName(findBuffer.cFileName, UseThisName, DoneFile); /* Add the filename to the tmp string path */ _tcscat(tmpDestPath, DoneFile); } } /* Build the string path to the source file */ _tcscpy(tmpSrcPath,szSrcPath); _tcscat (tmpSrcPath, findBuffer.cFileName); /* Check to see if the file is the same file */ if (!bTouch && !_tcscmp(tmpSrcPath, tmpDestPath)) { ConOutResPrintf(STRING_COPY_ERROR2); nErrorLevel = 1; break; } /* only print source name when more then one file */ if (bMultipleSource) ConOutPrintf(_T("%s\n"), tmpSrcPath); /* Handle any overriding / prompting that needs to be done */ if (((!(dwFlags & COPY_NO_PROMPT) && IsExistingFile (tmpDestPath)) || dwFlags & COPY_PROMPT) && !bTouch) nOverwrite = CopyOverwrite(tmpDestPath); if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK) continue; if (nOverwrite == PROMPT_ALL || (nOverwrite == PROMPT_YES && bAppend)) dwFlags |= COPY_NO_PROMPT; /* Tell weather the copy was successful or not */ if (copy(tmpSrcPath,tmpDestPath, bAppend, dwFlags, bTouch)) { nFiles++; //LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, RC_STRING_MAX_SIZE); } else { /* print out the error message */ ConOutResPrintf(STRING_COPY_ERROR3); ConOutFormatMessage (GetLastError(), szSrcPath); nErrorLevel = 1; } /* Loop through all wildcard files */ } while (FindNextFile(hFile, &findBuffer)); /* Loop through all files in src string with a + */ } while(!bDone); /* print out the number of files copied */ ConOutResPrintf(STRING_COPY_FILE, bAppend ? 1 : nFiles); if (hFile) FindClose(hFile); if (arg != NULL) freep(arg); return 0; }
void Util::ErrorLog(CString strError) { ost::MutexLock lock(g_ErrorLoglock); puts(strError); // return; CString strPath; strPath=GetRootPath(); strPath+="/temp/mserror.log"; ThreadFile tf(strPath); strError+="\r\n"; CTime stime=CTime::GetCurrentTimeEx(); CString strlog; strlog.Format("%s\t%s",stime.Format().c_str(),strError.getText()); char *pstr=strlog.getText(); // 判断文件大小:在不打开文件的情况下实现 struct _stat buf; if( _stat( pstr, &buf ) == 0 ) { if( buf.st_size > 10000*1024 ) { FILE *log = fopen( pstr, "w" ); if( log != NULL ) fclose( log ); } } tf.append(pstr,(ccxx_size_t)strlen(pstr)); /* Lock l(g_ErrorLoglock); CString strTemp=_T(""), strFile=_T(""); strFile.Format("%s\\MonitorManager\\meerror.log",g_strRootPath); CTime time=CTime::GetCurrentTime(); strTemp=time.Format("%Y-%m-%d %H:%M:%S"); strTemp+="\t"+strError+"\r\n"; #ifndef DEBUG_T FILE *fp=NULL; fp=::fopen(strFile,"a+"); if(fp==NULL) { printf("���ʧ�\n"); return ; } ::fputs(strTemp,fp); ::fclose(fp); #else printf("%s",strTemp); #endif */ return ; }