Skip to content

Commit

Permalink
Tweaks and cosmetics
Browse files Browse the repository at this point in the history
Fixes various compiler and intellisense warnings
  • Loading branch information
brianferguson committed Sep 15, 2022
1 parent 42d5518 commit 5e66445
Show file tree
Hide file tree
Showing 79 changed files with 1,341 additions and 1,215 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.patch
*.txt
*.user
*.aps
/.vs
/ipch
/TestBench
Expand Down
11 changes: 6 additions & 5 deletions Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
//_CrtSetBreakAlloc(000);

// Prevent system error message boxes.
UINT oldMode = SetErrorMode(0);
UINT oldMode = SetErrorMode(0U);
SetErrorMode(oldMode | SEM_FAILCRITICALERRORS);

HINSTANCE instance = (HINSTANCE)&__ImageBase;
Expand All @@ -75,7 +75,7 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
}
}

WCHAR message[128];
WCHAR message[128] = { 0 };
wsprintf(
message,
L"Rainmeter.dll load error %ld.",
Expand All @@ -85,13 +85,13 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
else
{
// Stub prodecure. If icon resources have been removed, try to launch the actual Rainmeter.exe.
HKEY hKey;
HKEY hKey = nullptr;
const REGSAM desiredSam = KEY_QUERY_VALUE | KEY_WOW64_32KEY;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Rainmeter", 0, desiredSam, &hKey) == ERROR_SUCCESS)
{
const DWORD size = MAX_PATH;
WCHAR buffer[size];
DWORD type = 0;
WCHAR buffer[size] = { 0 };
DWORD type = 0UL;
if (RegQueryValueEx(hKey, nullptr , nullptr, &type, (LPBYTE)buffer, (LPDWORD)&size) == ERROR_SUCCESS &&
type == REG_SZ)
{
Expand All @@ -100,6 +100,7 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
ShellExecute(nullptr, L"open", buffer, args, nullptr, SW_SHOWNORMAL);
}
RegCloseKey(hKey);
hKey = nullptr;
}

return 0;
Expand Down
1 change: 1 addition & 0 deletions Common/Dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void BaseDialog::Show(const WCHAR* title, short x, short y, short w, short h, DW
}

delete [] dt;
dt = nullptr;
}

void BaseDialog::CreateControls(const ControlTemplate::Control* cts, UINT ctCount, HFONT font, ControlTemplate::GetStringFunc getString)
Expand Down
4 changes: 2 additions & 2 deletions Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ bool GetBinaryFileBitness(const WCHAR* path, WORD& bitness)
};

hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, nullptr);
if (hFile == INVALID_HANDLE_VALUE) return cleanUp(false);
if (!hFile || hFile == INVALID_HANDLE_VALUE) return cleanUp(false);

hMapping = CreateFileMapping(hFile, nullptr, PAGE_READONLY | SEC_IMAGE, 0UL, 0UL, nullptr);
if (hMapping == INVALID_HANDLE_VALUE) return cleanUp(false);
if (!hMapping || hMapping == INVALID_HANDLE_VALUE) return cleanUp(false);

addrMapping = MapViewOfFile(hMapping, FILE_MAP_READ, 0UL, 0UL, 0UL);
if (!addrMapping) return cleanUp(false);
Expand Down
21 changes: 10 additions & 11 deletions Common/Gfx/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ void Canvas::DrawTextW(const std::wstring& srcStr, const TextFormat& format, con
rect.bottom - rect.top,
!m_AccurateText && m_TextAntiAliasing)) return;

D2D1_POINT_2F drawPosition;
D2D1_POINT_2F drawPosition = D2D1::Point2F();
drawPosition.x = [&]()
{
if (!m_AccurateText)
Expand Down Expand Up @@ -558,12 +558,11 @@ bool Canvas::MeasureTextLinesW(const std::wstring& str, const TextFormat& format
return true;
}

void Canvas::DrawBitmap(const D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect)
void Canvas::DrawBitmap(D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect)
{
auto& segments = bitmap->m_Segments;
for (auto seg : segments)
for (auto& segment : bitmap->m_Segments)
{
const auto rSeg = seg.GetRect();
const auto& rSeg = segment.GetRect();
D2D1_RECT_F rSrc = (rSeg.left < rSeg.right && rSeg.top < rSeg.bottom) ?
D2D1::RectF(
max(rSeg.left, srcRect.left),
Expand Down Expand Up @@ -591,11 +590,11 @@ void Canvas::DrawBitmap(const D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, con
rSrc.left -= m_MaxBitmapSize;
}

m_Target->DrawBitmap(seg.GetBitmap(), rDst, 1.0f, D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC, &rSrc);
m_Target->DrawBitmap(segment.GetBitmap(), rDst, 1.0f, D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC, &rSrc);
}
}

void Canvas::DrawTiledBitmap(const D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect)
void Canvas::DrawTiledBitmap(D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect)
{
const FLOAT width = (FLOAT)bitmap->m_Width;
const FLOAT height = (FLOAT)bitmap->m_Height;
Expand All @@ -621,7 +620,7 @@ void Canvas::DrawTiledBitmap(const D2DBitmap* bitmap, const D2D1_RECT_F& dstRect
}
}

void Canvas::DrawMaskedBitmap(const D2DBitmap* bitmap, const D2DBitmap* maskBitmap, const D2D1_RECT_F& dstRect,
void Canvas::DrawMaskedBitmap(D2DBitmap* bitmap, D2DBitmap* maskBitmap, const D2D1_RECT_F& dstRect,
const D2D1_RECT_F& srcRect, const D2D1_RECT_F& srcRect2)
{
if (!bitmap || !maskBitmap) return;
Expand All @@ -645,7 +644,7 @@ void Canvas::DrawMaskedBitmap(const D2DBitmap* bitmap, const D2DBitmap* maskBitm
(r1.bottom - r1.top) / height * r2.bottom);
};

for (auto bseg : bitmap->m_Segments)
for (auto& bseg : bitmap->m_Segments)
{
const auto rSeg = bseg.GetRect();
const auto rDst = getRectSubRegion(rSeg, dstRect);
Expand All @@ -671,7 +670,7 @@ void Canvas::DrawMaskedBitmap(const D2DBitmap* bitmap, const D2DBitmap* maskBitm
const auto aaMode = m_Target->GetAntialiasMode();
m_Target->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED); // required

for (auto mseg : maskBitmap->m_Segments)
for (auto& mseg : maskBitmap->m_Segments)
{
const auto rmSeg = mseg.GetRect();
const auto rmDst = getRectSubRegion(rmSeg, dstRect);
Expand Down Expand Up @@ -719,7 +718,7 @@ void Canvas::FillGradientRectangle(const D2D1_RECT_F& rect, const D2D1_COLOR_F&

Microsoft::WRL::ComPtr<ID2D1GradientStopCollection> pGradientStops;

D2D1_GRADIENT_STOP gradientStops[2];
D2D1_GRADIENT_STOP gradientStops[2] = { 0 };
gradientStops[0].color = color1;
gradientStops[0].position = 0.0f;
gradientStops[1].color = color2;
Expand Down
6 changes: 3 additions & 3 deletions Common/Gfx/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class Canvas
bool MeasureTextW(const std::wstring& srcStr, const TextFormat& format, D2D1_SIZE_F& size);
bool MeasureTextLinesW(const std::wstring& srcStr, const TextFormat& format, D2D1_SIZE_F& size, UINT32& lines);

void DrawBitmap(const D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect);
void DrawTiledBitmap(const D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect);
void DrawMaskedBitmap(const D2DBitmap* bitmap, const D2DBitmap* maskBitmap, const D2D1_RECT_F& dstRect,
void DrawBitmap(D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect);
void DrawTiledBitmap(D2DBitmap* bitmap, const D2D1_RECT_F& dstRect, const D2D1_RECT_F& srcRect);
void DrawMaskedBitmap(D2DBitmap* bitmap, D2DBitmap* maskBitmap, const D2D1_RECT_F& dstRect,
const D2D1_RECT_F& srcRect, const D2D1_RECT_F& srcRect2);

void FillRectangle(const D2D1_RECT_F& rect, const D2D1_COLOR_F& color);
Expand Down
2 changes: 1 addition & 1 deletion Common/Gfx/TextFormatD2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool TextFormatD2D::CreateLayout(ID2D1DeviceContext* target, const std::wstring&

bool strChanged = false;
if (strLen != m_LastString.length() ||
memcmp(str, m_LastString.c_str(), (strLen + 1) * sizeof(WCHAR)) != 0)
memcmp(str, m_LastString.c_str(), ((size_t)strLen + 1ULL) * sizeof(WCHAR)) != 0)
{
strChanged = true;
m_LastString.assign(str, strLen);
Expand Down
2 changes: 2 additions & 0 deletions Common/Gfx/TextInlineFormat/TextInlineFormatGradientColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ struct GradientHelper
DWRITE_TEXT_RANGE range;
std::vector<DWRITE_TEXT_RANGE> innerRanges;
std::vector<Microsoft::WRL::ComPtr<ID2D1LinearGradientBrush>> brushes;

GradientHelper() : range() {}
};

}
Expand Down
6 changes: 3 additions & 3 deletions Common/MathParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ struct Parser
char valTop;
int obrDist;

Parser() : opTop(0), valTop(-1), obrDist(2) { opStack[0].type = Operator::OpeningBracket; }
Parser() : opStack(), numStack(), opTop(0), valTop(-1), obrDist(2) { opStack[0].type = Operator::OpeningBracket; }
};

static const WCHAR* CalcToObr(Parser& parser);
Expand Down Expand Up @@ -361,7 +361,7 @@ const WCHAR* Parse(

default:
{
Operation op;
Operation op = {};
op.type = lexer.value.oper;
switch (op.type)
{
Expand Down Expand Up @@ -401,7 +401,7 @@ const WCHAR* Parse(

case Token::Name:
{
Operation op;
Operation op = {};
if (lexer.nameLen <= FUNC_MAX_LEN &&
((op.funcIndex = GetFunctionIndex(lexer.name, (BYTE)lexer.nameLen)) != FUNC_INVALID))
{
Expand Down
2 changes: 2 additions & 0 deletions Common/PathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ void ExpandEnvironmentVariables(std::wstring& path)
}

delete [] buffer;
buffer = nullptr;
bufSize = ret;
buffer = new WCHAR[bufSize];
}
while (true);
}

delete [] buffer;
buffer = nullptr;
}
}

Expand Down
7 changes: 3 additions & 4 deletions Common/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::wstring& GetBuildNumberFromRegistry()
return s_BuildNumber;
}

};
}; // namespace

inline bool IsWindows11OrGreater()
{
Expand Down Expand Up @@ -77,8 +77,7 @@ Platform& Platform::GetInstance()

void Platform::Initialize()
{
// Is Windows 64 bit?
m_Is64BitWindows = [&]() -> bool
m_Is64Bit = [&]() -> bool
{
#if _WIN64
return true;
Expand Down Expand Up @@ -185,7 +184,7 @@ void Platform::Initialize()

m_FriendlyName += L')';
}
m_FriendlyName += m_Is64BitWindows ? L" 64-bit" : L" 32-bit";
m_FriendlyName += m_Is64Bit ? L" 64-bit" : L" 32-bit";

// Retrieve user language LCID
LANGID id = GetUserDefaultUILanguage();
Expand Down
6 changes: 4 additions & 2 deletions Common/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

#include <string>

inline bool IsWindows11OrGreater();

class Platform
{
public:
static Platform& GetInstance();

bool Is64BitWindows() { return m_Is64BitWindows; }
bool Is64Bit() { return m_Is64Bit; }

std::wstring GetName() { return m_Name; }
std::wstring GetFriendlyName() { return m_FriendlyName; }
Expand All @@ -33,7 +35,7 @@ class Platform

void Initialize();

bool m_Is64BitWindows;
bool m_Is64Bit;

std::wstring m_Name;
std::wstring m_FriendlyName;
Expand Down
2 changes: 1 addition & 1 deletion Library/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void CommandHandler::DoWriteKeyValueBang(std::vector<std::wstring>& args, Skin*
}

// Verify whether the file exists.
if (_waccess(iniFile, 0) == -1)
if (_waccess_s(iniFile, 0) != 0)
{
LogErrorF(skin, L"!WriteKeyValue: File not found: %s", iniFile);
return;
Expand Down
Loading

0 comments on commit 5e66445

Please sign in to comment.