Example #1
0
   /**
   *  Iterate through the given directory location. Remove files and directories recursively until empty
   * @param directory, the directory to remove content from
   * @param removeDirectory, whether or not the start directory should be removed
   *  @return how many entities that were not removed. I.e. a successfull remove of all would have zero entities left
   */ 
   Result<bool> CleanDirectory(const std::string & directory, const bool removeDirectory){
      std::string report;
      bool noFailures = true;

      std::vector<std::string> foundDirectories;
      size_t filesRemoved {0};
      auto cleanAllFiles = FileIO::CleanDirectoryOfFileContents(directory, filesRemoved, foundDirectories);

      if (cleanAllFiles.HasFailed()) {
         report = {"Failed to remove files from " +  directory};
         noFailures = false;
      } 
     

       while (foundDirectories.size() > 0){
          auto result = CleanDirectory(foundDirectories.back(), true);
          foundDirectories.pop_back();

          if (result.HasFailed()) {
             noFailures = false;
             report.append("\n").append(result.error);
          }
       }

       // no content should exist at this point. Safe to remove the directory
       if (removeDirectory) {
          auto result = FileIO::RemoveEmptyDirectories({{directory}});
          if (result.HasFailed()){
             noFailures = false;
             report.append("\n").append(result.error);
          }
       }
    
      return Result<bool> {noFailures, report};
   }
Example #2
0
void
ManagedFileListWidget::RefreshList()
{
  items.clear();

  bool download_active = false;
  for (auto i = repository.begin(), end = repository.end(); i != end; ++i) {
    const auto &remote_file = *i;
    DownloadStatus download_status;
    const bool is_downloading = IsDownloading(remote_file, download_status);

    const auto path = LocalPath(remote_file);
    if (!path.IsNull() &&
        (is_downloading || File::Exists(path))) {
      download_active |= is_downloading;

      const Path base = path.GetBase();
      if (base.IsNull())
        continue;

      items.append().Set(base.c_str(),
                         is_downloading ? &download_status : nullptr,
                         HasFailed(remote_file));
    }
  }

  ListControl &list = GetList();
  list.SetLength(items.size());
  list.Invalidate();

#ifdef HAVE_DOWNLOAD_MANAGER
  if (download_active && !Timer::IsActive())
    Timer::Schedule(1000);
#endif
}
//--------------------------------------------------------------------------------------
// Updates the manoeuvre. This mostly consists of processing any messages received from
// the participating entities and reacting accordingly. This can include the sending
// out of follow-up orders for entities that have completed a stage of the manoeuvre. Eventually
// the function should also check whether the goal of the manoeuvre has been achieved in 
// order to initiate termination.
// Param1: The time passed since the last update.
// Returns a behaviour status representing the state of the manoeuvre.
//--------------------------------------------------------------------------------------
BehaviourStatus GuardedFlagCapture::Update(float deltaTime)
{
	// Keep track of who has reached the target and let those defend until all have arrived
	SortOutProcessedMessages();
	ProcessMessages();

	m_timer += deltaTime;

	if(m_updateMovementTargetsInterval != 0.0f && m_timer >= m_updateMovementTargetsInterval)
	{
		UpdateMovementTargets();
		m_timer = 0.0f;
	}

	if(!IsActive() || HasFailed() || (GetNumberOfParticipants() < GetMinNumberOfParticipants()))
	{
		// The manoeuvre will fail if something failed during the initiation or if it wasn't
		// initiated at all.
		return StatusFailure;
	}else if(HasSucceeded())
	{
		return StatusSuccess;
	}

	return StatusRunning;
}
Example #4
0
void
ManagedFileListWidget::RefreshList()
{
  items.clear();

  bool download_active = false;
  for (auto i = repository.begin(), end = repository.end(); i != end; ++i) {
    const auto &remote_file = *i;
    DownloadStatus download_status;
    const bool is_downloading = IsDownloading(remote_file, download_status);

    TCHAR path[MAX_PATH];
    if (LocalPath(path, remote_file) &&
        (is_downloading || File::Exists(path))) {
      download_active |= is_downloading;
      items.append().Set(BaseName(path),
                         is_downloading ? &download_status : NULL,
                         HasFailed(remote_file));
    }
  }

  ListControl &list = GetList();
  list.SetLength(items.size());
  list.Invalidate();

#ifdef HAVE_DOWNLOAD_MANAGER
  if (download_active && !Timer::IsActive())
    Timer::Schedule(1000);
#endif
}
Example #5
0
   /**
    * Reads content of Ascii file
    * @param pathToFile to read
    * @return Result<std::string> all the content of the file, and/or an error string 
    *         if something went wrong 
    */
   Result<std::string> ReadAsciiFileContent(const std::string& pathToFile) {
      auto result = ReadBinaryFileContent(pathToFile);
      if(result.HasFailed()) {
        return Result<std::string>{{}, result.error};
      }

      std::string contents(reinterpret_cast<const char*> (result.result.data()), result.result.size());
      return Result<std::string>{contents};
    }
unsigned VChatClient::GetAllChannelsEx()
{
	Reset();
	VChatAPI::GetAllChannels(NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::SetBanStatusEx(unsigned userID,
									 unsigned banStatus)
{
	Reset();
	VChatAPI::SetBanStatus(userID, banStatus, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::DeactivateVoiceAccount(const std::string &avatarName, 
								 const std::string &game, 
								 const std::string &world)
{

	Reset();
	VChatAPI::DeactivateVoiceAccount(avatarName, game, world, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}
	return m_result;
}
unsigned VChatClient::GetChannelInfoEx( const std::string &channelName, 
										const std::string &game, 
										const std::string &server)
{
	Reset();
	VChatAPI::GetChannelInfo(channelName, game, server, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::GetCharacterChannelEx(const unsigned stationID,
										const std::string &characterName,
										const std::string &worldName,
										const std::string &gameCode)
{
	Reset();
	VChatAPI::GetCharacterChannel(stationID, characterName, worldName, gameCode, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::ChangePasswordEx(const std::string &channelName, 
									   const std::string &game, 
									   const std::string &server, 
									   const std::string &password)
{
	Reset();
	VChatAPI::ChangePassword(channelName, game, server, password, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::GetAccountEx(const std::string &avatarName, 
								const std::string &game, 
								const std::string &world, 
								unsigned userID,
								unsigned avatarID)
{

	Reset();
	VChatAPI::GetAccount(avatarName, game, world, userID, avatarID, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}
	return m_result;
}
unsigned VChatClient::ChannelCommandEx( const std::string &srcUserName, 
										const std::string &destUserName, 
										const std::string &destChannelAddress, 
										unsigned command,
										unsigned banTimeout)
{
	Reset();
	VChatAPI::ChannelCommand(srcUserName, destUserName, destChannelAddress, command, banTimeout, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
Example #14
0
//--------------------------------------------------------------------------------------
// Updates the manoeuvre. This mostly consists of processing any messages received from
// the participating entities and reacting accordingly. This can include the sending
// out of follow-up orders for entities that have completed a stage of the manoeuvre. Eventually
// the function should also check whether the goal of the manoeuvre has been achieved in 
// order to initiate termination.
// Param1: The time passed since the last update.
// Returns a behaviour status representing the state of the manoeuvre.
//--------------------------------------------------------------------------------------
BehaviourStatus SimpleBaseAttack::Update(float deltaTime)
{
	// Keep track of who has reached the target and let those defend until all have arrived
	SortOutProcessedMessages();
	ProcessMessages();

	if(!IsActive() || HasFailed() || (GetNumberOfParticipants() < GetMinNumberOfParticipants()))
	{
		// The manoeuvre will fail if something failed during the initiation or if it wasn't
		// initiated at all.
		return StatusFailure;
	}else if(HasSucceeded())
	{
		return StatusSuccess;
	}

	return StatusRunning;
}
unsigned VChatClient::GetChannelEx( const std::string &channelName, 
									const std::string &game, 
									const std::string &server, 
									const std::string &description, 
									const std::string &password,
									unsigned limit,
									bool persistent)
{
	Reset();
	VChatAPI::GetChannel(channelName, game, server, description, password, limit, persistent, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::GetProximityChannelEx(const std::string &channelName, 
											const std::string &game, 
											const std::string &server, 
											const std::string &description, 
											const std::string &password,
											unsigned limit,
											bool persistent,
											unsigned maxRange,
											unsigned clamping,
											float rollOff,
											float maxGain,
											unsigned distModel)
{
	Reset();
	VChatAPI::GetProximityChannel(channelName, game, server, description, password, limit, persistent, maxRange, clamping, rollOff, maxGain, distModel, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
unsigned VChatClient::AddCharacterChannelEx(const unsigned stationID,
										const unsigned avatarID,
										const std::string &characterName,
										const std::string &worldName,
										const std::string &gameCode,
										const std::string &channelType,
										const std::string &channelDescription,
										const std::string &password,
										const std::string &channelAddress,
										const std::string &locale)
{
	Reset();
	VChatAPI::AddCharacterChannel(stationID, avatarID, characterName, worldName, 
								  gameCode, channelType, channelDescription, 
								  password, channelAddress, locale, NULL);

	while(!IsDone() && !HasFailed())
	{
		Process();
		soe::Sleep(10);
	}

	return m_result;
}
Example #18
0
bool CTL_BCPInCmd::Send(void)
{
    unsigned int i;
    CS_INT       datalen = 0;
    size_t       len = 0;
    char         buff[2048];

    CheckIsDead();

    if ( !WasSent() ) {
        // we need to init the bcp
        CheckSFB(blk_init(x_GetSybaseCmd(), CS_BLK_IN,
                          (CS_CHAR*) GetQuery().data(), GetQuery().size()),
                 "blk_init failed", 123001);

        SetWasSent();

        // check what needs to be default
        CS_DATAFMT fmt;

        for (i = 0;  i < GetBindParamsImpl().NofParams();  i++) {
            if (GetBindParamsImpl().GetParamStatus(i) != 0) {
                continue;
            }


            SetHasFailed((Check(blk_describe(x_GetSybaseCmd(),
                                             i + 1,
                                             &fmt)) != CS_SUCCEED));
            CHECK_DRIVER_ERROR(
                HasFailed(),
                "blk_describe failed (check the number of "
                "columns in a table)." + GetDbgInfo(),
                123002 );
        }
    }


    SetHasFailed(!x_AssignParams());
    CHECK_DRIVER_ERROR( HasFailed(), "Cannot assign the params." + GetDbgInfo(), 123004 );

    switch ( Check(blk_rowxfer(x_GetSybaseCmd())) ) {
    case CS_BLK_HAS_TEXT:
        for (i = 0;  i < GetBindParamsImpl().NofParams();  i++) {
            if (GetBindParamsImpl().GetParamStatus(i) == 0)
                continue;

            CDB_Object& param = *GetBindParamsImpl().GetParam(i);

            if (param.IsNULL()) {
                continue;
            }
            else if (param.GetType() == eDB_Text  ||  param.GetType() == eDB_Image) {
                CDB_Stream& par = dynamic_cast<CDB_Stream&> (param);

                for (datalen = (CS_INT) par.Size();  datalen > 0;
                    datalen -= (CS_INT) len)
                {
                    len = par.Read(buff, sizeof(buff));

                    SetHasFailed((Check(blk_textxfer(x_GetSybaseCmd(),
                                                    (CS_BYTE*) buff,
                                                    (CS_INT) len,
                                                    0)
                                        ) == CS_FAIL));

                    CHECK_DRIVER_ERROR(
                        HasFailed(),
                        "blk_textxfer failed for the text/image field." + GetDbgInfo(), 123005
                        );
                }
            }
        }
    case CS_SUCCEED:
        ++m_RowCount;
        return true;
    default:
        SetHasFailed();
        CHECK_DRIVER_ERROR( HasFailed(), "blk_rowxfer failed." + GetDbgInfo(), 123007 );
    }

    return false;
}
Example #19
0
 gcc_pure
 bool HasFailed(const AvailableFile &file) const {
   return HasFailed(file.GetName());
 }