Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/fix warnigs #91

Merged
merged 14 commits into from
Sep 16, 2024
8 changes: 8 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 @@ -306,4 +306,7 @@
<data name="Reboot" xml:space="preserve">
<value>*Application restart required</value>
</data>
<data name="AllowOnlyOneInstance" xml:space="preserve">
<value>Allow only one Instance</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/SmartCommander/Assets/Resources.ru-RU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,7 @@
<data name="Reboot" xml:space="preserve">
<value>*Требуется перезапуск приложения</value>
</data>
<data name="AllowOnlyOneInstance" xml:space="preserve">
<value>Разрешать только один экземпляр приложения</value>
</data>
</root>
2 changes: 1 addition & 1 deletion src/SmartCommander/Converters/BitmapValueConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BitmapValueConverter : IValueConverter
}
else
{
var assemblyName = Assembly.GetEntryAssembly().GetName().Name;
var assemblyName = Assembly.GetEntryAssembly()?.GetName().Name;
uri = new Uri($"avares://{assemblyName}/{rawUri}");
}

Expand Down
1 change: 1 addition & 0 deletions src/SmartCommander/Models/OptionsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ static OptionsModel()
public string RightPanePath { get; set; } = "";

public bool IsDarkThemeEnabled { get; set; }
public bool AllowOnlyOneInstance { get; set; } = true;
public string Language { get; set; } = "en-US";

}
Expand Down
36 changes: 12 additions & 24 deletions src/SmartCommander/Program.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
using Avalonia;
using Avalonia.ReactiveUI;
using SmartCommander.Models;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace SmartCommander
{
internal class Program
{
static FileStream? _lockFile;
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args)
{
var exception = false;
var haveSecondInstance = false;
var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SmartCommander");
Directory.CreateDirectory(dir);
try
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_lockFile = File.Open(Path.Combine(dir, ".lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
_lockFile.Lock(0, 0);
}
BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
catch
{
exception = true;
}

if (exception)
string currentProcessName = Process.GetCurrentProcess().ProcessName;
var runningProcesses = Process.GetProcessesByName(currentProcessName);
haveSecondInstance = (runningProcesses.Length > 1);

if (haveSecondInstance && OptionsModel.Instance.AllowOnlyOneInstance)
{
try
{
var client = new NamedPipeClientStream("SmartCommanderActivation");
client.Connect(1000);
using (StreamWriter writer = new StreamWriter(client))
{
writer.WriteLine("ActivateSmartCommander");
writer.Flush();
writer.Flush();
}

}
catch { }
}
else {
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}

}
Expand Down
10 changes: 2 additions & 8 deletions src/SmartCommander/ViewModels/CopyMoveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@ public CopyMoveViewModel(bool copy, string text, string directory)

public void SaveClose(Window window)
{
if (window != null)
{
window.Close(this);
}
window?.Close(this);
}

public void Close(Window window)
{
if (window != null)
{
window.Close();
}
window?.Close(this);
}
}
}
6 changes: 3 additions & 3 deletions src/SmartCommander/ViewModels/FileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public string Name
// moving here is fast since they are guaranteed to be on the same drive
if (IsFolder)
{
destination = Path.Combine(Path.GetDirectoryName(FullName), value);
destination = Path.Combine(Path.GetDirectoryName(FullName) ?? "", value);
Directory.Move(FullName, destination);
}
else
{
destination = Path.Combine(Path.GetDirectoryName(FullName), value + "." + Extension);
File.Move(FullName, destination);
destination = Path.Combine(Path.GetDirectoryName(FullName) ?? "", value);
File.Move(FullName, destination);
}
_name = value;
FullName = destination;
Expand Down
14 changes: 8 additions & 6 deletions src/SmartCommander/ViewModels/FilesPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public string CurrentDirectory
{
_currentDirectory = value;
GetFilesFolders(CurrentDirectory, FoldersFilesList);
this.RaisePropertyChanged("CurrentDirectory");
this.RaisePropertyChanged("CurrentDirectoryInfo");
this.RaisePropertyChanged(nameof(CurrentDirectory));
this.RaisePropertyChanged(nameof(CurrentDirectoryInfo));
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public bool IsSelected
set
{
_isSelected = value;
this.RaisePropertyChanged("GridBorderBrush");
this.RaisePropertyChanged(nameof(GridBorderBrush));

if (value)
{
Expand All @@ -100,7 +100,7 @@ public bool IsSelected
}


public bool IsCurrentDirectoryDisplayed
public static bool IsCurrentDirectoryDisplayed
{
get => OptionsModel.Instance.IsCurrentDirectoryDisplayed;
}
Expand All @@ -112,13 +112,14 @@ public bool IsCurrentDirectoryDisplayed

public ObservableCollection<FileViewModel> FoldersFilesList { get; set; } = new ObservableCollection<FileViewModel>();

public FilesPaneViewModel()
public FilesPaneViewModel(EventHandler focusHandler)
{
_mainVM = new MainWindowViewModel();
ShowViewerDialog = new Interaction<ViewerViewModel, ViewerViewModel?>();
FocusChanged += focusHandler;
}

public FilesPaneViewModel(MainWindowViewModel mainVM)
public FilesPaneViewModel(MainWindowViewModel mainVM, EventHandler focusHandler)
{
CurrentDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
ViewCommand = ReactiveCommand.Create(View);
Expand All @@ -129,6 +130,7 @@ public FilesPaneViewModel(MainWindowViewModel mainVM)
FilesPaneBackspaceCommand = ReactiveCommand.Create(() => ProcessCurrentItem(true));
ShowViewerDialog = new Interaction<ViewerViewModel, ViewerViewModel?>();
_mainVM = mainVM;
FocusChanged += focusHandler;
}

public ReactiveCommand<Unit, Unit>? FilesPaneEnterCommand { get; }
Expand Down
23 changes: 10 additions & 13 deletions src/SmartCommander/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ public MainWindowViewModel()
F8Command = ReactiveCommand.Create(Delete);
OptionsCommand = ReactiveCommand.CreateFromTask(ShowOptions);

LeftFileViewModel = new FilesPaneViewModel(this);
LeftFileViewModel.FocusChanged += OnFocusChanged;

RightFileViewModel = new FilesPaneViewModel(this);
RightFileViewModel.FocusChanged += OnFocusChanged;
LeftFileViewModel = new FilesPaneViewModel(this, OnFocusChanged);
RightFileViewModel = new FilesPaneViewModel(this, OnFocusChanged);
SelectedPane = RightFileViewModel;

if (!string.IsNullOrEmpty(OptionsModel.Instance.LeftPanePath))
{
Expand Down Expand Up @@ -88,7 +86,6 @@ private void OnFocusChanged(object? sender, EventArgs e)
public ReactiveCommand<Unit, Unit> F6Command { get; }
public ReactiveCommand<Unit, Unit> F7Command { get; }
public ReactiveCommand<Unit, Unit> F8Command { get; }
public ReactiveCommand<Unit, Unit> TabCommand { get; }
public ReactiveCommand<Unit, Unit> OptionsCommand { get; }

public FilesPaneViewModel LeftFileViewModel { get; }
Expand All @@ -112,16 +109,16 @@ public string CommandText
set
{
_commandText = value;
this.RaisePropertyChanged("CommandText");
this.RaisePropertyChanged(nameof(CommandText));
}
}

public Interaction<CopyMoveViewModel, CopyMoveViewModel?> ShowCopyDialog { get; }

public Interaction<OptionsViewModel, OptionsViewModel?> ShowOptionsDialog { get; }

public bool IsFunctionKeysDisplayed => OptionsModel.Instance.IsFunctionKeysDisplayed;
public bool IsCommandLineDisplayed => OptionsModel.Instance.IsCommandLineDisplayed;
public static bool IsFunctionKeysDisplayed => OptionsModel.Instance.IsFunctionKeysDisplayed;
public static bool IsCommandLineDisplayed => OptionsModel.Instance.IsCommandLineDisplayed;

public void Exit()
{
Expand Down Expand Up @@ -544,10 +541,10 @@ public async Task ShowOptions()
var result = await ShowOptionsDialog.Handle(optionsModel);
if (result != null)
{
this.RaisePropertyChanged("IsFunctionKeysDisplayed");
this.RaisePropertyChanged("IsCommandLineDisplayed");
SelectedPane.RaisePropertyChanged("IsCurrentDirectoryDisplayed");
SecondPane.RaisePropertyChanged("IsCurrentDirectoryDisplayed");
this.RaisePropertyChanged(nameof(IsFunctionKeysDisplayed));
this.RaisePropertyChanged(nameof(IsCommandLineDisplayed));
SelectedPane.RaisePropertyChanged(nameof(FilesPaneViewModel.IsCurrentDirectoryDisplayed));
SecondPane.RaisePropertyChanged(nameof(FilesPaneViewModel.IsCurrentDirectoryDisplayed));
SetTheme();
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/SmartCommander/ViewModels/OptionsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public OptionsViewModel()
ConfirmationWhenDeleteNonEmpty = Model.ConfirmationWhenDeleteNonEmpty;
SaveWindowPositionSize = Model.SaveWindowPositionSize;
IsDarkThemeEnabled = Model.IsDarkThemeEnabled;
AllowOnlyOneInstance = Model.AllowOnlyOneInstance;

AvailableCultures = new ObservableCollection<CultureInfo>(GetAvailableCultures());
var lang = AvailableCultures.FirstOrDefault(x => x.Name == Model.Language);
SelectedCulture = lang is null ? AvailableCultures.FirstOrDefault() : lang;
var lang = AvailableCultures.First(x => x.Name == Model.Language);
SelectedCulture = lang ?? AvailableCultures.First();
}

public bool IsCurrentDirectoryDisplayed { get; set; }
Expand All @@ -72,6 +73,7 @@ public OptionsViewModel()
public bool SaveWindowPositionSize { get; set; }

public bool IsDarkThemeEnabled { get; set; }
public bool AllowOnlyOneInstance { get; set; }

public ReactiveCommand<Window, Unit> OKCommand { get; }
public ReactiveCommand<Window, Unit> CancelCommand { get; }
Expand All @@ -87,12 +89,11 @@ public void SaveClose(Window window)
Model.SaveWindowPositionSize = SaveWindowPositionSize;
Model.IsDarkThemeEnabled = IsDarkThemeEnabled;
Model.Language = SelectedCulture.Name;
Model.AllowOnlyOneInstance = AllowOnlyOneInstance;

Model.Save();
if (window != null)
{
window.Close(this);
}
window?.Close(this);

}

public void Close(Window window)
Expand Down
6 changes: 4 additions & 2 deletions src/SmartCommander/Views/OptionsWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="300"
Width="600" Height="300"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="350"
Width="600" Height="350"
x:Class="SmartCommander.Views.OptionsWindow"
ShowInTaskbar="False"
Icon="/Assets/main.ico"
Expand Down Expand Up @@ -33,6 +33,8 @@
Content="{x:Static assets:Resources.DisplayCommandLine}"></CheckBox>
<CheckBox IsChecked="{Binding SaveWindowPositionSize}"
Content="{x:Static assets:Resources.SaveWindowPositionSize}"></CheckBox>
<CheckBox IsChecked="{Binding AllowOnlyOneInstance}"
Content="{x:Static assets:Resources.AllowOnlyOneInstance}"></CheckBox>
<RadioButton IsChecked="{Binding !IsDarkThemeEnabled}"
Content="{x:Static assets:Resources.LightTheme}"></RadioButton>
<RadioButton IsChecked="{Binding IsDarkThemeEnabled}"
Expand Down
Loading