Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SMB3Explorer/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Windows.Threading;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using SMB3Explorer.AppConfig;
using SMB3Explorer.ApplicationConfig;
using SMB3Explorer.Services.ApplicationContext;
using SMB3Explorer.Services.CsvWriterWrapper;
using SMB3Explorer.Services.DataService;
Expand Down Expand Up @@ -51,7 +51,7 @@ private static Task ConfigureServices(IServiceCollection services)
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IApplicationContext, ApplicationContext>();
services.AddSingleton<ISystemIoWrapper, SystemIoWrapper>();
services.AddSingleton<IApplicationConfig, ApplicationConfig>();
services.AddSingleton<IApplicationConfig, ApplicationConfig.ApplicationConfig>();

services.AddSingleton<MainWindow>(serviceProvider => new MainWindow
{
Expand Down
13 changes: 0 additions & 13 deletions SMB3Explorer/AppConfig/Models/League.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using OneOf;
using OneOf.Types;
using Serilog;
using SMB3Explorer.AppConfig.Models;
using SMB3Explorer.ApplicationConfig.Models;
using SMB3Explorer.Constants;

namespace SMB3Explorer.AppConfig;
namespace SMB3Explorer.ApplicationConfig;

public class ApplicationConfig : IApplicationConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using OneOf;
using OneOf.Types;
using SMB3Explorer.AppConfig.Models;
using SMB3Explorer.ApplicationConfig.Models;

namespace SMB3Explorer.AppConfig;
namespace SMB3Explorer.ApplicationConfig;

public interface IApplicationConfig
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Newtonsoft.Json;
using SMB3Explorer.Enums;

namespace SMB3Explorer.AppConfig.Models;
namespace SMB3Explorer.ApplicationConfig.Models;

public class ConfigOptions
{
Expand Down
28 changes: 28 additions & 0 deletions SMB3Explorer/ApplicationConfig/Models/League.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using Newtonsoft.Json;

namespace SMB3Explorer.ApplicationConfig.Models;

public class League
{
[JsonProperty("name")]
public string Name { get; set; } = string.Empty;

[JsonProperty("id")]
public Guid Id { get; set; }

[JsonProperty("playerTeam")]
public string? PlayerTeam { get; set; }

[JsonProperty("numSeasons")]
public int? NumSeasons { get; set; }

[JsonProperty("numTimesAccessed")]
public int NumTimesAccessed { get; set; }

[JsonProperty("firstAccessed")]
public DateTime FirstAccessed { get; set; }

[JsonProperty("lastAccessed")]
public DateTime LastAccessed { get; set; }
}
38 changes: 37 additions & 1 deletion SMB3Explorer/Models/Internal/Smb4LeagueSelection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
using System;
using System.Text;

namespace SMB3Explorer.Models.Internal;

public record Smb4LeagueSelection(string LeagueName, Guid LeagueId);
public record Smb4LeagueSelection(string LeagueName, Guid SaveGameLeagueId, string? PlayerTeam, int? NumSeasons)
{
public int NumTimesAccessed { get; set; }
public DateTime FirstAccessed { get; set; }
public DateTime LastAccessed { get; set; }

// ReSharper disable once UnusedMember.Global
public string DisplayName
{
get
{
var sb = new StringBuilder(LeagueName);

if (!string.IsNullOrEmpty(PlayerTeam) && NumSeasons is not null)
{
sb.Append($" ({NumSeasons} seasons as {PlayerTeam})");
}

sb.Append($", first accessed {FirstAccessed.ToShortDateString()}");
return sb.ToString();
}
}

public virtual bool Equals(Smb4LeagueSelection? other)
{
return other is not null &&
LeagueName == other.LeagueName &&
SaveGameLeagueId == other.SaveGameLeagueId &&
PlayerTeam == other.PlayerTeam;
}

public override int GetHashCode()
{
return HashCode.Combine(LeagueName, SaveGameLeagueId, PlayerTeam);
}
}
4 changes: 0 additions & 4 deletions SMB3Explorer/Resources/Sql/GetLeagues.sql

This file was deleted.

7 changes: 7 additions & 0 deletions SMB3Explorer/Resources/Sql/GetLeaguesForSmb4SaveGame.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT tl.name AS LeagueName, tt.teamName, COUNT(ts.GUID) AS NumSeasons
FROM t_leagues tl
LEFT JOIN t_franchise tf on tl.GUID = tf.leagueGUID
LEFT JOIN t_teams tt on tf.playerTeamGUID = tt.GUID
LEFT JOIN t_seasons ts on tl.GUID = ts.historicalLeagueGUID
WHERE tl.originalGUID IS NULL
LIMIT 1;
3 changes: 2 additions & 1 deletion SMB3Explorer/SMB3Explorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@
<None Remove="Resources\Sql\MostRecentSeasonSchedule.sql" />
<EmbeddedResource Include="Resources\Sql\MostRecentSeasonSchedule.sql" />
<None Remove="Resources\Sql\GetLeagues.sql" />
<EmbeddedResource Include="Resources\Sql\GetLeagues.sql" />
<None Remove="Resources\Sql\MostRecentSeasonPlayersSmb3.sql" />
<EmbeddedResource Include="Resources\Sql\MostRecentSeasonPlayersSmb3.sql" />
<None Remove="Resources\Sql\MostRecentSeasonPlayersSmb4.sql" />
<EmbeddedResource Include="Resources\Sql\MostRecentSeasonPlayersSmb4.sql" />
<None Remove="Resources\Sql\GetLeaguesForSmb4SaveGame.sql" />
<EmbeddedResource Include="Resources\Sql\GetLeaguesForSmb4SaveGame.sql" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public bool FranchiseSeasonsLoading

public SelectedGame SelectedGame { get; set; }

public string? MostRecentSelectedSaveFilePath { get; set; }

public event PropertyChangedEventHandler? PropertyChanged;

private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ public interface IApplicationContext
FranchiseSeason? MostRecentFranchiseSeason { get; set; }
bool FranchiseSeasonsLoading { get; set; }
SelectedGame SelectedGame { get; set; }
string? MostRecentSelectedSaveFilePath { get; set; }
event PropertyChangedEventHandler? PropertyChanged;
}
33 changes: 14 additions & 19 deletions SMB3Explorer/Services/DataService/DataServiceInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,37 +102,32 @@ public async Task<OneOf<List<Smb4LeagueSelection>, Error<string>>> EstablishDbCo
Log.Error("Invalid save file, missing expected tables");
return new Error<string>("Invalid save file, missing expected tables");
}

if (_applicationContext.MostRecentSelectedSaveFilePath is null) return new List<Smb4LeagueSelection>();

List<Smb4LeagueSelection> leagues = new();
var command2 = Connection.CreateCommand();
commandText = SqlRunner.GetSqlCommand(SqlFile.GetLeagues);
commandText = SqlRunner.GetSqlCommand(SqlFile.GetLeaguesForSmb4SaveGame);
command2.CommandText = commandText;
var reader2 = await command2.ExecuteReaderAsync();

var smb4LeagueId = Guid.Empty;
var smb4LeagueFilePath = _applicationContext.MostRecentSelectedSaveFilePath;

if (smb4LeagueFilePath is not null)
var smb4LeagueFileName = Path.GetFileName(filePath);
var smb4LeagueName = Path.GetFileNameWithoutExtension(smb4LeagueFileName);
smb4LeagueName = smb4LeagueName[7..];
var ok = Guid.TryParse(smb4LeagueName, out var smb4LeagueId);
if (!ok)
{
var smb4LeagueFileName = Path.GetFileName(smb4LeagueFilePath);
var smb4LeagueName = Path.GetFileNameWithoutExtension(smb4LeagueFileName);
smb4LeagueName = smb4LeagueName[7..];
var ok = Guid.TryParse(smb4LeagueName, out smb4LeagueId);
if (!ok)
{
Log.Error("Failed to parse GUID from file name {FileName}. " +
"This occurs when we are attempting to cache the SMB4 league in the " +
"config for later on", smb4LeagueFileName);
return new Error<string>("Failed to parse GUID from file name.");
}
Log.Error("Failed to parse GUID from file name {FileName}. " +
"This occurs when we are attempting to cache the SMB4 league in the " +
"config for later on", smb4LeagueFileName);
return new Error<string>("Failed to parse GUID from file name.");
}

while (reader2.Read())
{
var leagueName = reader2.GetString(0);
var league = new Smb4LeagueSelection(leagueName, smb4LeagueId);
var playerTeamName = reader2.IsDBNull(1) ? null : reader2.GetString(1);
int? numSeasons = reader2.IsDBNull(2) ? null : reader2.GetInt32(2);

var league = new Smb4LeagueSelection(leagueName, smb4LeagueId, playerTeamName, numSeasons);
leagues.Add(league);
}

Expand Down
4 changes: 2 additions & 2 deletions SMB3Explorer/Utils/SqlRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public enum SqlFile
[Description("MostRecentSeasonSchedule.sql")]
MostRecentSeasonSchedule,

[Description("GetLeagues.sql")]
GetLeagues,
[Description("GetLeaguesForSmb4SaveGame.sql")]
GetLeaguesForSmb4SaveGame,
}

public static class SqlRunner
Expand Down
Loading