cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
ninja -C buildRequires MSVC (GNU/MinGW is explicitly rejected). ImGui is fetched automatically via CMake FetchContent at configure time (requires network access). The CMake config auto-detects x64/x86 for linking the correct pre-built lib. The output is build/name_exchanger_x64.exe (or _x86).
Windows desktop app (C++20, ImGui, DirectX 11) that swaps the names of two files or directories. A no-GUI command-line mode is also supported (name_exchanger <path1> <path2> [preserve]).
The actual file/directory rename logic lives in a pre-compiled Rust library at lib/name_exchanger_x64.lib and lib/name_exchanger_x86.lib, exposed via:
extern "C" int exchange(const char* path1, const char* path2, bool preserve_ext);
// return 0 = success, 1 = not found, 2 = permission denied, 3 = target exists, 4 = same file, 5 = invalid path-
main.cpp—WinMainentry point. Enforces single-instance via a named mutex (CFFD3CF9A003453C9893A8CD49EF7ED5). If a second instance starts, it finds and activates the existing window instead. -
src/app.hpp/src/app.cpp— The entire application: window creation, D3D11/ImGui init, the main loop, and the full UI rendering inRenderUI(). Uses aPopTooltip()/PopFont()pattern throughout — each UI element is responsible for popping whatever style/font/color it pushes. Top bar uses custom icon-font "letters" (A–H) rendered viakIconFontDatafromfont_data.hpp; each maps to a toolbar button glyph. -
src/utils.hpp/src/utils.cpp—Utf16ToUtf8/Utf8ToUtf16converters,IsRunAsAdmin(), andRunAsAdmin().RunAsAdminhandles privilege escalation viaShellExecuteEx(runas)and de-escalation by duplicating explorer's token. -
src/i18n.hpp/src/i18n.cpp— Three-language i18n (Simplified Chinese, Traditional Chinese, English).DetectSystemLanguage()usesGetUserDefaultUILanguage(). All UI strings live inLocaleStringsstructs;GetCurrentLocale()caches detection result. -
src/d3d_helpers.hpp/src/d3d_helpers.cpp— Thin helpers for D3D11 device/swapchain/render-target lifecycle. Tries hardware device first, falls back to WARP software rasterizer. -
src/tray.hpp/src/tray.cpp— System tray icon setup/removal viaShell_NotifyIconW. Tray messages arrive asWM_USER + 1and are handled inHandleMessage. -
src/font_data.hpp— Auto-generated binary blob from a custom TTF icon font. ThekIconFontDataarray is loaded as an ImGui memory font at 15pt. -
res/— Windows resource files: icon, version info, andversion.hpp.
- The window is borderless (
WS_POPUP), with a custom top bar painted in the Windows accent color. Empty area of the top bar is draggable (simulatesWM_NCLBUTTONDOWNonHTCAPTION). - DPI changes trigger font rebuild (
WM_DPICHANGEDhandler inHandleMessage). - Theme changes (
WM_THEMECHANGED,WM_SETTINGCHANGE) causeApplySystemTheme()to re-read system colors and Windows dark-mode setting. - Input focus is cleared when the window loses foreground to avoid stale ImGui active IDs.
- All font face names are resolved against
c:\Windows\Fonts\msyh.ttc(Chinese) with a fallback to ImGui default.
All internal path data is UTF-8 (std::string). The Win32 layer and ImGui's InputText need UTF-8, so paths are converted at the boundary via Utf16ToUtf8/Utf8ToUtf16. Console output (for CLI mode errors) writes UTF-8 to stderr.