int TInetFile::OpenFile(char*Url) { if(hUrl!=NULL)InternetCloseHandle(hUrl); if(internet!=NULL)InternetCloseHandle(internet); internet=InternetOpen(Application->Title.c_str(),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0); if(internet==(HANDLE)NULL) { return 1; } String sU=Url; sU=sU.UpperCase(); if(sU.Pos("FTP://")) //Это FTP файл { Protokol=INET_FILE_FTP; }else //Это HTTP файл { Protokol=INET_FILE_HTTP; } hUrl=InternetOpenUrl(internet,Url,NULL,0,INTERNET_FLAG_EXISTING_CONNECT,0); if(hUrl==NULL) { InternetCloseHandle(internet); return 2; } Error=false; CheckFileSize(); Position=0; return 0; }
/*----------------------------------------------------------------------- * Function : * Prototype : void CDebug::printf (const char *fmt, ... ) * Description : Prints formatted string to log-file * Parameters : const char *fmt - format string ... - list of parameters * Return : void * History : */ void CDebug::printf (int nLevel, const char* strMod, const char *fmt, ... ) { DWORD x; char buf[256]; SYSTEMTIME time; char buffer[MSG_BUFFER_SIZE]; char buffer2[MSG_BUFFER_SIZE]; va_list arglist; DWORD dwDiffTime; if((nLevel < m_nLogLevel) || (nLevel < 0) || !m_bEnabled) return; memset(buffer, 0, sizeof(buffer)); memset(buffer2, 0, sizeof(buffer2)); memset(buf, 0, sizeof(buf)); EnterCriticalSection(&m_hLock ); // Do this inside the section in case we have to delete // the file CheckFileSize(); // Format string va_start(arglist, fmt); wvsprintf(buffer, fmt, arglist); va_end(arglist); // Format time stamp GetLocalTime(&time); dwDiffTime = GetTickCount() - m_dwStartTime; SetFilePointer(m_hFile, 0, 0, FILE_END ); // XML Version if( m_bUseXML ) { ReplaceXMLChars(buffer, strlen(buffer), buffer2); wsprintf(buf, "<LINE><ELAPSED>%d.%03d</ELAPSED><DATE>%02d/%02d/%02d</DATE><TIME>%02d:%02d:%02d</TIME>", dwDiffTime/1000, dwDiffTime%1000, time.wMonth, time.wDay, time.wYear, time.wHour, time.wMinute, time.wSecond); WriteFile(m_hFile, buf, lstrlen(buf), &x, 0 ); wsprintf(buf, "<MODULE>%s</MODULE><MESSAGE>", strMod); WriteFile(m_hFile, buf, lstrlen(buf), &x, 0 ); if(nLevel == DEBUG_ERROR) WriteFile(m_hFile, "ERROR - ", 8, &x, 0 ); WriteFile(m_hFile, buffer2, lstrlen(buffer2), &x, 0 ); WriteFile(m_hFile, "</MESSAGE></LINE>", 17, &x, 0 ); } else { wsprintf(buf, "%d.%03d\t%02d/%02d/%02d %02d:%02d:%02d\t%s\t\t", dwDiffTime/1000, dwDiffTime%1000, time.wMonth, time.wDay, time.wYear, time.wHour, time.wMinute, time.wSecond, strMod); // Write time stamp and formatted string to log-file WriteFile(m_hFile, buf, lstrlen(buf), &x, 0 ); if(nLevel == DEBUG_ERROR) WriteFile(m_hFile, "ERROR - ", 8, &x, 0 ); WriteFile(m_hFile, buffer, lstrlen(buffer), &x, 0 ); WriteFile(m_hFile, CrLf, lstrlen(CrLf), &x, 0 ); } FlushFileBuffers(m_hFile); LeaveCriticalSection(&m_hLock ); }
int __cdecl main(int argc, char *argv[]) { HANDLE hFile = NULL; BOOL bRc = FALSE; DWORD lpNumberOfBytesWritten; LARGE_INTEGER qwFileSize; LARGE_INTEGER qwFileSize2; char * data = "1234567890"; qwFileSize.QuadPart = 0; qwFileSize2.QuadPart = 0; if (0 != PAL_Initialize(argc,argv)) { return FAIL; } /* test on a null file */ bRc = GetFileSizeEx(NULL, &qwFileSize); if (bRc != FALSE) { Fail("GetFileSizeEx: ERROR -> Returned status as TRUE for " "a null handle.\n"); } /* test on an invalid file */ bRc = GetFileSizeEx(INVALID_HANDLE_VALUE, &qwFileSize); if (bRc != FALSE) { Fail("GetFileSizeEx: ERROR -> Returned status as TRUE for " "an invalid handle.\n"); } /* create a test file */ hFile = CreateFile(szTextFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(hFile == INVALID_HANDLE_VALUE) { Fail("GetFileSizeEx: ERROR -> Unable to create file \"%s\".\n", szTextFile); } /* give the file a size */ CheckFileSize(hFile, 256, 0); /* make the file large using the high order option */ CheckFileSize(hFile, 256, 1); /* set the file size to zero */ CheckFileSize(hFile, 0, 0); /* test if file size changes by writing to it. */ /* get file size */ GetFileSizeEx(hFile, &qwFileSize); /* test writing to the file */ if(WriteFile(hFile, data, strlen(data), &lpNumberOfBytesWritten, NULL)==0) { Trace("GetFileSizeEx: ERROR -> Call to WriteFile failed with %ld.\n", GetLastError()); CleanUp(hFile); Fail(""); } /* make sure the buffer flushed.*/ if(FlushFileBuffers(hFile)==0) { Trace("GetFileSizeEx: ERROR -> Call to FlushFileBuffers failed with %ld.\n", GetLastError()); CleanUp(hFile); Fail(""); } /* get file size after writing some chars */ GetFileSizeEx(hFile, &qwFileSize2); if((qwFileSize2.QuadPart-qwFileSize.QuadPart) !=strlen(data)) { CleanUp(hFile); Fail("GetFileSizeEx: ERROR -> File size did not increase properly after.\n" "writing %d chars\n", strlen(data)); } CleanUp(hFile); PAL_Terminate(); return PASS; }
void Search::SearchLoop() { while(true) { if (!DownLevel()) { break; } while (SI.GetState()==SI.Ok && _srchState==Ok) { if (SI.IsDots()) { SI.NextItem(); if (SI.IsDots()) { SI.NextItem(); }; }else if (SI.IsReparsePoint()) { if (!_fsValid && CheckWord()) { std::wstring w(SI.GetPath()); w+=SI.GetName(); OutputString(w.c_str()); if(_srchState==Ok) { _directoriesFound++; }; } if (_srchState==Ok) { _directoryCount++; SI.NextItem(); } }else if (SI.IsDirectory()) { if (!_fsValid && CheckWord()) { std::wstring w(SI.GetPath()); w+=SI.GetName(); OutputString(w.c_str()); if(_srchState==Ok) { _directoriesFound++; }; }; if(_srchState==Ok) { _directoryCount++; OpenDir(); } }else { if (CheckWord() && CheckFileSize()) { std::wstring w(SI.GetPath()); w+=SI.GetName(); OutputString(w.c_str()); if (_srchState==Ok) { _filesFound++; } }; if(_srchState==Ok) { SI.NextItem(); _fileCount++;//Seems like it counts one too much, but the FindFirstFile isn't counted, so it evens out. //This is for the windows/winsxs folder, which often stalls the whole program if ((_fileCount%100==0)&&(clock()-_cycleTimer)>=150 && _stable) { SetTimer(_h,1,1,0); return; } } }; }; }; }