| 679 | } |
| 680 | |
| 681 | bool CConsole::ExecuteFile(const char *pFilename, int ClientId, bool LogFailure, int StorageType) |
| 682 | { |
| 683 | int Count = 0; |
| 684 | // make sure that this isn't being executed already and that recursion limit isn't met |
| 685 | for(CExecFile *pCur = m_pFirstExec; pCur; pCur = pCur->m_pPrev) |
| 686 | { |
| 687 | Count++; |
| 688 | |
| 689 | if(str_comp(pFilename, pCur->m_pFilename) == 0 || Count > FILE_RECURSION_LIMIT) |
| 690 | return false; |
| 691 | } |
| 692 | if(!m_pStorage) |
| 693 | return false; |
| 694 | |
| 695 | // push this one to the stack |
| 696 | CExecFile ThisFile; |
| 697 | CExecFile *pPrev = m_pFirstExec; |
| 698 | ThisFile.m_pFilename = pFilename; |
| 699 | ThisFile.m_pPrev = m_pFirstExec; |
| 700 | m_pFirstExec = &ThisFile; |
| 701 | |
| 702 | // exec the file |
| 703 | CLineReader LineReader; |
| 704 | bool Success = false; |
| 705 | char aBuf[32 + IO_MAX_PATH_LENGTH]; |
| 706 | if(LineReader.OpenFile(m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType))) |
| 707 | { |
| 708 | str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename); |
| 709 | Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); |
| 710 | |
| 711 | while(const char *pLine = LineReader.Get()) |
| 712 | { |
| 713 | ExecuteLine(pLine, ClientId); |
| 714 | } |
| 715 | |
| 716 | Success = true; |
| 717 | } |
| 718 | else if(LogFailure) |
| 719 | { |
| 720 | str_format(aBuf, sizeof(aBuf), "failed to open '%s'", pFilename); |
| 721 | Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf); |
| 722 | } |
| 723 | |
| 724 | m_pFirstExec = pPrev; |
| 725 | return Success; |
| 726 | } |
| 727 | |
| 728 | void CConsole::Con_Echo(IResult *pResult, void *pUserData) |
| 729 | { |
no test coverage detected