From c26c2bc4a1e97ea50a2daad620c343e6c5dd81c1 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 9 Oct 2018 20:19:01 +0000 Subject: Fixed a number of warnings from the static analyzer and switched to GetTickCount64 (or a surrogate function on pre-Vista) whereever we use millisecond values --- common/tracer.cpp | 2 +- windirstat/Controls/TreeListControl.cpp | 12 +-- windirstat/Controls/TreeListControl.h | 8 +- windirstat/Controls/ownerdrawnlistcontrol.cpp | 7 ++ windirstat/Controls/pacman.cpp | 18 +++-- windirstat/Controls/pacman.h | 2 +- windirstat/Controls/sortinglistcontrol.cpp | 5 ++ windirstat/Controls/treemap.cpp | 3 + windirstat/Controls/typeview.cpp | 3 +- windirstat/Dialogs/SelectDrivesDlg.cpp | 8 +- windirstat/Dialogs/aboutdlg.cpp | 8 +- windirstat/PageTreelist.cpp | 3 + windirstat/WorkLimiter.cpp | 18 ++--- windirstat/WorkLimiter.h | 19 +++-- windirstat/dirstatview.cpp | 1 + windirstat/getosplatformstring.cpp | 7 +- windirstat/globalhelpers.cpp | 16 ++-- windirstat/globalhelpers.h | 2 +- windirstat/item.cpp | 18 ++--- windirstat/item.h | 6 +- windirstat/mainframe.cpp | 7 +- windirstat/stdafx.cpp | 108 ++++++++++++++++++-------- windirstat/stdafx.h | 11 ++- windirstat/windirstat.cpp | 21 +++-- windirstat/windirstat.h | 2 +- 25 files changed, 206 insertions(+), 109 deletions(-) diff --git a/common/tracer.cpp b/common/tracer.cpp index 35bcd1b..30e74b2 100644 --- a/common/tracer.cpp +++ b/common/tracer.cpp @@ -59,7 +59,7 @@ CWDSTracerConsole::CWDSTracerConsole() CWDSTracerConsole::~CWDSTracerConsole() { _tprintf(_T("Press a key to continue/close.\n")); - _getch(); + (void)_getch(); ::FreeConsole(); } #endif // VTRACE_TO_CONSOLE diff --git a/windirstat/Controls/TreeListControl.cpp b/windirstat/Controls/TreeListControl.cpp index 8271d1d..10cf005 100644 --- a/windirstat/Controls/TreeListControl.cpp +++ b/windirstat/Controls/TreeListControl.cpp @@ -264,17 +264,7 @@ void CTreeListItem::SetVisible(bool visible) if(visible) { ASSERT(!IsVisible()); - m_vi = new VISIBLEINFO; - if(GetParent() == NULL) - { - m_vi->indent = 0; - } - else - { - m_vi->indent = GetParent()->GetIndent() + 1; - } - m_vi->image = -1; - m_vi->isExpanded = false; + m_vi = new VISIBLEINFO((GetParent() == NULL) ? 0 : GetParent()->GetIndent() + 1); } else { diff --git a/windirstat/Controls/TreeListControl.h b/windirstat/Controls/TreeListControl.h index 2a554a9..d21d251 100644 --- a/windirstat/Controls/TreeListControl.h +++ b/windirstat/Controls/TreeListControl.h @@ -55,6 +55,12 @@ class CTreeListItem: public COwnerDrawnListItem CArray sortedChildren; CPacman pacman; + + VISIBLEINFO(int iIndent) + : indent(iIndent) + , image(-1) + , isExpanded(false) + {} }; public: @@ -185,7 +191,7 @@ protected: afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); + // afx_msg BOOL OnEraseBkgnd(CDC* pDC); }; #endif // __WDS_TREELISTCONTROL_H__ diff --git a/windirstat/Controls/ownerdrawnlistcontrol.cpp b/windirstat/Controls/ownerdrawnlistcontrol.cpp index 5878f93..0d7bfee 100644 --- a/windirstat/Controls/ownerdrawnlistcontrol.cpp +++ b/windirstat/Controls/ownerdrawnlistcontrol.cpp @@ -210,6 +210,9 @@ COwnerDrawnListControl::COwnerDrawnListControl(LPCTSTR name, int rowHeight) , m_showGrid(false) , m_showStripes(false) , m_showFullRowSelection(false) + , m_yFirstItem(-1) + , m_windowColor(CLR_NONE) + , m_stripeColor(CLR_NONE) { ASSERT(rowHeight > 0); InitializeColors(); @@ -606,10 +609,14 @@ int COwnerDrawnListControl::GetSubItemWidth(COwnerDrawnListItem *item, int subit BEGIN_MESSAGE_MAP(COwnerDrawnListControl, CSortingListControl) ON_WM_ERASEBKGND() +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_DIVIDERDBLCLICKA, 0, OnHdnDividerdblclick) +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_DIVIDERDBLCLICKW, 0, OnHdnDividerdblclick) ON_WM_VSCROLL() +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging) +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging) ON_WM_SHOWWINDOW() END_MESSAGE_MAP() diff --git a/windirstat/Controls/pacman.cpp b/windirstat/Controls/pacman.cpp index 3e4d801..f9fd0f2 100644 --- a/windirstat/Controls/pacman.cpp +++ b/windirstat/Controls/pacman.cpp @@ -29,16 +29,20 @@ namespace { - DWORD UPDATEINTERVAL = 40; // ms - double MOUTHSPEED = 0.0030; // aperture alteration / ms + const ULONGLONG UPDATEINTERVAL = 40; // ms + const double MOUTHSPEED = 0.0030; // aperture alteration / ms } CPacman::CPacman() - : m_readJobs(0) + : m_bgcolor(::GetSysColor(COLOR_WINDOW)) , m_speed(0.0005) , m_moving(false) + , m_readJobs(0) + , m_toTheRight(true) + , m_position(0) + , m_mouthOpening(false) + , m_aperture(0) , m_lastUpdate(0) - , m_bgcolor(::GetSysColor(COLOR_WINDOW)) { Reset(); } @@ -64,7 +68,7 @@ void CPacman::SetSpeed(double speed) void CPacman::Start(bool start) { m_moving = start; - m_lastUpdate = ::GetTickCount(); + m_lastUpdate = _GetTickCount64(); } bool CPacman::Drive(ULONGLONG readJobs) @@ -76,8 +80,8 @@ bool CPacman::Drive(ULONGLONG readJobs) return false; } - DWORD now = ::GetTickCount(); - DWORD delta = now - m_lastUpdate; + const ULONGLONG now = _GetTickCount64(); + const ULONGLONG delta = now - m_lastUpdate; if(delta < UPDATEINTERVAL) { diff --git a/windirstat/Controls/pacman.h b/windirstat/Controls/pacman.h index 0bc6daa..2bfc0d3 100644 --- a/windirstat/Controls/pacman.h +++ b/windirstat/Controls/pacman.h @@ -49,7 +49,7 @@ private: double m_position; // 0...1 bool m_mouthOpening; // Mouth is opening double m_aperture; // 0...1 - DWORD m_lastUpdate; // TickCount + ULONGLONG m_lastUpdate; // TickCount }; #endif // __WDS_PACMAN_H__ diff --git a/windirstat/Controls/sortinglistcontrol.cpp b/windirstat/Controls/sortinglistcontrol.cpp index 7f17115..21c81b4 100644 --- a/windirstat/Controls/sortinglistcontrol.cpp +++ b/windirstat/Controls/sortinglistcontrol.cpp @@ -261,10 +261,15 @@ int CALLBACK CSortingListControl::_CompareFunc(LPARAM lParam1, LPARAM lParam2, L } BEGIN_MESSAGE_MAP(CSortingListControl, CListCtrl) +#pragma warning(suppress: 26454) ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnLvnGetdispinfo) +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_ITEMCLICKA, 0, OnHdnItemclick) +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_ITEMCLICKW, 0, OnHdnItemclick) +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_ITEMDBLCLICKA, 0, OnHdnItemdblclick) +#pragma warning(suppress: 26454) ON_NOTIFY(HDN_ITEMDBLCLICKW, 0, OnHdnItemdblclick) ON_WM_DESTROY() END_MESSAGE_MAP() diff --git a/windirstat/Controls/treemap.cpp b/windirstat/Controls/treemap.cpp index f91dd00..9cfe604 100644 --- a/windirstat/Controls/treemap.cpp +++ b/windirstat/Controls/treemap.cpp @@ -215,6 +215,9 @@ CTreemap::Options CTreemap::GetOldDefaultOptions() } CTreemap::CTreemap(Callback *callback) + : m_Lx(0.) + , m_Ly(0.) + , m_Lz(0.) { m_callback = callback; SetOptions(&_defaultOptions); diff --git a/windirstat/Controls/typeview.cpp b/windirstat/Controls/typeview.cpp index 3a83972..04442bb 100644 --- a/windirstat/Controls/typeview.cpp +++ b/windirstat/Controls/typeview.cpp @@ -217,8 +217,10 @@ int CExtensionListControl::CListItem::Compare(const CSortingListItem *baseOther, BEGIN_MESSAGE_MAP(CExtensionListControl, COwnerDrawnListControl) ON_WM_MEASUREITEM_REFLECT() ON_WM_DESTROY() +#pragma warning(suppress: 26454) ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnLvnDeleteitem) ON_WM_SETFOCUS() +#pragma warning(suppress: 26454) ON_NOTIFY_REFLECT(LVN_ITEMCHANGED, OnLvnItemchanged) ON_WM_KEYDOWN() END_MESSAGE_MAP() @@ -276,7 +278,6 @@ void CExtensionListControl::Initialize() void CExtensionListControl::OnDestroy() { - SetImageList(NULL, LVSIL_SMALL); COwnerDrawnListControl::OnDestroy(); } diff --git a/windirstat/Dialogs/SelectDrivesDlg.cpp b/windirstat/Dialogs/SelectDrivesDlg.cpp index 034d22e..00c1db7 100644 --- a/windirstat/Dialogs/SelectDrivesDlg.cpp +++ b/windirstat/Dialogs/SelectDrivesDlg.cpp @@ -260,11 +260,11 @@ CString CDriveItem::GetText(int subitem) const case COL_GRAPH: if(m_querying) { - s.LoadString(IDS_QUERYING); + VERIFY(s.LoadString(IDS_QUERYING)); } else if(!m_success) { - s.LoadString(IDS_NOTACCESSIBLE); + VERIFY(s.LoadString(IDS_NOTACCESSIBLE)); } break; @@ -453,6 +453,7 @@ void CDrivesList::OnLButtonDown(UINT /*nFlags*/, CPoint /*point*/) ZeroMemory(&lv, sizeof(lv)); lv.hdr.hwndFrom = m_hWnd; lv.hdr.idFrom = GetDlgCtrlID(); +#pragma warning(suppress: 26454) lv.hdr.code = LVN_ITEMCHANGED; GetParent()->SendMessage(WM_NOTIFY, GetDlgCtrlID(), (LPARAM)&lv); @@ -482,8 +483,10 @@ void CDrivesList::OnNMDblclk(NMHDR * /*pNMHDR*/, LRESULT *pResult) BEGIN_MESSAGE_MAP(CDrivesList, COwnerDrawnListControl) ON_WM_LBUTTONDOWN() +#pragma warning(suppress: 26454) ON_NOTIFY_REFLECT(LVN_DELETEITEM, OnLvnDeleteitem) ON_WM_MEASUREITEM_REFLECT() +#pragma warning(suppress: 26454) ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk) END_MESSAGE_MAP() @@ -533,6 +536,7 @@ BEGIN_MESSAGE_MAP(CSelectDrivesDlg, CDialog) ON_BN_CLICKED(IDC_SOMEDRIVES, OnBnClickedSomedrives) ON_EN_CHANGE(IDC_FOLDERNAME, OnEnChangeFoldername) ON_WM_MEASUREITEM() +#pragma warning(suppress: 26454) ON_NOTIFY(LVN_ITEMCHANGED, IDC_DRIVES, OnLvnItemchangedDrives) ON_BN_CLICKED(IDC_ALLLOCALDRIVES, OnBnClickedAlllocaldrives) ON_WM_SIZE() diff --git a/windirstat/Dialogs/aboutdlg.cpp b/windirstat/Dialogs/aboutdlg.cpp index b4e58c0..db1c90f 100644 --- a/windirstat/Dialogs/aboutdlg.cpp +++ b/windirstat/Dialogs/aboutdlg.cpp @@ -67,6 +67,11 @@ namespace } hresource = ::LoadResource(dll, hrsrc); + if (!hresource) + { + MdThrowLastWinerror(); + } + const BYTE *pData = (const BYTE *)::LockResource(hresource); CComBSTR bstr(dwSize, (LPCSTR)pData); @@ -153,7 +158,7 @@ void CAboutDlg::CMyTabControl::SetPageText(int tab) break; case TAB_THANKSTO: { - text.LoadString(IDS_ABOUT_THANKSTOTEXT); + VERIFY(text.LoadString(IDS_ABOUT_THANKSTOTEXT)); } break; case TAB_LICENSE: @@ -345,6 +350,7 @@ void CAboutDlg::DoDataExchange(CDataExchange* pDX) } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) +#pragma warning(suppress: 26454) ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnTcnSelchangeTab) ON_WM_SIZE() ON_WM_GETMINMAXINFO() diff --git a/windirstat/PageTreelist.cpp b/windirstat/PageTreelist.cpp index 8fb5e09..8c05f94 100644 --- a/windirstat/PageTreelist.cpp +++ b/windirstat/PageTreelist.cpp @@ -32,6 +32,9 @@ IMPLEMENT_DYNAMIC(CPageTreelist, CPropertyPage) CPageTreelist::CPageTreelist() : CPropertyPage(CPageTreelist::IDD) + , m_pacmanAnimation(FALSE) + , m_showTimeSpent(FALSE) + , m_treelistColorCount(TREELISTCOLORCOUNT) { } diff --git a/windirstat/WorkLimiter.cpp b/windirstat/WorkLimiter.cpp index 398dc79..91de963 100644 --- a/windirstat/WorkLimiter.cpp +++ b/windirstat/WorkLimiter.cpp @@ -12,9 +12,9 @@ CWorkLimiter::~CWorkLimiter() { } -void CWorkLimiter::Start(DWORD ticks) +void CWorkLimiter::Start(ULONGLONG ticks) { - DWORD start = Now(); + ULONGLONG start = CWorkLimiter::Now(); m_done = false; m_tickLimit = start + ticks; m_prevTicks = start; @@ -25,9 +25,9 @@ bool CWorkLimiter::IsDone() const if (m_done) return true; // check remaining ticks - DWORD now = Now(); + ULONGLONG now = CWorkLimiter::Now(); // signed subtraction to deal with overflow - long remaining = m_tickLimit - now; + ULONGLONG remaining = m_tickLimit - now; if (remaining <= 0) { m_done = true; @@ -35,7 +35,7 @@ bool CWorkLimiter::IsDone() const } // check if there are any pending window messages - long elapsed = now - m_prevTicks; + ULONGLONG elapsed = now - m_prevTicks; if (elapsed > 10) { m_prevTicks = now; @@ -50,11 +50,7 @@ bool CWorkLimiter::IsDone() const return false; } -void CWorkLimiter::DoFileWork() +inline ULONGLONG CWorkLimiter::Now() { -} - -DWORD CWorkLimiter::Now() const -{ - return ::GetTickCount(); + return _GetTickCount64(); } diff --git a/windirstat/WorkLimiter.h b/windirstat/WorkLimiter.h index 6c8d61b..a19791a 100644 --- a/windirstat/WorkLimiter.h +++ b/windirstat/WorkLimiter.h @@ -27,20 +27,19 @@ class CWorkLimiter { public: - CWorkLimiter(); - ~CWorkLimiter(); + CWorkLimiter(); + ~CWorkLimiter(); - void Start(DWORD ticks); - bool IsDone() const; - void DoFileWork(); + void Start(ULONGLONG ticks); + bool IsDone() const; private: - DWORD Now() const; + static ULONGLONG Now(); private: - mutable bool m_done; - DWORD m_tickLimit; - mutable DWORD m_prevTicks; + mutable bool m_done; + ULONGLONG m_tickLimit; + mutable ULONGLONG m_prevTicks; }; -#endif \ No newline at end of file +#endif diff --git a/windirstat/dirstatview.cpp b/windirstat/dirstatview.cpp index 75ae516..553bc22 100644 --- a/windirstat/dirstatview.cpp +++ b/windirstat/dirstatview.cpp @@ -244,6 +244,7 @@ BEGIN_MESSAGE_MAP(CDirstatView, CView) ON_WM_DESTROY() ON_WM_SETFOCUS() ON_WM_SETTINGCHANGE() +#pragma warning(suppress: 26454) ON_NOTIFY(LVN_ITEMCHANGED, _nIdTreeListControl, OnLvnItemchanged) ON_UPDATE_COMMAND_UI(ID_POPUP_TOGGLE, OnUpdatePopupToggle) ON_COMMAND(ID_POPUP_TOGGLE, OnPopupToggle) diff --git a/windirstat/getosplatformstring.cpp b/windirstat/getosplatformstring.cpp index 7e6f2ac..e04494d 100644 --- a/windirstat/getosplatformstring.cpp +++ b/windirstat/getosplatformstring.cpp @@ -45,7 +45,12 @@ CString GetOsPlatformString() if(!RtlGetVersion) { - *(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "RtlGetVersion"); + HMODULE hNtDll = GetModuleHandle(_T("ntdll.dll")); + if(!hNtDll) + { + return LoadString(IDS__UNKNOWN_); + } + *(FARPROC*)&RtlGetVersion = GetProcAddress(hNtDll, "RtlGetVersion"); ASSERT(RtlGetVersion != NULL); if(!RtlGetVersion) { diff --git a/windirstat/globalhelpers.cpp b/windirstat/globalhelpers.cpp index d02880c..bda3f26 100644 --- a/windirstat/globalhelpers.cpp +++ b/windirstat/globalhelpers.cpp @@ -302,25 +302,25 @@ CString FormatAttributes(DWORD attr) return attributes; } -CString FormatMilliseconds(DWORD ms) +CString FormatMilliseconds(ULONGLONG ms) { CString ret; - DWORD sec = (ms + 500) / 1000; + ULONGLONG sec = (ms + 500) / 1000; - DWORD s = sec % 60; - DWORD min = sec / 60; + ULONGLONG s = sec % 60; + ULONGLONG min = sec / 60; - DWORD m = min % 60; + ULONGLONG m = min % 60; - DWORD h = min / 60; + ULONGLONG h = min / 60; if(h > 0) { - ret.Format(_T("%u:%02u:%02u"), h, m, s); + ret.Format(_T("%I64u:%02I64u:%02I64u"), h, m, s); } else { - ret.Format(_T("%u:%02u"), m, s); + ret.Format(_T("%I64u:%02I64u"), m, s); } return ret; } diff --git a/windirstat/globalhelpers.h b/windirstat/globalhelpers.h index 995a877..588d6f0 100644 --- a/windirstat/globalhelpers.h +++ b/windirstat/globalhelpers.h @@ -36,7 +36,7 @@ CString FormatDouble(double d); CString PadWidthBlanks(CString n, int width); CString FormatFileTime(const FILETIME& t); CString FormatAttributes(DWORD attr); -CString FormatMilliseconds(DWORD ms); +CString FormatMilliseconds(ULONGLONG ms); CString GetParseNameOfMyComputer(); void GetPidlOfMyComputer(LPITEMIDLIST *ppidl); void ShellExecuteWithAssocDialog(HWND hwnd, LPCTSTR filename); diff --git a/windirstat/item.cpp b/windirstat/item.cpp index cdb567d..469bc1d 100644 --- a/windirstat/item.cpp +++ b/windirstat/item.cpp @@ -163,7 +163,7 @@ CString CItem::GetText(int subitem) const else { if(m_readJobs == 1) - s.LoadString(IDS_ONEREADJOB); + VERIFY(s.LoadString(IDS_ONEREADJOB)); else s.FormatMessage(IDS_sREADJOBS, FormatCount(m_readJobs).GetString()); } @@ -1038,12 +1038,12 @@ void CItem::SetDone() m_done = true; } -DWORD CItem::GetTicksWorked() const +ULONGLONG CItem::GetTicksWorked() const { return m_ticksWorked; } -void CItem::AddTicksWorked(DWORD more) +void CItem::AddTicksWorked(ULONGLONG more) { m_ticksWorked += more; } @@ -1059,7 +1059,7 @@ void CItem::DoSomeWork(CWorkLimiter* limiter) DriveVisualUpdateDuringWork(); - const DWORD start = ::GetTickCount(); + const ULONGLONG start = _GetTickCount64(); if(GetType() == IT_DRIVE || GetType() == IT_DIRECTORY) { @@ -1133,7 +1133,7 @@ void CItem::DoSomeWork(CWorkLimiter* limiter) UpwardAddSubdirs(dirCount); SetReadJobDone(); - AddTicksWorked(::GetTickCount() - start); + AddTicksWorked(_GetTickCount64() - start); } if(GetType() == IT_DRIVE) { @@ -1162,10 +1162,10 @@ void CItem::DoSomeWork(CWorkLimiter* limiter) return; } - DWORD startChildren = ::GetTickCount(); + const ULONGLONG startChildren = _GetTickCount64(); while(!limiter->IsDone()) { - DWORD minticks = UINT_MAX; + ULONGLONG minticks = ULONGLONG_MAX; CItem *minchild = NULL; for(int i = 0; i < GetChildrenCount(); i++) { @@ -1185,12 +1185,12 @@ void CItem::DoSomeWork(CWorkLimiter* limiter) SetDone(); break; } - if (!limiter->IsDone()) + if (!limiter->IsDone()) { minchild->DoSomeWork(limiter); } } - AddTicksWorked(::GetTickCount() - startChildren); + AddTicksWorked(_GetTickCount64() - startChildren); } else { diff --git a/windirstat/item.h b/windirstat/item.h index 2624779..b8839e6 100644 --- a/windirstat/item.h +++ b/windirstat/item.h @@ -180,8 +180,8 @@ public: void SetReadJobDone(bool done = true); bool IsDone() const; void SetDone(); - DWORD GetTicksWorked() const; - void AddTicksWorked(DWORD more); + ULONGLONG GetTicksWorked() const; + void AddTicksWorked(ULONGLONG more); void DoSomeWork(CWorkLimiter* limiter); bool StartRefresh(); void UpwardSetUndone(); @@ -227,7 +227,7 @@ private: bool m_readJobDone; // FindFiles() (our own read job) is finished. bool m_done; // Whole Subtree is done. - DWORD m_ticksWorked; // ms time spent on this item. + ULONGLONG m_ticksWorked; // ms time spent on this item. ULONGLONG m_readJobs; // # "read jobs" in subtree. diff --git a/windirstat/mainframe.cpp b/windirstat/mainframe.cpp index 25d3a43..bbf8a2e 100644 --- a/windirstat/mainframe.cpp +++ b/windirstat/mainframe.cpp @@ -556,7 +556,7 @@ void CMainFrame::UpdateProgress() if(IsProgressSuspended()) { - suspended.LoadString(IDS_SUSPENDED_); + VERIFY(suspended.LoadString(IDS_SUSPENDED_)); } if(m_progressRange > 0) @@ -897,6 +897,11 @@ void CMainFrame::CopyToClipboard(LPCTSTR psz) LPVOID lp = ::GlobalLock(h); ASSERT(lp != NULL); + if (!lp) + { + MdThrowStringException(_T("GlobalLock failed.")); + } + _tcscpy_s((LPTSTR)lp, cchBufLen, psz); ::GlobalUnlock(h); diff --git a/windirstat/stdafx.cpp b/windirstat/stdafx.cpp index 3c5e83a..3970128 100644 --- a/windirstat/stdafx.cpp +++ b/windirstat/stdafx.cpp @@ -1,32 +1,76 @@ -// stdafx.cpp - source file that includes just the standard includes -// -// WinDirStat - Directory Statistics -// Copyright (C) 2003-2005 Bernhard Seifert -// Copyright (C) 2004-2017 WinDirStat Team (windirstat.net) -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// - -#include "stdafx.h" - -#if !defined(HAVE_WIN7_SDK) || !HAVE_WIN7_SDK -# if _MSC_VER <= 1500 -# if !defined(_ANSISTRING) || !defined(ANSISTRING) -# define _ANSISTRING(text) #text -# define ANSISTRING(text) _ANSISTRING(text) -# endif -# pragma message (ANSISTRING(__FILE__) "(" ANSISTRING(__LINE__) ") : warning: You're building a feature-incomplete WinDirStat ('#define HAVE_WIN7_SDK' missing or 0). Refer to https://bitbucket.org/windirstat/windirstat/wiki/Building for details on how to build with this version of Visual Studio.") -# endif // Visual C/C++ 2008 and below -#endif // HAVE_WIN7_SDK +// stdafx.cpp - source file that includes just the standard includes +// +// WinDirStat - Directory Statistics +// Copyright (C) 2003-2005 Bernhard Seifert +// Copyright (C) 2004-2017 WinDirStat Team (windirstat.net) +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// + +#include "stdafx.h" + +#if !defined(HAVE_WIN7_SDK) || !HAVE_WIN7_SDK +# if _MSC_VER <= 1500 +# if !defined(_ANSISTRING) || !defined(ANSISTRING) +# define _ANSISTRING(text) #text +# define ANSISTRING(text) _ANSISTRING(text) +# endif +# pragma message (ANSISTRING(__FILE__) "(" ANSISTRING(__LINE__) ") : warning: You're building a feature-incomplete WinDirStat ('#define HAVE_WIN7_SDK' missing or 0). Refer to https://bitbucket.org/windirstat/windirstat/wiki/Building for details on how to build with this version of Visual Studio.") +# endif // Visual C/C++ 2008 and below +#endif // HAVE_WIN7_SDK + +#if (_WIN32_WINNT < _WIN32_WINNT_VISTA) +namespace { + // Borrowed from: http://terryto-blog.tumblr.com/post/6722591298/gettickcount64-alternatives + static ULONGLONG WINAPI CompatibleGetTickCount64_() + { + static __declspec(thread) ULONGLONG high = 0; + static __declspec(thread) ULONG lastLow = 0; +#pragma warning(suppress: 28159) + const ULONG low = GetTickCount(); + if (lastLow > low) + { /* wrapped */ + high += 0x100000000I64; + } /* else... not wrapped */ + lastLow = low; + return high | (ULONGLONG)low; + } +} + +typedef ULONGLONG(WINAPI *GetTickCount64_t)(void); +EXTERN_C GetTickCount64_t _GetTickCount64 = NULL; + +void InitGetTickCount64() +{ + if (!_GetTickCount64) + { + static HMODULE hKernel32 = ::GetModuleHandle(_T("kernel32.dll")); + if (hKernel32) + { + GetTickCount64_t pfnGetTickCount64 = (GetTickCount64_t)::GetProcAddress(hKernel32, "GetTickCount64"); + if (pfnGetTickCount64) + { + _GetTickCount64 = pfnGetTickCount64; + } + } + } + if (!_GetTickCount64) + { + // Fallback + _GetTickCount64 = CompatibleGetTickCount64_; + } +} + +#endif /* (_WIN32_WINNT < _WIN32_WINNT_VISTA) */ diff --git a/windirstat/stdafx.h b/windirstat/stdafx.h index ff866ee..21d1d6f 100644 --- a/windirstat/stdafx.h +++ b/windirstat/stdafx.h @@ -22,7 +22,7 @@ // #ifndef __STDAFX_H_VER__ -#define __STDAFX_H_VER__ 2017112319 +#define __STDAFX_H_VER__ 2018100918 #if (defined(_MSC_VER) && (_MSC_VER >= 1020)) || defined(__MCPP) #pragma once #endif /* Check for "#pragma once" support */ @@ -59,6 +59,7 @@ #include // floor(), fmod(), sqrt() etc. #include // DBL_MAX #include // PROCESS_MEMORY_INFO +#include // ULONGLONG_MAX #include // ComPtr<> @@ -71,4 +72,12 @@ template int signum(T x) { return (x) < 0 ? -1 : (x) == 0 ? 0 : 1; } /// signum function for unsigned numbers. template int usignum(T x, T y) { return (x) < (y) ? -1 : (x) == (y) ? 0 : 1; } +#if (_WIN32_WINNT >= _WIN32_WINNT_VISTA) +#define _GetTickCount64 GetTickCount64 +#else +typedef ULONGLONG(WINAPI *GetTickCount64_t)(void); +EXTERN_C GetTickCount64_t _GetTickCount64; +void InitGetTickCount64(); +#endif /* (_WIN32_WINNT >= _WIN32_WINNT_VISTA) */ + #endif /* __STDAFX_H_VER__ */ diff --git a/windirstat/windirstat.cpp b/windirstat/windirstat.cpp index fd325ff..c60ad9f 100644 --- a/windirstat/windirstat.cpp +++ b/windirstat/windirstat.cpp @@ -92,7 +92,11 @@ CDirstatApp::CDirstatApp() , m_langid(0) , m_workingSet(0) , m_pageFaults(0) - , m_lastPeriodicalRamUsageUpdate(::GetTickCount()) +# if (_WIN32_WINNT < _WIN32_WINNT_VISTA) + , m_lastPeriodicalRamUsageUpdate(0) +# else + , m_lastPeriodicalRamUsageUpdate(_GetTickCount64()) +# endif /* (_WIN32_WINNT < _WIN32_WINNT_VISTA) */ , m_altColor(GetAlternativeColor(RGB(0x00, 0x00, 0xFF), _T("AltColor"))) , m_altEncryptionColor(GetAlternativeColor(RGB(0x00, 0x80, 0x00), _T("AltEncryptionColor"))) # if SUPPORT_ELEVATION @@ -107,6 +111,11 @@ CDirstatApp::CDirstatApp() TestScanResourceDllName(); # endif +# if (_WIN32_WINNT < _WIN32_WINNT_VISTA) + InitGetTickCount64(); + m_lastPeriodicalRamUsageUpdate = _GetTickCount64(); +# endif /* (_WIN32_WINNT < _WIN32_WINNT_VISTA) */ + # if SUPPORT_ELEVATION m_ElevationEventName.Format(WINDIRSTAT_EVENT_NAME_FMT, GetCurrentDesktopName().GetBuffer(), GetCurrentWinstaName().GetBuffer()); VTRACE(_T("Elevation event: %s"), m_ElevationEventName.GetBuffer()); @@ -118,8 +127,8 @@ CDirstatApp::~CDirstatApp() #if SUPPORT_ELEVATION if (m_ElevationEvent) { - CloseHandle(m_ElevationEvent); //make sure this is the very last thing that is destroyed (way after WM_CLOSE) - } + ::CloseHandle(m_ElevationEvent); //make sure this is the very last thing that is destroyed (way after WM_CLOSE) + } #endif // SUPPORT_ELEVATION } @@ -136,10 +145,10 @@ void CDirstatApp::UpdateRamUsage() void CDirstatApp::PeriodicalUpdateRamUsage() { - if(::GetTickCount() - m_lastPeriodicalRamUsageUpdate > 1200) + if(_GetTickCount64() - m_lastPeriodicalRamUsageUpdate > 1200) { UpdateRamUsage(); - m_lastPeriodicalRamUsageUpdate = ::GetTickCount(); + m_lastPeriodicalRamUsageUpdate = _GetTickCount64(); } } @@ -382,7 +391,7 @@ bool CDirstatApp::IsCorrectResourceDll(LPCTSTR path) return false; } - // TODO: introduce some method of checking the resource version + // TODO/FIXME: introduce some method of checking the resource version CString reference = LoadString(IDS_RESOURCEVERSION); diff --git a/windirstat/windirstat.h b/windirstat/windirstat.h index bc6f916..499b98c 100644 --- a/windirstat/windirstat.h +++ b/windirstat/windirstat.h @@ -118,7 +118,7 @@ protected: CMyImageList m_myImageList; // Our central image list ULONGLONG m_workingSet; // Current working set (RAM usage) ULONGLONG m_pageFaults; // Page faults so far (unused) - DWORD m_lastPeriodicalRamUsageUpdate; // Tick count + ULONGLONG m_lastPeriodicalRamUsageUpdate; // Tick count COLORREF m_altColor; // Coloring of compressed items COLORREF m_altEncryptionColor; // Coloring of encrypted items #if SUPPORT_ELEVATION -- cgit v1.2.3