Пример #1
0
/*
* DeleteAllRscFiles:  Delete all resource files in resource directory.
*   Also resets last download time to 0.
*/
void DeleteAllRscFiles(void)
{
	HANDLE hFindFile;
	WIN32_FIND_DATA file_info;
	char path[MAX_PATH + FILENAME_MAX], game_path[MAX_PATH];
	
	GetGamePath( game_path );
	// Reset last download time to never
	DownloadSetTime(0);
	
	debug(("Deleting all resource files\n"));
	sprintf(path, "%s%s\\*.*", game_path, resource_dir);
	
	hFindFile = FindFirstFile(path, &file_info);
	if (hFindFile == INVALID_HANDLE_VALUE)
		return;
	
	for(;;)
	{
		// Skip directories
		if (!(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
		{
			sprintf(path, "%s%s\\%s", game_path, resource_dir, file_info.cFileName);  
			
			if (unlink(path) != 0)
				ClientError(hInst, hMain, IDS_CANTDELETE, path);
		}
		
		if (FindNextFile(hFindFile, &file_info) == FALSE)
			break;
	}
	FindClose(hFindFile);
}
Пример #2
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;
}