#include "stdafx.h" void SaveLog(LPCTSTR pstrFormat, ...) { CString strText; try { // format and write the data we were given va_list args; va_start(args, pstrFormat); strText.FormatV(pstrFormat, args); va_end(args); } catch(CMemoryException *e) { e->Delete(); } catch(...) { return ; } static CString strFilePath; if (strFilePath.IsEmpty()) { TCHAR *szPath=strFilePath.GetBuffer(MAX_PATH); GetModuleFileName(AfxGetInstanceHandle(),szPath,MAX_PATH); PathRemoveFileSpec(szPath); strFilePath.ReleaseBuffer(); } CTime cTime = CTime::GetCurrentTime(); CFile mFile; if (mFile.Open(strFilePath+cTime.Format(_T("\\Log\\WS_%y-%m-%d.txt")),CFile::modeCreate|CFile::modeNoTruncate|CFile::modeReadWrite,NULL)==TRUE) { mFile.SeekToEnd(); strText.Insert(0, cTime.Format(_T("[%H:%M:%S]"))); strText += _T("\r\n"); mFile.Write(strText.GetBuffer(), strText.GetLength()); mFile.Close(); } } short AfxHexValue(char chIn) { unsigned char ch = (unsigned char)chIn; if (ch >= '0' && ch <= '9') return (short)(ch - '0'); if (ch >= 'A' && ch <= 'F') return (short)(ch - 'A' + 10); if (ch >= 'a' && ch <= 'f') return (short)(ch - 'a' + 10); return -1; } BOOL AfxIsUnsafeUrlChar(char chIn) { unsigned char ch = (unsigned char)chIn; switch(ch) { case ';': case '\\': case '?': case '@': case '&': case '=': case '+': case '$': case ',': case ' ': case '<': case '>': case '#': case '%': case '\"': case '{': case '}': case '|': case '^': case '[': case ']': case '`': return TRUE; default: { if (ch < 32 || ch > 126) return TRUE; return FALSE; } } } CString URLDecode(LPCTSTR lpszURL) { CString strResult = _T(""); // Convert all escaped characters in lpszURL to their real values int nValue = 0; char ch; BOOL bContinue = TRUE; while ((ch = *lpszURL) != 0) { if (bContinue) { if (ch == '%') { if ((*(lpszURL+1) == '\0') || (*(lpszURL+2) == '\0')) { bContinue = FALSE; break; } ch = *(++lpszURL); // currently assuming 2 hex values after '%' as per the RFC 2396 document nValue = 16*AfxHexValue(ch); nValue+= AfxHexValue(*(++lpszURL)); strResult += (char)nValue; } else // non-escape character { if (bContinue) strResult += ch; } } lpszURL++; } // replace '+' with " " strResult.Replace(_T("+"), _T(" ")); return strResult; } enum { UNICODE_CALC_SIZE = 1, UNICODE_GET_BYTES = 2 }; //将unicode转义字符序列转换为内存中的unicode字符串 int unicode_bytes(char* p_unicode_escape_chars, wchar_t *bytes, int flag) { int unicode_count = 0; int length = strlen(p_unicode_escape_chars); for (int char_index = 0; char_index