示例#1
0
bool DeleteDirectory(const UnicodeString & ADirName)
{
  TSearchRecChecked SearchRec;
  bool retval = true;
  if (::FindFirst(ADirName + L"\\*", faAnyFile, SearchRec) == 0) // VCL Function
  {
    if (FLAGSET(SearchRec.Attr, faDirectory))
    {
      if ((SearchRec.Name != THISDIRECTORY) && (SearchRec.Name != PARENTDIRECTORY))
        retval = DeleteDirectory(ADirName + L"\\" + SearchRec.Name);
    }
    else
    {
      retval = ::DeleteFile(ApiPath(ADirName + L"\\" + SearchRec.Name));
    }

    if (retval)
    {
      while (FindNextChecked(SearchRec) == 0)
      { // VCL Function
        if (FLAGSET(SearchRec.Attr, faDirectory))
        {
          if ((SearchRec.Name != THISDIRECTORY) && (SearchRec.Name != PARENTDIRECTORY))
            retval = DeleteDirectory(ADirName + L"\\" + SearchRec.Name);
        }
        else
        {
          retval = ::DeleteFile(ApiPath(ADirName + L"\\" + SearchRec.Name));
        }

        if (!retval)
        {
          break;
        }
      }
    }
  }
  FindClose(SearchRec);
  if (retval)
  {
    retval = ::RemoveDir(ADirName); // VCL function
  }
  return retval;
}
示例#2
0
void TConfiguration::SetRandomSeedFile(const UnicodeString & Value)
{
  if (GetRandomSeedFile() != Value)
  {
    UnicodeString PrevRandomSeedFileName = GetRandomSeedFileName();

    FRandomSeedFile = Value;

    // never allow empty seed file to avoid Putty trying to reinitialize the path
    if (GetRandomSeedFileName().IsEmpty())
    {
      FRandomSeedFile = FDefaultRandomSeedFile;
    }

    if (!PrevRandomSeedFileName.IsEmpty() &&
        (PrevRandomSeedFileName != GetRandomSeedFileName()) &&
        ::FileExists(ApiPath(PrevRandomSeedFileName)))
    {
      // ignore any error
      ::DeleteFile(ApiPath(PrevRandomSeedFileName));
    }
  }
}
示例#3
0
void TConfiguration::CleanupRandomSeedFile()
{
  try
  {
    DontSaveRandomSeed();
    if (::FileExists(ApiPath(GetRandomSeedFileName())))
    {
      DeleteFileChecked(GetRandomSeedFileName());
    }
  }
  catch (Exception & E)
  {
    throw ExtException(&E, LoadStr(CLEANUP_SEEDFILE_ERROR));
  }
}
示例#4
0
UnicodeString TCustomFileSystem::CreateTargetDirectory(
  IN const UnicodeString & AFileName,
  IN const UnicodeString & ADirectory,
  IN const TCopyParamType * CopyParam)
{
  UnicodeString Result = ADirectory;
  UnicodeString DestFileName = CopyParam->ChangeFileName(base::UnixExtractFileName(AFileName),
    osRemote, true);
  UnicodeString FileNamePath = ::ExtractFilePath(DestFileName);
  if (!FileNamePath.IsEmpty())
  {
    Result = ::IncludeTrailingBackslash(ADirectory + FileNamePath);
    ::ForceDirectories(ApiPath(Result));
  }
  return Result;
}
static FILE *LocalOpenLogFile(UnicodeString LogFileName, TDateTime Started, TSessionData *SessionData, bool Append, UnicodeString &ANewFileName)
{
  UnicodeString NewFileName = StripPathQuotes(GetExpandedLogFileName(LogFileName, Started, SessionData));
  FILE *Result = _wfsopen(ApiPath(NewFileName).c_str(),
      Append ? L"ab" : L"wb", SH_DENYWR);
  if (Result != nullptr)
  {
    setvbuf(Result, nullptr, _IONBF, BUFSIZ);
    ANewFileName = NewFileName;
  }
  else
  {
    throw ECRTExtException(FMTLOAD(LOG_OPENERROR, NewFileName));
  }
  return Result;
}
示例#6
0
//---------------------------------------------------------------------------
bool __fastcall FindFile(UnicodeString & Path)
{
  bool Result = FileExists(ApiPath(Path));
  if (!Result)
  {
    UnicodeString Paths = GetEnvironmentVariable(L"PATH");
    if (!Paths.IsEmpty())
    {
      UnicodeString NewPath = FileSearch(ExtractFileName(Path), Paths);
      Result = !NewPath.IsEmpty();
      if (Result)
      {
        Path = NewPath;
      }
    }
  }
  return Result;
}
示例#7
0
void TConfiguration::CleanupIniFile()
{
#if 0
  try
  {
    if (::FileExists(ApiPath(GetIniFileStorageNameForReading())))
    {
      DeleteFileChecked(GetIniFileStorageNameForReading());
    }
    if (GetStorage() == stIniFile)
    {
      FDontSave = true;
    }
  }
  catch (Exception & E)
  {
    throw ExtException(&E, LoadStr(CLEANUP_INIFILE_ERROR));
  }
#endif
}