Skip to content

Commit

Permalink
Fix bug where filename with space couldn't be open
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrietS committed Oct 20, 2024
1 parent d39d70e commit 7c299d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/LogAlligator.App/LineProvider/BufferedFileLineProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public class BufferedFileLineProvider(Uri path) : ILineProvider
public async Task LoadData(Action<int> progressCallback, CancellationToken token)
{
await LoadLinesData(progressCallback, token);

const FileOptions fileOptions = FileOptions.RandomAccess; // profile if better: FileOptions.SequentialScan;
_stream = new FileStream(path.AbsolutePath, FileMode.Open, FileAccess.Read, FileShare.Read, 65536, fileOptions);
_stream = new FileStream(path.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read, 65536, fileOptions);
_reader = new StreamReader(_stream, Encoding.UTF8, true, 300, true);
}

private async Task LoadLinesData(Action<int> progressCallback, CancellationToken token)
{
const FileOptions fileOptions = FileOptions.SequentialScan | FileOptions.Asynchronous;
await using var stream = new FileStream(path.AbsolutePath, FileMode.Open, FileAccess.Read, FileShare.Read, 65536, fileOptions);
await using var stream = new FileStream(path.LocalPath, FileMode.Open, FileAccess.Read, FileShare.Read, 65536, fileOptions);
var reader = new StreamLineReader(stream, 65536);
int lineNumber = 1;

Expand All @@ -36,13 +36,13 @@ private async Task LoadLinesData(Action<int> progressCallback, CancellationToken
_lines.Add((lineNumber, line.Begin, (int)line.Length));
lineNumber++;

if (_lines.Count % 100 == 0)
if (_lines.Count % 100 == 0)
progressCallback(_lines.Count);
}

progressCallback(_lines.Count);
}

public int Count => _lines.Count;

public string this[int index]
Expand All @@ -59,7 +59,7 @@ public int GetLineLength(int index)
{
if (index < 0 || index >= _lines.Count)
throw new ArgumentOutOfRangeException(nameof(index));

return _lines[index].Length;
}

Expand Down
10 changes: 5 additions & 5 deletions src/LogAlligator.App/LineProvider/StupidFileLineProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ namespace LogAlligator.App.LineProvider;
public class StupidFileLineProvider(Uri path) : ILineProvider
{
private string[] _lines = [];

public async Task LoadData(Action<int> progressCallback, CancellationToken token)
{
await Task.Delay(1000, token);
progressCallback(100);
await Task.Delay(1000, token);
progressCallback(200);
_lines = await File.ReadAllLinesAsync(path.AbsolutePath, token);

_lines = await File.ReadAllLinesAsync(path.LocalPath, token);
}

public int Count => _lines.Length;

public string this[int index]
Expand All @@ -40,7 +40,7 @@ public int GetLineLength(int index)
{
if (index < 0 || index >= _lines.Length)
throw new ArgumentOutOfRangeException(nameof(index));

return _lines[index].Length;
}

Expand Down
16 changes: 8 additions & 8 deletions src/LogAlligator.App/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ private void OnDrop(object? sender, DragEventArgs e)
var file = GetFileFromDragEvent(e);
if (file == null)
return;

this.Activate(); // Bring window to front
Log.Debug("Dropped file: {FileName}", file.Name);
AddFileTab(file);
}

private void OnDragOver(object? sender, DragEventArgs e)
{
e.DragEffects = GetFileFromDragEvent(e) != null ? DragDropEffects.Copy : DragDropEffects.None;
Expand All @@ -56,7 +56,7 @@ private void OnDragOver(object? sender, DragEventArgs e)

return files[0] as IStorageFile;
}

public async void OnLoadData()
{
if (Design.IsDesignMode) return;
Expand All @@ -71,7 +71,7 @@ public async void OnLoadData()
}
AddFileTab(file);
}

public void OnSwitchTheme()
{
Application.Current!.RequestedThemeVariant = Application.Current!.ActualThemeVariant == ThemeVariant.Light
Expand All @@ -83,7 +83,7 @@ public void OnExit()
{
Close();
}

private async void MenuBar_Open_OnClick(object? sender, RoutedEventArgs e)
{
var files = await this.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
Expand All @@ -107,11 +107,11 @@ private void AddFileTab(IStorageFile file)
{
var fileView = new FileView { FilePath = file.Path };
var fileTab = new TabItem { Header = file.Name, Content = fileView };

fileView.RemovalRequested += (_, _) => OnTabRequestedRemoval(fileTab);
fileTab.ContextMenu = CreateFileTabContextMenu(fileTab);

ToolTip.SetTip(fileTab, file.Path.AbsolutePath);
ToolTip.SetTip(fileTab, file.Path.LocalPath);
FileTabs.SelectedIndex = FileTabs.Items.Add(fileTab);

fileView.Focus();
Expand All @@ -125,7 +125,7 @@ private ContextMenu CreateFileTabContextMenu(TabItem tab)
ctxMenu.Items.Add(closeMenuItem);
return ctxMenu;
}

private void OnTabRequestedRemoval(TabItem tab)
{
Log.Debug($"Removing tab {tab.Header}");
Expand Down

0 comments on commit 7c299d5

Please sign in to comment.