| | |
| | | |
| | | void CToolUnits::createDir(const char* pszDir) |
| | | { |
| | | if (isDirectory(std::string(pszDir))) { |
| | | return; |
| | | } |
| | | |
| | | CString strDir = pszDir; |
| | | int lastIndex = 0; |
| | | int index = strDir.Find(_T("\\"), lastIndex); |
| | |
| | | return (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY)); |
| | | } |
| | | |
| | | double CToolUnits::toInt32(const char* pBuffer) |
| | | int CToolUnits::toInt32(const char* pBuffer) |
| | | { |
| | | return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8 | (pBuffer[2] & 0xff) << 16 | (pBuffer[3] & 0xff) << 24; |
| | | return (pBuffer[0] & 0xff) | ((pBuffer[1] & 0xff) << 8) | ((pBuffer[2] & 0xff) << 16) | ((pBuffer[3] & 0xff) << 24); |
| | | } |
| | | |
| | | double CToolUnits::toInt16(const char* pBuffer) |
| | | int CToolUnits::toInt16(const char* pBuffer) |
| | | { |
| | | return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8; |
| | | } |
| | | |
| | | BOOL CToolUnits::getBit(const char c, int index) |
| | | { |
| | | switch (index) |
| | | { |
| | | case 0: |
| | | return c & 0x01; |
| | | break; |
| | | case 1: |
| | | return c & 0x02; |
| | | break; |
| | | case 2: |
| | | return c & 0x04; |
| | | break; |
| | | case 3: |
| | | return c & 0x08; |
| | | break; |
| | | case 4: |
| | | return c & 0x10; |
| | | break; |
| | | case 5: |
| | | return c & 0x20; |
| | | break; |
| | | case 6: |
| | | return c & 0x40; |
| | | break; |
| | | case 7: |
| | | return c & 0x80; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | return FALSE; |
| | | } |
| | | |
| | | void CToolUnits::setBit(char* p, int index) |
| | | { |
| | | int byteIndex = 0; |
| | | byte b = 0; |
| | | if (index >= 8) byteIndex = 1; |
| | | switch (index) |
| | | { |
| | | case 0: |
| | | case 8: |
| | | b = 0x1; |
| | | break; |
| | | case 1: |
| | | case 9: |
| | | b = 0x2; |
| | | break; |
| | | case 2: |
| | | case 0xA: |
| | | b = 0x4; |
| | | break; |
| | | case 3: |
| | | case 0xB: |
| | | b = 0x8; |
| | | break; |
| | | case 4: |
| | | case 0xC: |
| | | b = 0x10; |
| | | break; |
| | | case 5: |
| | | case 0xD: |
| | | b = 0x20; |
| | | break; |
| | | case 6: |
| | | case 0xE: |
| | | b = 0x40; |
| | | break; |
| | | case 7: |
| | | case 0xF: |
| | | b = 0x80; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | |
| | | p[byteIndex] = b; |
| | | } |
| | | |
| | | void CToolUnits::setDlgItemDouble(CWnd* pWnd, int nCtrlId, double value) |
| | |
| | | strText.Format(_T("%.03f"), value); |
| | | pWnd->SetDlgItemText(nCtrlId, strText); |
| | | } |
| | | |
| | | std::vector<CString> CToolUnits::GetFileNamesInDirectory(const CString& strFolderPath, const CString& strExtension) |
| | | { |
| | | std::vector<CString> fileNames; |
| | | |
| | | // 确保目录路径最后有反斜杠 |
| | | CString strSearchPath = strFolderPath; |
| | | if (strSearchPath[strSearchPath.GetLength() - 1] != '\\') { |
| | | strSearchPath += '\\'; |
| | | } |
| | | |
| | | CString finalExtension = strExtension; |
| | | if (finalExtension.Find('.') == -1) { |
| | | finalExtension = '.' + finalExtension; |
| | | } |
| | | strSearchPath += "*" + finalExtension; |
| | | |
| | | std::unique_ptr<CFileFind> finder = std::make_unique<CFileFind>(); |
| | | BOOL bWorking = finder->FindFile(strSearchPath); |
| | | |
| | | // 遍历文件夹 |
| | | while (bWorking) { |
| | | bWorking = finder->FindNextFile(); |
| | | if (!finder->IsDirectory()) { |
| | | CString fileName = finder->GetFileName(); |
| | | int dotPos = fileName.ReverseFind('.'); |
| | | if (dotPos != -1) { |
| | | fileName = fileName.Left(dotPos); |
| | | } |
| | | fileNames.push_back(fileName); |
| | | } |
| | | } |
| | | |
| | | return fileNames; |
| | | } |
| | | |
| | | std::string CToolUnits::getRecipePath() |
| | | { |
| | | return getCurrentExePath() + "\\Recipe"; |
| | | } |
| | | |
| | | std::string CToolUnits::getCurrentTimeString() |
| | | { |
| | | struct tm ltm; |
| | | time_t now = time(0); |
| | | localtime_s(<m, &now); // 使用安全的 localtime_s 函数 |
| | | |
| | | char buffer[256]; |
| | | sprintf_s(buffer, sizeof(buffer), "%04d-%02d-%02d %02d:%02d:%02d", |
| | | ltm.tm_year + 1900, ltm.tm_mon + 1, ltm.tm_mday, |
| | | ltm.tm_hour, ltm.tm_min, ltm.tm_sec); |
| | | |
| | | return std::string(buffer); |
| | | } |