Skip to content

#69 support compile under Windows#723

Draft
lidaobing wants to merge 43 commits into
mainfrom
bf_69_windows_2
Draft

#69 support compile under Windows#723
lidaobing wants to merge 43 commits into
mainfrom
bf_69_windows_2

Conversation

@lidaobing

@lidaobing lidaobing commented Jul 5, 2026

Copy link
Copy Markdown
Member

/close #69

  • send/recv msg
  • send/recv image
  • send/recv file
  • send/recv dir
  • scan neighbors when start
  • chat log / system log
  • crash problem

Summary by Sourcery

Modernize time formatting and networking includes while aligning string allocation with GLib utilities.

Bug Fixes:

  • Use GLib g_strdup for string duplication to ensure consistency with GLib memory management.

Enhancements:

  • Replace gettimeofday/localtime-based timestamp generation with GLib GDateTime for log output.
  • Introduce a cross-platform iptux_network.h header to centralize network-related includes for Windows and Unix-like systems.
  • Clean up low-level networking includes from utility headers to reduce unnecessary dependencies.

Tests:

  • Update UiModelsTest to use GLib g_strdup for test data string allocation.

@lidaobing lidaobing self-assigned this Jul 5, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors 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 formatting

flowchart 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]
Loading

File-Level Changes

Change Details Files
Switch time formatting to GLib GDateTime for log timestamp generation.
  • Replace gettimeofday/localtime_r/strftime-based timestamp construction with GDateTime-based time retrieval.
  • Compute hour, minute, and fractional seconds via g_date_time_get_* APIs.
  • Format the timestamp string with millisecond precision using stringFormat and a single format string.
  • Ensure the GDateTime object is properly unref’d after use.
src/iptux-utils/output.cpp
Align string duplication with GLib conventions in core data structures and tests.
  • Replace strdup with g_strdup when assigning fileInfo.filepath in ProgramData::ReadProgData.
  • Replace strdup with g_strdup for cpal->sign in UiModelsTest, keeping tests consistent with production code.
src/iptux-core/ProgramData.cpp
src/iptux/UiModelsTest.cpp
Centralize and make platform-specific network-related includes while removing unused POSIX networking headers from generic utilities.
  • Introduce a new internal iptux_network.h header that abstracts platform-specific network includes for Windows vs. non-Windows builds.
  • Update support.cpp to include iptux_network.h instead of directly including <net/if.h>.
  • Remove <netinet/in.h> from utils.h to avoid leaking low-level networking headers into generic utility code.
src/iptux-core/internal/support.cpp
src/iptux-utils/utils.h
src/iptux-core/internal/iptux_network.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Test Results

69 tests  ±0   69 ✅ ±0   3s ⏱️ ±0s
32 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 69e4b7e. ± Comparison against base commit 6b98e8e.

♻️ This comment has been updated with latest results.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/iptux-utils/output.cpp Outdated
@lidaobing lidaobing marked this pull request as draft July 5, 2026 01:32
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 32.44275% with 177 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.54%. Comparing base (6b98e8e) to head (69e4b7e).

Files with missing lines Patch % Lines
src/iptux-core/internal/RecvFileData.cpp 0.00% 53 Missing ⚠️
src/iptux-core/internal/AnalogFS.cpp 12.50% 35 Missing ⚠️
src/iptux-utils/utils.cpp 62.16% 28 Missing ⚠️
src/iptux-core/internal/SendFileData.cpp 0.00% 27 Missing ⚠️
src/iptux/DataSettings.cpp 0.00% 19 Missing ⚠️
src/iptux/LogSystem.cpp 78.94% 4 Missing ⚠️
src/iptux-core/internal/SendFile.cpp 0.00% 2 Missing ⚠️
src/iptux-core/internal/TcpData.cpp 66.66% 2 Missing ⚠️
src/iptux-utils/output.cpp 77.77% 2 Missing ⚠️
src/iptux/RevisePal.cpp 0.00% 2 Missing ⚠️
... and 3 more
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lidaobing lidaobing changed the title 1 #69 support compile under Windows Jul 5, 2026
Comment thread src/iptux-core/ModelsTest.cpp
lidaobing and others added 10 commits July 5, 2026 19:34
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.h and 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.

Comment on lines +44 to 48
int len;
char optval;

optval = 1;
len = sizeof(optval);
Comment thread src/iptux/DataSettings.cpp Outdated
if (!::getcwd(path, MAX_PATHLEN)) {
gchar* current_dir = g_get_current_dir();
if (current_dir) {
strncpy(path, current_dir, MAX_PATHLEN);
Comment on lines +1 to +5
#include "UIHelperWindows.h"
#include "iptux-utils/output.h"
#include <windows.h>
#include <shellapi.h>

Comment on lines +7 to +28
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double check on this

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

有没有办法编译成windows版的?

2 participants