Skip to content

Commit

Permalink
Added the possibility to scan a directory for executables (Leo-Corpor…
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Nov 5, 2023
1 parent 4ad792e commit 5bbd0e2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Gavilya/ViewModels/ExecutableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class ExecutableViewModel : ViewModelBase

public ICommand ClickCommand { get; }

public ExecutableViewModel(string name, string filePath, GameEditionViewModel gameEditionViewModel)
{
public ExecutableViewModel(string name, string filePath, GameEditionViewModel gameEditionViewModel)
{
Name = name;
FilePath = filePath;
_gameEditionViewModel = gameEditionViewModel;
Expand Down
25 changes: 25 additions & 0 deletions Gavilya/ViewModels/GameEditionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using Gavilya.Helpers;
using Gavilya.Models;
using Gavilya.Models.Rawg;
using Gavilya.Services;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -163,6 +164,9 @@ public bool CanExecute
private bool _isUwpOpen = false;
public bool IsUwpOpen { get => _isUwpOpen; set { _isUwpOpen = value; OnPropertyChanged(nameof(IsUwpOpen)); } }

private bool _isExeSelectorOpen = false;
public bool IsExeSelectorOpen { get => _isExeSelectorOpen; set { _isExeSelectorOpen = value; OnPropertyChanged(nameof(IsExeSelectorOpen)); } }


private bool _isRawgOpen = false;
public bool IsRawgOpen { get => _isRawgOpen; set { _isRawgOpen = value; OnPropertyChanged(nameof(IsRawgOpen)); } }
Expand Down Expand Up @@ -194,6 +198,9 @@ public bool CanExecute
private List<UwpSelectorViewModel> _uwpApps;
public List<UwpSelectorViewModel> UwpApps { get => _uwpApps; set { _uwpApps = value; OnPropertyChanged(nameof(UwpApps)); } }

private List<ExecutableViewModel> _exeApps;
public List<ExecutableViewModel> ExeApps { get => _exeApps; set { _exeApps = value; OnPropertyChanged(nameof(ExeApps)); } }

private Visibility _dragAreaVis = Visibility.Collapsed;
public Visibility DragAreaVis { get => _dragAreaVis; set { _dragAreaVis = value; OnPropertyChanged(nameof(DragAreaVis)); } }

Expand Down Expand Up @@ -229,6 +236,8 @@ public bool CanExecute
public ICommand ShowConvertSectionCommand { get; }
public ICommand ProcessHelpCommand { get; }
public ICommand DropCommand { get; }
public ICommand ScanCommand { get; }
public ICommand CloseExeSelectorCommand { get; }

/// <summary>
/// This constructor is used when editing an exisiting game.
Expand All @@ -255,6 +264,7 @@ public GameEditionViewModel(Game game, GameList games, List<Tag> tags, MainViewM
ShowConvertSectionCommand = new RelayCommand(ShowConvert);
ProcessHelpCommand = new RelayCommand(ShowProcessHelp);
DropCommand = new RelayCommand(ExecuteDrop);
ScanCommand = new RelayCommand(Scan);

// Load properties
Name = game.Name;
Expand Down Expand Up @@ -322,6 +332,7 @@ public GameEditionViewModel(GameType gameType, GameList games, List<Tag> tags, M
RawgSearchCommand = new RelayCommand(SearchRawg);
ProcessHelpCommand = new RelayCommand(ShowProcessHelp);
DropCommand = new RelayCommand(ExecuteDrop);
ScanCommand = new RelayCommand(Scan);

SelectedTags = new();

Expand Down Expand Up @@ -483,4 +494,18 @@ private void ShowProcessHelp(object? obj)
{
MessageBox.Show(Properties.Resources.ProcessNameHelp, Properties.Resources.Help, MessageBoxButton.OK, MessageBoxImage.Information);
}

private void Scan(object? obj)
{
using System.Windows.Forms.FolderBrowserDialog dialog = new();
System.Windows.Forms.DialogResult result = dialog.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
{
string selectedPath = dialog.SelectedPath;
GameScannerService gameScannerService = new();
ExeApps = gameScannerService.ScanForExecutables(selectedPath, this);
IsExeSelectorOpen = true;
}
}
}
66 changes: 66 additions & 0 deletions Gavilya/Views/GameEditionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,79 @@
</StackPanel>
</Border>
</Button>
<Button
x:Name="SelectExeBtn"
Padding="5"
Background="{DynamicResource Background2}"
Command="{Binding ScanCommand}"
Content="{x:Static lang:Resources.ScanDirectory}"
Cursor="Hand"
FontWeight="Bold"
Foreground="{DynamicResource Foreground}"
Style="{DynamicResource RegularButton}" />

<TextBlock
x:Name="LocationTxt"
Margin="5"
d:Text="C:\Games\Game.exe"
Text="{Binding Command}" />
</StackPanel>
<Popup
Width="400"
Height="250"
AllowsTransparency="True"
IsOpen="{Binding IsExeSelectorOpen}"
Placement="Top"
PlacementTarget="{Binding ElementName=SelectExeBtn}"
StaysOpen="True">
<Border
Margin="10"
Padding="10"
Background="{DynamicResource Background}"
CornerRadius="10">
<Border.Effect>
<DropShadowEffect
BlurRadius="10"
Opacity="0.4"
RenderingBias="Quality"
ShadowDepth="0"
Color="Black" />
</Border.Effect>

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer>
<ItemsControl ItemsSource="{Binding ExeApps}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type vm:ExecutableViewModel}">
<components:ExecutableSelectorComponent />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<Button
Grid.Row="1"
Margin="5"
Padding="5"
HorizontalAlignment="Center"
Background="{DynamicResource Background2}"
Command="{Binding ScanCommand}"
Content="{x:Static lang:Resources.Close}"
Cursor="Hand"
FontWeight="Bold"
Foreground="{DynamicResource Foreground}"
Style="{DynamicResource RegularButton}" />
</Grid>
</Border>
</Popup>
<TextBlock
Margin="0 10"
VerticalAlignment="Center"
Expand Down

0 comments on commit 5bbd0e2

Please sign in to comment.