Skip to content

Commit

Permalink
[1] Remove file name extension check for formatting CLEF/JSON data.
Browse files Browse the repository at this point in the history
[2] Fix behavior of switching formatting CLEF/JSON data in LogDataSourceOptionsDialog.
  • Loading branch information
hamster620 committed Jan 11, 2025
1 parent 22c854c commit 1328095
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 39 deletions.
6 changes: 0 additions & 6 deletions ULogViewer/Controls/LogDataSourceOptionsDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@
<Image Classes="Icon" Source="{DynamicResource Image/Icon.Question.Outline}"/>
</Button>
</WrapPanel>
<TextBlock Classes="Dialog_TextBlock_Description"
IsVisible="{Binding #window.IsFileNameSupported}"
Text="{DynamicResource String/LogDataSourceOptions.FormatJsonData.Description}"/>
</StackPanel>
<ToggleSwitch Name="formatJsonDataSwitch" Classes="Dialog_Item_ToggleSwitch"/>
</asControls:DialogItem>
Expand All @@ -256,9 +253,6 @@
<Image Classes="Icon" Source="{DynamicResource Image/Icon.Question.Outline}"/>
</Button>
</WrapPanel>
<TextBlock Classes="Dialog_TextBlock_Description"
IsVisible="{Binding #window.IsFileNameSupported}"
Text="{DynamicResource String/LogDataSourceOptions.FormatXmlData.Description}"/>
</StackPanel>
<ToggleSwitch Name="formatXmlDataSwitch" Classes="Dialog_Item_ToggleSwitch"/>
</asControls:DialogItem>
Expand Down
27 changes: 11 additions & 16 deletions ULogViewer/Controls/LogDataSourceOptionsDialog.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ public LogDataSourceOptionsDialog()
this.encodingComboBox = this.Get<ComboBox>(nameof(encodingComboBox));
this.environmentVariablesListBox = this.Get<AppSuite.Controls.ListBox>(nameof(environmentVariablesListBox));
this.fileNameTextBox = this.Get<TextBox>(nameof(fileNameTextBox));
this.formatJsonDataSwitch = this.Get<ToggleSwitch>(nameof(formatJsonDataSwitch));
this.formatXmlDataSwitch = this.Get<ToggleSwitch>(nameof(formatXmlDataSwitch));
this.formatJsonDataSwitch = this.Get<ToggleSwitch>(nameof(formatJsonDataSwitch)).Also(it =>
{
it.IsCheckedChanged += this.OnFormatDataSwitchIsCheckedChanged;
});
this.formatXmlDataSwitch = this.Get<ToggleSwitch>(nameof(formatXmlDataSwitch)).Also(it =>
{
it.IsCheckedChanged += this.OnFormatDataSwitchIsCheckedChanged;
});
this.includeStderrSwitch = this.Get<ToggleSwitch>(nameof(includeStderrSwitch));
this.ipAddressTextBox = this.Get<IPAddressTextBox>(nameof(ipAddressTextBox));
this.isResourceOnAzureSwitch = this.Get<ToggleSwitch>(nameof(isResourceOnAzureSwitch));
Expand Down Expand Up @@ -607,9 +613,7 @@ void OnEditorControlPropertyChanged(object? sender, AvaloniaPropertyChangedEvent
// Called when check state of one of switch for formatting data changed.
void OnFormatDataSwitchIsCheckedChanged(object? sender, RoutedEventArgs e)
{
if (sender is not ToggleSwitch toggleSwitch
|| !toggleSwitch.IsEnabled
|| this.GetValue(IsFileNameSupportedProperty))
if (sender is not ToggleSwitch toggleSwitch || !toggleSwitch.IsEnabled)
return;
if (!toggleSwitch.IsChecked.GetValueOrDefault())
{
Expand Down Expand Up @@ -726,18 +730,9 @@ protected override void OnOpening(EventArgs e)
this.initFocusedControl ??= this.fileNameTextBox;
}
if (this.GetValue(IsFormatJsonDataSupportedProperty))
{
this.formatJsonDataSwitch.IsChecked = options.FormatJsonData;
this.formatJsonDataSwitch.IsCheckedChanged += this.OnFormatDataSwitchIsCheckedChanged;
}
if (this.GetValue(IsFormatXmlDataSupportedProperty))
{
if (!this.GetValue(IsFormatJsonDataSupportedProperty) || !options.FormatJsonData)
this.formatXmlDataSwitch.IsChecked = options.FormatXmlData;
else
this.formatXmlDataSwitch.IsEnabled = false;
this.formatXmlDataSwitch.IsCheckedChanged += this.OnFormatDataSwitchIsCheckedChanged;
}
if (this.GetValue(IsFormatXmlDataSupportedProperty))
this.formatXmlDataSwitch.IsChecked = options.FormatXmlData;
if (this.GetValue(IsIncludeStandardErrorSupportedProperty))
this.includeStderrSwitch.IsChecked = options.IncludeStandardError;
if (this.IsWorkingDirectorySupported)
Expand Down
19 changes: 11 additions & 8 deletions ULogViewer/Logs/DataSources/FileLogDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ protected override void OnReaderClosed()
this.Logger.LogWarning("Use temp file '{tempFilePath}'", tempFilePath);
return new FileStream(tempFilePath ?? fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite).Let(stream =>
{
var reader = Path.GetExtension(fileName).ToLower() switch
TextReader reader;
if (options.FormatJsonData)
reader = new FormattedJsonTextReader(new StreamReader(stream, encoding));
else
{
".gz" => new GZipStream(stream, CompressionMode.Decompress).Let(gzipStream =>
new StreamReader(gzipStream, encoding)),
".json" => options.FormatJsonData
? new FormattedJsonTextReader(new StreamReader(stream, encoding))
: new StreamReader(stream, encoding),
_ => (TextReader)new StreamReader(stream, encoding),
};
reader = Path.GetExtension(fileName).ToLower() switch
{
".gz" => new GZipStream(stream, CompressionMode.Decompress).Let(gzipStream =>
new StreamReader(gzipStream, encoding)),
_ => (TextReader)new StreamReader(stream, encoding),
};
}
this.tempFilePath = tempFilePath;
result = LogDataSourceState.ReaderOpened;
return reader;
Expand Down
7 changes: 7 additions & 0 deletions ULogViewer/Logs/DataSources/ILogDataSourceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ public static LogDataSourceOptions Load(JsonElement jsonObject)
break;
}
}
if (options.FormatClefData)
{
options.FormatJsonData = false;
options.FormatXmlData = false;
}
else if (options.FormatJsonData)
options.FormatXmlData = false;
return options;
}
finally
Expand Down
3 changes: 0 additions & 3 deletions ULogViewer/Strings/Default.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,8 @@ return False</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.EnvironmentVariables.Duplicated">The environment variables '{0}' is already added before.</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FileName">File path</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatClefData">Format CLEF data when reading</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatClefData.Description">Available only for file with .clef extension.</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatJsonData">Format JSON data when reading</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatJsonData.Description">Available only for file with .json extension.</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatXmlData">Format XML data when reading</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatXmlData.Description">Available only for file with .xml extension.</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IncludeStandardError">Include Standard Error (stderr)</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IPEndPoint">IP address</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IsResourceOnAzure">This is the resource on Azure</sys:String>
Expand Down
3 changes: 0 additions & 3 deletions ULogViewer/Strings/zh-CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,8 @@ return False</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.EnvironmentVariables.Duplicated">环境变量 '{0}' 先前已加入。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FileName">文件路径</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatClefData">读取时格式化 CLEF 资料</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatClefData.Description">仅针对扩展名为 .clef 之文件有效。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatJsonData">读取时格式化 JSON 资料</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatJsonData.Description">仅针对扩展名为 .json 之文件有效。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatXmlData">读取时格式化 XML 资料</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatXmlData.Description">仅针对扩展名为 .xml 之文件有效。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IncludeStandardError">包含标准错误输出 (stderr)</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IPEndPoint">IP 地址</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IsResourceOnAzure">这是 Azure 上的资源</sys:String>
Expand Down
3 changes: 0 additions & 3 deletions ULogViewer/Strings/zh-TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,8 @@ return False</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.EnvironmentVariables.Duplicated">環境變數 '{0}' 先前已加入。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FileName">檔案路徑</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatClefData">讀取時格式化 CLEF 資料</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatClefData.Description">僅針對副檔名為 .clef 之檔案有效。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatJsonData">讀取時格式化 JSON 資料</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatJsonData.Description">僅針對副檔名為 .json 之檔案有效。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatXmlData">讀取時格式化 XML 資料</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.FormatXmlData.Description">僅針對副檔名為 .xml 之檔案有效。</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IncludeStandardError">包含標準錯誤輸出 (stderr)</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IPEndPoint">IP 位址</sys:String>
<sys:String x:Key="String/LogDataSourceOptions.IsResourceOnAzure">這是 Azure 上的資源</sys:String>
Expand Down

0 comments on commit 1328095

Please sign in to comment.