Skip to content

Commit 6a14047

Browse files
committed
SQ easy
SonarQube: trivial fixes (nullptr, in-class init, static const, explicit ctor)
1 parent 8448c3e commit 6a14047

6 files changed

Lines changed: 84 additions & 103 deletions

File tree

CPP/7zip/UI/FileManager/App.cpp

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ extern bool g_bProcessError;
4545

4646
#define kTempDirPrefix FTEXT("7zE")
4747

48+
// Walk up, delete found archive.
49+
static void DeleteSourceArchive_WalkUp(CPanel &srcPanel, UString srcFilePath)
50+
{
51+
while (!srcFilePath.IsEmpty())
52+
{
53+
if (srcFilePath.Back() == L'\\')
54+
srcFilePath.DeleteBack();
55+
const DWORD dwAttr = GetFileAttributesW(srcFilePath);
56+
57+
if (dwAttr != INVALID_FILE_ATTRIBUTES)
58+
{
59+
if (dwAttr & FILE_ATTRIBUTE_ARCHIVE)
60+
NDir::DeleteFileIfArchive(us2fs(srcFilePath));
61+
return;
62+
}
63+
64+
const int n = srcFilePath.ReverseFind(L'\\');
65+
if (n == -1)
66+
return;
67+
srcPanel.OpenParentFolder();
68+
srcFilePath.ReleaseBuf_SetEnd(n);
69+
}
70+
}
71+
4872
void CPanelCallbackImp::OnTab()
4973
{
5074
if (g_App.NumPanels != 1)
@@ -938,38 +962,7 @@ void CApp::OnCopy(bool move, bool copyToSame, unsigned srcPanelIndex)
938962
{
939963
UString srcFilePath(srcPanel._currentFolderPrefix);
940964
srcPanel.OpenParentFolder();
941-
942-
while (!srcFilePath.IsEmpty())
943-
{
944-
if (srcFilePath.Back() == '\\')
945-
{
946-
srcFilePath.DeleteBack();
947-
}
948-
DWORD dwAttr = GetFileAttributesW(srcFilePath);
949-
950-
if (dwAttr == INVALID_FILE_ATTRIBUTES)
951-
{
952-
int n = srcFilePath.ReverseFind(L'\\');
953-
if (n != -1)
954-
{
955-
srcPanel.OpenParentFolder();
956-
srcFilePath.ReleaseBuf_SetEnd(n);
957-
}
958-
else
959-
{
960-
break;
961-
}
962-
}
963-
else if (dwAttr & FILE_ATTRIBUTE_ARCHIVE)
964-
{
965-
NDir::DeleteFileIfArchive(us2fs(srcFilePath));
966-
break;
967-
}
968-
else // directory or other non-archive
969-
{
970-
break;
971-
}
972-
}
965+
DeleteSourceArchive_WalkUp(srcPanel, srcFilePath);
973966
}
974967
if (close7Zip)
975968
{

CPP/7zip/UI/FileManager/CopyDialog.cpp

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ static bool IsFileExistentAndNotDir(const wchar_t * lpszFile)
3030
&& ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == 0);
3131
}
3232

33+
// Walk up, extract archive basename.
34+
static void FindRealFileName_WalkUp(UString &pathPrefix, UString &realName)
35+
{
36+
while (!pathPrefix.IsEmpty())
37+
{
38+
if (pathPrefix.Back() == L'\\')
39+
pathPrefix.DeleteBack();
40+
41+
if (IsFileExistentAndNotDir(pathPrefix))
42+
{
43+
const int slash = pathPrefix.ReverseFind(L'\\');
44+
const int dot = pathPrefix.ReverseFind(L'.');
45+
const int start = (slash != -1) ? slash + 1 : 0;
46+
const int end = (dot == -1 || dot <= start) ? pathPrefix.Len() : dot;
47+
realName = pathPrefix.Mid(start, end - start);
48+
return;
49+
}
50+
51+
const int slash = pathPrefix.ReverseFind(L'\\');
52+
if (slash == -1)
53+
return;
54+
pathPrefix.ReleaseBuf_SetEnd(slash);
55+
}
56+
}
57+
3358
bool CCopyDialog::OnInit()
3459
{
3560
#ifdef Z7_LANG
@@ -74,42 +99,7 @@ bool CCopyDialog::OnInit()
7499
}
75100
else
76101
{
77-
while (!CurrentFolderPrefix.IsEmpty())
78-
{
79-
if (CurrentFolderPrefix.Back() == '\\')
80-
{
81-
CurrentFolderPrefix.DeleteBack();
82-
}
83-
84-
if (IsFileExistentAndNotDir(CurrentFolderPrefix))
85-
{
86-
int n = CurrentFolderPrefix.ReverseFind(L'\\');
87-
int m = CurrentFolderPrefix.ReverseFind(L'.');
88-
if (n != -1)
89-
{
90-
n++;
91-
}
92-
else
93-
{
94-
n = 0;
95-
}
96-
if (m == -1 || m <= n) m = CurrentFolderPrefix.Len();
97-
RealFileName = CurrentFolderPrefix.Mid(n, m - n);
98-
break;
99-
}
100-
else
101-
{
102-
int n = CurrentFolderPrefix.ReverseFind(L'\\');
103-
if (n != -1)
104-
{
105-
CurrentFolderPrefix.ReleaseBuf_SetEnd(n);
106-
}
107-
else
108-
{
109-
break;
110-
}
111-
}
112-
}
102+
FindRealFileName_WalkUp(CurrentFolderPrefix, RealFileName);
113103
}
114104

115105
return CModalDialog::OnInit();

CPP/7zip/UI/FileManager/CopyDialog.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ class CCopyDialog: public NWindows::NControl::CModalDialog
2727
void ShowPathFreeSpace(UString & strPath);
2828

2929
public:
30-
CCopyDialog(): OpenOutputFolder(false), DeleteSourceFile(false), Close7Zip(false) {}
30+
CCopyDialog() {}
3131

3232
UString Title;
3333
UString Static;
3434
UString Value;
3535
UString Info;
3636
UStringVector Strings;
3737

38-
bool OpenOutputFolder;
39-
bool DeleteSourceFile;
40-
bool Close7Zip;
38+
bool OpenOutputFolder = false;
39+
bool DeleteSourceFile = false;
40+
bool Close7Zip = false;
4141

4242
UString CurrentFolderPrefix;
4343
UString RealFileName;

CPP/7zip/UI/FileManager/ProgressDialog2.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ extern bool g_DisableUserQuestions;
2929
// Set true by CProgressDialog when error messages occur.
3030
bool g_bProcessError = false;
3131

32-
#define WM_TRAY_ICON_NOTIFY (WM_APP + 10)
33-
#define ID_SYSTRAY_ICON 100
32+
static const UINT WM_TRAY_ICON_NOTIFY = WM_APP + 10;
33+
static const UINT ID_SYSTRAY_ICON = 100;
3434

3535
static BOOL SetSysTray(HWND dlg,
3636
DWORD message,
@@ -50,7 +50,7 @@ static BOOL SetSysTray(HWND dlg,
5050
data.uCallbackMessage = callbackMessage;
5151
data.hIcon = icon;
5252

53-
if (tip != NULL && *tip != 0)
53+
if (tip != nullptr && *tip != 0)
5454
{
5555
::lstrcpynW(data.szTip, tip, sizeof(data.szTip) / sizeof(WCHAR));
5656
}
@@ -304,9 +304,9 @@ CProgressDialog::CProgressDialog():
304304
MainWindow(NULL)
305305
{
306306
for (int i = 0; i < kNumTrayIcons; i++)
307-
_iconSysTrayArray[i] = NULL;
307+
_iconSysTrayArray[i] = nullptr;
308308
_sysTrayIconArrayId = -1;
309-
_sysTrayMenu = NULL;
309+
_sysTrayMenu = nullptr;
310310

311311
if (_dialogCreatedEvent.Create() != S_OK)
312312
throw 1334987;
@@ -894,7 +894,7 @@ void CProgressDialog::UpdateStatInfo(bool showAll)
894894
*p = 0;
895895
SetItemText(IDC_PROGRESS_PERCENT, szPercent);
896896

897-
if (_background && _iconSysTrayArray[0] != NULL)
897+
if (_background && _iconSysTrayArray[0] != nullptr)
898898
UpdateSysTrayIcon(false, true);
899899
}
900900
}
@@ -1127,22 +1127,22 @@ bool CProgressDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
11271127
}
11281128
if (_background)
11291129
{
1130-
SetSysTray(_window, NIM_DELETE, ID_SYSTRAY_ICON, 0, 0, NULL, NULL);
1131-
if (MainWindow != 0)
1130+
SetSysTray(_window, NIM_DELETE, ID_SYSTRAY_ICON, 0, 0, nullptr, nullptr);
1131+
if (MainWindow != nullptr)
11321132
ShowWindow(MainWindow, SW_SHOW);
11331133
}
1134-
if (_iconSysTrayArray[0] != NULL)
1134+
if (_iconSysTrayArray[0] != nullptr)
11351135
{
11361136
for (int i = 0; i < kNumTrayIcons; i++)
11371137
{
11381138
DestroyIcon(_iconSysTrayArray[i]);
1139-
_iconSysTrayArray[i] = NULL;
1139+
_iconSysTrayArray[i] = nullptr;
11401140
}
11411141
}
1142-
if (_sysTrayMenu != NULL)
1142+
if (_sysTrayMenu != nullptr)
11431143
{
11441144
::DestroyMenu(_sysTrayMenu);
1145-
_sysTrayMenu = NULL;
1145+
_sysTrayMenu = nullptr;
11461146
}
11471147
return OnExternalCloseMessage();
11481148
}
@@ -1204,7 +1204,7 @@ void CProgressDialog::SetPauseText()
12041204
SetItemText(IDB_PAUSE, pszText);
12051205
SetTitleText();
12061206

1207-
if (_sysTrayMenu != NULL)
1207+
if (_sysTrayMenu != nullptr)
12081208
ModifyMenuW(_sysTrayMenu, IDB_PAUSE, MF_BYCOMMAND, IDB_PAUSE, pszText);
12091209
}
12101210

@@ -1235,19 +1235,19 @@ void CProgressDialog::OnPriorityButton()
12351235
SetPriorityClass(GetCurrentProcess(), _background ? IDLE_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS);
12361236
if (!_background) // foreground
12371237
{
1238-
if (_iconSysTrayArray[0] != NULL)
1238+
if (_iconSysTrayArray[0] != nullptr)
12391239
{
1240-
if (MainWindow != 0)
1240+
if (MainWindow != nullptr)
12411241
ShowWindow(MainWindow, SW_SHOW);
12421242
Show(SW_SHOW);
1243-
SetSysTray(_window, NIM_DELETE, ID_SYSTRAY_ICON, 0, 0, NULL, NULL);
1243+
SetSysTray(_window, NIM_DELETE, ID_SYSTRAY_ICON, 0, 0, nullptr, nullptr);
12441244
}
12451245
}
12461246
else
12471247
{
12481248
if (LoadSysTrayIcons())
12491249
{
1250-
if (MainWindow != 0)
1250+
if (MainWindow != nullptr)
12511251
ShowWindow(MainWindow, SW_HIDE);
12521252
Show(SW_HIDE);
12531253
UpdateSysTrayIcon(true, true);
@@ -1501,15 +1501,15 @@ void CProgressDialog::CopyToClipboard()
15011501

15021502
bool CProgressDialog::LoadSysTrayIcons()
15031503
{
1504-
if (_iconSysTrayArray[0] != NULL) return true;
1504+
if (_iconSysTrayArray[0] != nullptr) return true;
15051505

15061506
int id = IDI_SYSTRAY_0;
15071507
for (int n = 0; n < kNumTrayIcons; n++, id++)
15081508
{
15091509
_iconSysTrayArray[n] = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(id), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
15101510
}
15111511

1512-
return _iconSysTrayArray[0] != NULL;
1512+
return _iconSysTrayArray[0] != nullptr;
15131513
}
15141514

15151515
void CProgressDialog::UpdateSysTrayIcon(bool addIcon, bool updateTip)
@@ -1530,7 +1530,7 @@ void CProgressDialog::UpdateSysTrayIcon(bool addIcon, bool updateTip)
15301530

15311531
if (!SetSysTray(_window, NIM_MODIFY, ID_SYSTRAY_ICON, flags, 0, _iconSysTrayArray[newIconId], tip))
15321532
{
1533-
SetSysTray(_window, NIM_DELETE, ID_SYSTRAY_ICON, 0, 0, NULL, NULL);
1533+
SetSysTray(_window, NIM_DELETE, ID_SYSTRAY_ICON, 0, 0, nullptr, nullptr);
15341534
SetSysTray(_window, NIM_ADD, ID_SYSTRAY_ICON, NIF_ICON | NIF_MESSAGE | NIF_TIP, WM_TRAY_ICON_NOTIFY,
15351535
_iconSysTrayArray[newIconId], tip);
15361536
}
@@ -1541,13 +1541,13 @@ void CProgressDialog::UpdateSysTrayIcon(bool addIcon, bool updateTip)
15411541

15421542
bool CProgressDialog::CreateSysTrayMenu()
15431543
{
1544-
if (_sysTrayMenu != NULL) return true;
1544+
if (_sysTrayMenu != nullptr) return true;
15451545

15461546
_sysTrayMenu = CreatePopupMenu();
15471547
AppendMenuW(_sysTrayMenu, MF_STRING, IDB_PROGRESS_BACKGROUND, _foreground_String);
15481548
AppendMenuW(_sysTrayMenu, MF_STRING, IDB_PAUSE, Sync.Get_Paused() ? _continue_String : _pause_String);
15491549
AppendMenuW(_sysTrayMenu, MF_STRING, IDCANCEL, cancelString);
1550-
return _sysTrayMenu != NULL;
1550+
return _sysTrayMenu != nullptr;
15511551
}
15521552

15531553
bool CProgressDialog::OnTrayNotification(LPARAM lParam)
@@ -1559,7 +1559,7 @@ bool CProgressDialog::OnTrayNotification(LPARAM lParam)
15591559
{
15601560
POINT point;
15611561
::GetCursorPos(&point);
1562-
::TrackPopupMenu(_sysTrayMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, point.x, point.y, 0, _window, NULL);
1562+
::TrackPopupMenu(_sysTrayMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, point.x, point.y, 0, _window, nullptr);
15631563
// BUGFIX: see "PRB: Menus for Notification Icons Don't Work Correctly"
15641564
::PostMessage(_window, WM_NULL, 0, 0);
15651565
}

CPP/7zip/UI/GUI/ExtractDialog.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CExtractDialog: public NWindows::NControl::CModalDialog
6161
virtual bool OnButtonClicked(unsigned buttonID, HWND buttonHWND) Z7_override;
6262
virtual void OnOK() Z7_override;
6363
void OnButtonOpenPath();
64-
virtual bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam) Z7_override;
64+
bool OnCommand(unsigned code, unsigned itemID, LPARAM lParam) Z7_override;
6565

6666
#ifndef Z7_NO_REGISTRY
6767

@@ -85,11 +85,11 @@ class CExtractDialog: public NWindows::NControl::CModalDialog
8585
UString Password;
8686
#endif
8787
bool PathMode_Force;
88-
bool OverwriteMode_Force;
88+
bool OverwriteMode_Force = false;
8989
NExtract::NPathMode::EEnum PathMode;
9090
NExtract::NOverwriteMode::EEnum OverwriteMode;
9191

92-
bool DeleteSourceFile;
92+
bool DeleteSourceFile = false;
9393

9494
#ifndef Z7_SFX
9595
// CBoolPair AltStreams;
@@ -110,9 +110,7 @@ class CExtractDialog: public NWindows::NControl::CModalDialog
110110
}
111111

112112
CExtractDialog():
113-
PathMode_Force(false),
114-
OverwriteMode_Force(false),
115-
DeleteSourceFile(false)
113+
PathMode_Force(false)
116114
{
117115
ElimDup.Val = true;
118116
}

CPP/Windows/Control/Dialog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ namespace NControl {
1515
class CDialog: public CWindow
1616
{
1717
// Z7_CLASS_NO_COPY(CDialog)
18-
protected:
18+
private:
1919
SIZE _minTrackSize;
2020
public:
21-
CDialog(HWND wnd = NULL): CWindow(wnd) { _minTrackSize.cx = 0; _minTrackSize.cy = 0; }
21+
explicit CDialog(HWND wnd = nullptr): CWindow(wnd) { _minTrackSize.cx = 0; _minTrackSize.cy = 0; }
2222
virtual ~CDialog() {}
2323

2424
void Set_MinTrackSize_FromCurrent(int numX, int denX, int numY, int denY);

0 commit comments

Comments
 (0)