Skip to content

Commit 8d7b667

Browse files
committed
If not all records are loaded buttons are diabled;
Fixed issue in Setting order of Items was the wrong way, so chnages to LimitDuration whwre wrong; Support of magic word for delimiter in the beginning of the file; Rebuild FastColoredTextBox.dll from scratch as it was reported as infected;
1 parent 34972c3 commit 8d7b667

File tree

12 files changed

+119
-105
lines changed

12 files changed

+119
-105
lines changed

Application/FormEditSettings.cs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ public FormEditSettings(in ViewSettings viewSettings, in IFileSettingPhysicalFil
6060

6161
InitializeComponent();
6262

63-
if (m_ViewSettings.LimitDuration == ViewSettings.Duration.Unlimited)
64-
domainUpDownLimit.SelectedIndex = 4;
65-
else if (m_ViewSettings.LimitDuration == ViewSettings.Duration.TenSecond)
66-
domainUpDownLimit.SelectedIndex = 3;
67-
else if (m_ViewSettings.LimitDuration == ViewSettings.Duration.TwoSecond)
68-
domainUpDownLimit.SelectedIndex = 2;
69-
else if (m_ViewSettings.LimitDuration == ViewSettings.Duration.Second)
70-
domainUpDownLimit.SelectedIndex = 1;
71-
else
72-
domainUpDownLimit.SelectedIndex = 0;
63+
domainUpDownLimit.SelectedIndex = m_ViewSettings.LimitDuration switch
64+
{
65+
ViewSettings.Duration.Unlimited => 0,
66+
ViewSettings.Duration.TenSecond => 1,
67+
ViewSettings.Duration.TwoSecond => 2,
68+
ViewSettings.Duration.Second => 3,
69+
ViewSettings.Duration.HalfSecond => 4
70+
};
7371

7472
toolTip.SetToolTip(checkBoxAllowRowCombining,
7573
@"Try to combine rows, it can happen if the column does contain a linefeed and is not properly quoted.
@@ -154,7 +152,7 @@ await buttonGuessCP.RunWithHourglassAsync(async () =>
154152
#if NET5_0_OR_GREATER
155153
await
156154
#endif
157-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
155+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
158156
var (codepage, bom) = await improvedStream.GuessCodePage(m_CancellationTokenSource.Token);
159157
csvFile.CodePageId = codepage;
160158
csvFile.ByteOrderMark = bom;
@@ -170,7 +168,7 @@ await buttonGuessDelimiter.RunWithHourglassAsync(async () =>
170168
#if NET5_0_OR_GREATER
171169
await
172170
#endif
173-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
171+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
174172
var res = await improvedStream.GuessDelimiter(csvFile.CodePageId, csvFile.SkipRows,
175173
csvFile.EscapePrefix,
176174
m_CancellationTokenSource.Token);
@@ -189,7 +187,7 @@ await buttonGuessTextQualifier.RunWithHourglassAsync(async () =>
189187
#if NET5_0_OR_GREATER
190188
await
191189
#endif
192-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
190+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
193191
qualifier = await improvedStream.GuessQualifier(csvFile.CodePageId, csvFile.SkipRows,
194192
csvFile.FieldDelimiter, csvFile.EscapePrefix,
195193
m_CancellationTokenSource.Token);
@@ -207,7 +205,7 @@ await buttonSkipLine.RunWithHourglassAsync(async () =>
207205
#if NET5_0_OR_GREATER
208206
await
209207
#endif
210-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
208+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
211209
csvFile.SkipRows = await improvedStream.GuessStartRow(csvFile.CodePageId, csvFile.FieldDelimiter,
212210
csvFile.FieldQualifier, csvFile.CommentLine, m_CancellationTokenSource.Token);
213211
});
@@ -280,7 +278,7 @@ await buttonNewLine.RunWithHourglassAsync(async () =>
280278
#if NET5_0_OR_GREATER
281279
await
282280
#endif
283-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
281+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
284282
cboRecordDelimiter.SelectedValue = (int) await improvedStream.GuessNewline(csvFile.CodePageId,
285283
csvFile.SkipRows,
286284
csvFile.FieldQualifier, m_CancellationTokenSource.Token);
@@ -319,15 +317,15 @@ private void TextBoxFile_Validating(object? sender, CancelEventArgs e)
319317

320318
private void DomainUpDownTime_SelectedItemChanged(object? sender, EventArgs e)
321319
{
322-
m_ViewSettings.LimitDuration = domainUpDownLimit.SelectedIndex switch
323-
{
324-
4 => ViewSettings.Duration.Unlimited,
325-
3 => ViewSettings.Duration.TenSecond,
326-
2 => ViewSettings.Duration.TwoSecond,
327-
1 => ViewSettings.Duration.Second,
328-
0 => ViewSettings.Duration.HalfSecond,
329-
_ => m_ViewSettings.LimitDuration
330-
};
320+
if (domainUpDownLimit.SelectedIndex != -1)
321+
m_ViewSettings.LimitDuration = domainUpDownLimit.SelectedIndex switch
322+
{
323+
0 => ViewSettings.Duration.Unlimited,
324+
1 => ViewSettings.Duration.TenSecond,
325+
2 => ViewSettings.Duration.TwoSecond,
326+
3 => ViewSettings.Duration.Second,
327+
4 => ViewSettings.Duration.HalfSecond
328+
};
331329
}
332330

333331
private async void ButtonGuessHeader_Click(object? sender, EventArgs e)
@@ -338,7 +336,7 @@ await buttonGuessHeader.RunWithHourglassAsync(async () =>
338336
#if NET5_0_OR_GREATER
339337
await
340338
#endif
341-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
339+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
342340
var res = await improvedStream.GuessHasHeader(csvFile.CodePageId, csvFile.SkipRows, csvFile.CommentLine,
343341
csvFile.FieldDelimiter, m_CancellationTokenSource.Token);
344342
csvFile.HasFieldHeader = string.IsNullOrEmpty(res);
@@ -364,7 +362,7 @@ await buttonGuessLineComment.RunWithHourglassAsync(async () =>
364362
#if NET5_0_OR_GREATER
365363
await
366364
#endif
367-
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
365+
using var improvedStream = new ImprovedStream(new SourceAccess(csvFile));
368366
csvFile.CommentLine = await improvedStream.GuessLineComment(csvFile.CodePageId, csvFile.SkipRows,
369367
m_CancellationTokenSource.Token);
370368
});

Application/FormMain.Designer.cs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Application/ViewSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
*/
1414

15+
using Newtonsoft.Json;
1516
using System;
1617
using System.ComponentModel;
1718
using System.Windows.Forms;
@@ -111,6 +112,7 @@ public bool DetectFileChanges
111112
set => SetField(ref m_DetectFileChanges, value);
112113
}
113114

115+
[JsonIgnore]
114116
public TimeSpan DurationTimeSpan
115117
{
116118
get
@@ -121,7 +123,7 @@ public TimeSpan DurationTimeSpan
121123
Duration.Second => TimeSpan.FromSeconds(1),
122124
Duration.TwoSecond => TimeSpan.FromSeconds(2),
123125
Duration.TenSecond => TimeSpan.FromSeconds(10),
124-
_ => TimeSpan.FromMinutes(60),
126+
_ => TimeSpan.MaxValue
125127
};
126128
}
127129
}

Library/ClassLibraryCSV/CsvHelper.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,22 @@ public static async Task<Tuple<string, bool>> GuessDelimiter(
743743
using var textReader = await improvedStream.GetStreamReaderAtStart(codePageId, skipRows, cancellationToken)
744744
.ConfigureAwait(false);
745745

746+
if (textReader.CanSeek)
747+
{
748+
// read the first line and check if it does contain the magic word sep=
749+
var firstLine = (await textReader.ReadLineAsync().ConfigureAwait(false)).Trim().Replace(" ", "");
750+
if (firstLine.StartsWith("sep=", StringComparison.OrdinalIgnoreCase) && firstLine.Length > 4)
751+
{
752+
var resultFl = firstLine.Substring(4);
753+
if (resultFl.Equals("\\t", StringComparison.OrdinalIgnoreCase))
754+
resultFl = "Tab";
755+
Logger.Information("Delimiter from 'sep=' in first line: {delimiter}", resultFl);
756+
return new Tuple<string, bool>(resultFl, true);
757+
}
758+
759+
textReader.ToBeginning();
760+
}
761+
746762
return textReader.GuessDelimiter(escapeCharacter, null, cancellationToken);
747763
}
748764

@@ -1325,7 +1341,8 @@ private static DelimiterCounter GetDelimiterCounter(
13251341
IEnumerable<char>? disallowedDelimiter,
13261342
CancellationToken cancellationToken)
13271343
{
1328-
if (textReader is null) throw new ArgumentNullException(nameof(textReader));
1344+
if (textReader is null)
1345+
throw new ArgumentNullException(nameof(textReader));
13291346

13301347
var dc = new DelimiterCounter(numRows, disallowedDelimiter);
13311348
var escapeCharacter = escape.WrittenPunctuationToChar();
@@ -1334,7 +1351,6 @@ private static DelimiterCounter GetDelimiterCounter(
13341351
var readChar = -1;
13351352

13361353
var textReaderPosition = new ImprovedTextReaderPositionStore(textReader);
1337-
13381354
while (dc.LastRow < dc.NumRows && !textReaderPosition.AllRead() && !cancellationToken.IsCancellationRequested)
13391355
{
13401356
var lastChar = readChar;
@@ -1494,12 +1510,12 @@ private static Tuple<string, bool> GuessDelimiter(
14941510
else
14951511
{
14961512
// otherwise find the best
1497-
1498-
var sums = new Dictionary<int, Tuple<long,long>>();
1513+
1514+
var sums = new Dictionary<int, Tuple<long, long>>();
14991515

15001516
foreach (var index in validSeparatorIndex)
15011517
{
1502-
var totalRows = (double) (dc.LastRow - startRow);
1518+
var totalRows = (double) (dc.LastRow - startRow);
15031519
var sumCount = 0;
15041520
// If there are enough rows skip the first rows, there might be a descriptive introduction
15051521
// this can not be done in case there are not many rows
@@ -1515,7 +1531,7 @@ private static Tuple<string, bool> GuessDelimiter(
15151531
// Only proceed if there is usually more then one occurrence and we have more then one row
15161532
if (avg < 1 || dc.SeparatorRows[index] == 1)
15171533
continue;
1518-
1534+
15191535

15201536
// First determine the variance, low value means and even distribution
15211537
long variance = 0;
@@ -1544,7 +1560,7 @@ private static Tuple<string, bool> GuessDelimiter(
15441560
return new Tuple<string, bool>("Tab", false);
15451561
}
15461562

1547-
var result = match == '\t' ? "Tab" : match.ToString(CultureInfo.CurrentCulture);
1563+
var result = match == '\t' ? "Tab" : match.ToStringHandle0().ToString(CultureInfo.CurrentCulture);
15481564
Logger.Information("Column Delimiter: {delimiter}", result);
15491565
return new Tuple<string, bool>(result, true);
15501566
}

Library/ClassLibraryCSV/ImprovedTextReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public int Read()
178178
public async Task<string> ReadLineAsync()
179179
{
180180
LineNumber++;
181-
return await StreamReader.ReadLineAsync();
181+
return await StreamReader.ReadLineAsync().ConfigureAwait(false);
182182
}
183183

184184
/// <summary>

Library/DLL/FastColoredTextBox.dll

2 KB
Binary file not shown.

Library/SharedAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
// Version information for an assembly consists of the following four values: Major Version Minor
1212
// Version Build Number Revision You can specify all the values or you can default the Build and.Json
1313
// Revision Numbers by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")]
14-
[assembly: AssemblyVersion("1.6.27.554")]
15-
[assembly: AssemblyFileVersion("1.6.27.554")]
16-
[assembly: AssemblyInformationalVersion("1.6.27.554")] // a.k.a. "Product version"
14+
[assembly: AssemblyVersion("1.6.28.555")]
15+
[assembly: AssemblyFileVersion("1.6.28.555")]
16+
[assembly: AssemblyInformationalVersion("1.6.28.555")] // a.k.a. "Product version"

0 commit comments

Comments
 (0)