From fcd7eccd2926067f5cf2f7a19088e19c6eaa8fc3 Mon Sep 17 00:00:00 2001 From: CodingNinja Date: Mon, 21 Aug 2023 10:54:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 304 +++++++ .gitattributes | 63 ++ .gitignore | 363 ++++++++ ActiveWindowDebugger.sln | 25 + .../ActiveWindowDebugger.csproj | 24 + ActiveWindowDebugger/ActiveWindowLog.cs | 36 + ActiveWindowDebugger/App.xaml | 11 + ActiveWindowDebugger/App.xaml.cs | 228 +++++ ActiveWindowDebugger/AssemblyInfo.cs | 10 + ActiveWindowDebugger/FodyWeavers.xml | 3 + .../InvertableBooleanToVisibilityConverter.cs | 32 + ActiveWindowDebugger/MainWindow.xaml | 432 ++++++++++ ActiveWindowDebugger/MainWindow.xaml.cs | 788 ++++++++++++++++++ ActiveWindowDebugger/MyResources.xaml | 80 ++ .../Properties/launchSettings.json | 7 + ActiveWindowDebugger/RadioMenuItem.cs | 56 ++ ActiveWindowDebugger/WindowExtensions.cs | 78 ++ ActiveWindowDebugger/app.manifest | 75 ++ ActiveWindowDebugger/awd_logo_1024x1024.ico | Bin 0 -> 432697 bytes ActiveWindowDebugger/awd_logo_1024x1024.png | Bin 0 -> 209251 bytes ActiveWindowDebugger/screenshot.png | Bin 0 -> 57624 bytes LICENSE | 21 + README.en.md | 57 ++ README.md | 55 ++ 24 files changed, 2748 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 ActiveWindowDebugger.sln create mode 100644 ActiveWindowDebugger/ActiveWindowDebugger.csproj create mode 100644 ActiveWindowDebugger/ActiveWindowLog.cs create mode 100644 ActiveWindowDebugger/App.xaml create mode 100644 ActiveWindowDebugger/App.xaml.cs create mode 100644 ActiveWindowDebugger/AssemblyInfo.cs create mode 100644 ActiveWindowDebugger/FodyWeavers.xml create mode 100644 ActiveWindowDebugger/InvertableBooleanToVisibilityConverter.cs create mode 100644 ActiveWindowDebugger/MainWindow.xaml create mode 100644 ActiveWindowDebugger/MainWindow.xaml.cs create mode 100644 ActiveWindowDebugger/MyResources.xaml create mode 100644 ActiveWindowDebugger/Properties/launchSettings.json create mode 100644 ActiveWindowDebugger/RadioMenuItem.cs create mode 100644 ActiveWindowDebugger/WindowExtensions.cs create mode 100644 ActiveWindowDebugger/app.manifest create mode 100644 ActiveWindowDebugger/awd_logo_1024x1024.ico create mode 100644 ActiveWindowDebugger/awd_logo_1024x1024.png create mode 100644 ActiveWindowDebugger/screenshot.png create mode 100644 LICENSE create mode 100644 README.en.md create mode 100644 README.md diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b803356 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,304 @@ +# 如果要从更高级别的目录继承 .editorconfig 设置,请删除以下行 +root = true + +# c# 文件 +[*.cs] + +#### Core EditorConfig 选项 #### + +# 缩进和间距 +indent_size = 4 +indent_style = space +tab_width = 4 + +# 新行首选项 +end_of_line = crlf +insert_final_newline = false + +#### .NET 编码约定 #### + +# 组织 Using +dotnet_separate_import_directive_groups = true +dotnet_sort_system_directives_first = true +file_header_template = unset + +# this. 和 Me. 首选项 +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion + +# 语言关键字与 bcl 类型首选项 +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = false:suggestion + +# 括号首选项 +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion + +# 修饰符首选项 +dotnet_style_require_accessibility_modifiers = for_non_interface_members + +# 表达式级首选项 +dotnet_style_coalesce_expression = true +dotnet_style_collection_initializer = true +dotnet_style_explicit_tuple_names = true +dotnet_style_namespace_match_folder = true +dotnet_style_null_propagation = true +dotnet_style_object_initializer = true +dotnet_style_operator_placement_when_wrapping = beginning_of_line +dotnet_style_prefer_auto_properties = true:suggestion +dotnet_style_prefer_compound_assignment = true +dotnet_style_prefer_conditional_expression_over_assignment = true +dotnet_style_prefer_conditional_expression_over_return = true +dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed +dotnet_style_prefer_inferred_anonymous_type_member_names = true +dotnet_style_prefer_inferred_tuple_names = true +dotnet_style_prefer_is_null_check_over_reference_equality_method = true +dotnet_style_prefer_simplified_boolean_expressions = true +dotnet_style_prefer_simplified_interpolation = true + +# 字段首选项 +dotnet_style_readonly_field = true + +# 参数首选项 +dotnet_code_quality_unused_parameters = all + +# 禁止显示首选项 +dotnet_remove_unnecessary_suppression_exclusions = 0 + +# 新行首选项 +dotnet_style_allow_multiple_blank_lines_experimental = false:suggestion +dotnet_style_allow_statement_immediately_after_block_experimental = false:suggestion + +#### c# 编码约定 #### + +# var 首选项 +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion + +# Expression-bodied 成员 +csharp_style_expression_bodied_accessors = when_on_single_line:suggestion +csharp_style_expression_bodied_constructors = false:suggestion +csharp_style_expression_bodied_indexers = when_on_single_line:suggestion +csharp_style_expression_bodied_lambdas = when_on_single_line:suggestion +csharp_style_expression_bodied_local_functions = false:suggestion +csharp_style_expression_bodied_methods = false:suggestion +csharp_style_expression_bodied_operators = false:suggestion +csharp_style_expression_bodied_properties = when_on_single_line:suggestion + +# 模式匹配首选项 +csharp_style_pattern_matching_over_as_with_null_check = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_prefer_extended_property_pattern = true +csharp_style_prefer_not_pattern = true +csharp_style_prefer_pattern_matching = true:suggestion +csharp_style_prefer_switch_expression = true + +# Null 检查首选项 +csharp_style_conditional_delegate_call = true + +# 修饰符首选项 +csharp_prefer_static_local_function = true +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async +csharp_style_prefer_readonly_struct = true + +# 代码块首选项 +csharp_prefer_braces = true:suggestion +csharp_prefer_simple_using_statement = true +csharp_style_namespace_declarations = file_scoped:suggestion +csharp_style_prefer_method_group_conversion = true +csharp_style_prefer_top_level_statements = true + +# 表达式级首选项 +csharp_prefer_simple_default_expression = true +csharp_style_deconstructed_variable_declaration = true +csharp_style_implicit_object_creation_when_type_is_apparent = true +csharp_style_inlined_variable_declaration = true +csharp_style_prefer_index_operator = true +csharp_style_prefer_local_over_anonymous_function = true +csharp_style_prefer_null_check_over_type_check = true +csharp_style_prefer_range_operator = true +csharp_style_prefer_tuple_swap = true +csharp_style_prefer_utf8_string_literals = true +csharp_style_throw_expression = true +csharp_style_unused_value_assignment_preference = discard_variable:silent +csharp_style_unused_value_expression_statement_preference = discard_variable + +# "using" 指令首选项 +csharp_using_directive_placement = outside_namespace:suggestion + +# 新行首选项 +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:suggestion +csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:suggestion +csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:suggestion +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:suggestion +csharp_style_allow_embedded_statements_on_same_line_experimental = false:suggestion + +#### C# 格式规则 #### + +# 新行首选项 +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = types,methods,properties,control_blocks,accessors +csharp_new_line_between_query_expression_clauses = true + +# 缩进首选项 +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +# 空格键首选项 +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +# 包装首选项 +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +#### 命名样式 #### + +# 命名规则 + +dotnet_naming_rule.命名空间_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.命名空间_should_be_pascalcase.symbols = 命名空间 +dotnet_naming_rule.命名空间_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.类型_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.类型_should_be_pascalcase.symbols = 类型 +dotnet_naming_rule.类型_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.接口_should_be_interface.severity = suggestion +dotnet_naming_rule.接口_should_be_interface.symbols = 接口 +dotnet_naming_rule.接口_should_be_interface.style = interface + +dotnet_naming_rule.抽象类_should_be_abstractmethod.severity = suggestion +dotnet_naming_rule.抽象类_should_be_abstractmethod.symbols = 抽象类 +dotnet_naming_rule.抽象类_should_be_abstractmethod.style = abstractmethod + +dotnet_naming_rule.非字段成员_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.非字段成员_should_be_pascalcase.symbols = 非字段成员 +dotnet_naming_rule.非字段成员_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.类型参数_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.类型参数_should_be_pascalcase.symbols = 类型参数 +dotnet_naming_rule.类型参数_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.公共字段_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.公共字段_should_be_pascalcase.symbols = 公共字段 +dotnet_naming_rule.公共字段_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.字段_should_be__camelcase.severity = suggestion +dotnet_naming_rule.字段_should_be__camelcase.symbols = 字段 +dotnet_naming_rule.字段_should_be__camelcase.style = _camelcase + +dotnet_naming_rule.局部参数_should_be_camelcase.severity = suggestion +dotnet_naming_rule.局部参数_should_be_camelcase.symbols = 局部参数 +dotnet_naming_rule.局部参数_should_be_camelcase.style = camelcase + +dotnet_naming_rule.异步方法_should_be_asyncmethod.severity = suggestion +dotnet_naming_rule.异步方法_should_be_asyncmethod.symbols = 异步方法 +dotnet_naming_rule.异步方法_should_be_asyncmethod.style = asyncmethod + +# 符号规范 + +dotnet_naming_symbols.命名空间.applicable_kinds = namespace +dotnet_naming_symbols.命名空间.applicable_accessibilities = * +dotnet_naming_symbols.命名空间.required_modifiers = + +dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.类型.applicable_accessibilities = * +dotnet_naming_symbols.类型.required_modifiers = + +dotnet_naming_symbols.接口.applicable_kinds = interface +dotnet_naming_symbols.接口.applicable_accessibilities = * +dotnet_naming_symbols.接口.required_modifiers = + +dotnet_naming_symbols.抽象类.applicable_kinds = class +dotnet_naming_symbols.抽象类.applicable_accessibilities = * +dotnet_naming_symbols.抽象类.required_modifiers = abstract + +dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, delegate, method, local_function +dotnet_naming_symbols.非字段成员.applicable_accessibilities = * +dotnet_naming_symbols.非字段成员.required_modifiers = + +dotnet_naming_symbols.类型参数.applicable_kinds = type_parameter +dotnet_naming_symbols.类型参数.applicable_accessibilities = * +dotnet_naming_symbols.类型参数.required_modifiers = + +dotnet_naming_symbols.字段.applicable_kinds = field +dotnet_naming_symbols.字段.applicable_accessibilities = * +dotnet_naming_symbols.字段.required_modifiers = + +dotnet_naming_symbols.公共字段.applicable_kinds = field +dotnet_naming_symbols.公共字段.applicable_accessibilities = public, internal +dotnet_naming_symbols.公共字段.required_modifiers = + +dotnet_naming_symbols.局部参数.applicable_kinds = parameter, local +dotnet_naming_symbols.局部参数.applicable_accessibilities = * +dotnet_naming_symbols.局部参数.required_modifiers = + +dotnet_naming_symbols.异步方法.applicable_kinds = method, local_function +dotnet_naming_symbols.异步方法.applicable_accessibilities = * +dotnet_naming_symbols.异步方法.required_modifiers = async + +# 命名样式 + +dotnet_naming_style.pascalcase.required_prefix = +dotnet_naming_style.pascalcase.required_suffix = +dotnet_naming_style.pascalcase.word_separator = +dotnet_naming_style.pascalcase.capitalization = pascal_case + +dotnet_naming_style.camelcase.required_prefix = +dotnet_naming_style.camelcase.required_suffix = +dotnet_naming_style.camelcase.word_separator = +dotnet_naming_style.camelcase.capitalization = camel_case + +dotnet_naming_style._camelcase.required_prefix = _ +dotnet_naming_style._camelcase.required_suffix = +dotnet_naming_style._camelcase.word_separator = +dotnet_naming_style._camelcase.capitalization = camel_case + +dotnet_naming_style.interface.required_prefix = I +dotnet_naming_style.interface.required_suffix = +dotnet_naming_style.interface.word_separator = +dotnet_naming_style.interface.capitalization = pascal_case + +dotnet_naming_style.abstractmethod.required_prefix = +dotnet_naming_style.abstractmethod.required_suffix = Base +dotnet_naming_style.abstractmethod.word_separator = +dotnet_naming_style.abstractmethod.capitalization = pascal_case + +dotnet_naming_style.asyncmethod.required_prefix = +dotnet_naming_style.asyncmethod.required_suffix = Async +dotnet_naming_style.asyncmethod.word_separator = +dotnet_naming_style.asyncmethod.capitalization = pascal_case \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/ActiveWindowDebugger.sln b/ActiveWindowDebugger.sln new file mode 100644 index 0000000..99e12f6 --- /dev/null +++ b/ActiveWindowDebugger.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33122.133 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ActiveWindowDebugger", "ActiveWindowDebugger\ActiveWindowDebugger.csproj", "{54ED2FBC-55F1-4D31-9133-1ED6F837626A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {54ED2FBC-55F1-4D31-9133-1ED6F837626A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {54ED2FBC-55F1-4D31-9133-1ED6F837626A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {54ED2FBC-55F1-4D31-9133-1ED6F837626A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {54ED2FBC-55F1-4D31-9133-1ED6F837626A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {482E0DD1-D92B-4A7E-B3FA-19216B45F1EB} + EndGlobalSection +EndGlobal diff --git a/ActiveWindowDebugger/ActiveWindowDebugger.csproj b/ActiveWindowDebugger/ActiveWindowDebugger.csproj new file mode 100644 index 0000000..c3158d6 --- /dev/null +++ b/ActiveWindowDebugger/ActiveWindowDebugger.csproj @@ -0,0 +1,24 @@ + + + + WinExe + net7.0-windows + enable + true + awd_logo_1024x1024.ico + app.manifest + true + true + 1.0 + + + + + + + + + + + + diff --git a/ActiveWindowDebugger/ActiveWindowLog.cs b/ActiveWindowDebugger/ActiveWindowLog.cs new file mode 100644 index 0000000..4046133 --- /dev/null +++ b/ActiveWindowDebugger/ActiveWindowLog.cs @@ -0,0 +1,36 @@ +using System; +using System.Diagnostics; + +using PropertyChanged; + +namespace ActiveWindowDebugger; + +[AddINotifyPropertyChangedInterface] +public class ActiveWindowLog +{ + public string? Name => Process?.ProcessName; + + public int? PID => Process?.Id; + + public Process Process { get; init; } + + public DateTime Time { get; init; } + + public string? Title => Process?.MainWindowTitle; + + public ActiveWindowLog(DateTime time, Process process) + { + Time = time; + Process = process; + } + + public override string ToString() + { + return $"[{Time:HH:mm:ss.fff}] [{PID,-5}] [{Name}] {Title}"; + } + + public string ToStringWithoutTime() + { + return $"[{PID,-5}] [{Name}] {Title}"; + } +} diff --git a/ActiveWindowDebugger/App.xaml b/ActiveWindowDebugger/App.xaml new file mode 100644 index 0000000..4558e0c --- /dev/null +++ b/ActiveWindowDebugger/App.xaml @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/ActiveWindowDebugger/App.xaml.cs b/ActiveWindowDebugger/App.xaml.cs new file mode 100644 index 0000000..d6f7aea --- /dev/null +++ b/ActiveWindowDebugger/App.xaml.cs @@ -0,0 +1,228 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Windows; + +namespace ActiveWindowDebugger; + +/// +/// Interaction logic for App.xaml +/// +public partial class App : Application +{ + private const string _usage = """ + [基础] + --poll: 激活频率(ms), 默认值: 1. + --topmost: 置顶 AWD 窗口, 默认值: True. + --single: 单实例模式, 默认值: False. + + [自动开始条件] + --auto-start: 启用/禁用自动开始, 默认值: False. + --auto-start-state: True: 活动状态; False: 非活动状态; null: 任意状态, 默认值: True. + --auto-start-pid: 进程 ID, -1 表示当前活动进程, 默认值: -1. + --auto-start-meet: 满足或不满足正则表达式条件, 默认值: True. + --auto-start-regex: 正则表达式(匹配进程的主窗口标题), 默认值: ".*". + --auto-start-match-case: 正则表达式是否区分大小写, 默认值: True. + + [自动停止条件] + --auto-stop: 启用/禁用自动停止, 默认值: False. + --auto-stop-state: True: 活动状态; False: 非活动状态; null: 任意状态, 默认值: True. + --auto-stop-pid: 进程 ID, -1 表示当前活动进程, 默认值: -1. + --auto-stop-meet: 满足或不满足正则表达式, 默认值: True. + --auto-stop-regex: 正则表达式(匹配进程的主窗口标题), 默认值: ".*". + --auto-stop-match-case: 正则表达式是否区分大小写, 默认值: True. + """; + + protected override void OnStartup(StartupEventArgs e) + { + try + { + var arguments = new Dictionary(); + + string prettyArgs = String.Join(' ', e.Args); + + if (e.Args.Length % 2 != 0) + { + throw new ArgumentException($"参数缺失或过多: {prettyArgs}"); + } + + for (int index = 0; index < e.Args.Length - 1; index += 2) + { + if (!e.Args[index].StartsWith("--")) + { + throw new ArgumentException($"参数 '{e.Args[index]}' 必须使用 '--' 开头。"); + } + + arguments.Add(e.Args[index].TrimStart('-'), value: e.Args[index + 1]); + } + + bool single = false; + + if (arguments.TryGetValue("single", out string? value)) + { + single = Convert.ToBoolean(value); + } + + string activatePoll = "1"; + bool topmost = true; + + bool autoStart = false; + bool? autoStartState = true; + int autoStartPid = -1; + bool autoStartMeet = true; + string autoStartRegex = ".*"; + bool autoStartMatchCase = true; + + bool autoStop = false; + bool? autoStopState = true; + int autoStopPid = -1; + bool autoStopMeet = true; + string autoStopRegex = ".*"; + bool autoStopMatchCase = true; + + if (arguments.TryGetValue("poll", out value)) + { + activatePoll = value; + } + + if (arguments.TryGetValue("topmost", out value)) + { + topmost = Convert.ToBoolean(value); + } + + if (arguments.TryGetValue("auto-start", out value)) + { + autoStart = Convert.ToBoolean(value); + } + + if (arguments.TryGetValue("auto-start-state", out value)) + { + if (value.ToLower() == "null") + { + autoStartState = null; + } + else + { + autoStartState = Convert.ToBoolean(value); + } + } + + if (arguments.TryGetValue("auto-start-pid", out value)) + { + autoStartPid = Convert.ToInt32(value); + } + + if (arguments.TryGetValue("auto-start-meet", out value)) + { + autoStartMeet = Convert.ToBoolean(value); + } + + if (arguments.TryGetValue("auto-start-regex", out value)) + { + autoStartRegex = value; + } + + if (arguments.TryGetValue("auto-start-match-case", out value)) + { + autoStartMatchCase = Convert.ToBoolean(value); + } + + if (arguments.TryGetValue("auto-stop", out value)) + { + autoStop = Convert.ToBoolean(value); + } + + if (arguments.TryGetValue("auto-stop-state", out value)) + { + if (value.ToLower() == "null") + { + autoStopState = null; + } + else + { + autoStopState = Convert.ToBoolean(value); + } + } + + if (arguments.TryGetValue("auto-stop-pid", out value)) + { + autoStopPid = Convert.ToInt32(value); + } + + if (arguments.TryGetValue("auto-stop-meet", out value)) + { + autoStopMeet = Convert.ToBoolean(value); + } + + if (arguments.TryGetValue("auto-stop-regex", out value)) + { + autoStopRegex = value; + } + + if (arguments.TryGetValue("auto-stop-match-case", out value)) + { + autoStopMatchCase = Convert.ToBoolean(value); + } + + if (single) + { + CloseOtherInstances(); + } + + var mainWindow = new MainWindow(activatePoll, + autoStart, autoStartState, autoStartPid, autoStartMeet, autoStartRegex, autoStartMatchCase, + autoStop, autoStopState, autoStopPid, autoStopMeet, autoStopRegex, autoStopMatchCase) { + IsTopmost = topmost + }; + + mainWindow.Show(); + } + catch (Exception ex) + { + MessageBox.Show( + $"{ex.Message}\n\n用法:\n{_usage}", + "ActiveWindowDebugger: 命令行参数错误", + MessageBoxButton.OK, + MessageBoxImage.Error, + MessageBoxResult.OK); + + var mainWindow = new MainWindow(); + mainWindow.Show(); + } + } + + private static void CloseOtherInstances() + { + var curr = Process.GetCurrentProcess(); + var instances = Process.GetProcessesByName(curr.ProcessName) + .Where(x => { + try + { + return x?.MainModule?.FileName == curr.MainModule?.FileName; + } + catch + { + return false; + } + }); + + bool exists = instances.Count() > 1; + + if (exists) + { + foreach (var p in instances) + { + try + { + if (p.Id != curr.Id) + { + p.Kill(); + } + } + catch + { } + } + } + } +} diff --git a/ActiveWindowDebugger/AssemblyInfo.cs b/ActiveWindowDebugger/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/ActiveWindowDebugger/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/ActiveWindowDebugger/FodyWeavers.xml b/ActiveWindowDebugger/FodyWeavers.xml new file mode 100644 index 0000000..d5abfed --- /dev/null +++ b/ActiveWindowDebugger/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ActiveWindowDebugger/InvertableBooleanToVisibilityConverter.cs b/ActiveWindowDebugger/InvertableBooleanToVisibilityConverter.cs new file mode 100644 index 0000000..b1eb7fb --- /dev/null +++ b/ActiveWindowDebugger/InvertableBooleanToVisibilityConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace ActiveWindowDebugger; + +[ValueConversion(typeof(bool), typeof(Visibility))] +public class InvertableBooleanToVisibilityConverter : IValueConverter +{ + private enum Parameters + { + Normal, Inverted + } + + public object Convert(object value, Type targetType, + object parameter, CultureInfo culture) + { + bool boolValue = (bool)value; + var direction = (Parameters)Enum.Parse(typeof(Parameters), (string)parameter); + + return direction == Parameters.Inverted + ? !boolValue ? Visibility.Visible : Visibility.Collapsed + : (object)(boolValue ? Visibility.Visible : Visibility.Collapsed); + } + + public object ConvertBack(object value, Type targetType, + object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } +} diff --git a/ActiveWindowDebugger/MainWindow.xaml b/ActiveWindowDebugger/MainWindow.xaml new file mode 100644 index 0000000..85a7016 --- /dev/null +++ b/ActiveWindowDebugger/MainWindow.xaml @@ -0,0 +1,432 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +