void CActiveMember::SetTerminalID(CString newVal) { GPropertyInit( TerminalID, newVal ); if (GetTerminalID().IsEmpty()) { SetIsOnLine( FALSE ); } }
CString CActiveMember::GetTermIdInfo() { CString strTmp; if (GetTerminalID().IsEmpty()) { } else { strTmp = GetTerminalID(); if (!IsActive() && GetAvailavleBalance() > 0) //失去激活且有钱 { strTmp.Append(_T("(失去连接)")); } } return strTmp; }
bool CUsbKeyOperation::SelfCheck(CString &info) { USES_CONVERSION; unsigned char test_plain_text[]="123456789ABCDEF"; int test_plain_txt_len= 15; unsigned char *pSignedBuffer=NULL;//需要清理缓冲区 int Signedbuffer_len=0; //加密 unsigned char* pstr = test_plain_text; if(SignedEncryptPkt(1, pstr,test_plain_txt_len,(unsigned char**)&pSignedBuffer,Signedbuffer_len)==false) { info= info + _T("USB KEY 自检, 签名, 加密 失败."); LOG(ERROR)<<T2A(info); if(NULL != pSignedBuffer) { free(pSignedBuffer); pSignedBuffer=NULL; } return false; } ////here for general use to handle with verify packet header, maybe change it later. //pSignedBuffer[BZ_LEN+UKID_LEN]='0'; // ////对密文解密 unsigned char *pBuffer=NULL;//需要清理缓冲区 int buffer_len=0; char bz; if(DecryptVerifyPkt(1, pSignedBuffer,Signedbuffer_len,bz,(unsigned char**)&pBuffer,buffer_len,info)==false) { info= info + _T("USB KEY 自检, 解密, 验签 失败."); LOG(ERROR)<<T2A(info); if(NULL!=pSignedBuffer) { free(pSignedBuffer); pSignedBuffer=NULL; } if(NULL!=pBuffer) { free(pBuffer); pBuffer=NULL; } return false; } //检查一致性 for(int i=0;i<buffer_len;i++) { if(pBuffer[i]!=pstr[i]) { info=info+_T("原始明文与解密后明文两者内容不一致"); LOG(ERROR)<<info; LOG(ERROR)<<"Origin Plain Text:"<<(pstr); LOG(ERROR)<<"Decrypted Text:"<<(pBuffer); return false; } } if(pSignedBuffer!=NULL) { free(pSignedBuffer); pSignedBuffer=NULL; } if(pBuffer!=NULL) { free(pBuffer); pBuffer=NULL; } CString terminal_id; CString user_id; CString err_info; terminal_id.Empty(); user_id.Empty(); terminal_id = GetTerminalID(err_info); user_id = GetUserID(err_info); info=info + _T("USBKey ID: ")+terminal_id + user_id; return true; }
char* TANSIParser::ParseEscape(char* pszBuffer, char* pszBufferEnd) { char *pszChar; // Check if we have enough characters in buffer. if ((pszBufferEnd - pszBuffer) < 2) return pszBuffer; // I.Ioannou 04 Sep 1997 // there is no need for pszBuffer++; after each command // Decode the command. pszBuffer++; switch (*pszBuffer++) { case 'A': // Cursor up Console.MoveCursorPosition(0, -1); break; // Cursor down case 'B': Console.MoveCursorPosition(0, 1); break; // Cursor right case 'C': Console.MoveCursorPosition(1, 0); break; // LF *or* cursor left (Paul Brannan 6/27/98) case 'D': if(vt52_mode) Console.MoveCursorPosition(-1, 0); else Console.index(); break; // CR/LF (Paul Brannan 6/26/98) case 'E': Console.WriteCtrlString("\r\n", 2); break; // Special graphics char set (Paul Brannan 6/27/98) case 'F': Charmap.setmap('0'); break; // ASCII char set (Paul Brannan 6/27/98) case 'G': Charmap.setmap('B'); break; // Home cursor/tab set case 'H': if(ini.get_vt100_mode()) { int x = Console.GetCursorX(); if(x != 0) { int t = tab_stops[x - 1]; for(int j = x - 1; j >= 0 && tab_stops[j] == t; j--) tab_stops[j] = x; } } else { // I.Ioannou 04 Sep 1997 (0,0) not (1,1) ConSetCursorPos(0, 0); } break; // Reverse line feed (Paul Brannan 6/27/98) // FIX ME!!! reverse_index is wrong to be calling here // (Paul Brannan 12/2/98) case 'I': Console.reverse_index(); break; // Erase end of screen case 'J': Console.ClearEOScreen(); break; // Erase EOL case 'K': Console.ClearEOLine(); break; // Scroll Up one line //Reverse index case 'M': Console.reverse_index(); break; // Direct cursor addressing case 'Y': if ((pszBufferEnd - pszBuffer) >= 2){ // if we subtract '\x1F', then we may end up with a negative // cursor position! (Paul Brannan 6/26/98) ConSetCursorPos(pszBuffer[1] - ' ', pszBuffer[0] - ' '); pszBuffer+=2; } else { pszBuffer--; // Paul Brannan 6/26/98 } break; // Terminal ID Request case 'Z': { const char* szTerminalId = GetTerminalID(); Network.WriteString(szTerminalId, strlen(szTerminalId)); break; } // reset terminal to defaults case 'c': ResetTerminal(); break; // Enter alternate keypad mode case '=': KeyTrans.set_ext_mode(APP3_KEY); break; // Exit alternate keypad mode case '>': KeyTrans.unset_ext_mode(APP3_KEY); break; // Enter ANSI mode case '<': KeyTrans.unset_ext_mode(APP2_KEY); // exit vt52 mode break; // Graphics processor on (See note 3) case '1': break; // Line size commands case '#': //Line size commands // (Paul Brannan 6/26/98) if(pszBuffer < pszBufferEnd) { switch(*pszBuffer++) { case '3': break; // top half of a double-height line case '4': break; // bottom half of a double-height line case '6': break; // current line becomes double-width case '8': Console.ClearScreen('E'); break; } } else { pszBuffer--; } break; // Graphics processor off (See note 3) case '2': break; // Save cursor and attribs case '7': SaveCurY(Console.GetRawCursorY()); SaveCurX(Console.GetRawCursorX()); iSavedAttributes = Console.GetAttrib(); break; // Restore cursor position and attribs case '8': Console.SetRawCursorPosition(iSavedCurX, iSavedCurY); Console.SetAttrib(iSavedAttributes); break; // Set G0 map (Paul Brannan 6/25/98) case '(': if (pszBuffer < pszBufferEnd) { map_G0 = *pszBuffer; if(current_map == 0) Charmap.setmap(map_G0); pszBuffer++; } else { pszBuffer--; } break; // Set G1 map (Paul Brannan 6/25/98) case ')': if (pszBuffer < pszBufferEnd) { map_G1 = *pszBuffer; if(current_map == 1) Charmap.setmap(map_G1); pszBuffer++; } else { pszBuffer--; } break; // This doesn't do anything, as far as I can tell, but it does take // a parameter (Paul Brannan 6/27/98) case '%': if (pszBuffer < pszBufferEnd) { pszBuffer++; } else { pszBuffer--; } break; // ANSI escape sequence case '[': // Check if we have whole escape sequence in buffer. // This should not be isalpha anymore (Paul Brannan 9/1/98) pszChar = pszBuffer; while ((pszChar < pszBufferEnd) && (*pszChar <= '?')) pszChar++; if (pszChar == pszBufferEnd) pszBuffer -= 2; else pszBuffer = ParseEscapeANSI(pszBuffer, pszBufferEnd); break; #ifdef MTE_SUPPORT case '~': // Frediano Ziglio, 5/31/2000 // Meridian Terminal Emulator extension // !!! same as ANSI // !!! should put in MTE procedure pszChar = pszBuffer; while ((pszChar < pszBufferEnd) && (*pszChar <= '?')) pszChar++; if (pszChar == pszBufferEnd) pszBuffer -= 2; else pszBuffer = ParseEscapeMTE(pszBuffer, pszBufferEnd); break; #endif default: #ifdef DEBUG Console.Beep(); #endif break; } return pszBuffer; }
char* TANSIParser::ParseEscapeANSI(char* pszBuffer, char* pszBufferEnd) { // The buffer contains something like <ESC>[pA // where p is an optional decimal number specifying the count by which the // appropriate action should take place. // The pointer pszBuffer points us to the p, <ESC> and [ are // already 'consumed' // TITUS: Simplification of the code: Assume default count of 1 in case // there are no parameters. char tmpc; const int nParam = 10; // Maximum number of parameters int iParam[nParam] = {1, 0, 0, 0, 0}; // Assume 1 Parameter, Default 1 int iCurrentParam = 0; DWORD flag = 0; int missing_param = 0; // Get parameters from escape sequence. while ((tmpc = *pszBuffer) <= '?') { if(tmpc < '0' || tmpc > '9') { // Check for parameter delimiter. if(tmpc == ';') { // This is a hack (Paul Brannan 6/27/98) if(*(pszBuffer - 1) == '[') missing_param = iCurrentParam+1; pszBuffer++; continue; } // It is legal to have control characters inside ANSI sequences // (Paul Brannan 6/26/98) if(tmpc < ' ') { Console.WriteCtrlChar(tmpc); pszBuffer++; continue; } // A new way of handling flags (Paul Brannan 12/2/98) switch(tmpc) { case '$': flag |= FLAG_DOLLAR; break; case '?': flag |= FLAG_QMARK; break; case '>': flag |= FLAG_GREATER; break; case '<': flag |= FLAG_LESS; break; case '!': flag |= FLAG_EXCLAM; break; case '&': flag |= FLAG_AMPERSAND; break; case '/': flag |= FLAG_SLASH; break; case '=': flag |= FLAG_EQUAL; break; case '\"': flag |= FLAG_QUOTE; break; default: flag |= FLAG_OTHER; break; } pszBuffer++; } // Got Numerical Parameter. iParam[iCurrentParam] = strtoul(pszBuffer, &pszBuffer, 10); if (iCurrentParam < nParam) iCurrentParam++; } //~~~ TITUS: Apparently the digit is optional (look at termcap or terminfo) // So: If there is no digit, assume a count of 1 switch ((unsigned char)*pszBuffer++) { // Insert Character case '@': if(iParam[0] == 0) iParam[0] = 1; // Paul Brannan 9/1/98 Console.InsertCharacter(iParam[0]); break; // Move cursor up. case 'A': if(iParam[0] == 0) iParam[0] = 1; Console.MoveCursorPosition(0, -iParam[0]); break; // Move cursor down. // Added by I.Ioannou 06 April, 1997 case 'B': case 'e': if(iParam[0] == 0) iParam[0] = 1; Console.MoveCursorPosition(0, iParam[0]); break; // Move cursor right. // Added by I.Ioannou 06 April, 1997 case 'C': case 'a': // Handle cursor size sequences (Jose Cesar Otero Rodriquez and // Paul Brannan, 3/27/1999) if(flag & FLAG_EQUAL) { switch(iParam[0]) { case 7: Console.SetCursorSize(50); break; case 11: Console.SetCursorSize(6); break; case 32: Console.SetCursorSize(0); break; default: Console.SetCursorSize(13); } } else { if(iParam[0] == 0) iParam[0] = 1; Console.MoveCursorPosition(iParam[0], 0); break; } // Move cursor left. case 'D': if(iParam[0] == 0) iParam[0] = 1; Console.MoveCursorPosition(-iParam[0], 0); break; // Move cursor to beginning of line, p lines down. // Added by I.Ioannou 06 April, 1997 case 'E': Console.MoveCursorPosition(-Console.GetCursorX(), iParam[0]); break; // Moves active position to beginning of line, p lines up // Added by I.Ioannou 06 April, 1997 // With '=' this changes the default fg color (Paul Brannan 6/27/98) case 'F': if(flag & FLAG_EQUAL) Console.setDefaultFg(iParam[0]); else Console.MoveCursorPosition(-Console.GetCursorX(), -iParam[0]); break; // Go to column p // Added by I.Ioannou 06 April, 1997 // With '=' this changes the default bg color (Paul Brannan 6/27/98) case '`': case 'G': // 'G' is from Linux kernel sources if(flag & FLAG_EQUAL) { Console.setDefaultBg(iParam[0]); } else { if (iCurrentParam < 1) // Alter Default iParam[0] = 0; // this was backward, and we should subtract 1 from x // (Paul Brannan 5/27/98) ConSetCursorPos(iParam[0] - 1, Console.GetCursorY()); } break; // Set cursor position. case 'f': case 'H': if (iCurrentParam < 2 || iParam[1] < 1) iParam[1] = 1; ConSetCursorPos(iParam[1] - 1, iParam[0] - 1); break; // Clear screen case 'J': if ( iCurrentParam < 1 ) iParam[0] = 0; // Alter Default switch (iParam[0]) { case 0: Console.ClearEOScreen(); break; case 1: Console.ClearBOScreen(); break; case 2: Console.ClearScreen(); Console.SetRawCursorPosition(0, 0); break; } break; // Clear line case 'K': if (iCurrentParam < 1) // Alter Default iParam[0] = 0; switch (iParam[0]) { case 0: Console.ClearEOLine(); break; case 1: Console.ClearBOLine(); break; case 2: Console.ClearLine(); break; } break; // Insert p new, blank lines. // Added by I.Ioannou 06 April, 1997 case 'L': { // for (int i = 1; i <= iParam[0]; i++) // This should speed things up a bit (Paul Brannan 9/2/98) Console.ScrollDown(Console.GetRawCursorY(), -1, iParam[0]); break; } // Delete p lines. // Added by I.Ioannou 06 April, 1997 case 'M': { for (int i = 1; i <= iParam[0]; i++) // This should speed things up a bit (Paul Brannan 9/2/98) Console.ScrollDown(Console.GetRawCursorY(), -1, -1); break; } // DELETE CHAR case 'P': Console.DeleteCharacter(iParam[0]); break; // Scrolls screen up (down? -- PB) p lines, // Added by I.Ioannou 06 April, 1997 // ANSI X3.64-1979 references this but I didn't // found it in any telnet implementation // note 05 Oct 97 : but SCO terminfo uses them, so uncomment them !! case 'S': { //for (int i = 1; i <= iParam[0]; i++) // This should speed things up a bit (Paul Brannan 9/2/98) Console.ScrollDown(-1, -1, -iParam[0]); break; } // Scrolls screen up p lines, // Added by I.Ioannou 06 April, 1997 // ANSI X3.64-1979 references this but I didn't // found it in any telnet implementation // note 05 Oct 97 : but SCO terminfo uses them, so uncomment them !! case 'T': { // for (int i = 1; i <= iParam[0]; i++) // This should speed things up a bit (Paul Brannan 9/2/98) Console.ScrollDown(-1, -1, iParam[0]); break; } // Erases p characters up to the end of line // Added by I.Ioannou 06 April, 1997 case 'X': { int iKeepX = Console.GetRawCursorX(); int iKeepY = Console.GetRawCursorY(); if (iParam[0] > Console.GetWidth()) iParam[0] = Console.GetWidth(); // up to the end of line for ( int i = 1; i <= iParam[0]; i++ ) Console.WriteString(" ", 1); Console.SetRawCursorPosition(iKeepX , iKeepY); break; } // Go back p tab stops // Added by I.Ioannou 06 April, 1997 // Implemented by Paul Brannan, 4/13/2000 case 'Z': { int x = Console.GetCursorX(); for(int j = 0; x > 0 && j < iParam[0]; j++) while(x > 0 && tab_stops[j] == tab_stops[x]) x--; Console.SetCursorPosition(x, Console.GetCursorY()); } break; // Get Terminal ID case 'c': { const char* szTerminalId = GetTerminalID(); Network.WriteString(szTerminalId, strlen(szTerminalId)); break; } // TITUS++ 2. November 1998: Repeat Character. case 'b': // isprint may be causing problems (Paul Brannan 3/27/99) // if ( isprint(last_char) ) { char buf[150]; // at most 1 line (max 132 chars) if ( iParam[0] > 149 ) iParam[0] = 149; memset(buf, last_char, iParam[0]); buf[iParam[0]] = 0; if ( fast_write ) Console.WriteStringFast(buf, iParam[0]); else Console.WriteString(buf, iParam[0]); // } /* IF */ break; // Go to line p // Added by I.Ioannou 06 April, 1997 case 'd': if (iCurrentParam < 1) // Alter Default iParam[0] = 0; // this was backward, and we should subtract 1 from y // (Paul Brannan 5/27/98) ConSetCursorPos(Console.GetCursorX(), iParam[0] - 1); break; // iBCS2 tab erase // Added by I.Ioannou 06 April, 1997 case 'g': if (iCurrentParam < 1) // Alter Default iParam[0] = 0; switch (iParam[0]) { case 0: { // Clear the horizontal tab stop at the current active position for(int j = 0; j < MAX_TAB_POSITIONS; j++) { int x = Console.GetCursorX(); if(tab_stops[j] == x) tab_stops[j] = tab_stops[x + 1]; } } break; case 2: // I think this might be "set as default?" break; case 3: { // Clear all tab stops for(int j = 0; j < MAX_TAB_POSITIONS; j++) tab_stops[j] = -1; } break; } break; // Set extended mode case 'h': { for (int i = 0; i < iCurrentParam; i++) { // Changed to a switch statement (Paul Brannan 5/27/98) if(flag & FLAG_QMARK) { switch(iParam[i]) { case 1: // App cursor keys KeyTrans.set_ext_mode(APP_KEY); break; case 2: // VT102 mode vt52_mode = 0; KeyTrans.unset_ext_mode(APP2_KEY); break; case 3: // 132 columns if(ini.get_wide_enable()) { Console.SetWindowSize(132, -1); } break; case 4: // smooth scrolling break; case 5: // Light background Console.Lightbg(); break; case 6: // Stay in margins ignore_margins = 0; break; case 7: Console.setLineWrap(true); break; case 8: // Auto-repeat keys break; case 18: // Send FF to printer break; case 19: // Entire screen legal for printer break; case 25: // Visible cursor break; case 66: // Application numeric keypad break; default: #ifdef DEBUG Console.Beep(); #endif break; } } else { switch(iParam[i]) { case 2: // Lock keyboard break; case 3: // Act upon control codes (PB 12/5/98) print_ctrl = 0; break; case 4: // Set insert mode Console.InsertMode(1); break; case 12: // Local echo off break; case 20: // Newline sends cr/lf KeyTrans.set_ext_mode(APP4_KEY); newline_mode = true; break; default: #ifdef DEBUG Console.Beep(); #endif break; } } } } break; // Print Screen case 'i': if (iCurrentParam < 1) iParam[0]=0; switch (iParam[0]){ case 0: break; // Print Screen case 1: break; // Print Line // Added I.Ioannou 06 April, 1997 case 4: // Stop Print Log InPrintMode = 0; if ( printfile != NULL ) fclose(printfile); break; case 5: // Start Print Log printfile = fopen(ini.get_printer_name(), "ab"); if (printfile != NULL) InPrintMode = 1; break; } break; // Unset extended mode case 'l': { for (int i = 0; i < iCurrentParam; i++) { // Changed to a switch statement (Paul Brannan 5/27/98) if(flag & FLAG_QMARK) { switch(iParam[i]) { case 1: // Numeric cursor keys KeyTrans.unset_ext_mode(APP_KEY); break; case 2: // VT52 mode vt52_mode = 1; KeyTrans.set_ext_mode(APP2_KEY); break; case 3: // 80 columns if(ini.get_wide_enable()) { Console.SetWindowSize(80, -1); } break; case 4: // jump scrolling break; case 5: // Dark background Console.Darkbg(); break; case 6: // Ignore margins ignore_margins = 1; break; case 7: Console.setLineWrap(false); break; case 8: // Auto-repeat keys break; case 19: // Only send scrolling region to printer break; case 25: // Invisible cursor break; case 66: // Numeric keypad break; default: #ifdef DEBUG Console.Beep(); #endif break; } } else { switch(iParam[i]) { case 2: // Unlock keyboard break; case 3: // Display control codes (PB 12/5/98) print_ctrl = 1; break; case 4: // Set overtype mode Console.InsertMode(0); break; case 12: // Local echo on break; case 20: // sends lf only KeyTrans.unset_ext_mode(APP4_KEY); newline_mode = false; break; default: #ifdef DEBUG Console.Beep(); #endif break; } } } } break; // Set color case 'm': if(missing_param) Console.Normal(); if(iCurrentParam == 0) { Console.Normal(); } else { for(int i = 0; i < iCurrentParam; i++) ConSetAttribute(iParam[i]); } break; // report cursor position Row X Col case 'n': if (iCurrentParam == 1 && iParam[0]==5) { // report the cursor position Network.WriteString("\x1B[0n", 4); break; } if (iCurrentParam == 1 && iParam[0]==6){ // report the cursor position // The cursor position needs to be sent as a single string // (Paul Brannan 6/27/98) char szCursorReport[40] = "\x1B["; itoa(Console.GetCursorY() + 1, &szCursorReport[strlen(szCursorReport)], 10); strcat(szCursorReport, ";"); itoa(Console.GetCursorX() + 1, &szCursorReport[strlen(szCursorReport)], 10); strcat(szCursorReport, "R"); Network.WriteString(szCursorReport, strlen(szCursorReport)); } break; // Miscellaneous weird sequences (Paul Brannan 6/27/98) case 'p': // Set conformance level if(flag & FLAG_QUOTE) { break; } // Soft terminal reset if(flag & FLAG_EXCLAM) { break; } // Report mode settings if(flag & FLAG_DOLLAR) { break; } break; // Scroll Screen case 'r': if (iCurrentParam < 1) { // Enable scrolling for entire display Console.SetScroll(-1, -1); break; } if (iCurrentParam >1) { // Enable scrolling from row1 to row2 Console.SetScroll(iParam[0] - 1, iParam[1] - 1); // If the cursor is outside the scrolling range, fix it // (Paul Brannan 6/26/98) // if(Console.GetRawCursorY() < iParam[0] - 1) { // Console.SetRawCursorPosition(Console.GetCursorX(), // iParam[0] - 1); // } // if(Console.GetRawCursorY() > iParam[1] - 1) { // Console.SetRawCursorPosition(Console.GetCursorX(), // iParam[1] - 1); // } } // Move the cursor to the home position (Paul Brannan 12/2/98) Console.SetCursorPosition(0, 0); break; // Save cursor position case 's': SaveCurY(Console.GetRawCursorY()); SaveCurX(Console.GetRawCursorX()); break; // Restore cursor position case 'u': Console.SetRawCursorPosition(iSavedCurX, iSavedCurY); break; // DEC terminal report (Paul Brannan 6/28/98) case 'x': if(iParam[0]) Network.WriteString("\033[3;1;1;128;128;1;0x", 20); else Network.WriteString("\033[2;1;1;128;128;1;0x", 20); break; default: #ifdef DEBUG Console.Beep(); #endif break; } return pszBuffer; }
bool WorkingParameters::LoadConfigFromServer() { LastErrorHolder errorHolder; TCHAR configFilePath[MAX_PATH]; GetModuleFileName(NULL, configFilePath, _countof(configFilePath)); PathRemoveFileSpec(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("FTPCONFIG.ini")); TCHAR serverIP[128]; GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath); int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath); TCHAR userName[128]; GetPrivateProfileString(TEXT("Config"), TEXT("User"), NULL, userName, _countof(userName), configFilePath); TCHAR password[128]; GetPrivateProfileString(TEXT("Config"), TEXT("Password"), NULL, password, _countof(password), configFilePath); FtpClient client; if (!client.Connect(serverIP, serverPort, DecodePassword(userName), DecodePassword(password))) { errorHolder.SaveLastError(); return false; } TCHAR appConfigPath[MAX_PATH]; GetAppDataPath(appConfigPath); PathAddBackslash(appConfigPath); _tcscat(appConfigPath, _T("config")); if (!CreateDirectoryRecusively(appConfigPath)) { errorHolder.SaveLastError(); return false; } PathAddBackslash(appConfigPath); TCHAR remoteTerminalPath[MAX_PATH]; GetPrivateProfileString(TEXT("Config"), TEXT("RemoteTerminalPath"), NULL, remoteTerminalPath, _countof(remoteTerminalPath), configFilePath); // 获取机器识别码 lux TCHAR id[200] = { 0 }; GetTerminalID(id); // 将机器识别码写入配置文件中,方便查询 WritePrivateProfileString(TEXT("Config"), TEXT("TerminalID"), id, configFilePath); // 根据设备唯一识别码下载相应可变配置文件 lux // 为了防止因服务器下载失败而清除本地配置文件,以临时文件的形式先保存,下载成功以后再覆盖原文件 TCHAR tempFilePath[MAX_PATH]; GetTempPath(_countof(tempFilePath), tempFilePath); GetTempFileName(tempFilePath, _T("~"), 0, tempFilePath); TCHAR remoteConfigFilePath[MAX_PATH]; _tcscpy(remoteConfigFilePath, remoteTerminalPath); _tcscat(remoteConfigFilePath, id); _tcscat(remoteConfigFilePath, _T(".ini")); if (!client.GetFile(remoteConfigFilePath, tempFilePath)) { errorHolder.SaveLastError(); return false; } TCHAR localConfigFilePath[MAX_PATH]; _tcscpy(localConfigFilePath, appConfigPath); _tcscat(localConfigFilePath, _T("model.ini")); BOOL bMoveSuccess = MoveFileEx(tempFilePath, localConfigFilePath, MOVEFILE_COPY_ALLOWED + MOVEFILE_REPLACE_EXISTING); if (bMoveSuccess) { DeleteFile(tempFilePath); } else { DeleteFile(tempFilePath); return false; } if (!LoadConfig()) { errorHolder.SaveLastError(); return false; } return true; }
void DebugLogger::StartDebug() { #pragma pack(push) #pragma pack(1) struct RecordData { char appVersion[16]; char sn[SERIAL_NUMBER_LENGTH]; char op[64]; char offline; char modelID[4]; char terminalID[200]; char firmwareVersion[FIRMWARE_VERSION_LENGTH]; int selfTestState; int debugState[16]; char mac[20]; }; #pragma pack(pop) if (logFile_.m_hFile != INVALID_HANDLE_VALUE) { logFile_.Close(); } // 根据可变配置文件中的配置项决定是否上传数据 lux VariableConfigBlock *config = WorkingParameters::GetInstance()->GetCurrentConfigParameters(); int uploadLevel = config->GetIntParameter(_T("UploadLevel"), 1); if (uploadLevel == 0) { return; } DeviceInfo deviceInfo; if (!DeviceProxy::GetInstance()->GetDeviceInfo(&deviceInfo)) { return; } CString fileName(logPath_); fileName.AppendChar(_T('\\')); for (int i = 0; i < _countof(deviceInfo.sn) && deviceInfo.sn[i] != '\0'; i++) { char ch = deviceInfo.sn[i]; if (ch == ' ' || ch == '\\' || ch == '//' || ch == ':' || ch == '*' || ch == '|' || ch == '?' || ch == '<' || ch == '>') { fileName.AppendChar(_T('_')); } else { fileName.AppendChar(ch); } } fileName.AppendChar(_T('_')); SYSTEMTIME now; GetLocalTime(&now); fileName.AppendFormat(_T("%04d%02d%02d_%02d%02d%02d.dat"), (int)now.wYear, (int)now.wMonth, (int)now.wDay, (int)now.wHour, (int)now.wMinute, (int)now.wSecond); try { logFile_.Open(fileName, CFile::typeBinary | CFile::modeCreate | CFile::shareExclusive | CFile::modeWrite); } catch (CFileException *e) { e->Delete(); } RecordData data; ZeroMemory(&data, sizeof(data)); CString appVersion = AfxGetApp()->GetProfileString(_T(""), _T("Version")); strncpy(data.appVersion, CT2A(appVersion, CP_UTF8), _countof(data.appVersion)); strncpy(data.sn, deviceInfo.sn, _countof(data.sn)); strncpy(data.op, CT2A(WorkingParameters::GetInstance()->GetUserName(), CP_UTF8), _countof(data.op)); int curID = WorkingParameters::GetInstance()->GetCurrentModelId(); strncpy(data.modelID, (char *)&curID, _countof(data.modelID)); TCHAR terminalID[200] = { 0 }; GetTerminalID(terminalID); strncpy(data.terminalID, CT2A(terminalID, CP_UTF8), _countof(data.terminalID)); strncpy(data.firmwareVersion, deviceInfo.firmwareVersion, _countof(data.firmwareVersion)); data.offline = WorkingParameters::GetInstance()->IsOffline() ? 1 : 0; data.selfTestState = deviceInfo.selfTestState; ASSERT(sizeof(data.debugState) == sizeof(deviceInfo.debugState)); memcpy(data.debugState, deviceInfo.debugState, sizeof(data.debugState)); if (!DeviceProxy::GetInstance()->GetMacAddr(data.mac, _countof(data.mac))) { memset(data.mac, 0, _countof(data.mac)); } WriteRecord("SDG ", &data, sizeof(data)); }