Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lpeyr committed Dec 8, 2023
1 parent 920f828 commit 064a9d0
Show file tree
Hide file tree
Showing 31 changed files with 273 additions and 276 deletions.
20 changes: 10 additions & 10 deletions Gavilya/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private bool IsSaveDay(int day)

private void CreateJumpLists(GameList games)
{
JumpList jumpList = new();
JumpList jumpList = new();

var gTasks = games.Where(g => g.IsFavorite).Select(g => new JumpTask()
{
Expand Down Expand Up @@ -158,16 +158,16 @@ private void CreateJumpLists(GameList games)
IconResourcePath = Assembly.GetEntryAssembly()?.Location
});

jumpList.JumpItems.Add(new JumpTask()
{
Title = Gavilya.Properties.Resources.Favorites,
Arguments = "/page 2",
Description = Gavilya.Properties.Resources.Favorites,
CustomCategory = Gavilya.Properties.Resources.Tasks,
IconResourcePath = Assembly.GetEntryAssembly()?.Location
});
jumpList.JumpItems.Add(new JumpTask()
{
Title = Gavilya.Properties.Resources.Favorites,
Arguments = "/page 2",
Description = Gavilya.Properties.Resources.Favorites,
CustomCategory = Gavilya.Properties.Resources.Tasks,
IconResourcePath = Assembly.GetEntryAssembly()?.Location
});

jumpList.JumpItems.Add(new JumpTask()
jumpList.JumpItems.Add(new JumpTask()
{
Title = Gavilya.Properties.Resources.MyProfile,
Arguments = "/page 3",
Expand Down
2 changes: 1 addition & 1 deletion Gavilya/Commands/DropBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

using System.Windows.Input;
using System.Windows;
using System.Windows.Input;

namespace Gavilya.Commands
{
Expand Down
12 changes: 6 additions & 6 deletions Gavilya/Components/ExecutableSelectorComponent.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace Gavilya.Components
/// Interaction logic for ExecutableSelectorComponent.xaml
/// </summary>
public partial class ExecutableSelectorComponent : UserControl
{
public ExecutableSelectorComponent()
{
InitializeComponent();
}
}
{
public ExecutableSelectorComponent()
{
InitializeComponent();
}
}
}
2 changes: 1 addition & 1 deletion Gavilya/Components/MinimalGameComponent.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ public partial class MinimalGameComponent : UserControl
public MinimalGameComponent()
{
InitializeComponent();
}
}
}
82 changes: 41 additions & 41 deletions Gavilya/Helpers/GameLauncherHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,30 @@ public GameLauncherHelper(Game game, GameList games)
};
}

public bool Launch()
{
// Check location if the game is a Win32 app
if (_game.GameType == GameType.Win32 && !File.Exists(_game.Command)) return false; // Abort
if (_game.GameType == GameType.Steam && !CanLaunchSteamGame(_game)) return false;
public bool Launch()
{
// Check location if the game is a Win32 app
if (_game.GameType == GameType.Win32 && !File.Exists(_game.Command)) return false; // Abort
if (_game.GameType == GameType.Steam && !CanLaunchSteamGame(_game)) return false;

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

_games[_games.IndexOf(_game)] = _game;
_games[_games.IndexOf(_game)] = _game;

if (_game.GameType == GameType.Steam) Process.Start("cmd", "/c start " + _game.Command);
if (_game.GameType == GameType.Win32) Process.Start(_game.Command);
if (_game.GameType == GameType.Steam) Process.Start("cmd", "/c start " + _game.Command);
if (_game.GameType == GameType.Win32) Process.Start(_game.Command);

_dispatcherTimer.Start();
_dispatcherTimer.Start();

return true;
}
return true;
}

/// <summary>
/// This method only works on Win32 Games.
/// </summary>
/// <returns></returns>
public bool LaunchAsAdmin()
/// <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;
Expand All @@ -113,30 +113,30 @@ public bool LaunchAsAdmin()
return true;
}

private static bool CanLaunchSteamGame(Game game)
{
private static bool CanLaunchSteamGame(Game game)
{
// Detect if a steam game you are trying to run is installed.
try
{
String steamAppKeyFormat = @"SOFTWARE\Valve\Steam\Apps\" + game.Command.Replace("steam://rungameid/", "");
RegistryKey steamAppKey = Registry.CurrentUser.OpenSubKey(steamAppKeyFormat);
string isSteamGameInstalled = steamAppKey.GetValue("Installed").ToString();

if (isSteamGameInstalled != "1")
{
MessageBox.Show(Properties.Resources.SteamAppNotInstalled, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
}
catch
{
return false;
}

return true; // Return true, Steam can launch game.
}

public class GameEventArgs : EventArgs
try
{
String steamAppKeyFormat = @"SOFTWARE\Valve\Steam\Apps\" + game.Command.Replace("steam://rungameid/", "");
RegistryKey steamAppKey = Registry.CurrentUser.OpenSubKey(steamAppKeyFormat);
string isSteamGameInstalled = steamAppKey.GetValue("Installed").ToString();

if (isSteamGameInstalled != "1")
{
MessageBox.Show(Properties.Resources.SteamAppNotInstalled, Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
}
catch
{
return false;
}

return true; // Return true, Steam can launch game.
}

public class GameEventArgs : EventArgs
{
public Game Game { get; init; }

Expand Down
16 changes: 8 additions & 8 deletions Gavilya/Models/GameList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public List<GameList> GetSortedGameLists()
DateTime now = DateTime.Now;
DateTime todayStart = now.Date;
DateTime yesterdayStart = todayStart.AddDays(-1);
DateTime thisWeekStart = now.AddDays((int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - (int)now.DayOfWeek);
DateTime thisMonthStart = new(now.Year, now.Month, 1);
DateTime thisWeekStart = now.AddDays((int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - (int)now.DayOfWeek);
DateTime thisMonthStart = new(now.Year, now.Month, 1);

GameList todayList = new(Properties.Resources.Today);
GameList yesterdayList = new(Properties.Resources.Yesterday);
GameList thisWeekList = new(Properties.Resources.ThisWeek);
GameList thisMonthList = new(Properties.Resources.ThisMonth);
GameList yesterdayList = new(Properties.Resources.Yesterday);
GameList thisWeekList = new(Properties.Resources.ThisWeek);
GameList thisMonthList = new(Properties.Resources.ThisMonth);
GameList otherList = new(Properties.Resources.LongTimeAgo);

foreach (Game game in this)
Expand All @@ -118,7 +118,7 @@ public List<GameList> GetSortedGameLists()
else if (lastPlayTime >= thisWeekStart)
{
thisWeekList.Add(game);
}
}
else if (lastPlayTime >= thisMonthStart)
{
thisMonthList.Add(game);
Expand All @@ -133,8 +133,8 @@ public List<GameList> GetSortedGameLists()

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

return sortedGames;
Expand Down
16 changes: 8 additions & 8 deletions Gavilya/Models/Rawg/RawgClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public async Task<int> GetId()
Method = Method.Get
};

// Create a request
request.AddQueryParameter("search", _gameName); // Config the request
// Create a request
request.AddQueryParameter("search", _gameName); // Config the request
request.AddQueryParameter("key", ApiKeys.RawgApiKey);

var response = await client.ExecuteAsync(request); // Execute the request and store the result
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task<int> GetId()
{
Method = Method.Get
};

// Create a request
request.AddQueryParameter("key", ApiKeys.RawgApiKey);

Expand All @@ -122,19 +122,19 @@ public async Task<List<Achievement>> GetAchievementsAsync()
try
{
var client = new RestClient(new Uri($"https://api.rawg.io/api/games/{_gameId}/achievements?")); // Create a REST Client

var request = new RestRequest
{
Method = Method.Get
};

// Create a request
request.AddQueryParameter("key", ApiKeys.RawgApiKey);
request.AddQueryParameter("page_size", "20");

var response = await client.ExecuteAsync(request); // Execute the request and store the result
var achievementsResults = JsonSerializer.Deserialize<AchievementsResults>(response.Content); // Deserialize the content of the reponse

return achievementsResults?.Results ?? new(); // Return the results
}
catch (Exception ex)
Expand All @@ -149,12 +149,12 @@ public async Task<List<Achievement>> GetAchievementsAsync()
try
{
var client = new RestClient(new Uri("https://api.rawg.io/api/games?")); // Configure the client

var request = new RestRequest
{
Method = Method.Get
};

// Create a request
request.AddQueryParameter("search", _gameName); // Config the request
request.AddQueryParameter("key", ApiKeys.RawgApiKey);
Expand Down
4 changes: 2 additions & 2 deletions Gavilya/Models/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public enum Page
{
Home,
Library,
Favorites,
Recent,
Favorites,
Recent,
Profile
}

Expand Down
2 changes: 1 addition & 1 deletion Gavilya/Services/GameMigrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class GameMigrationService
private readonly string _filePath;

public GameMigrationService(string filePath)
{
{
_filePath = filePath;
}

Expand Down
30 changes: 15 additions & 15 deletions Gavilya/ViewModels/FavCardPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ namespace Gavilya.ViewModels;

class FavCardPageViewModel : ViewModelBase
{
public GameList Games { get; set; }
public GameList Games { get; set; }

private readonly List<Tag> _tags;
readonly MainViewModel _mainViewModel;
public List<GameCardViewModel> GamesVm => Games.Where(g => _mainViewModel.CurrentSettings.ShowHiddenGames ? true : !g.IsHidden).Select(g => new GameCardViewModel(g, Games, _tags, _mainViewModel)).ToList();
private readonly List<Tag> _tags;
readonly MainViewModel _mainViewModel;
public List<GameCardViewModel> GamesVm => Games.Where(g => _mainViewModel.CurrentSettings.ShowHiddenGames ? true : !g.IsHidden).Select(g => new GameCardViewModel(g, Games, _tags, _mainViewModel)).ToList();

private Visibility _placeholderVis;
public Visibility PlaceholderVis { get => _placeholderVis; set { _placeholderVis = value; OnPropertyChanged(nameof(PlaceholderVis)); } }
private Visibility _placeholderVis;
public Visibility PlaceholderVis { get => _placeholderVis; set { _placeholderVis = value; OnPropertyChanged(nameof(PlaceholderVis)); } }

public ICommand AddCommand { get; }
public ICommand AddCommand { get; }

public FavCardPageViewModel(GameList games, List<Tag> tags, MainViewModel mainViewModel)
{
Games = games;
_mainViewModel = mainViewModel;
_tags = tags;
public FavCardPageViewModel(GameList games, List<Tag> tags, MainViewModel mainViewModel)
{
Games = games;
_mainViewModel = mainViewModel;
_tags = tags;

PlaceholderVis = Games.Count > 0 ? Visibility.Collapsed : Visibility.Visible;
AddCommand = new RelayCommand((o) => _mainViewModel.CurrentViewModel = new GameEditionViewModel(Enums.GameType.Win32, games, _tags, _mainViewModel));
}
PlaceholderVis = Games.Count > 0 ? Visibility.Collapsed : Visibility.Visible;
AddCommand = new RelayCommand((o) => _mainViewModel.CurrentViewModel = new GameEditionViewModel(Enums.GameType.Win32, games, _tags, _mainViewModel));
}
}
Loading

0 comments on commit 064a9d0

Please sign in to comment.