Skip to content

Commit

Permalink
Added too large file check.
Browse files Browse the repository at this point in the history
Some fixes and refactoring.
  • Loading branch information
anovik committed Aug 30, 2024
1 parent a67c025 commit 86549aa
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 54 deletions.
9 changes: 9 additions & 0 deletions src/SmartCommander/Assets/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/SmartCommander/Assets/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,7 @@
<data name="DirectoryExists" xml:space="preserve">
<value>Directory {0} already exists.</value>
</data>
<data name="TooLargeSize" xml:space="preserve">
<value>Too large file size for viewing.</value>
</data>
</root>
12 changes: 9 additions & 3 deletions src/SmartCommander/ViewModels/FilesPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Reactive;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Path = System.IO.Path;

namespace SmartCommander.ViewModels
Expand Down Expand Up @@ -267,18 +268,23 @@ public void Update()

public void View()
{
View(null);
_= View(null);
}

public async void View(Action<ButtonResult, object?>? resultAction)
public async Task View(Action<ButtonResult, object?>? resultAction)
{
if (CurrentItem == null)
return;
if (!CurrentItem.IsFolder)
{
// TODO: check file size
if (Convert.ToUInt64(CurrentItem.Size) > 128*1024*1024)
{
MessageBox_Show(resultAction, Resources.TooLargeSize, Resources.Alert, ButtonEnum.Ok);
return;
}
var copy = new ViewerViewModel(CurrentItem.FullName);
await ShowViewerDialog.Handle(copy);
resultAction?.Invoke(ButtonResult.Ok, null);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/SmartCommander/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void View()
return;
}
_F3Busy = true;
SelectedPane.View(F3Finished);
_= SelectedPane.View(F3Finished);
}

public void Edit()
Expand Down
2 changes: 1 addition & 1 deletion src/SmartCommander/ViewModels/ViewerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public ViewerViewModel(string filename)
{
Text = File.ReadAllText(filename);
}
catch { }
catch { Text = ""; }
}

public string Text { get; set; }
Expand Down
12 changes: 1 addition & 11 deletions src/SmartCommander/Views/CopyMoveWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace SmartCommander.Views
{
Expand All @@ -9,14 +7,6 @@ public partial class CopyMoveWindow : Window
public CopyMoveWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
}
32 changes: 7 additions & 25 deletions src/SmartCommander/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public MainWindow()
Opened += OnOpened;
InitializeComponent();

this.WhenActivated(d => d(ViewModel!.ShowCopyDialog.RegisterHandler(DoShowCopyDialogAsync)));
this.WhenActivated(d => d(ViewModel!.ShowOptionsDialog.RegisterHandler(DoShowOptionsDialogAsync)));
this.WhenActivated(d => d(ViewModel!.ShowViewerDialog.RegisterHandler(DoShowViewerDialogAsync)));
this.WhenActivated(d => d(ViewModel!.ShowCopyDialog.RegisterHandler(DoShowDialogAsync<CopyMoveViewModel, CopyMoveWindow>)));
this.WhenActivated(d => d(ViewModel!.ShowOptionsDialog.RegisterHandler(DoShowDialogAsync<OptionsViewModel, OptionsWindow>)));
this.WhenActivated(d => d(ViewModel!.ShowViewerDialog.RegisterHandler(DoShowDialogAsync<ViewerViewModel, ViewerWindow>)));

progressWindow = new ProgressWindow();

Expand Down Expand Up @@ -56,32 +56,14 @@ public MainWindow()
};
}

private async Task DoShowViewerDialogAsync(InteractionContext<ViewerViewModel, ViewerViewModel?> interaction)
private async Task DoShowDialogAsync<T1, T2>(InteractionContext<T1, T1?> interaction) where T2 : Window, new()
{
var dialog = new ViewerWindow();
var dialog = new T2();
dialog.DataContext = interaction.Input;

var result = await dialog.ShowDialog<ViewerViewModel>(this);
var result = await dialog.ShowDialog<T1>(this);
interaction.SetOutput(result);
}

private async Task DoShowCopyDialogAsync(InteractionContext<CopyMoveViewModel, CopyMoveViewModel?> interaction)
{
var dialog = new CopyMoveWindow();
dialog.DataContext = interaction.Input;

var result = await dialog.ShowDialog<CopyMoveViewModel>(this);
interaction.SetOutput(result);
}

private async Task DoShowOptionsDialogAsync(InteractionContext<OptionsViewModel, OptionsViewModel?> interaction)
{
var dialog = new OptionsWindow();
dialog.DataContext = interaction.Input;

var result = await dialog.ShowDialog<OptionsViewModel>(this);
interaction.SetOutput(result);
}
}

private void OnOpened(object? sender, EventArgs e)
{
Expand Down
15 changes: 2 additions & 13 deletions src/SmartCommander/Views/OptionsWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace SmartCommander.Views
{
public partial class OptionsWindow : Window
{
public OptionsWindow()
{
InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif

}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
InitializeComponent();
}
}
}

0 comments on commit 86549aa

Please sign in to comment.