123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #include "rar.hpp"
- bool FileCreate(RAROptions *Cmd,File *NewFile,wchar *Name,size_t MaxNameSize,
- bool *UserReject,int64 FileSize,RarTime *FileTime,bool WriteOnly)
- {
- return true;
- 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,Cmd->DisableNames);
- return NewFile!=NULL ? NewFile->Create(Name,FileMode):DelFile(Name);
- }
- bool GetAutoRenamedName(wchar *Name,size_t MaxNameSize)
- {
- return true;
- wchar NewName[NM];
- size_t NameLength=wcslen(Name);
- wchar *Ext=GetExt(Name);
- if (Ext==NULL)
- Ext=Name+NameLength;
- for (uint FileVer=1;;FileVer++)
- {
- swprintf(NewName,ASIZE(NewName),L"%.*ls(%u)%ls",uint(Ext-Name),Name,FileVer,Ext);
- if (!FileExist(NewName))
- {
- wcsncpyz(Name,NewName,MaxNameSize);
- break;
- }
- if (FileVer>=1000000)
- return false;
- }
- return true;
- }
- #if defined(_WIN_ALL)
- bool UpdateExistingShortName(const wchar *Name)
- {
- wchar LongPathName[NM];
- DWORD Res=GetLongPathName(Name,LongPathName,ASIZE(LongPathName));
- if (Res==0 || Res>=ASIZE(LongPathName))
- return false;
- wchar ShortPathName[NM];
- Res=GetShortPathName(Name,ShortPathName,ASIZE(ShortPathName));
- if (Res==0 || Res>=ASIZE(ShortPathName))
- return false;
- wchar *LongName=PointToName(LongPathName);
- wchar *ShortName=PointToName(ShortPathName);
-
-
-
- if (*ShortName==0 || wcsicomp(LongName,ShortName)==0 ||
- wcsicomp(PointToName(Name),ShortName)!=0)
- return false;
-
- wchar NewName[NM];
- *NewName=0;
- for (int I=0;I<10000 && *NewName==0;I+=123)
- {
-
-
- wcsncpyz(NewName,Name,ASIZE(NewName));
-
- swprintf(PointToName(NewName),ASIZE(NewName),L"rtmp%d",I);
-
-
- if (FileExist(NewName))
- *NewName=0;
- }
-
- if (*NewName==0)
- return false;
-
-
-
-
- wchar FullName[NM];
- wcsncpyz(FullName,Name,ASIZE(FullName));
- SetName(FullName,LongName,ASIZE(FullName));
-
-
-
- if (!MoveFile(FullName,NewName))
- return false;
-
-
-
-
- File KeepShortFile;
- bool Created=false;
- if (!FileExist(Name))
- Created=KeepShortFile.Create(Name,FMF_WRITE|FMF_SHAREREAD);
-
-
-
- MoveFile(NewName,FullName);
- if (Created)
- {
-
- KeepShortFile.Close();
- KeepShortFile.Delete();
- }
-
-
-
- return true;
- }
- #endif
|