Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 76 additions & 20 deletions third_party/ImFileDialog/ImFileDialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)

Check notice on line 1 in third_party/ImFileDialog/ImFileDialog.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 10.18 to 10.09, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.

Check notice on line 1 in third_party/ImFileDialog/ImFileDialog.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Primitive Obsession

The ratio of primitive types in function arguments decreases from 69.77% to 68.18%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.

Check notice on line 1 in third_party/ImFileDialog/ImFileDialog.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: String Heavy Function Arguments

The ratio of strings in function arguments decreases from 44.19% to 43.18%, threshold = 39.0%. The functions in this file have a high ratio of strings as arguments. Avoid adding more.
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "ImFileDialog.h"
Expand All @@ -17,8 +17,11 @@

#ifdef _WIN32
#include <windows.h>
#include <commctrl.h>
#include <commoncontrols.h>
#include <shellapi.h>
#include <lmcons.h>
#pragma comment(lib, "Comctl32.lib")
#pragma comment(lib, "Shell32.lib")
#else
#include <unistd.h>
Expand All @@ -33,6 +36,74 @@
static std::string u8StringToString(const std::u8string& str) {
return reinterpret_cast<const char*>(str.c_str());
}

namespace
{
struct Image
{
std::vector<uint8_t> Pixels;
int Width, Height;
};

#ifdef _WIN32
std::optional<Image> GetFileIconWin32(const SHFILEINFOW& sfi)
{
auto list = static_cast<HIMAGELIST>(nullptr);

if (FAILED(SHGetImageList(SHIL_LARGE, IID_IImageList, reinterpret_cast<void**>(&list))))
{
return std::nullopt;
}

const auto icon = ImageList_GetIcon(list, sfi.iIcon, ILD_NORMAL);

if (icon == nullptr)
{
return std::nullopt;
}

std::optional<Image> image;

ICONINFO info = {};

if (GetIconInfo(icon, &info))
{
if (info.hbmColor != nullptr)
{
DIBSECTION ds = {};

if (GetObject(info.hbmColor, sizeof(ds), &ds))
{
const auto bm = ds.dsBm;
const auto bw = bm.bmWidth;
const auto bh = bm.bmHeight;

if (const auto size = bw * bh * (bm.bmBitsPixel / 8); size > 0)
{
auto bits = std::vector<uint8_t>();

bits.resize(size);

if (GetBitmapBits(info.hbmColor, size, bits.data()))
{
image = Image{.Pixels = bits, .Width = bw, .Height = bh};
}
}
}
}

DeleteObject(info.hbmColor);

DeleteObject(info.hbmMask);
}

DestroyIcon(icon);

return image;
}

Check warning on line 103 in third_party/ImFileDialog/ImFileDialog.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Deep, Nested Complexity

GetFileIconWin32 has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.
#endif
}

namespace ifd {
static const char* GetDefaultFolderIcon();
static const char* GetDefaultFileIcon();
Expand Down Expand Up @@ -748,27 +819,12 @@
m_iconIndices.push_back(fileInfo.iIcon);
m_iconFilepaths.push_back(pathU8);

ICONINFO iconInfo = { 0 };
GetIconInfo(fileInfo.hIcon, &iconInfo);

if (iconInfo.hbmColor == nullptr)
return nullptr;

DIBSECTION ds;
GetObject(iconInfo.hbmColor, sizeof(ds), &ds);
int byteSize = ds.dsBm.bmWidth * ds.dsBm.bmHeight * (ds.dsBm.bmBitsPixel / 8);

if (byteSize == 0)
return nullptr;

uint8_t* data = (uint8_t*)malloc(byteSize);
GetBitmapBits(iconInfo.hbmColor, byteSize, data);

m_icons[pathU8] = this->CreateTexture(data, ds.dsBm.bmWidth, ds.dsBm.bmHeight, 0);

free(data);
if (auto image = GetFileIconWin32(fileInfo); image.has_value())
{
return m_icons[pathU8] = this->CreateTexture(image->Pixels.data(), image->Width, image->Height, 0);
}

return m_icons[pathU8];
return nullptr;

Check notice on line 827 in third_party/ImFileDialog/ImFileDialog.cpp

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Complex Method

FileDialog::m_getIcon decreases in cyclomatic complexity from 17 to 16, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
#else
if (m_icons.count(u8StringToString(path.u8string())) > 0)
return m_icons[u8StringToString(path.u8string())];
Expand Down
Loading