void CEllipseCenterGroup::AddPoint(CAtlList<EllipseCenter>& centers, IntersectFunction intersect, int x, int y) { POSITION pos = centers.GetTailPosition(); while (pos) { POSITION posCur = pos; auto& center = centers.GetPrev(pos); int dyIntersect = intersect(x - center.x, y - center.y); if (dyIntersect != CEllipse::NO_INTERSECT_INNER) { int yIntersect = (dyIntersect == CEllipse::NO_INTERSECT_OUTER) ? (y - m_pEllipse->GetYRadius() - 1) : (center.y + dyIntersect); if (yIntersect < center.yStopDrawing) { center.yStopDrawing = yIntersect; if (pos && center.yStopDrawing <= centers.GetAt(pos).yStopDrawing) { centers.RemoveAt(posCur); } } else { break; } } } auto& center = centers.GetAt(centers.AddTail()); center.x = x; center.y = y; center.yStopDrawing = y + m_pEllipse->GetYRadius(); }
void CWebServer::OnRequest(CWebClientSocket* pClient, CStringA& hdr, CStringA& body) { CPath p(pClient->m_path); CStringA ext = p.GetExtension().MakeLower(); CStringA mime; if (ext.IsEmpty()) { mime = "text/html"; } else { m_mimes.Lookup(ext, mime); } hdr = "HTTP/1.0 200 OK\r\n"; bool fHandled = false, fCGI = false; if (!fHandled && m_webroot.IsDirectory()) { CStringA tmphdr; fHandled = fCGI = CallCGI(pClient, tmphdr, body, mime); if (fHandled) { tmphdr.Replace("\r\n", "\n"); CAtlList<CStringA> hdrlines; ExplodeMin(tmphdr, hdrlines, '\n'); POSITION pos = hdrlines.GetHeadPosition(); while (pos) { POSITION cur = pos; CAtlList<CStringA> sl; CStringA key = Explode(hdrlines.GetNext(pos), sl, ':', 2); if (sl.GetCount() < 2) { continue; } key.Trim().MakeLower(); if (key == "content-type") { mime = sl.GetTail().Trim(); hdrlines.RemoveAt(cur); } else if (key == "content-length") { hdrlines.RemoveAt(cur); } } tmphdr = Implode(hdrlines, '\n'); tmphdr.Replace("\n", "\r\n"); hdr += tmphdr + "\r\n"; } } RequestHandler rh = NULL; if (!fHandled && m_internalpages.Lookup(pClient->m_path, rh) && (pClient->*rh)(hdr, body, mime)) { if (mime.IsEmpty()) { mime = "text/html"; } CString redir; if (pClient->m_get.Lookup(_T("redir"), redir) || pClient->m_post.Lookup(_T("redir"), redir)) { if (redir.IsEmpty()) { redir = '/'; } hdr = "HTTP/1.0 302 Found\r\n" "Location: " + CStringA(redir) + "\r\n"; return; } fHandled = true; } if (!fHandled && m_webroot.IsDirectory()) { fHandled = LoadPage(0, body, pClient->m_path); } UINT resid; CStringA res; if (!fHandled && m_downloads.Lookup(pClient->m_path, resid) && (LoadResource(resid, res, _T("FILE")) || LoadResource(resid, res, _T("PNG")))) { if (mime.IsEmpty()) { mime = "application/octet-stream"; } memcpy(body.GetBufferSetLength(res.GetLength()), res.GetBuffer(), res.GetLength()); fHandled = true; } if (!fHandled) { hdr = mime == "text/html" ? "HTTP/1.0 301 Moved Permanently\r\n" "Location: /404.html\r\n" : "HTTP/1.0 404 Not Found\r\n"; return; } if ((mime == "text/html" || mime == "text/javascript") && !fCGI) { if (mime == "text/html") { hdr += "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n" "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n" "Pragma: no-cache\r\n"; CStringA debug; if (AfxGetAppSettings().fWebServerPrintDebugInfo) { debug += "<br><hr>\r\n"; debug += "<div id=\"debug\">"; CString key, value; POSITION pos; pos = pClient->m_hdrlines.GetStartPosition(); while (pos) { pClient->m_hdrlines.GetNextAssoc(pos, key, value); debug += "HEADER[" + key + "] = " + value + "\r\n"; } debug += "cmd: " + pClient->m_cmd + "\r\n"; debug += "path: " + pClient->m_path + "\r\n"; debug += "ver: " + pClient->m_ver + "\r\n"; pos = pClient->m_get.GetStartPosition(); while (pos) { pClient->m_get.GetNextAssoc(pos, key, value); debug += "GET[" + key + "] = " + value + "\r\n"; } pos = pClient->m_post.GetStartPosition(); while (pos) { pClient->m_post.GetNextAssoc(pos, key, value); debug += "POST[" + key + "] = " + value + "\r\n"; } pos = pClient->m_cookie.GetStartPosition(); while (pos) { pClient->m_cookie.GetNextAssoc(pos, key, value); debug += "COOKIE[" + key + "] = " + value + "\r\n"; } pos = pClient->m_request.GetStartPosition(); while (pos) { pClient->m_request.GetNextAssoc(pos, key, value); debug += "REQUEST[" + key + "] = " + value + "\r\n"; } debug += "</div>"; } body.Replace("[debug]", debug); } body.Replace("[browserpath]", "/browser.html"); body.Replace("[commandpath]", "/command.html"); body.Replace("[controlspath]", "/controls.html"); body.Replace("[indexpath]", "/index.html"); body.Replace("[path]", CStringA(pClient->m_path)); body.Replace("[setposcommand]", CMD_SETPOS); body.Replace("[setvolumecommand]", CMD_SETVOLUME); body.Replace("[wmcname]", "wm_command"); // TODO: add more general tags to replace } // gzip if (AfxGetAppSettings().fWebServerUseCompression && hdr.Find("Content-Encoding:") < 0) do { CString accept_encoding; pClient->m_hdrlines.Lookup(_T("accept-encoding"), accept_encoding); accept_encoding.MakeLower(); CAtlList<CString> sl; ExplodeMin(accept_encoding, sl, ','); if (!sl.Find(_T("gzip"))) { break; } CHAR path[_MAX_PATH], fn[_MAX_PATH]; if (!GetTempPathA(_MAX_PATH, path) || !GetTempFileNameA(path, "mpc_gz", 0, fn)) { break; } gzFile gf = gzopen(fn, "wb9"); if (!gf || gzwrite(gf, (LPVOID)(LPCSTR)body, body.GetLength()) != body.GetLength()) { if (gf) { gzclose(gf); } DeleteFileA(fn); break; } gzclose(gf); FILE* f = NULL; if (fopen_s(&f, fn, "rb")) { DeleteFileA(fn); break; } fseek(f, 0, 2); CHAR* s = body.GetBufferSetLength(ftell(f)); fseek(f, 0, 0); int len = (int)fread(s, 1, body.GetLength(), f); ASSERT(len == body.GetLength()); #ifndef _DEBUG UNREFERENCED_PARAMETER(len); #endif fclose(f); DeleteFileA(fn); hdr += "Content-Encoding: gzip\r\n"; } while (0); CStringA content; content.Format( "Content-Type: %s\r\n" "Content-Length: %d\r\n", mime, body.GetLength()); hdr += content; }
void CWebServer::OnRequest(CWebClientSocket* pClient, CStringA& hdr, CStringA& body) { CPath p(AToT(pClient->m_path)); CStringA ext = p.GetExtension().MakeLower(); CStringA mime; if (ext.IsEmpty()) { mime = "text/html"; } else { m_mimes.Lookup(ext, mime); } hdr = "HTTP/1.0 200 OK\r\n"; bool fHandled = false, fCGI = false; if (!fHandled && m_webroot.IsDirectory()) { CStringA tmphdr; fHandled = fCGI = CallCGI(pClient, tmphdr, body, mime); if (fHandled) { tmphdr.Replace("\r\n", "\n"); CAtlList<CStringA> hdrlines; ExplodeMin(tmphdr, hdrlines, '\n'); POSITION pos = hdrlines.GetHeadPosition(); while (pos) { POSITION cur = pos; CAtlList<CStringA> sl; CStringA key = Explode(hdrlines.GetNext(pos), sl, ':', 2); if (sl.GetCount() < 2) { continue; } key.Trim().MakeLower(); if (key == "content-type") { mime = sl.GetTail().Trim(); hdrlines.RemoveAt(cur); } else if (key == "content-length") { hdrlines.RemoveAt(cur); } } tmphdr = Implode(hdrlines, "\r\n"); hdr += tmphdr + "\r\n"; } } RequestHandler rh = NULL; if (!fHandled && m_internalpages.Lookup(pClient->m_path, rh) && (pClient->*rh)(hdr, body, mime)) { if (mime.IsEmpty()) { mime = "text/html"; } CString redir; if (pClient->m_get.Lookup("redir", redir) || pClient->m_post.Lookup("redir", redir)) { if (redir.IsEmpty()) { redir = '/'; } hdr = "HTTP/1.0 302 Found\r\n" "Location: " + CStringA(redir) + "\r\n"; return; } fHandled = true; } if (!fHandled && m_webroot.IsDirectory()) { fHandled = LoadPage(0, body, UTF8To16(pClient->m_path)); } UINT resid; if (!fHandled && m_downloads.Lookup(pClient->m_path, resid) && (LoadResource(resid, body, _T("FILE")) || LoadResource(resid, body, _T("PNG")))) { if (mime.IsEmpty()) { mime = "application/octet-stream"; } fHandled = true; } if (!fHandled) { hdr = mime == "text/html" ? "HTTP/1.0 301 Moved Permanently\r\n" "Location: /404.html\r\n" : "HTTP/1.0 404 Not Found\r\n"; return; } if ((mime == "text/html" || mime == "text/javascript") && !fCGI) { if (mime == "text/html") { hdr += "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n" "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n" "Pragma: no-cache\r\n"; CStringA debug; if (AfxGetAppSettings().fWebServerPrintDebugInfo) { debug += "<br><hr>\r\n"; debug += "<div id=\"debug\">"; CStringA key; POSITION pos; { CStringA value; pos = pClient->m_hdrlines.GetStartPosition(); while (pos) { pClient->m_hdrlines.GetNextAssoc(pos, key, value); debug += "HEADER[" + key + "] = " + value + "\r\n"; } } debug += "cmd: " + pClient->m_cmd + "\r\n"; debug += "path: " + pClient->m_path + "\r\n"; debug += "ver: " + pClient->m_ver + "\r\n"; { CString value; pos = pClient->m_get.GetStartPosition(); while (pos) { pClient->m_get.GetNextAssoc(pos, key, value); debug += "GET[" + HtmlSpecialChars(key) + "] = " + HtmlSpecialChars(UTF8(value)) + "\r\n"; } pos = pClient->m_post.GetStartPosition(); while (pos) { pClient->m_post.GetNextAssoc(pos, key, value); debug += "POST[" + HtmlSpecialChars(key) + "] = " + HtmlSpecialChars(UTF8(value)) + "\r\n"; } pos = pClient->m_cookie.GetStartPosition(); while (pos) { pClient->m_cookie.GetNextAssoc(pos, key, value); debug += "COOKIE[" + HtmlSpecialChars(key) + "] = " + HtmlSpecialChars(UTF8(value)) + "\r\n"; } pos = pClient->m_request.GetStartPosition(); while (pos) { pClient->m_request.GetNextAssoc(pos, key, value); debug += "REQUEST[" + HtmlSpecialChars(key) + "] = " + HtmlSpecialChars(UTF8(value)) + "\r\n"; } } debug += "</div>"; } body.Replace("[debug]", debug); } body.Replace("[browserpath]", "/browser.html"); body.Replace("[commandpath]", "/command.html"); body.Replace("[controlspath]", "/controls.html"); body.Replace("[indexpath]", "/index.html"); body.Replace("[path]", pClient->m_path); body.Replace("[setposcommand]", CMD_SETPOS); body.Replace("[setvolumecommand]", CMD_SETVOLUME); body.Replace("[wmcname]", "wm_command"); // TODO: add more general tags to replace } // gzip if (AfxGetAppSettings().fWebServerUseCompression && !body.IsEmpty() && hdr.Find("Content-Encoding:") < 0 && ext != ".png" && ext != ".jpeg" && ext != ".gif") do { CStringA accept_encoding; pClient->m_hdrlines.Lookup("accept-encoding", accept_encoding); accept_encoding.MakeLower(); CAtlList<CStringA> sl; ExplodeMin(accept_encoding, sl, ','); if (!sl.Find("gzip")) { break; } // Allocate deflate state z_stream strm; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; int ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY); if (ret != Z_OK) { ASSERT(0); break; } int gzippedBuffLen = body.GetLength(); BYTE* gzippedBuff = DEBUG_NEW BYTE[gzippedBuffLen]; // Compress strm.avail_in = body.GetLength(); strm.next_in = (Bytef*)(LPCSTR)body; strm.avail_out = gzippedBuffLen; strm.next_out = gzippedBuff; ret = deflate(&strm, Z_FINISH); if (ret != Z_STREAM_END || strm.avail_in != 0) { ASSERT(0); deflateEnd(&strm); delete [] gzippedBuff; break; } gzippedBuffLen -= strm.avail_out; memcpy(body.GetBufferSetLength(gzippedBuffLen), gzippedBuff, gzippedBuffLen); // Clean up deflateEnd(&strm); delete [] gzippedBuff; hdr += "Content-Encoding: gzip\r\n"; } while (0); CStringA content; content.Format( "Content-Type: %s\r\n" "Content-Length: %d\r\n", mime, body.GetLength()); hdr += content; }
BOOL bigfilehelper::GetAutoDestDirFromSize(CString& strDir) { BOOL retval = FALSE; CAtlArray<TCHAR> buffer; TCHAR* pBuffer = NULL; DWORD dwSize; CAtlList<CString> logicalDrvs; CString strDrv; POSITION pos = NULL; POSITION max_size_pos = NULL; ULONGLONG uMaxSize = 0; DWORD dwSectorsPerCluster; DWORD dwBytesPerSector; DWORD dwNumberOfFreeClusters; DWORD dwTotalNumberOfClusters; CString strSysDrv; TCHAR szVolName[MAX_PATH+1] = { 0 }; TCHAR szFileSystem[MAX_PATH+1] = { 0 }; BOOL fRetCode; SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS); if (!GetSystemDrive(strSysDrv)) goto clean0; buffer.SetCount(512); pBuffer = buffer.GetData(); dwSize = (DWORD)buffer.GetCount(); memset(pBuffer, 0, dwSize * sizeof(TCHAR)); dwSize = GetLogicalDriveStrings(dwSize, buffer.GetData()); if (dwSize > 2) { strDrv = pBuffer; logicalDrvs.AddTail(strDrv); for (DWORD i = 3; i < dwSize; ++i) { if (pBuffer[i] != 0 && pBuffer[i - 1] == 0) { strDrv = pBuffer + i; logicalDrvs.AddTail(strDrv); } } } pos = logicalDrvs.GetHeadPosition(); while (pos) { POSITION current = pos; CString _drv = logicalDrvs.GetNext(pos); _drv.MakeLower(); if (_drv == _T("a:\\") || _drv == _T("b:\\")) { logicalDrvs.RemoveAt(current); continue; } UINT uType = GetDriveType(_drv); if (uType != DRIVE_FIXED && uType != DRIVE_REMOVABLE) { logicalDrvs.RemoveAt(current); continue; } if (strSysDrv.CompareNoCase(_drv)==0) { logicalDrvs.RemoveAt(current); continue; } RtlZeroMemory(szVolName, sizeof(szVolName)); RtlZeroMemory(szFileSystem, sizeof(szFileSystem)); fRetCode = GetVolumeInformation( _drv, szVolName, MAX_PATH+1, NULL, NULL, NULL, szFileSystem, MAX_PATH+1 ); if (!fRetCode) { logicalDrvs.RemoveAt(current); continue; } } pos = logicalDrvs.GetHeadPosition(); while (pos) { POSITION current = pos; const CString& _drv = logicalDrvs.GetNext(pos); BOOL fRetCode = GetDiskFreeSpace( _drv, &dwSectorsPerCluster, &dwBytesPerSector, &dwNumberOfFreeClusters, &dwTotalNumberOfClusters ); if (!fRetCode) continue; ULONGLONG uCurrentFreeSize = (ULONGLONG)dwNumberOfFreeClusters * dwSectorsPerCluster * dwBytesPerSector; if (uCurrentFreeSize > uMaxSize) { max_size_pos = current; uMaxSize = uCurrentFreeSize; } } if (max_size_pos==NULL) goto clean0; strDir = logicalDrvs.GetAt(max_size_pos); strDir += _T("系统盘大文件"); retval = TRUE; clean0: return retval; }
void cupdatenetlib::tryRealUpdate(BOOL bNoWaiting){ struct szaMoveFile { CString szMoveSrcFile; CString szMoveDestFile; }; CAtlList<szaMoveFile> szaMoveFiles; for(int i = 0; i < m_UpdateFileArray.GetCount(); i++){ //if(szaLists.GetCount() < (i+LFILETOTALPARMS)){ break; } UpdateInfo* pInfo = (UpdateInfo*) m_UpdateFileArray.GetAt(i); CString szSetupPath = pInfo->strPath; //SVP_LogMsg5(L"Move %s %d",szSetupPath ,pInfo->bReadyToCopy ); if (szSetupPath.CompareNoCase( _T("splayer.exe")) == 0){ if(!svpToolBox.ifFileExist(szBasePath + szSetupPath) ){ if (svpToolBox.ifFileExist(szBasePath + _T("mplayerc.exe"))) szSetupPath = _T("mplayerc.exe"); else if (svpToolBox.ifFileExist(szBasePath + _T("svplayer.exe"))) szSetupPath = _T("svplayer.exe"); else szSetupPath = _T("splayer.exe"); } } bool bUpdateThis = pInfo->bReadyToCopy ? true : false; if(bUpdateThis){ //if not match download szaMoveFile mFiles; mFiles.szMoveSrcFile = szUpdfilesPath + pInfo->strTempName ; mFiles.szMoveDestFile = szBasePath + szSetupPath; szaMoveFiles.AddTail(mFiles); // while( MoveFileEx( szUpdfilesPath + szaLists.GetAt(i+LFILETMPATH) , szBasePath + szSetupPath , MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH) == 0 ){ // Sleep(50000); // } } } BOOL bFirstRound = true; while(1){ POSITION pos = szaMoveFiles.GetHeadPosition(); if(!pos){ break;} bWaiting = TRUE; while(pos){ szaMoveFile mFiles; POSITION orgPos = pos; mFiles = szaMoveFiles.GetNext(pos); if(!svpToolBox.ifFileExist(mFiles.szMoveSrcFile)){ szaMoveFiles.RemoveAt(orgPos); continue; } svpToolBox.CreatDirForFile(mFiles.szMoveDestFile); SetFileAttributes(mFiles.szMoveDestFile , FILE_ATTRIBUTE_NORMAL); //SVP_LogMsg5(L"Move %s %s", mFiles.szMoveSrcFile , mFiles.szMoveDestFile ); if( MoveFileEx( mFiles.szMoveSrcFile , mFiles.szMoveDestFile , MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH) == 0 && bFirstRound){ // only use MOVEFILE_DELAY_UNTIL_REBOOT on FirstRound MoveFileEx( mFiles.szMoveSrcFile , mFiles.szMoveDestFile , /*MOVEFILE_COPY_ALLOWED|*/MOVEFILE_REPLACE_EXISTING|MOVEFILE_DELAY_UNTIL_REBOOT) ; } /* if(mFiles.szMoveDestFile.Right(11).CompareNoCase(_T("Updater.exe")) == 0){ szaMoveFiles.RemoveAt(orgPos); continue; } SVP_LogMsg5(mFiles.szMoveDestFile.Right(11));*/ } bFirstRound = FALSE; Sleep(1500); if(bNoWaiting) break; } bWaiting = FALSE; }
static BOOL ValidateItem(int index, BOOL bNewState, BOOL bDisplayErrors) { ServiceItem* pSvcItem = NULL; LVITEM truc = {}; truc.mask = LVIF_PARAM; truc.iItem = index; ListView_GetItem(hServicesListCtrl, &truc); // The lParam member must be valid. pSvcItem = reinterpret_cast<ServiceItem*>(truc.lParam); if (!pSvcItem) return FALSE; // // Allow modifications only if the service is not a required service for the system, // or allow only the activation of a disabled required service. // BOOL bOldState = !!(ListView_GetCheckState(hServicesListCtrl, truc.iItem /* == index */) % 2); if ( !pSvcItem->m_bIsRequired || (pSvcItem->m_bIsRequired && !pSvcItem->m_bIsEnabled && bOldState == FALSE && bNewState == TRUE) ) { if (bOldState == bNewState) return FALSE; ListView_SetCheckState(hServicesListCtrl, index, bNewState); if (pSvcItem->m_bIsEnabled) // Enabled service. { if (bNewState == FALSE) // To be deactivated. { userModificationsList.AddTail(pSvcItem->m_lpszSvcName); } else if (bNewState == TRUE) // To be reactivated { POSITION it = userModificationsList.Find(pSvcItem->m_lpszSvcName); if (it) { userModificationsList.RemoveAt(it); } else { OutputDebugString(_T("(1) \"WTF: What The Fukhurmajalmahamadahaldeliya ?!\" (The Dictator, Sacha Baron Cohen)\n")); } } } else // Disabled service. { if (bNewState == TRUE) // To be activated. { userModificationsList.AddTail(pSvcItem->m_lpszSvcName); } else if (bNewState == FALSE) // To be redeactivated { POSITION it = userModificationsList.Find(pSvcItem->m_lpszSvcName); if (it) { userModificationsList.RemoveAt(it); } else { OutputDebugString(_T("(2) \"WTF: What The Fukhurmajalmahamadahaldeliya ?!\" (The Dictator, Sacha Baron Cohen)\n")); } } } return TRUE; } else { if (bDisplayErrors) { DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_REQUIRED_SERVICES_DISABLING_DIALOG), hServicesPage /* hMainWnd */, RequiredServicesDisablingDialogWndProc); } return FALSE; } }