Skip to content

Commit

Permalink
Merge pull request Leo-Corporation#422 from Leo-Corporation/vNext
Browse files Browse the repository at this point in the history
Version 4.1.0.2310
  • Loading branch information
lpeyr authored Oct 24, 2023
2 parents 8df4108 + e076ccf commit c27a300
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 35 deletions.
36 changes: 36 additions & 0 deletions Gavilya/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,10 @@
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollContentPresenter CanContentScroll="{TemplateBinding CanContentScroll}" />
<ScrollBar
x:Name="PART_VerticalScrollBar"
Expand Down Expand Up @@ -638,6 +642,38 @@
</ControlTemplate>
</ScrollBar.Template>
</ScrollBar>
<ScrollBar
x:Name="PART_HorizontalScrollBar"
Grid.Row="1"
Grid.Column="0"
Height="8"
Maximum="{TemplateBinding ScrollableWidth}"
Minimum="0"
Orientation="Horizontal"
ViewportSize="{TemplateBinding ViewportWidth}"
Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}">
<ScrollBar.Template>
<ControlTemplate TargetType="{x:Type ScrollBar}">
<Track x:Name="PART_Track">
<Track.Thumb>
<Thumb Background="{DynamicResource SelectedBackground}">
<Thumb.Template>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border
Margin="5"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4" />
</ControlTemplate>
</Thumb.Template>
</Thumb>
</Track.Thumb>
</Track>
</ControlTemplate>
</ScrollBar.Template>
</ScrollBar>
</Grid>
</ControlTemplate>

Expand Down
6 changes: 3 additions & 3 deletions Gavilya/Gavilya.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<UseWindowsForms>True</UseWindowsForms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Title>Gavilya</Title>
<Version>4.0.1.2309</Version>
<Version>4.1.0.2310</Version>
<Authors>Léo Corporation</Authors>
<Description>Gavilya is a simple game launcher for Windows.</Description>
<Copyright>© 2023</Copyright>
Expand Down Expand Up @@ -53,8 +53,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.39" />
<PackageReference Include="MouseKeyHook" Version="5.7.1" />
<PackageReference Include="PeyrSharp.Core" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Env" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Core" Version="1.10.0.2310" />
<PackageReference Include="PeyrSharp.Env" Version="1.10.0.2310" />
<PackageReference Include="RestSharp" Version="110.2.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Gavilya/Helpers/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
namespace Gavilya.Helpers;
public static class Context
{
public static string Version => "4.0.1.2309";
public static string Version => "4.1.0.2310";
public static string LastVersionLink => "https://raw.githubusercontent.com/Leo-Corporation/LeoCorp-Docs/master/Liens/Update%20System/Gavilya/Version.txt";
}
20 changes: 20 additions & 0 deletions Gavilya/Helpers/GameLauncherHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ public bool Launch()
return true;
}

/// <summary>
/// This method only works on Win32 Games.
/// </summary>
/// <returns></returns>
public bool LaunchAsAdmin()
{
// Check location if the game is a Win32 app
if (_game.GameType != GameType.Win32) return false;
if (!File.Exists(_game.Command)) return false; // Abort

_game.LastTimePlayed = Sys.UnixTime;
OnGameUpdatedEvent?.Invoke(this, new(_game));

_games[_games.IndexOf(_game)] = _game;
Sys.ExecuteAsAdmin(_game.Command);
_dispatcherTimer.Start();

return true;
}

private static bool CanLaunchSteamGame()
{
try
Expand Down
18 changes: 11 additions & 7 deletions Gavilya/Models/GameList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ public GameList GetRange(int start, int end)
return results;
}

public GameList SortByPlayTime(bool sortByMostPlayed)
public GameList SortByPlayTime(bool sortByMostPlayed, bool showHiddenGames)
{
List<Game> sortedGames;

if (sortByMostPlayed)
{
sortedGames = this.OrderByDescending(game => game.TotalTimePlayed).ToList();
sortedGames = this.Where(game => showHiddenGames || !game.IsHidden).OrderByDescending(game => game.TotalTimePlayed).ToList();
}
else
{
sortedGames = this.OrderBy(game => game.TotalTimePlayed).ToList();
sortedGames = this.Where(game => showHiddenGames || !game.IsHidden).OrderBy(game => game.TotalTimePlayed).ToList();
}

return new GameList(sortedGames);
Expand Down Expand Up @@ -116,10 +116,14 @@ public List<GameList> GetSortedGameLists()
}
}

return new List<GameList>
{
todayList, yesterdayList, thisMonthList, otherList
};
List<GameList> sortedGames = new();

if (todayList.Count > 0) sortedGames.Add(todayList);
if (yesterdayList.Count > 0) sortedGames.Add(yesterdayList);
if (thisMonthList.Count > 0) sortedGames.Add(thisMonthList);
if (otherList.Count > 0) sortedGames.Add(otherList);

return sortedGames;
}

public List<GameList> GetSortedGameByTag()
Expand Down
7 changes: 7 additions & 0 deletions Gavilya/ViewModels/GameEditionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public bool CanExecute
private string _packageFamilyName;
public string PackageFamilyName { get => _packageFamilyName; set { _packageFamilyName = value; OnPropertyChanged(nameof(PackageFamilyName)); } }

private string _applyBtnString;
public string ApplyBtnString { get => _applyBtnString; set { _applyBtnString = value; OnPropertyChanged(nameof(ApplyBtnString)); } }

private ImageSource _imgSrc;
public ImageSource ImageSource { get => _imgSrc; set { _imgSrc = value; OnPropertyChanged(nameof(ImageSource)); } }

Expand Down Expand Up @@ -291,6 +294,8 @@ public GameEditionViewModel(Game game, GameList games, List<Tag> tags, MainViewM
DragAreaVis = game.GameType == GameType.Win32 ? Visibility.Visible : Visibility.Collapsed;
UwpFieldsVis = game.GameType == GameType.UWP ? Visibility.Visible : Visibility.Collapsed;
SteamFieldsVis = game.GameType == GameType.Steam ? Visibility.Visible : Visibility.Collapsed;

ApplyBtnString = Properties.Resources.EditGame;
}

/// <summary>
Expand Down Expand Up @@ -324,6 +329,8 @@ public GameEditionViewModel(GameType gameType, GameList games, List<Tag> tags, M
DragAreaVis = gameType == GameType.Win32 ? Visibility.Visible : Visibility.Collapsed;
UwpFieldsVis = gameType == GameType.UWP ? Visibility.Visible : Visibility.Collapsed;
SteamFieldsVis = gameType == GameType.Steam ? Visibility.Visible : Visibility.Collapsed;

ApplyBtnString = Properties.Resources.AddGame;
}

private void ShowConvert(object? obj)
Expand Down
20 changes: 20 additions & 0 deletions Gavilya/ViewModels/GamePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,15 @@ public bool IsFavorite
private Visibility _platformVis = Visibility.Collapsed;
public Visibility PlatformVis { get => _platformVis; set { _platformVis = value; OnPropertyChanged(nameof(PlatformVis)); } }

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

public ICommand PlayCommand { get; }
public ICommand FavCommand { get; }
public ICommand EditCommand { get; }
public ICommand SeeOnRawgCommand { get; }
public ICommand LaunchAsAdminCommand { get; }

private int _totalRatings = 0;
private string _slug;
public GamePageViewModel(Game game, GameList games, List<Tag> tags, MainViewModel mainViewModel)
Expand All @@ -199,11 +204,15 @@ public GamePageViewModel(Game game, GameList games, List<Tag> tags, MainViewMode
Command = game.Command;
IsFavorite = game.IsFavorite;

// Launch as admin button
AdminVis = game.GameType == Enums.GameType.Win32 ? Visibility.Visible : Visibility.Collapsed;

// Commands
EditCommand = new RelayCommand(Edit);
SeeOnRawgCommand = new RelayCommand(OpenRawg);
FavCommand = new RelayCommand(Fav);
PlayCommand = new RelayCommand(Play);
LaunchAsAdminCommand = new RelayCommand(LaunchAsAdmin);

// Rawg
if (game.RawgId == -1) return;
Expand Down Expand Up @@ -233,6 +242,17 @@ private void OpenRawg(object? obj)
Process.Start("explorer.exe", $"https://rawg.io/games/{_slug}");
}

private void LaunchAsAdmin(object? obj)
{
_mainViewModel.GameLauncherHelper = new(_game, _games);
_mainViewModel.GameLauncherHelper.OnGameUpdatedEvent += (o, e) =>
{
LastTimePlayed = e.Game.LastTimePlayed;
TotalTimePlayed = e.Game.TotalTimePlayed;
};
_mainViewModel.GameLauncherHelper.LaunchAsAdmin();
}

private async void LoadRawg()
{
var rawgClient = new RawgClient(_game.RawgId);
Expand Down
2 changes: 1 addition & 1 deletion Gavilya/ViewModels/HomePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public HomePageViewModel(GameList games, MainViewModel mainViewModel)
PlaceholderVis = Visibility.Visible;
ContentVis = Visibility.Collapsed;
}
StatsView = new(_games);
StatsView = new(_games, _mainViewModel.CurrentSettings.ShowHiddenGames);
}
}
13 changes: 12 additions & 1 deletion Gavilya/ViewModels/ListPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ namespace Gavilya.ViewModels;
public class ListPageViewModel : ViewModelBase
{
public GameList Games { get; set; }
public List<GameListViewModel> GamesVm => Games.Where(g => _mainViewModel.CurrentSettings.ShowHiddenGames ? true : !g.IsHidden).Select(g => new GameListViewModel(g, Games, _tags, this, _mainViewModel)).ToList();
public List<GameListViewModel> GamesVm { get => _gamesVm; set { _gamesVm = value; OnPropertyChanged(nameof(GamesVm)); } }
public List<GameListViewModel> FavGamesVm { get => _favGamesVm; set { _favGamesVm = value; OnPropertyChanged(nameof(FavGamesVm)); } }

private ViewModelBase _viewModelBase;
private List<GameListViewModel> _gamesVm;
private List<GameListViewModel> _favGamesVm;
private readonly List<Tag> _tags;
private readonly MainViewModel _mainViewModel;

Expand All @@ -44,5 +47,13 @@ public ListPageViewModel(GameList games, List<Tag> tags, MainViewModel mainViewM
_tags = tags;
_mainViewModel = mainViewModel;
CurrentGameView = new ListPlaceholder();

GamesVm = Games.Where(g => (_mainViewModel.CurrentSettings.ShowHiddenGames || !g.IsHidden) && !g.IsFavorite).Select(g => new GameListViewModel(g, Games, _tags, this, _mainViewModel)).ToList();
FavGamesVm = Games.Where(g => (_mainViewModel.CurrentSettings.ShowHiddenGames || !g.IsHidden) && g.IsFavorite).Select(g => new GameListViewModel(g, Games, _tags, this, _mainViewModel)).ToList();
Games.CollectionChanged += (o, e) =>
{
GamesVm = Games.Where(g => (_mainViewModel.CurrentSettings.ShowHiddenGames || !g.IsHidden) && !g.IsFavorite).Select(g => new GameListViewModel(g, Games, _tags, this, _mainViewModel)).ToList();
FavGamesVm = Games.Where(g => (_mainViewModel.CurrentSettings.ShowHiddenGames || !g.IsHidden) && g.IsFavorite).Select(g => new GameListViewModel(g, Games, _tags, this, _mainViewModel)).ToList();
};
}
}
2 changes: 1 addition & 1 deletion Gavilya/ViewModels/ProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ProfileViewModel(Profile profile, ProfileData profileData, GameList games
total += games[i].TotalTimePlayed;
}
TotalText = $"{total / 3600d:0.0}{Properties.Resources.HourShort}";
var sortedGames = _games.SortByPlayTime(true);
var sortedGames = _games.SortByPlayTime(true, _profile.Settings.ShowHiddenGames);

TopGames = new(sortedGames.Take(3).Select((g, i) => new StatGameViewModel(i, g, null)));
ProfilePicture = string.IsNullOrEmpty(profile.ProfilePictureFilePath) ? "pack://application:,,,/Gavilya;component/Assets/DefaultPP.png" : profile.ProfilePictureFilePath;
Expand Down
16 changes: 16 additions & 0 deletions Gavilya/ViewModels/Settings/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace Gavilya.ViewModels.Settings;
public class AboutViewModel : ViewModelBase
Expand All @@ -39,6 +40,15 @@ public class AboutViewModel : ViewModelBase

public string Version => Context.Version;

private string _statusMessage = Properties.Resources.UpdateUn;
public string StatusMessage { get => _statusMessage; set { _statusMessage = value; OnPropertyChanged(nameof(StatusMessage)); } }

private string _statusIcon = "\uF299";
public string StatusIcon { get => _statusIcon; set { _statusIcon = value; OnPropertyChanged(nameof(StatusIcon)); } }

private SolidColorBrush _iconColor = new() { Color = Color.FromRgb(37, 222, 15) };
public SolidColorBrush IconColor { get => _iconColor; set { _iconColor = value; OnPropertyChanged(nameof(IconColor)); } }

public ICommand UpdateCommand { get; }
public ICommand LicensesCommand { get; }
public ICommand OpenRepoCommand { get; }
Expand All @@ -58,6 +68,9 @@ private async void CheckUpdate(object? obj)
var lastVer = await Update.GetLastVersionAsync(Context.LastVersionLink);
if (Update.IsAvailable(lastVer, Context.Version))
{
StatusMessage = Properties.Resources.UpdateAv;
StatusIcon = "\uF36E";
IconColor = new() { Color = Color.FromRgb(255, 50, 30) };
if (MessageBox.Show($"{Properties.Resources.UpdateAvMessage}\n{Properties.Resources.UpdateVersion} {lastVer}\n\n{Properties.Resources.ContinueInstall}", $"{Properties.Resources.Version} {lastVer}", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No)
{
return;
Expand All @@ -66,6 +79,9 @@ private async void CheckUpdate(object? obj)
Sys.ExecuteAsAdmin(Directory.GetCurrentDirectory() + @"\Xalyus Updater.exe"); // Start the updater
Application.Current.Shutdown(); // Close
}
StatusMessage = Properties.Resources.UpdateUn;
StatusIcon = "\uF299";
IconColor = new() { Color = Color.FromRgb(37, 222, 15) };
}
}

Expand Down
2 changes: 1 addition & 1 deletion Gavilya/ViewModels/Settings/FpsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class FpsViewModel : ViewModelBase
private string _opacity;
public string Opacity { get => _opacity; set { _opacity = value; OnPropertyChanged(nameof(Opacity)); } }

public string CombinationString => string.Format(Properties.Resources.OpenFpsCounter, "Control+Shift+S");
public string CombinationString => string.Format(Properties.Resources.OpenFpsCounter, "Control+Shift+F");
public ICommand SaveCommand { get; }

public FpsViewModel(Profile profile, ProfileData profileData, MainViewModel mainViewModel)
Expand Down
10 changes: 5 additions & 5 deletions Gavilya/ViewModels/StatsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class StatsViewModel : ViewModelBase
{
private string _totalTime;
private readonly GameList _games;

private readonly bool _showHiddenGames;
private string _name;
public string Name
{
Expand Down Expand Up @@ -118,17 +118,17 @@ public string TotalTimePlayed
public ObservableCollection<RecInfo> Rectangles { get; set; }

public ICommand SortCommand { get; }
public StatsViewModel(GameList games)
public StatsViewModel(GameList games, bool showHiddenGames)
{
_games = games;

_showHiddenGames = showHiddenGames;
if (_games.Count == 0)
{
StatVis = Visibility.Collapsed;
PlaceholderVis = Visibility.Visible;
return;
}
SortedGames = _games.SortByPlayTime(SortByMostPlayed);
SortedGames = _games.SortByPlayTime(SortByMostPlayed, _showHiddenGames);
SortedGamesVm = SortedGames.Take(10).Select((g, i) => new StatGameViewModel(i, g, this)).ToList();

int total = 0;
Expand All @@ -153,7 +153,7 @@ private void Sort(object? obj)
SortByMostPlayed = !SortByMostPlayed;
SortIcon = SortByMostPlayed ? "\uF19C" : "\uF149";
SortText = SortByMostPlayed ? Properties.Resources.MostPlayed : Properties.Resources.LeastPlayed;
SortedGames = _games.SortByPlayTime(SortByMostPlayed);
SortedGames = _games.SortByPlayTime(SortByMostPlayed, _showHiddenGames);
SortedGamesVm = SortedGames.Take(10).Select((g, i) => new StatGameViewModel(i, g, this)).ToList();

if (SortedGames.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion Gavilya/Views/GameEditionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@
VerticalAlignment="Center"
Background="{DynamicResource Accent}"
Command="{Binding AddCommand}"
Content="{x:Static lang:Resources.AddGame}"
Content="{Binding ApplyBtnString}"
Cursor="Hand"
FontWeight="Bold"
IsEnabled="{Binding CanExecute}"
Expand Down
4 changes: 3 additions & 1 deletion Gavilya/Views/GamePageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@
Margin="0 0 10 0"
HorizontalAlignment="Center"
Background="{DynamicResource Background2}"
Command="{Binding LaunchAsAdminCommand}"
Content="&#xF8C0;"
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
FontSize="14"
FontWeight="Normal"
Foreground="{DynamicResource Foreground}"
Style="{StaticResource RegularButton}">
Style="{StaticResource RegularButton}"
Visibility="{Binding AdminVis}">
<Button.ToolTip>
<ToolTip
Background="{DynamicResource Background}"
Expand Down
Loading

0 comments on commit c27a300

Please sign in to comment.