Skip to content

Commit bddfb53

Browse files
committed
Migrated the codebase to C++ modules, replacing most traditional header/source pairs with .ixx module interface files and updating includes/imports accordingly.
* Updated all relevant `#include` directives to use `import` statements for both standard library and WinRT/WinUI namespaces, following modern C++23 module practices. * Refactored many implementation files to remove precompiled header usage and direct includes, instead relying on module imports. * Updated the project file (`OpenNet.vcxproj`) to: - Add `.ixx` files as module interface units. - Remove precompiled header usage. - Enable STL module builds. - Reference updated NuGet packages for Windows App SDK, WinUI, and related dependencies. - Add a custom MSBuild target to inject forced includes for XAML-generated files. * Replaced all usages of deprecated or removed header files with their module equivalents. * Updated type usages throughout the codebase to prefer explicit types (e.g., `std::uint32_t` instead of `uint32_t`), in line with project coding guidelines. * Refactored and modernized class and struct definitions, especially for data models, to use explicit types and modern C++ idioms. * Updated all WinRT and WinUI code to use module imports, and fixed up XAML code-behind files to use the new import model. * Replaced all `wil::resume_foreground` with `winrtplus::resume_foreground` where appropriate, reflecting a change in coroutine dispatching utilities. * Added new modules for settings management (`LocalSetting.ixx`, `SettingKeys.ixx`) and guide state (`GuideState.ixx`).
1 parent db4ddb4 commit bddfb53

257 files changed

Lines changed: 10616 additions & 8826 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Visual Studio generated .editorconfig file with C++ settings.
2+
root = true
3+
4+
[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
5+
6+
# Visual C++ Code Style settings
7+
8+
cpp_generate_documentation_comments = xml
9+
10+
# Visual C++ Formatting settings
11+
12+
indent_style = tab
13+
indent_size = 4
14+
tab_width= 4
15+
cpp_indent_braces = false
16+
cpp_indent_multi_line_relative_to = innermost_parenthesis
17+
cpp_indent_within_parentheses = align_to_parenthesis
18+
cpp_indent_preserve_within_parentheses = false
19+
cpp_indent_case_contents = true
20+
cpp_indent_case_labels = true
21+
cpp_indent_case_contents_when_block = false
22+
cpp_indent_lambda_braces_when_parameter = false
23+
cpp_indent_goto_labels = one_left
24+
cpp_indent_preprocessor = leftmost_column
25+
cpp_indent_access_specifiers = false
26+
cpp_indent_namespace_contents = true
27+
cpp_indent_preserve_comments = false
28+
cpp_new_line_before_open_brace_namespace = new_line
29+
cpp_new_line_before_open_brace_type = new_line
30+
cpp_new_line_before_open_brace_function = new_line
31+
cpp_new_line_before_open_brace_block = new_line
32+
cpp_new_line_before_open_brace_lambda = new_line
33+
cpp_new_line_scope_braces_on_separate_lines = true
34+
cpp_new_line_close_brace_same_line_empty_type = false
35+
cpp_new_line_close_brace_same_line_empty_function = false
36+
cpp_new_line_before_catch = true
37+
cpp_new_line_before_else = true
38+
cpp_new_line_before_while_in_do_while = true
39+
cpp_space_before_function_open_parenthesis = remove
40+
cpp_space_within_parameter_list_parentheses = false
41+
cpp_space_between_empty_parameter_list_parentheses = false
42+
cpp_space_after_keywords_in_control_flow_statements = true
43+
cpp_space_within_control_flow_statement_parentheses = false
44+
cpp_space_before_lambda_open_parenthesis = false
45+
cpp_space_within_cast_parentheses = false
46+
cpp_space_after_cast_close_parenthesis = false
47+
cpp_space_within_expression_parentheses = false
48+
cpp_space_before_block_open_brace = true
49+
cpp_space_between_empty_braces = false
50+
cpp_space_before_initializer_list_open_brace = false
51+
cpp_space_within_initializer_list_braces = true
52+
cpp_space_preserve_in_initializer_list = true
53+
cpp_space_before_open_square_bracket = false
54+
cpp_space_within_square_brackets = false
55+
cpp_space_before_empty_square_brackets = false
56+
cpp_space_between_empty_square_brackets = false
57+
cpp_space_group_square_brackets = true
58+
cpp_space_within_lambda_brackets = false
59+
cpp_space_between_empty_lambda_brackets = false
60+
cpp_space_before_comma = false
61+
cpp_space_after_comma = true
62+
cpp_space_remove_around_member_operators = true
63+
cpp_space_before_inheritance_colon = true
64+
cpp_space_before_constructor_colon = true
65+
cpp_space_remove_before_semicolon = true
66+
cpp_space_after_semicolon = true
67+
cpp_space_remove_around_unary_operator = true
68+
cpp_space_around_binary_operator = insert
69+
cpp_space_around_assignment_operator = ignore
70+
cpp_space_pointer_reference_alignment = left
71+
cpp_space_around_ternary_operator = insert
72+
cpp_use_unreal_engine_macro_formatting = true
73+
cpp_wrap_preserve_blocks = never
74+
75+
# Visual C++ Include Cleanup settings
76+
77+
cpp_include_cleanup_add_missing_error_tag_type = none
78+
cpp_include_cleanup_remove_unused_error_tag_type = none
79+
cpp_include_cleanup_optimize_unused_error_tag_type = none
80+
cpp_include_cleanup_sort_after_edits = false
81+
cpp_include_cleanup_format_after_edits = false
82+
cpp_sort_includes_error_tag_type = none
83+
cpp_sort_includes_priority_case_sensitive = false
84+
cpp_sort_includes_priority_style = quoted
85+
cpp_includes_style = default
86+
cpp_includes_use_forward_slash = true

OpenNet/App.xaml.cpp

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
#include "pch.h"
2-
#include "App.xaml.h"
1+
module;
2+
#define WIN32_LEAN_AND_MEAN
3+
#include <sentry.h>
4+
#include <Shlwapi.h>
5+
6+
#include "XamlWorkaround.h"
37
#include "MainWindow.xaml.h"
48
#include "UI/Shell/NotifyIconXamlHostWindow.xaml.h"
59
#include "UI/Xaml/View/Dialog/CloseToTrayDialog.h"
6-
#include "Helpers/WindowHelper.h"
7-
#include "Helpers/ThemeHelper.h"
8-
#include "Core/P2PManager.h"
9-
#include "Core/DownloadManager.h"
10-
#include "Core/RSS/RSSManager.h"
11-
#include "Core/GeoIP/GeoIPManager.h"
12-
#include "Core/AppSettingsDatabase.h"
13-
14-
#include <winrt/Windows.ApplicationModel.Activation.h>
15-
#include <winrt/Microsoft.Windows.Storage.h>
16-
#include <winrt/Microsoft.UI.Xaml.Controls.h>
17-
#include <winrt/Microsoft.UI.Composition.SystemBackdrops.h>
18-
#include <winrt/Microsoft.UI.Xaml.Media.h>
19-
#include <winrt/WinUI3Package.h>
20-
#include <sentry.h>
21-
#include <Shlwapi.h>
22-
#include <winrt/Microsoft.UI.Xaml.Media.Imaging.h>
10+
11+
module OpenNet.App;
12+
13+
import OpenNet.Core.AppSettingsDatabase;
14+
import OpenNet.Core.DownloadManager;
15+
import OpenNet.Core.GeoIP.GeoIPManager;
16+
import OpenNet.Core.P2PManager;
17+
import OpenNet.Core.RSS.RSSManager;;
18+
import OpenNet.Helpers.ThemeHelper;
19+
import OpenNet.Helpers.WindowHelper;
20+
import winrt.Windows.ApplicationModel.Activation;
21+
import winrt.Windows.UI;
22+
import winrt.Microsoft.Windows.Storage;
23+
import winrt.Microsoft.UI.Xaml.Controls;
24+
import winrt.Microsoft.UI.Composition.SystemBackdrops;
25+
import winrt.Microsoft.UI.Xaml.Media;
26+
import winrt.Microsoft.UI.Xaml.Media.Imaging;
2327

2428
using namespace winrt;
2529
using namespace Microsoft::UI::Xaml;
@@ -31,12 +35,12 @@ using namespace winrt::Microsoft::UI::Xaml::Media::Imaging;
3135

3236
namespace
3337
{
34-
constexpr auto kBackdropFallbackColorKey = "backdrop_fallback_color";
35-
constexpr auto kBackdropTintColorKey = "backdrop_tint_color";
36-
constexpr auto kBackdropLuminosityOpacityKey = "backdrop_luminosity_opacity";
37-
constexpr auto kBackdropTintOpacityKey = "backdrop_tint_opacity";
38-
constexpr auto kBackdropEnableWhenInactiveKey = "backdrop_enable_when_inactive";
39-
constexpr auto kBackdropUseFallbackKey = "backdrop_use_fallback";
38+
constexpr auto kBackdropFallbackColorKey = "backdrop_fallback_color";
39+
constexpr auto kBackdropTintColorKey = "backdrop_tint_color";
40+
constexpr auto kBackdropLuminosityOpacityKey = "backdrop_luminosity_opacity";
41+
constexpr auto kBackdropTintOpacityKey = "backdrop_tint_opacity";
42+
constexpr auto kBackdropEnableWhenInactiveKey = "backdrop_enable_when_inactive";
43+
constexpr auto kBackdropUseFallbackKey = "backdrop_use_fallback";
4044

4145
winrt::Windows::UI::Color ColorFromArgb(int64_t argb)
4246
{
@@ -265,9 +269,8 @@ namespace winrt::OpenNet::implementation
265269
// Apply saved theme to the window
266270
::OpenNet::Helpers::ThemeHelper::UpdateThemeForWindow(window);
267271

268-
// Create and show system tray icon (assign to static member, not a local)
269-
trayIcon = OpenNet::UI::Shell::NotifyIconXamlHostWindow();
270-
trayIcon.Show();
272+
// show system tray icon
273+
trayIcon->Show();
271274

272275
// Register window closing event - close strategy (hide to tray / ask / exit)
273276
window.AppWindow().Closing([](auto const&, winrt::Microsoft::UI::Windowing::AppWindowClosingEventArgs const& args)
@@ -450,7 +453,7 @@ namespace winrt::OpenNet::implementation
450453
// Remove tray icon (UI operation, OK on UI thread)
451454
if (trayIcon)
452455
{
453-
trayIcon.Remove();
456+
trayIcon->Remove();
454457
trayIcon = nullptr;
455458
}
456459

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
#pragma once
1+
module;
22

33
#include "App.xaml.g.h"
4-
#include <winrt/Windows.ApplicationModel.Activation.h>
5-
#include <winrt/Microsoft.Windows.AppLifecycle.h>
6-
#include <winrt/OpenNet.UI.Shell.h>
4+
#include "UI/Shell/NotifyIconXamlHostWindow.xaml.h"
75

8-
namespace winrt::OpenNet::implementation
6+
export module OpenNet.App;
7+
8+
import winrt.OpenNet.UI.Xaml.View.Pages;
9+
import winrt.WinUI3Package;
10+
import winrt.Windows.ApplicationModel.Activation;
11+
import winrt.Microsoft.Windows.AppLifecycle;
12+
13+
export namespace winrt::OpenNet::implementation
914
{
1015
struct App : AppT<App>
1116
{
@@ -18,7 +23,7 @@ namespace winrt::OpenNet::implementation
1823
static void HandleActivation(winrt::Microsoft::Windows::AppLifecycle::AppActivationArguments const&);
1924

2025
static inline winrt::Microsoft::UI::Xaml::Window window{ nullptr };
21-
static inline winrt::OpenNet::UI::Shell::NotifyIconXamlHostWindow trayIcon{ nullptr };
26+
static inline winrt::com_ptr<winrt::OpenNet::UI::Shell::implementation::NotifyIconXamlHostWindow> trayIcon;
2227
// Set to true before calling Application::Exit() so the Closing handler
2328
// does not cancel the close and hide the window to tray.
2429
static inline bool s_isExiting{ false };

OpenNet/Controls/SpeedGraph/SpeedGraph.xaml.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
#include "pch.h"
1+
#include "XamlWorkaround.h"
22
#include "SpeedGraph.xaml.h"
33
#if __has_include("Controls/SpeedGraph/SpeedGraph.g.cpp")
44
#include "Controls/SpeedGraph/SpeedGraph.g.cpp"
55
#endif
6-
#include <winrt/Microsoft.UI.Xaml.Media.Animation.h>
7-
#include <format>
6+
87
#include "Core/DataGraph/ReadableUnitConverter.h"
98

9+
import winrt.Microsoft.UI.Xaml.Media.Animation;
10+
1011
using namespace winrt;
1112
using namespace Microsoft::UI::Xaml;
1213

OpenNet/Controls/SpeedGraph/SpeedGraph.xaml.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#pragma once
22

3+
// workaround for xamlc generated .xaml.g.h
4+
import winrt.Microsoft.UI.Xaml.Shapes;
5+
36
#include "Controls/SpeedGraph/SpeedGraph.g.h"
4-
#include "winrt/Microsoft.UI.Xaml.h"
5-
#include "winrt/Microsoft.UI.Xaml.Markup.h"
6-
#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h"
7-
#include <winrt/Windows.UI.h>
8-
#include <winrt/Microsoft.Graphics.Canvas.Brushes.h>
9-
#include <winrt/Microsoft.Graphics.Canvas.Geometry.h>
10-
#include <winrt/Microsoft.Graphics.Canvas.UI.h>
11-
#include <winrt/Microsoft.Graphics.Canvas.UI.Xaml.h>
12-
13-
#include <chrono>
147
#include "Core/DataGraph/SpeedGraphData.h"
158
#include <ViewModels/ViewModelLocator.h>
169

10+
import winrt.Microsoft.UI.Xaml;
11+
import winrt.Microsoft.UI.Xaml.Markup;
12+
import winrt.Microsoft.UI.Xaml.Controls.Primitives;
13+
import winrt.Windows.UI;
14+
import winrt.Microsoft.Graphics.Canvas.Brushes;
15+
import winrt.Microsoft.Graphics.Canvas.Geometry;
16+
import winrt.Microsoft.Graphics.Canvas.UI;
17+
import winrt.Microsoft.Graphics.Canvas.UI.Xaml;
18+
1719
namespace winrt::OpenNet::Controls::SpeedGraph::implementation
1820
{
1921
struct SpeedGraph : SpeedGraphT<SpeedGraph>

OpenNet/Core/AppEnvironment.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
2-
#include <string>
2+
3+
import std;
34

45
namespace winrt::OpenNet::Core
56
{

OpenNet/Core/AppRuntime.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#include "pch.h"
2-
#include "AppRuntime.h"
3-
4-
#include "Core/Utils/Message.h"
1+
module;
2+
#include <Windows.h>
53
#include <openssl/evp.h>
64
#include <wil/registry.h>
7-
#include <winrt/Microsoft.Web.WebView2.Core.h>
5+
6+
module OpenNet.Core.AppRuntime;
7+
8+
import OpenNet.Core.Utils.Message;
9+
import winrt.Microsoft.Web.WebView2.Core;
810

911
namespace OpenNet::Core
1012
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#pragma once
1+
export module OpenNet.Core.AppRuntime;
22

33
#include "Web/WebView2/WebView2Version.h"
44

5-
namespace OpenNet::Core
5+
export namespace OpenNet::Core
66
{
77
class AppRuntime
88
{

OpenNet/Core/AppSettingsDatabase.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
*
66
* LICENSE: The MIT License
77
*/
8-
9-
#include "pch.h"
10-
#include "Core/AppSettingsDatabase.h"
8+
module;
9+
#include <Windows.h>
1110
#include "ThirdParty/Sqlite/sqlite3.h"
12-
#include "Core/IO/FileSystem.h"
1311

14-
#include <filesystem>
15-
#include <sstream>
12+
module OpenNet.Core.AppSettingsDatabase;
13+
14+
import OpenNet.Core.IO.FileSystem;
15+
import std;
1616

1717
namespace OpenNet::Core
1818
{
19+
using namespace std;
20+
1921
AppSettingsDatabase& AppSettingsDatabase::Instance()
2022
{
2123
static AppSettingsDatabase s_instance;

0 commit comments

Comments
 (0)