Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
indent_size = 2

[*.{cs,cpp,h,c,cc,cxx,hpp,hxx}]
indent_size = 4

[*.{cpp,h,c,cc,cxx,hpp,hxx}]
cpp_indent_braces = false
cpp_indent_multi_line_relative_to = statement_begin
cpp_new_line_before_open_brace_namespace = new_line
cpp_new_line_before_open_brace_type = new_line
cpp_new_line_before_open_brace_function = new_line
cpp_new_line_before_open_brace_block = new_line
cpp_new_line_before_catch = true
cpp_new_line_before_else = true
cpp_new_line_before_finally = true
cpp_space_before_function_open_parenthesis = false
cpp_space_within_parameter_list_parentheses = true
cpp_space_between_empty_parameter_list_parentheses = true
cpp_space_after_keywords_in_control_flow_statements = true
cpp_space_within_control_flow_statement_parentheses = true
cpp_space_before_semicolon_in_for_statement = false
cpp_space_after_semicolon_in_for_statement = true
cpp_space_around_binary_operator = insert
cpp_space_around_assignment_operator = insert

[*.xaml]
charset = utf-8-bom

[*.cs]
charset = utf-8-bom
# New line settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

# Indentation settings
csharp_indent_case_contents = true
csharp_indent_switch_labels = false
csharp_indent_labels = one_less_than_current

# Spacing settings
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 = 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_between_method_call_parameter_list_parentheses = true
csharp_space_between_method_declaration_parameter_list_parentheses = true
csharp_space_between_method_call_empty_parameter_list_parentheses = true
csharp_space_between_method_declaration_empty_parameter_list_parentheses = true
csharp_space_between_parentheses = control_flow_statements, expressions

# Style settings
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = false:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_prefer_braces = false:silent
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
5 changes: 5 additions & 0 deletions RegExpressWPFNET/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<TargetFramework>net9.0-windows7.0</TargetFramework>
</PropertyGroup>
</Project>
118 changes: 118 additions & 0 deletions RegExpressWPFNET/RegExpressLibrary/InternalConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows;

namespace RegExpressLibrary
{
public static class InternalConfig
{
public static bool SHOW_DEBUG_BUTTONS = false;
public static string[]? limited_engine_dlls;
[Flags]
public enum ON_EXCEPTION_ACTION
{
None,
MessageBox = 1 << 0,
DebuggerBreak = 1 << 1,
Rethrow = 1 << 2,
IncludeStackTrace = 1 << 3,
IncludeTraceDetails = 1 << 4,

}
public static ON_EXCEPTION_ACTION ON_EXCEPTION_DEBUGGER_ATTACHED = ON_EXCEPTION_ACTION.DebuggerBreak | ON_EXCEPTION_ACTION.IncludeTraceDetails | ON_EXCEPTION_ACTION.IncludeStackTrace;
public static ON_EXCEPTION_ACTION ON_EXCEPTION_STANDARD = ON_EXCEPTION_ACTION.MessageBox;
public static void HandleOtherCriticalError( String error, [System.Runtime.CompilerServices.CallerLineNumber] int source_line_number = 0, [System.Runtime.CompilerServices.CallerMemberName] string member_name = "", [System.Runtime.CompilerServices.CallerFilePath] string source_file_path = "" ) =>
_CriticalError( new StringBuilder( error ), source_line_number, member_name, source_file_path );
private static void _CriticalError( StringBuilder sb, [System.Runtime.CompilerServices.CallerLineNumber] int source_line_number = 0, [System.Runtime.CompilerServices.CallerMemberName] string member_name = "", [System.Runtime.CompilerServices.CallerFilePath] string source_file_path = "" )
{
var ON_EXCEPTION = Debugger.IsAttached ? ON_EXCEPTION_DEBUGGER_ATTACHED : ON_EXCEPTION_STANDARD;
if( ON_EXCEPTION.HasFlag( ON_EXCEPTION_ACTION.IncludeTraceDetails ) )
{
sb.Append( "Member: " ).AppendLine( member_name );
sb.Append( "File: " ).AppendLine( source_file_path );
sb.Append( "Line: " ).AppendLine( source_line_number.ToString( ) );
}

string message = sb.ToString( );

// MessageBox (on UI thread if possible)
if( ON_EXCEPTION.HasFlag( ON_EXCEPTION_ACTION.MessageBox ) )
{
try
{
if( Application.Current?.Dispatcher != null && !Application.Current.Dispatcher.CheckAccess( ) )
Application.Current.Dispatcher.Invoke( ( ) => MessageBox.Show( message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error ) );
else
MessageBox.Show( message, "Exception", MessageBoxButton.OK, MessageBoxImage.Error );

}
catch
{
// Fallback to Debug output if UI unavailable
Debug.WriteLine( message );
}
}

// Break into debugger if requested and a debugger is attached
if( ON_EXCEPTION.HasFlag( ON_EXCEPTION_ACTION.DebuggerBreak ) && Debugger.IsAttached )
Debugger.Break( );


// Always log to debug output for visibility
Debug.WriteLine( message );

}

public static bool HandleException( String msg, Exception exception, [System.Runtime.CompilerServices.CallerLineNumber] int source_line_number = 0, [System.Runtime.CompilerServices.CallerMemberName] string member_name = "", [System.Runtime.CompilerServices.CallerFilePath] string source_file_path = "", [CallerArgumentExpression( "exception" )] string exceptionName = "" )
{
if( exception == null ) return false;
var ON_EXCEPTION = Debugger.IsAttached ? ON_EXCEPTION_DEBUGGER_ATTACHED : ON_EXCEPTION_STANDARD;

// Build a diagnostic message
StringBuilder sb = new( );

sb.AppendLine( "Exception! " );
if( !String.IsNullOrWhiteSpace( msg ) )
sb.AppendLine( msg + " " );
if( ON_EXCEPTION.HasFlag( ON_EXCEPTION_ACTION.IncludeTraceDetails ) )
{
sb.Append( "Member: " ).AppendLine( member_name );
sb.Append( "File: " ).AppendLine( source_file_path );
sb.Append( "Line: " ).AppendLine( source_line_number.ToString( ) );
}
sb.Append( "Exception Var: " ).AppendLine( exceptionName );
sb.Append( "Type: " ).AppendLine( exception.GetType( ).FullName );
sb.Append( "Message: " ).AppendLine( exception.Message );

if( ON_EXCEPTION.HasFlag( ON_EXCEPTION_ACTION.IncludeStackTrace ) )
{
var st = exception.StackTrace;
if( !string.IsNullOrWhiteSpace( st ) )
{
sb.AppendLine( "StackTrace:" );
sb.AppendLine( st );
}
}
_CriticalError( sb, source_line_number, member_name, source_file_path );

return ( ON_EXCEPTION.HasFlag( ON_EXCEPTION_ACTION.Rethrow ) );
}
/// <summary>
/// Returns true if caller should rethrow the exception
/// </summary>
/// <param name="exception"></param>
/// <param name="source_line_number"></param>
/// <param name="member_name"></param>
/// <param name="source_file_path"></param>
/// <param name="exceptionName"></param>
/// <returns></returns>
public static bool HandleException( Exception exception, [System.Runtime.CompilerServices.CallerLineNumber] int source_line_number = 0, [System.Runtime.CompilerServices.CallerMemberName] string member_name = "", [System.Runtime.CompilerServices.CallerFilePath] string source_file_path = "", [CallerArgumentExpression( "exception" )] string exceptionName = "" ) =>
HandleException( string.Empty, exception, source_line_number, member_name, source_file_path, exceptionName );

}
}
21 changes: 12 additions & 9 deletions RegExpressWPFNET/RegExpressLibrary/PluginUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ public static class PluginLoader
}
catch( Exception exc )
{
if( Debugger.IsAttached ) Debugger.Break( );

MessageBox.Show( ownerWindow, $"Failed to load plugins using '{enginesJsonPath}'.\r\n\r\n{exc.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation );
if (InternalConfig.HandleException($"Failed to load plugins using '{enginesJsonPath}'", exc ))
throw;

return (null, null);
}
Expand All @@ -81,6 +80,11 @@ public static class PluginLoader
{
foreach( EngineData engine_data in engines_data.engines )
{
if ( InternalConfig.limited_engine_dlls?.Length > 0 && !InternalConfig.limited_engine_dlls.Any( dll => engine_data.path.Contains(dll, StringComparison.CurrentCultureIgnoreCase) ) )
{
Debug.WriteLine( $"Skipping plugin due to limited_engine_dlls \"{engine_data.path}\"..." );
continue;
}
string plugin_absolute_path = Path.Combine( plugin_root_folder, engine_data.path! );

try
Expand All @@ -106,18 +110,17 @@ public static class PluginLoader
}
catch( Exception exc )
{
if( Debugger.IsAttached ) Debugger.Break( );
if (InternalConfig.HandleException( $"Failed to create plugin \"{engine_data.path}\"", exc ))
throw;

MessageBox.Show( ownerWindow, $"Failed to create plugin \"{engine_data.path}\".\r\n\r\n{exc.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation );
}
}
}
}
catch( Exception exc )
{
if( Debugger.IsAttached ) Debugger.Break( );

MessageBox.Show( $"Failed to load plugin \"{engine_data.path}\".\r\n\r\n{exc.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation );
if (InternalConfig.HandleException( $"Failed to create plugin \"{engine_data.path}\"", exc ))
throw;
}
}
}
Expand All @@ -142,4 +145,4 @@ public static class PluginLoader

return (plugins, no_fm_plugins);
}
}
}
12 changes: 8 additions & 4 deletions RegExpressWPFNET/RegExpressLibrary/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public bool Start( ICancellable cnc )
catch( Exception exc )
{
_ = exc;
if( Debugger.IsAttached ) Debugger.Break( );
if (InternalConfig.HandleException( exc ))
throw;
}
} )
{
Expand All @@ -155,7 +156,8 @@ public bool Start( ICancellable cnc )
catch( Exception exc )
{
_ = exc;
if( Debugger.IsAttached ) Debugger.Break( );
if (InternalConfig.HandleException( exc ))
throw;
}
} )
{
Expand All @@ -174,7 +176,8 @@ public bool Start( ICancellable cnc )
catch( Exception exc )
{
_ = exc;
if( Debugger.IsAttached ) Debugger.Break( );
if (InternalConfig.HandleException( exc ))
throw;
}
} )
{
Expand Down Expand Up @@ -222,7 +225,8 @@ public bool Start( ICancellable cnc )
if( unchecked((uint)exc.HResult) != 0x80004005 && // 'E_ACCESSDENIED'
unchecked((uint)exc.HResult) != 0x80131509 ) // -2146233079, "Cannot process request because the process (<PID>) has exited."
{
if( Debugger.IsAttached ) Debugger.Break( );
if (InternalConfig.HandleException( exc ))
throw;
}

// ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
x:Name="userControl" DataContextChanged="userControl_DataContextChanged"
>
<CheckBox IsChecked="{Binding IsChecked, ElementName=userControl}" HorizontalAlignment="Left">
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap">
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" VerticalAlignment="Center" TextWrapping="Wrap">
<Run x:Name="run" Text="Sample text"/>
<Run>
<Run.Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public void SetRangesToUnderline( IReadOnlyList<(TextPointer start, TextPointer
// TODO: 'ExecutionEngineException' is now obsolete.

_ = exc;
if( Debugger.IsAttached ) Debugger.Break( );
if (RegExpressLibrary.InternalConfig.HandleException( exc ))
throw;
// ignore and accept the ranges
}
}
Expand Down
34 changes: 23 additions & 11 deletions RegExpressWPFNET/RegExpressWPFNET/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
xmlns:sys="clr-namespace:System;assembly=mscorlib"
StartupUri="MainWindow.xaml"
Startup="App_Startup"
ThemeMode="System"
>

<Application.Resources>

<SolidColorBrush x:Key="NormalBackground" Color="White"/>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/PresentationFramework.Fluent;component/Themes/Fluent.xaml" />
</ResourceDictionary.MergedDictionaries>
<local_controls:BoolNullVisibilityCollapsedConverter x:Key="boolNullVisibilityCollapsedConverter" />
<SolidColorBrush x:Key="NormalBackground" Color="White"/>

<Style x:Key="StackPanelWithLabels" TargetType="StackPanel" PresentationOptions:Freeze="True">
<Setter Property="Orientation" Value="Horizontal"/>
Expand Down Expand Up @@ -115,27 +120,34 @@
<Setter Property="Padding" Value="1 4 0 0"/>
</Style>

<Style TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
<Setter Property="Margin" Value="3"/>
</Style>
<Style TargetType="Button" x:Key="OurAccentButtonStyle" BasedOn="{StaticResource AccentButtonStyle}">
<Setter Property="Margin" Value="3"/>
</Style>

<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
<Style.Triggers>
<Style TargetType="CheckBox" BasedOn="{StaticResource DefaultCheckBoxStyle}">
<Setter Property="MinWidth" Value="50"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</Style.Triggers>
</Style>

<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter Property="Padding" Value="3 2"/>
<Setter Property="Height" Value="20"/>
</Style>
<Style TargetType="ComboBox" BasedOn="{StaticResource DefaultComboBoxStyle}">
<Setter Property="Padding" Value="3 2"/>
<Setter Property="Margin" Value="3"/>
</Style>

<Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
<Style TargetType="ComboBoxItem" BasedOn="{StaticResource DefaultComboBoxItemStyle}">
<Setter Property="Padding" Value="3 2"/>
<Setter Property="Margin" Value="0"/>
</Style>

<Style TargetType="Separator" BasedOn="{StaticResource {x:Type Separator}}">
<Setter Property="Margin" Value="3 3 3 4" />
<Setter Property="Margin" Value="3" />
</Style>

<!-- Inline Styles -->
Expand Down Expand Up @@ -613,7 +625,7 @@
</Setter>
</Style>
-->

</ResourceDictionary>
</Application.Resources>

</Application>
Loading