Ejemplo n.º 1
0
void TCPClient::DownloadFile(string fileName)
{
	auto file = new fstream();
	OpenFile(file, GetLocalFileName(fileName));
	fpos_t currentProgress = file->tellp();
	fpos_t fileSize = 0;

	auto done = false;
	cout << "Download started." << endl;
	while (!done)
	{
		try {
			SendMessage(this->_tcp_socket, CreateFileInfo(fileName, currentProgress));
			fileSize = ReceiveFileSize();
			ReceiveFile(file, currentProgress, fileSize);
			done = true;
		}
		catch (ConnectionInterrupted e) {
			currentProgress = e.GetProgress();
			Reconnect();
		}
		catch (ServerError) {
			file->close();
			throw;
		}
		catch (runtime_error e) {
			cout << e.what() << endl;
			Reconnect();
		}
	}
	file->close();
	cout << "Done." << endl;
}
Ejemplo n.º 2
0
// constructor supports creation of wxFileConfig objects of any type
wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
                           const wxString& strLocal, const wxString& strGlobal,
                           long style)
            : wxConfigBase(::GetAppName(appName), vendorName,
                           strLocal, strGlobal,
                           style),
              m_strLocalFile(strLocal), m_strGlobalFile(strGlobal)
{
  // Make up names for files if empty
  if ( m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) )
  {
    m_strLocalFile = GetLocalFileName(GetAppName());
  }

  if ( m_strGlobalFile.IsEmpty() && (style & wxCONFIG_USE_GLOBAL_FILE) )
  {
    m_strGlobalFile = GetGlobalFileName(GetAppName());
  }

  // Check if styles are not supplied, but filenames are, in which case
  // add the correct styles.
  if ( !m_strLocalFile.IsEmpty() )
    SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);

  if ( !m_strGlobalFile.IsEmpty() )
    SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE);

  // if the path is not absolute, prepend the standard directory to it
  // UNLESS wxCONFIG_USE_RELATIVE_PATH style is set
  if ( !(style & wxCONFIG_USE_RELATIVE_PATH) )
  {
      if ( !m_strLocalFile.IsEmpty() && !wxIsAbsolutePath(m_strLocalFile) )
      {
          wxString strLocal = m_strLocalFile;
          m_strLocalFile = GetLocalDir();
          m_strLocalFile << strLocal;
      }

      if ( !m_strGlobalFile.IsEmpty() && !wxIsAbsolutePath(m_strGlobalFile) )
      {
          wxString strGlobal = m_strGlobalFile;
          m_strGlobalFile = GetGlobalDir();
          m_strGlobalFile << strGlobal;
      }
  }

  SetUmask(-1);

  Init();
}
Ejemplo n.º 3
0
void UDPClient::DownloadFile(string fileName)
{
	file = new fstream();
	this->fileName = fileName;
	OpenFile(file, GetLocalFileName(fileName));
	fpos_t currentProgress = file->tellp();	
	fileSize = ConnectToServer();
	cout << "Download started. " << fileSize << endl;
	auto timer = new SpeedRater(currentProgress);
	ProgressHolder *progressHolder = new ProgressHolder(0, fileSize, "file");
	auto lastProgress = 0;
	auto done = fileSize <= currentProgress;
	fpos_t currentBatch = 0;

	InitMissingPackages();

	while (true) {
		try {
			ProcessBatches(file, fileSize);
		} catch (ServerError e) {
			cout << e.what() << endl;
			throw;
		} catch (runtime_error e) {
		}
		cout << "PROCESS BATCHES ENDED";
		if (missingPackages.size() == 0) {
			break;
		}
		SendMissingPackages();
	}

	//TODO: Implement write considering lost packages 
	ShowProgress(0, fileSize, fileSize, timer);
	//progressHolder->logFinish();

	file->close();
	cout << "Done." << endl;
}
Ejemplo n.º 4
0
 AbstractFileIO::ConfidenceLevel ItkImageIO::GetReaderConfidenceLevel() const
 {
   return m_ImageIO->CanReadFile(GetLocalFileName().c_str()) ? IFileReader::Supported : IFileReader::Unsupported;
 }