anchor.diff:      Result:= (not FileExists(fn)) or (FileUtil.FileSize(fn)=0);
     end;
     //
  +  procedure SaveViaTempCopy(const fn: string);
  +  var
  +    fnTemp: string;
  +  begin
  +    fnTemp:= GetTempFileName('', 'cudatext_');
  +    SaveSimple(fnTemp);
  +    if IsBadResultFile(fnTemp) then
  +      raise EFileNotFoundException.Create('Cannot save to a temp file.');
  +    CopyFile(fnTemp, fn);
  +    if IsBadResultFile(fn) then
  +      raise EFileNotFoundException.CreateFmt('Cannot save to "%s". Saved to a temporary file "%s".', [fn, fnTemp]);
  +  end;
  +  //
   var
     OldEncoding: string;
     OldAttr: Longint;
  -  STempFilename: string;
   begin
     Result:= true;
     while true do
  
positive.code:     AppFileAttrRestore(AFileName, OldAttr);
      exit;
    except
      if MsgBox(msgCannotSaveFile+#10+AFileName, MB_RETRYCANCEL or MB_ICONERROR) = IDCANCEL then
        exit(false);
    end;
  end;
  
  
negative.code:             SaveSimple(AFileName);
              MsgBox(Format(msgCannotSaveFileWithEnc, [OldEncoding]), MB_OK or MB_ICONWARNING);
            end;
          on E: EFOpenError do
            begin
              SaveViaTempCopy(AFileName);
              if IsBadResultFile(AFileName) then
                raise;
            end;
          else
            raise;
  