MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / FileCreate

Function FileCreate

Libraries/unrar/filcreat.cpp:6–54  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

4// It is useful we we need to overwrite an existing folder or file,
5// but need user confirmation for that.
6bool FileCreate(RAROptions *Cmd,File *NewFile,wchar *Name,size_t MaxNameSize,
7 bool *UserReject,int64 FileSize,RarTime *FileTime,bool WriteOnly)
8{
9 if (UserReject!=NULL)
10 *UserReject=false;
11#ifdef _WIN_ALL
12 bool ShortNameChanged=false;
13#endif
14 while (FileExist(Name))
15 {
16#if defined(_WIN_ALL)
17 if (!ShortNameChanged)
18 {
19 // Avoid the infinite loop if UpdateExistingShortName returns
20 // the same name.
21 ShortNameChanged=true;
22
23 // Maybe our long name matches the short name of existing file.
24 // Let's check if we can change the short name.
25 if (UpdateExistingShortName(Name))
26 continue;
27 }
28 // Allow short name check again. It is necessary, because rename and
29 // autorename below can change the name, so we need to check it again.
30 ShortNameChanged=false;
31#endif
32 UIASKREP_RESULT Choice=uiAskReplaceEx(Cmd,Name,MaxNameSize,FileSize,FileTime,(NewFile==NULL ? UIASKREP_F_NORENAME:0));
33
34 if (Choice==UIASKREP_R_REPLACE)
35 break;
36 if (Choice==UIASKREP_R_SKIP)
37 {
38 if (UserReject!=NULL)
39 *UserReject=true;
40 return false;
41 }
42 if (Choice==UIASKREP_R_CANCEL)
43 ErrHandler.Exit(RARX_USERBREAK);
44 }
45
46 // Try to truncate the existing file first instead of delete,
47 // so we preserve existing file permissions such as NTFS permissions.
48 uint FileMode=WriteOnly ? FMF_WRITE|FMF_SHAREREAD:FMF_UPDATE|FMF_SHAREREAD;
49 if (NewFile!=NULL && NewFile->Create(Name,FileMode))
50 return true;
51
52 CreatePath(Name,true);
53 return NewFile!=NULL ? NewFile->Create(Name,FileMode):DelFile(Name);
54}
55
56
57bool GetAutoRenamedName(wchar *Name,size_t MaxNameSize)

Callers 4

RestoreMethod · 0.85
ExtractCurrentFileMethod · 0.85
ExtrCreateDirMethod · 0.85
ExtrCreateFileMethod · 0.85

Calls 7

FileExistFunction · 0.85
UpdateExistingShortNameFunction · 0.85
uiAskReplaceExFunction · 0.85
CreatePathFunction · 0.85
DelFileFunction · 0.85
ExitMethod · 0.80
CreateMethod · 0.80

Tested by

no test coverage detected