Example #1
0
/*
 * DownloadUnarchiveFile: Unarchive archive zip_name to given
 *   directory.  Return True on success.
 */
Bool DownloadUnarchiveFile(char *zip_name, char *dir)
{
   Bool retval = True;

   // Does file exist?
   struct stat s;
   if (stat(zip_name, &s) != 0)
   {
      ClientError(hInst, hDownloadDialog, IDS_MISSINGARCHIVE, zip_name);
      return False;
   }

   while (1)
   {
      extraction_error = 0;
      TransferMessage(GetString(hInst, IDS_DECOMPRESSING));

      ExtractArchive(zip_name, dir);
      
      if (extraction_error == 0)
         // This means the user hit the abort button
         break;
      
      if (!AreYouSure(hInst, hDownloadDialog, YES_BUTTON, IDS_CANTUNCOMPRESS, 
                      zip_name, GetString(hInst, extraction_error)))
      {
         retval = False;
         break;
      }
   }

   return retval;
}
Example #2
0
/*
 * DownloadUncrushFile:  Unarchive Crusher archive zip_name to given directory.
 *   Return True on success.
 */
Bool DownloadUncrushFile(char *zip_name, char *dir)
{
   Bool retval = True;

   // Does file exist?
   struct stat s;
   if (stat(zip_name, &s) != 0)
   {
      ClientError(hInst, hDownloadDialog, IDS_MISSINGARCHIVE, zip_name);
      return False;
   }

   if (!WrapIsArchive(zip_name))
   {
      ClientError(hInst, hDownloadDialog, IDS_BADARCHIVE2, zip_name);
      return False;
   }

   WrapSetExtractionCallback(DownloadProgressCallback);

   while (1)
   {
      char temp_path[MAX_PATH];
      extraction_error = 0;
      TransferMessage(GetString(hInst, IDS_DECOMPRESSING));

      GetTempPath(sizeof(temp_path), temp_path);
      WrapExtractArchive(zip_name, dir, temp_path);
      
      if (extraction_error == 0)
         break;
      
      if (!AreYouSure(hInst, hDownloadDialog, YES_BUTTON, IDS_CANTUNCOMPRESS, 
                      zip_name, GetString(hInst, extraction_error)))
      {
         retval = False;
         break;
      }
   }

   WrapSetExtractionCallback(NULL);
   return retval;
}
Example #3
0
void AcceptMessage(int serverSocket)
{
	int clientSocket = 0;
	int clientAddressSize = 0;
	struct sockaddr_in clientAddress;
	char receiveMessageBuffer[BUFFERSIZE];
	char sendMessageBuffer[BUFFERSIZE];
	memset(receiveMessageBuffer,'\0',BUFFERSIZE);
	memset(sendMessageBuffer,'\0',BUFFERSIZE);
	while(true)
	{
		clientAddressSize = sizeof(clientAddress);
		clientSocket = accept(serverSocket,(struct sockaddr*)&clientAddress,&clientAddressSize);
		int receiveValue = recv(clientSocket,receiveMessageBuffer,BUFFERSIZE,0);
		printf("!! %d ,%s \n",receiveValue,receiveMessageBuffer);
		TransferMessage(receiveMessageBuffer,clientSocket);
		if(receiveValue < BUFFERSIZE)
		{	
			close(clientSocket);	
		}
	}
}
Example #4
0
/*
 * DownloadDialogProc:  Dialog procedure for displaying downloading progress.
 */
BOOL CALLBACK DownloadDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
   int fraction, i;
   HWND hGraph;
   BOOL bResult = FALSE;
   char temp[256];

   switch (message)
   {
   case WM_INITDIALOG:
      CenterWindow(hDlg, hMain);
      if (!advert)
      {
	 ShowWindow(hMain, SW_HIDE);
      }
      hDownloadDialog = hDlg;
      
      // Set up graph bar limits
      hGraph = GetDlgItem(hDlg, IDC_GRAPH);
      SendMessage(hGraph, GRPH_RANGESET, 0, 100);
      SendMessage(hGraph, GRPH_POSSET, 0, 0);
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BAR, GetColor(COLOR_BAR1));
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BKGND, GetColor(COLOR_BAR2));

      hGraph = GetDlgItem(hDlg, IDC_FILEGRAPH);
      SendMessage(hGraph, GRPH_RANGESET, 0, 100);
      SendMessage(hGraph, GRPH_POSSET, 0, 0);
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BAR, GetColor(COLOR_BAR1));
      SendMessage(hGraph, GRPH_COLORSET, GRAPHCOLOR_BKGND, GetColor(COLOR_BAR2));

      hGraph = GetDlgItem(hDlg, IDC_ANIMATE1);
      bResult = Animate_Open(hGraph, MAKEINTRESOURCE(IDA_DOWNLOAD));

      abort_download = False;
      PostMessage(hDlg, BK_TRANSFERSTART, 0, 0);

      GetDlgItemText(hDlg, IDC_FILESIZE, format, sizeof(format));
      sprintf(temp, format, (int)0, (int)0);
      SetDlgItemText(hDlg, IDC_FILESIZE, temp);

      return TRUE;

   case WM_DESTROY:
      if (!advert)
      {
	 ShowWindow(hMain, SW_SHOW);
	 UpdateWindow(hMain);
      }
      hDownloadDialog = NULL;
      return TRUE;

   case BK_TRANSFERSTART:
      info->hPostWnd = hDlg;
      hThread = (HANDLE)(unsigned long)_beginthread(TransferStart, 0, info);
      TransferMessage(GetString(hInst, IDS_CONNECTING), info->machine);
      return TRUE;

   case BK_FILESIZE:  // wParam is file index, lParam is file size
      if (wParam == 0)
	 TransferMessage(GetString(hInst, IDS_RETRIEVING));

      SetDlgItemText(hDlg, IDC_FILENAME, info->files[wParam].filename);
      total = lParam;
      sprintf(temp, format, 0, total);
      SetDlgItemText(hDlg, IDC_FILESIZE, temp);
      SendDlgItemMessage(hDlg, IDC_GRAPH, GRPH_POSSET, 0, 0);
      SendDlgItemMessage(hDlg, IDC_GRAPH, GRPH_RANGESET, 0, total);
      return TRUE;

   case BK_PROGRESS:

      // Update this file's progress indicator.
      SendDlgItemMessage(hDlg, IDC_GRAPH, GRPH_POSSET, 0, lParam);

      // Update this file's progress text message.
      sprintf(temp, format, (int)lParam, (int)total);
      SetDlgItemText(hDlg, IDC_FILESIZE, temp);

      // Compute the fraction for the overall graph.
      fraction = 0;
      if (total != 0)
	 fraction = lParam * 100 / total;
      fraction = (fraction + 100 * info->current_file) / info->num_files;

      // Update overall progress indicator.
      SendDlgItemMessage(hDlg, IDC_FILEGRAPH, GRPH_POSSET, 0, fraction);

      return TRUE;

   case BK_FILEDONE:  /* lParam is index of file in info */
      if (abort_download)
      {
	 AbortDownloadDialog();
	 return TRUE;
      }

      if (DownloadDone(&info->files[lParam]))
      {
	 if (abort_download)
	 {
	    AbortDownloadDialog();
	    return TRUE;
	 }

	 // Set download time
	 DownloadSetTime(info->files[lParam].time);

	 // If we're a guest, there may be additional files that we are supposed to skip.
	 // If so, we should set our download time to the last file, so that we will skip
	 // the download on the next entry into the game.
	 if (config.guest)
	    for (i = lParam + 1; i < info->num_files; i++)
	    {
	       if (info->files[i].flags & DF_GUEST)
		  break;
	       DownloadSetTime(info->files[i].time);
	    }

	 info->current_file++;

	 // Tell transfer thread to continue
	 TransferContinue();

	 TransferMessage(GetString(hInst, IDS_RETRIEVING));
      }
      else AbortDownloadDialog();
      return TRUE;

   case BK_TRANSFERDONE: 
      EndDialog(hDlg, IDOK);
      return TRUE;

   case WM_COMMAND:
      switch(GET_WM_COMMAND_ID(wParam, lParam))
      {
      case IDCANCEL:
         abort_download = True;
	 EndDialog(hDlg, IDCANCEL);
	 return TRUE;
      }
   }
   return FALSE;
}