#69 support compile under Windows#723
Conversation
Reviewer's GuideRefactors time formatting to use GLib’s GDateTime, replaces raw strdup with GLib g_strdup for consistency and potential future memory management alignment, and introduces a platform-specific network header to centralize network-related includes while cleaning up unused POSIX networking includes. Flow diagram for updated nowAsString time formattingflowchart TD
A[nowAsString] --> B[g_date_time_new_now_local]
B --> C[g_date_time_get_hour]
B --> D[g_date_time_get_minute]
B --> E[g_date_time_get_seconds]
B --> F[g_date_time_unref]
C --> G["stringFormat \"%02d:%02d:%06.3f\""]
D --> G
E --> G
G --> H[return formatted_time_string]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The change to nowAsString() alters the timestamp format and now uses a floating-point seconds value; consider using g_date_time_format() or integer micro/milliseconds (e.g., g_date_time_get_microsecond()) to preserve a stable, zero-padded
HH:MM:SS.mmmformat and avoid floating-point rounding artifacts. - Introducing iptux_network.h with platform-specific socket headers is good for portability, but putting
#pragma comment(lib, ...)into a header can have surprising effects for consumers; consider moving the library linkage pragmas into a dedicated translation unit or the build system instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The change to nowAsString() alters the timestamp format and now uses a floating-point seconds value; consider using g_date_time_format() or integer micro/milliseconds (e.g., g_date_time_get_microsecond()) to preserve a stable, zero-padded `HH:MM:SS.mmm` format and avoid floating-point rounding artifacts.
- Introducing iptux_network.h with platform-specific socket headers is good for portability, but putting `#pragma comment(lib, ...)` into a header can have surprising effects for consumers; consider moving the library linkage pragmas into a dedicated translation unit or the build system instead.
## Individual Comments
### Comment 1
<location path="src/iptux-utils/output.cpp" line_range="60" />
<code_context>
-
- strftime(buffer, sizeof(buffer), "%H:%M:%S", &timeinfo);
- return stringFormat("%s.%03d", buffer, int(tv.tv_usec / 1000));
+ return stringFormat("%02d:%02d:%06.3f", hour, minute, seconds);
}
</code_context>
<issue_to_address>
**suggestion:** The time formatting for seconds may introduce leading spaces and a slightly harder-to-read timestamp.
"%06.3f" pads `seconds` to width 6, so values < 10 will have a leading space (e.g. " 9.123"), which differs from the previous "HH:MM:SS.mmm" format and may affect readability or log parsing expectations. Consider reconstructing the timestamp from `g_date_time_get_second()` and `g_date_time_get_microsecond()/1000` with a format like `"%02d:%02d:%02d.%03d"`, or using `g_date_time_format()` for consistent, parseable output.
Suggested implementation:
```cpp
static string nowAsString() {
GDateTime* dt = g_date_time_new_now_local();
gint hour = g_date_time_get_hour(dt);
gint minute = g_date_time_get_minute(dt);
gint second = g_date_time_get_second(dt);
gint msec = g_date_time_get_microsecond(dt) / 1000;
g_date_time_unref(dt);
return stringFormat("%02d:%02d:%02d.%03d", hour, minute, second, msec);
}
```
If there are other helpers or logging functions relying on the old `"HH:MM:SS.mmm"`-from-`strftime` behavior, verify that their expectations still match this format. If consistent formatting across the codebase is critical, consider centralizing this timestamp creation in a shared utility function or replacing custom formatting with `g_date_time_format()` using a format string like `"%H:%M:%S.%f"` truncated to milliseconds.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #723 +/- ##
==========================================
- Coverage 51.88% 51.54% -0.34%
==========================================
Files 64 64
Lines 8714 8841 +127
==========================================
+ Hits 4521 4557 +36
- Misses 4193 4284 +91 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Add a Windows implementation based on GetAdaptersAddresses and compute\nbroadcast addresses from each IPv4 unicast prefix. Keep the existing\nUnix ioctl path unchanged and add required Windows link libraries\n(iphlpapi, ws2_32) in meson for core/core-test targets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR advances Windows build support for iptux (the C++/GTK LAN messenger) by introducing Windows-friendly build/link settings, consolidating networking platform includes, and replacing several POSIX-only helpers with GLib/GIO alternatives to improve cross-platform portability.
Changes:
- Add Windows-specific Meson dependencies/linking (e.g.,
ws2_32,iphlpapi) and a GitHub Actions Windows CI workflow update (MSYS2 CLANG64). - Centralize platform networking includes via
iptux_network.hand adjust code to use GLib/GIO APIs for IP parsing/formatting and file/path handling. - Introduce Windows path launching helper and gate/adjust tests and time APIs for Windows builds.
Reviewed changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/meson.build | Conditional crash utils / link args for Windows |
| src/main/iptux.cpp | Windows-safe localtime_* + disable crash handler |
| src/iptux/UiModelsTest.cpp | Use g_strdup; skip some tests on Windows |
| src/iptux/UiModels.cpp | Update message source enum name |
| src/iptux/UIHelperWindows.h | Declare Windows “open path” helper |
| src/iptux/UIHelperWindows.cpp | Implement Windows path launcher (ShellExecuteW) |
| src/iptux/UiHelperTest.cpp | Skip TZ/image tests on Windows |
| src/iptux/UiHelper.h | Use iptux_network.h; add iptux_open_path |
| src/iptux/UiHelper.cpp | Implement iptux_open_path + Windows branch; localtime_* |
| src/iptux/UiCoreThread.h | Remove non-portable network include |
| src/iptux/UiCoreThread.cpp | Remove non-portable socket include |
| src/iptux/RevisePal.cpp | Cast for ntohl formatting portability |
| src/iptux/meson.build | Add Windows deps and build UiHelperWindows.cpp |
| src/iptux/MainWindow.h | Undef Windows CreateWindow macro collision |
| src/iptux/MainWindow.cpp | Add Windows strcasestr compat + localtime_* |
| src/iptux/LogSystem.cpp | Add logging, error checks, GLib path building |
| src/iptux/DialogPeer.cpp | Use g_build_filename for received file paths |
| src/iptux/DataSettings.h | Add missing <string> include |
| src/iptux/DataSettings.cpp | Replace getline/inet_pton flow with portable parsing helpers |
| src/iptux/callback.cpp | Use nullptr for GTK dialog sentinel |
| src/iptux/Application.cpp | Avoid SIGPIPE handling on Windows; open log paths |
| src/iptux-utils/UtilsTest.cpp | Skip dupPath test on Windows |
| src/iptux-utils/utils.h | Introduce iptux_network.h, add GSocket read/write overloads, add is_ipv4 |
| src/iptux-utils/utils.cpp | Use GLib networking helpers; add GSocket read/write; portable dir iteration |
| src/iptux-utils/TestHelper.cpp | Read test data as binary |
| src/iptux-utils/output.h | Qualify logging macros with ::iptux:: |
| src/iptux-utils/output.cpp | Switch timestamp formatting to GDateTime |
| src/iptux-utils/meson.build | Add Windows libs to utils deps |
| src/iptux-utils/Exception.cpp | Inline getErrorCode() in header |
| src/iptux-core/ProgramData.cpp | Use g_strdup for filepath duplication |
| src/iptux-core/ModelsTest.cpp | Use new IP helpers in tests |
| src/iptux-core/Models.cpp | Remove non-portable network include |
| src/iptux-core/meson.build | Add Windows libs (ws2_32, iphlpapi) to core deps |
| src/iptux-core/internal/TcpData.cpp | Use O_BINARY; use this->socket consistently |
| src/iptux-core/internal/support.cpp | Add Windows broadcast discovery path; adjust socket reuse helper |
| src/iptux-core/internal/SendFileData.h | Switch from fd int to GSocket* |
| src/iptux-core/internal/SendFileData.cpp | Use GSocket*, O_BINARY, GLib basename/IP formatting |
| src/iptux-core/internal/SendFile.h | Switch send APIs to GSocket* |
| src/iptux-core/internal/SendFile.cpp | Adapt send pipeline to GSocket* + GLib basename |
| src/iptux-core/internal/RecvFileData.h | Add GOutputStream* receive path |
| src/iptux-core/internal/RecvFileData.cpp | Use GIO stream writing for Windows-friendly receiving |
| src/iptux-core/internal/iptux_network.h | New cross-platform networking include hub |
| src/iptux-core/internal/Command.cpp | Use O_BINARY; update enum usage; sendto cast tweak |
| src/iptux-core/internal/AnalogFS.cpp | Use GLib path building/current dir for portability |
| src/iptux-core/CoreThread.cpp | Remove non-portable socket include |
| src/api/iptux-core/TransFileModel.h | Add <cstdint> include |
| src/api/iptux-core/Models.h | Windows networking include + enum rename |
| src/api/iptux-core/Exception.h | Inline getErrorCode() |
| src/api/iptux-core/CoreThread.h | Remove non-portable network include |
| meson.build | Add warning suppressions helpful for clang/Windows toolchains |
| .github/workflows/windows.yml | Update Windows CI (checkout v4, MSYS2 CLANG64, extra checks) |
| .gitattributes | Enforce LF endings and mark binaries/testdata |
Comments suppressed due to low confidence (1)
src/iptux-core/internal/RecvFileData.cpp:521
- g_output_stream_write_all() returns gboolean (TRUE/FALSE), not -1. Comparing the return value to -1 will never detect failures, so receive-to-file may silently ignore write errors and report success incorrectly.
| int len; | ||
| char optval; | ||
|
|
||
| optval = 1; | ||
| len = sizeof(optval); |
| if (!::getcwd(path, MAX_PATHLEN)) { | ||
| gchar* current_dir = g_get_current_dir(); | ||
| if (current_dir) { | ||
| strncpy(path, current_dir, MAX_PATHLEN); |
| #include "UIHelperWindows.h" | ||
| #include "iptux-utils/output.h" | ||
| #include <windows.h> | ||
| #include <shellapi.h> | ||
|
|
| void iptux_launch_file_windows(const char* utf8_path) { | ||
| int len = MultiByteToWideChar(CP_UTF8, 0, utf8_path, -1, NULL, 0); | ||
| wchar_t* w_path = (wchar_t*)malloc(len * sizeof(wchar_t)); | ||
| MultiByteToWideChar(CP_UTF8, 0, utf8_path, -1, w_path, len); | ||
|
|
||
| HINSTANCE result = ShellExecuteW( | ||
| NULL, // 父窗口句柄 | ||
| L"open", // 操作类型:打开 | ||
| w_path, // 文件路径 | ||
| NULL, // 命令行参数 | ||
| NULL, // 工作目录 | ||
| SW_SHOWNORMAL // 显示方式 | ||
| ); | ||
|
|
||
| // 3. 释放内存 | ||
| free(w_path); | ||
|
|
||
| // 检查是否成功 | ||
| if ((INT_PTR)result <= 32) { | ||
| LOG_ERROR("Failed to open path: %s, error code: %jd", utf8_path, (intmax_t)(INT_PTR)result); | ||
| } | ||
| } |
| /* 检查好友数据是否存在 */ | ||
| len = sizeof(addr); | ||
| (void)len; | ||
| #if 0 |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
❌ The last analysis has failed. |
/close #69
Summary by Sourcery
Modernize time formatting and networking includes while aligning string allocation with GLib utilities.
Bug Fixes:
Enhancements:
Tests: