Esempio n. 1
0
int
www_fetch(char *url, char *savefile)
{    
  HINTERNET hUrlDump;
  extern HINTERNET hInternetSession; 
  DWORD dwSize=TRUE;
  LPSTR lpszData;
  LPSTR lpszOutPut;
  LPSTR lpszHolding;
  int nCounter=1;
  int nBufferSize;
  DWORD BigSize=8000;
  FILE *fSave;

  if ((fSave = fopen(savefile, "wb")) == NULL) {
    perror("www_fetch");
    return 0;
  }

  hUrlDump = InternetOpenUrl(hInternetSession, url, NULL, 0, 
			     INTERNET_FLAG_RAW_DATA, 0);
  if (!hUrlDump) {
    Win32Error("www_fetch/InternetOpenUrl");
    fclose(fSave);
    return 0;
  }

  do {

    /* Read the data */
    if(InternetReadFile(hUrlDump,(LPVOID)lpszData,BigSize,&dwSize) == FALSE) {
      Win32Error("www_fetch/InternetReadFile");
      break;
    }
    else {
      fwrite(lpszData, sizeof(char), dwSize , fSave);
      if (dwSize == 0) {
	break;
      }
    }
  }
  while (TRUE);
  
  /* Close the HINTERNET handle */
  InternetCloseHandle(hUrlDump);
  
  /* Set the cursor back to an arrow */
  SetCursor(LoadCursor(NULL,IDC_ARROW));
  
  /* Return */
  return TRUE;
}
Esempio n. 2
0
File: Files.cpp Progetto: lcs2/carpg
size_t FileStream::Read(void *Data, size_t Size)
{
	uint4 ReadSize;
	if (ReadFile(pimpl->m_File, Data, Size, (LPDWORD)&ReadSize, 0) == 0)
		throw Win32Error(Format("Nie mo¿na odczytaæ # B z pliku") % Size, __FILE__, __LINE__);
	return ReadSize;
}
Esempio n. 3
0
ComInitialization::ComInitialization()
{
    // OleInitialize/OleUninitialize is used instead of CoInitializeEx/CoUninitialize because it is required for use of IDropTarget's Drag and Drop functions
	HRESULT hr = OleInitialize(nullptr);
	if (FAILED(hr))
		throw Win32Error(hr, "OleInitialize");
}
bool FileInputStream::eof(){
	LARGE_INTEGER li, size;
	li.QuadPart = 0;
	if (!SetFilePointerEx(this->file, li, &li, FILE_CURRENT))
		throw Win32Error();
	GetFileSizeEx(this->file, &size);
	return li.QuadPart >= size.QuadPart;
}
Esempio n. 5
0
File: Files.cpp Progetto: lcs2/carpg
void FileStream::Write(const void *Data, size_t Size)
{
	uint4 WrittenSize;
	if (WriteFile(pimpl->m_File, Data, Size, (LPDWORD)&WrittenSize, 0) == 0)
		throw Win32Error(Format("Nie mo¿na zapisaæ # B do pliku") % Size, __FILE__, __LINE__);
	if (WrittenSize != Size)
		throw Error(Format("Nie mo¿na zapisaæ do pliku - zapisanych bajtów #/#") % WrittenSize % Size, __FILE__, __LINE__);
}
Esempio n. 6
0
File: Files.cpp Progetto: lcs2/carpg
int FileStream::GetPos()
{
	// Fuj! Ale to nieeleganckie. Szkoda, ¿e nie ma lepszego sposobu.
	uint4 r = SetFilePointer(pimpl->m_File, 0, 0, FILE_CURRENT);
	if (r == INVALID_SET_FILE_POINTER)
		throw Win32Error("Nie mo¿na odczytaæ pozycji w strumieniu plikowym", __FILE__, __LINE__);
	return (int)r;
}
void FileOutputStream::write(const void *buffer, size_t size){
	while (size){
		DWORD bytes_written;
		auto success = WriteFile(this->file, buffer, size & 0xFFFFFFFF, &bytes_written, nullptr);
		if (!success)
			throw Win32Error();
		if (bytes_written > size)
			// Huh?
			size = 0;
		else
			size -= bytes_written;
		buffer = (char *)buffer + bytes_written;
	}
}
Esempio n. 8
0
File: Files.cpp Progetto: lcs2/carpg
FileStream::FileStream(const string &FileName, FILE_MODE FileMode, bool Lock) :
	pimpl(new File_pimpl)
{
	uint4 DesiredAccess, ShareMode, CreationDisposition;
	switch (FileMode)
	{
	case FM_WRITE:
		DesiredAccess = GENERIC_WRITE;
		ShareMode = 0;
		CreationDisposition = CREATE_ALWAYS;
		break;
	case FM_WRITE_PLUS:
		DesiredAccess = GENERIC_WRITE | GENERIC_READ;
		ShareMode = 0;
		CreationDisposition = CREATE_ALWAYS;
		break;
	case FM_READ:
		DesiredAccess = GENERIC_READ;
		ShareMode = FILE_SHARE_READ;
		CreationDisposition = OPEN_EXISTING;
		break;
	case FM_READ_PLUS:
		DesiredAccess = GENERIC_WRITE | GENERIC_READ;
		ShareMode = 0;
		CreationDisposition = OPEN_EXISTING;
		break;
	case FM_APPEND:
		DesiredAccess = GENERIC_WRITE;
		ShareMode = 0;
		CreationDisposition = OPEN_ALWAYS;
		break;
	case FM_APPEND_PLUS:
		DesiredAccess = GENERIC_WRITE | GENERIC_READ;
		ShareMode = 0;
		CreationDisposition = OPEN_ALWAYS;
		break;
	}
	if (!Lock)
		ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;

	pimpl->m_File = CreateFileA(FileName.c_str(), DesiredAccess, ShareMode, 0, CreationDisposition, FILE_ATTRIBUTE_NORMAL, 0);
	if (pimpl->m_File == INVALID_HANDLE_VALUE)
		throw Win32Error("Nie mo¿na otworzyæ pliku: "+FileName, __FILE__, __LINE__);

	if (FileMode == FM_APPEND || FileMode == FM_APPEND_PLUS)
		SetPosFromEnd(0);
}
size_t FileInputStream::read(void *buffer, size_t size){
	size_t ret = 0;
	while (size){
		DWORD bytes_read;
		auto success = ReadFile(this->file, buffer, size & 0xFFFFFFFF, &bytes_read, nullptr);
		if (!success)
			throw Win32Error();
		if (bytes_read > size)
			// Huh?
			size = 0;
		else
			size -= bytes_read;
		buffer = (char *)buffer + bytes_read;
		ret += bytes_read;
	}
	return ret;
}
Esempio n. 10
0
FileOutputStream::FileOutputStream(const wchar_t *_path){
	auto path = path_from_string(_path);
	this->file = CreateFileW(path.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, 0, nullptr);
	if (this->file == INVALID_HANDLE_VALUE)
		throw Win32Error();
}
Esempio n. 11
0
FileInputStream::FileInputStream(const wchar_t *_path){
	auto path = path_from_string(_path);
	this->file = CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr);
	if (this->file == INVALID_HANDLE_VALUE)
		throw Win32Error();
}
Esempio n. 12
0
void __cdecl InitGui(void *param)
{
  HWND hparentwnd;
  HANDLE hinst;
  WNDCLASSEX wndclass;
  char szFile[80];

  hinst = GetModuleHandle(NULL);
  GetModuleFileName (hinst, szFile, sizeof(szFile));
#ifdef DEBUG
  printf ("hinst = %x\n", hinst);
  printf ("File = %s\n", szFile);
#endif
  /* Fill in window class structure with parameters that describe
     the main window. */
  /* CS_OWNDC : un DC pour chaque fenêtre de la classe */
  wndclass.cbSize        = sizeof(wndclass);
  wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wndclass.lpfnWndProc   = (WNDPROC)WndProc;
  wndclass.cbClsExtra    = 0;
  wndclass.cbWndExtra    = 0;
  wndclass.hInstance     = hinst;
  wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION);
  wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  wndclass.lpszClassName = szFile;
  wndclass.lpszMenuName  = NULL;

  if (!RegisterClassEx(&wndclass))
    Win32Error("Register class");

  hparentwnd = GetFocus();
  my_window = CreateWindow(szFile, szTitle, 
			   WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
			   CW_USEDEFAULT, 0, 
			   CW_USEDEFAULT, 0,
			   /* screenwidth, screendepth, */
			   hparentwnd, NULL, hinst, NULL);
  if (!my_window) {
    Win32Error("Create window");
  }
#ifdef DEBUG
  fprintf(stderr, "my_window = %x\n", my_window);
#endif
  
#ifdef LOOPMSG
  /* Acknowledge for UpdateWindow() (WM_PAINT message generated) */
  hMutex = CreateMutex(NULL, FALSE, "DrawingMutex");
  my_dc = GetDC(my_window);
  /* Device context for drawing and the associated bitmap. */
  drawing_dc = CreateCompatibleDC(my_dc);
  hbm = CreateCompatibleBitmap(my_dc, screenwidth, screendepth);
  SelectObject(drawing_dc, hbm);
  /* Blank the bitmap */
  SelectObject(drawing_dc, GetStockObject(WHITE_BRUSH));
  PatBlt(drawing_dc, 0, 0, screenwidth, screendepth, PATCOPY);
  hAccelTable = LoadAccelerators (hinst, szTitle);

  ShowWindow(my_window, SW_SHOWNORMAL);
  UpdateWindow(my_window);

  /* Running the message loop */
  while (GetMessage(&msg, my_window, 0, 0)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }

#else
  drawing_dc = my_dc = GetDC(my_window);
#endif
}
Esempio n. 13
0
LRESULT APIENTRY WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
  PAINTSTRUCT ps;
  int retval = 0;

#ifdef DEBUG
  fprintf(stderr, "Message %x\n", iMsg);
#endif
#ifdef LOOPMSG
  WaitForSingleObject(hMutex, INFINITE);
  switch (iMsg) {
  case WM_CREATE:
    xMinScroll = 0;
    xMaxScroll = screenwidth;
    xCurrentScroll = 0;

    yMinScroll = 0;
    yMaxScroll = screendepth;
    yCurrentScroll = 0;

    fScroll = FALSE;
    fSize = FALSE;

    break;
  case WM_SIZE:
    {
      int xNewSize, yNewSize;
      xNewSize = LOWORD(lParam);
      yNewSize = HIWORD(lParam);

      fSize = TRUE;

      xMaxScroll = max(screenwidth, xNewSize);
      xCurrentScroll = min(xCurrentScroll, xMaxScroll);

      si.cbSize = sizeof(si);
      si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
      si.nMin = xMinScroll;
      si.nMax = xMaxScroll;
      si.nPage = xNewSize;
      si.nPos = xCurrentScroll;
      SetScrollInfo(my_window, SB_HORZ, &si, TRUE);

      yMaxScroll = max(screendepth, yNewSize);
      yCurrentScroll = min(yCurrentScroll, yMaxScroll);

      si.cbSize = sizeof(si);
      si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
      si.nMin = yMinScroll;
      si.nMax = yMaxScroll;
      si.nPage = yNewSize;
      si.nPos = yCurrentScroll;
      SetScrollInfo(my_window, SB_VERT, &si, TRUE);
      }
  case WM_PAINT:
    {
#ifdef DEBUG
      fprintf(stderr, "WM_PAINT message hbm = %x\n", hbm);
#endif
      BeginPaint(my_window, &ps);
      /* Shouldn't repaint all the screen, but so easy! */
      if (!BitBlt(my_dc,
		    0, 0, 
		    screenwidth, screendepth,
		    drawing_dc, 
		    xCurrentScroll, 
		    yCurrentScroll, SRCCOPY))
		Win32Error("Bitblt");
      EndPaint(my_window, &ps);
      retval = 0;
      break;
    }
  case WM_HSCROLL:
    {
      int xDelta;
      int xNewPos;
      int yDelta = 0;
      switch (LOWORD(wParam)) {
      case SB_PAGEUP:
	xNewPos = xCurrentScroll - 50;
	break;
      case SB_PAGEDOWN:
	xNewPos = xCurrentScroll + 50;
	break;
      case SB_LINEUP:
	xNewPos = xCurrentScroll - 5;
	break;
      case SB_LINEDOWN:
	xNewPos = xCurrentScroll + 5;
	break;
      case SB_THUMBPOSITION:
	xNewPos = HIWORD(wParam);
	break;
      default:
	xNewPos = xCurrentScroll;
      }
      xNewPos = max(0, xNewPos);
      xNewPos = min(xMaxScroll, xNewPos);
      
      if (xNewPos == xCurrentScroll)
	break;
      
      fScroll = TRUE;
      
      xDelta = xNewPos - xCurrentScroll;
      xCurrentScroll = xNewPos;
      
      ScrollWindowEx(my_window, -xDelta, -yDelta, (CONST RECT *)NULL,
		     (CONST RECT *)NULL, (HRGN)NULL, (LPRECT)NULL,
		     SW_INVALIDATE);
      UpdateWindow(my_window);
      
      si.cbSize = sizeof(si);
      si.fMask = SIF_POS;
      si.nPos = xCurrentScroll;
      SetScrollInfo(my_window, SB_HORZ, &si, TRUE);
    }
  break;

  case WM_VSCROLL:
    {
      int xDelta = 0;
      int yNewPos;
      int yDelta;
      switch (LOWORD(wParam)) {
      case SB_PAGEUP:
	yNewPos = yCurrentScroll - 50;
	break;
      case SB_PAGEDOWN:
	yNewPos = yCurrentScroll + 50;
	break;
      case SB_LINEUP:
	yNewPos = yCurrentScroll - 5;
	break;
      case SB_LINEDOWN:
	yNewPos = yCurrentScroll + 5;
	break;
      case SB_THUMBPOSITION:
	yNewPos = HIWORD(wParam);
	break;
      default:
	yNewPos = yCurrentScroll;
      }
      yNewPos = max(0, yNewPos);
      yNewPos = min(yMaxScroll, yNewPos);
      
      if (yNewPos == yCurrentScroll)
	break;
      
      fScroll = TRUE;
      
      yDelta = yNewPos - yCurrentScroll;
      yCurrentScroll = yNewPos;
      
      ScrollWindowEx(my_window, -xDelta, -yDelta, (CONST RECT *)NULL,
		     (CONST RECT *)NULL, (HRGN)NULL, (LPRECT)NULL,
		     SW_INVALIDATE);
      UpdateWindow(my_window);
      
      si.cbSize = sizeof(si);
      si.fMask = SIF_POS;
      si.nPos = yCurrentScroll;
      SetScrollInfo(my_window, SB_VERT, &si, TRUE);
    }
  break;
  
  case WM_DESTROY:
    PostQuitMessage(0);
    retval = 0;
    break;
  default:
    retval = DefWindowProc(hwnd, iMsg, wParam, lParam);
    break;
  }
  ReleaseMutex(hMutex);
  return retval;
#else
  return DefWindowProc(hwnd, iMsg, wParam, lParam);
#endif
}
Esempio n. 14
0
File: Files.cpp Progetto: lcs2/carpg
void FileStream::Truncate()
{
	if (SetEndOfFile(pimpl->m_File) == 0)
		throw Win32Error("Nie mo¿na obci¹æ pliku", __FILE__, __LINE__);
}
Esempio n. 15
0
File: Files.cpp Progetto: lcs2/carpg
void FileStream::SetPosFromEnd(int pos)
{
	if (SetFilePointer(pimpl->m_File, pos, 0, FILE_END) == INVALID_SET_FILE_POINTER)
		throw Win32Error(Format("Nie mo¿na przesun¹æ pozycji w strumieniu plikowym do # od koñca") % pos, __FILE__, __LINE__);
}
Esempio n. 16
0
File: Files.cpp Progetto: lcs2/carpg
void FileStream::SetPosFromCurrent(int pos)
{
	if (SetFilePointer(pimpl->m_File, pos, 0, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
		throw Win32Error(Format("Nie mo¿na przesun¹æ pozycji w strumieniu plikowym do # od bie¿¹cej") % pos, __FILE__, __LINE__);
}