deps/unrar/filcreat.cpp
// If NewFile==NULL, we delete created file after user confirmation.
// It is useful we we need to overwrite an existing folder or file,
// but need user confirmation for that.
If NewFile==NULL, we delete created file after user confirmation.
It is useful we we need to overwrite an existing folder or file,
but need user confirmation for that.
If NewFile == NULL we delete created file after user confirmation . It is useful we we need to overwrite an existing folder or file but need user confirmation for that .
bool FileCreate(RAROptions *Cmd,File *NewFile,wchar *Name,size_t MaxNameSize,
                bool *UserReject,int64 FileSize,RarTime *FileTime,bool WriteOnly)
{
  if (UserReject!=NULL)
    *UserReject=false;
#ifdef _WIN_ALL
  bool ShortNameChanged=false;
#endif
  while (FileExist(Name))
  {
#if defined(_WIN_ALL)
    if (!ShortNameChanged)
    {
      ShortNameChanged=true;
      if (UpdateExistingShortName(Name))
        continue;
    }
    ShortNameChanged=false;
#endif
    UIASKREP_RESULT Choice=uiAskReplaceEx(Cmd,Name,MaxNameSize,FileSize,FileTime,(NewFile==NULL ? UIASKREP_F_NORENAME:0));
    if (Choice==UIASKREP_R_REPLACE)
      break;
    if (Choice==UIASKREP_R_SKIP)
    {
      if (UserReject!=NULL)
        *UserReject=true;
      return false;
    }
    if (Choice==UIASKREP_R_CANCEL)
      ErrHandler.Exit(RARX_USERBREAK);
  }
  uint FileMode=WriteOnly ? FMF_WRITE|FMF_SHAREREAD:FMF_UPDATE|FMF_SHAREREAD;
  if (NewFile!=NULL && NewFile->Create(Name,FileMode))
    return true;
  CreatePath(Name,true);
  return NewFile!=NULL ? NewFile->Create(Name,FileMode):DelFile(Name);
}
bool FileCreate ( RAROptions * Cmd , File * NewFile , wchar * Name , size_t MaxNameSize , bool * UserReject , int64 FileSize , RarTime * FileTime , bool WriteOnly ) { if ( UserReject != NULL ) * UserReject = false ; #ifdef _WIN_ALL bool ShortNameChanged = false ; #endif while ( FileExist ( Name ) ) { #if defined ( _WIN_ALL ) if ( ! ShortNameChanged ) { ShortNameChanged = true ; if ( UpdateExistingShortName ( Name ) ) continue ; } ShortNameChanged = false ; #endif UIASKREP_RESULT Choice = uiAskReplaceEx ( Cmd , Name , MaxNameSize , FileSize , FileTime , ( NewFile == NULL ? UIASKREP_F_NORENAME : 0 ) ) ; if ( Choice == UIASKREP_R_REPLACE ) break ; if ( Choice == UIASKREP_R_SKIP ) { if ( UserReject != NULL ) * UserReject = true ; return false ; } if ( Choice == UIASKREP_R_CANCEL ) ErrHandler . Exit ( RARX_USERBREAK ) ; } uint FileMode = WriteOnly ? FMF_WRITE | FMF_SHAREREAD : FMF_UPDATE | FMF_SHAREREAD ; if ( NewFile != NULL && NewFile -> Create ( Name , FileMode ) ) return true ; CreatePath ( Name , true ) ; return NewFile != NULL ? NewFile -> Create ( Name , FileMode ) : DelFile ( Name ) ; }
If NewFile==NULL, we delete created file after user confirmation.
If NewFile == NULL we delete created file after user confirmation .
// Avoid the infinite loop if UpdateExistingShortName returns // the same name. // Maybe our long name matches the short name of existing file. // Let's check if we can change the short name. // Allow short name check again. It is necessary, because rename and // autorename below can change the name, so we need to check it again. // Try to truncate the existing file first instead of delete, // so we preserve existing file permissions such as NTFS permissions.