Line | Count | Source (jump to first uncovered line) |
1 | | static bool GetAutoRenamedName(std::wstring &Name); |
2 | | static SOUND_NOTIFY_MODE uiSoundNotify; |
3 | | |
4 | | void uiInit(SOUND_NOTIFY_MODE Sound) |
5 | 0 | { |
6 | 0 | uiSoundNotify = Sound; |
7 | 0 | } |
8 | | |
9 | | |
10 | | // Additionally to handling user input, it analyzes and sets command options. |
11 | | // Returns only 'replace', 'skip' and 'cancel' codes. |
12 | | UIASKREP_RESULT uiAskReplaceEx(CommandData *Cmd,std::wstring &Name,int64 FileSize,RarTime *FileTime,uint Flags) |
13 | 12.1k | { |
14 | 12.1k | if (Cmd->Overwrite==OVERWRITE_NONE) |
15 | 0 | return UIASKREP_R_SKIP; |
16 | | |
17 | | #if !defined(SFX_MODULE) && !defined(SILENT) |
18 | | // Must be before Cmd->AllYes check or -y switch would override -or. |
19 | | if (Cmd->Overwrite==OVERWRITE_AUTORENAME && GetAutoRenamedName(Name)) |
20 | | return UIASKREP_R_REPLACE; |
21 | | #endif |
22 | | |
23 | 12.1k | std::wstring NewName=Name; |
24 | 12.1k | UIASKREP_RESULT Choice=Cmd->AllYes || Cmd->Overwrite==OVERWRITE_ALL ? |
25 | 12.1k | UIASKREP_R_REPLACE : uiAskReplace(NewName,FileSize,FileTime,Flags); |
26 | | |
27 | 12.1k | if (Choice==UIASKREP_R_REPLACE || Choice==UIASKREP_R_REPLACEALL) |
28 | 12.1k | { |
29 | 12.1k | PrepareToDelete(Name); |
30 | | |
31 | | // Overwrite the link itself instead of its target. |
32 | | // For normal files we prefer to inherit file attributes, permissions |
33 | | // and hard links. |
34 | 12.1k | FindData FD; |
35 | 12.1k | if (FindFile::FastFind(Name,&FD,true) && FD.IsLink) |
36 | 15 | DelFile(Name); |
37 | 12.1k | } |
38 | | |
39 | 12.1k | if (Choice==UIASKREP_R_REPLACEALL) |
40 | 0 | { |
41 | 0 | Cmd->Overwrite=OVERWRITE_ALL; |
42 | 0 | return UIASKREP_R_REPLACE; |
43 | 0 | } |
44 | 12.1k | if (Choice==UIASKREP_R_SKIPALL) |
45 | 0 | { |
46 | 0 | Cmd->Overwrite=OVERWRITE_NONE; |
47 | 0 | return UIASKREP_R_SKIP; |
48 | 0 | } |
49 | 12.1k | if (Choice==UIASKREP_R_RENAME) |
50 | 0 | { |
51 | 0 | if (GetNamePos(NewName)==0) |
52 | 0 | SetName(Name,NewName); |
53 | 0 | else |
54 | 0 | Name=NewName; |
55 | 0 | if (FileExist(Name)) |
56 | 0 | return uiAskReplaceEx(Cmd,Name,FileSize,FileTime,Flags); |
57 | 0 | return UIASKREP_R_REPLACE; |
58 | 0 | } |
59 | | #if !defined(SFX_MODULE) && !defined(SILENT) |
60 | | if (Choice==UIASKREP_R_RENAMEAUTO && GetAutoRenamedName(Name)) |
61 | | { |
62 | | Cmd->Overwrite=OVERWRITE_AUTORENAME; |
63 | | return UIASKREP_R_REPLACE; |
64 | | } |
65 | | #endif |
66 | 12.1k | return Choice; |
67 | 12.1k | } |
68 | | |
69 | | |
70 | | bool GetAutoRenamedName(std::wstring &Name) |
71 | 0 | { |
72 | 0 | std::wstring Ext=GetExt(Name); |
73 | 0 | for (uint FileVer=1;FileVer<1000000;FileVer++) |
74 | 0 | { |
75 | 0 | std::wstring NewName=Name; |
76 | 0 | RemoveExt(NewName); |
77 | 0 | wchar Ver[10]; |
78 | 0 | itoa(FileVer,Ver,ASIZE(Ver)); |
79 | 0 | NewName = NewName + L"(" + Ver + L")" + Ext; |
80 | 0 | if (!FileExist(NewName)) |
81 | 0 | { |
82 | 0 | Name=NewName; |
83 | 0 | return true; |
84 | 0 | } |
85 | 0 | } |
86 | 0 | return false; |
87 | 0 | } |