Skip to content

Commit

Permalink
chore: added some logs to game metadata service
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalHexx committed May 13, 2024
1 parent 446b5e4 commit ff5cf74
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace TeensyRom.Core.Games
{
public class GameMetadataService : IGameMetadataService
public class GameMetadataService(ILoggingService log) : IGameMetadataService
{
private string _gameArtPath => Path.Combine(Assembly.GetExecutingAssembly().GetPath(), GameConstants.Game_Image_Local_Path);
private string _localLoadingScreenPath => Path.Combine(_gameArtPath, GameConstants.Loading_Screen_Sub_Path);
Expand All @@ -31,16 +31,20 @@ private List<ViewableItemImage> LoadGameMetadata()
{
if(File.Exists(_gameMetadataFilePath))
{
log.Internal($"Reading game metadata file: {_gameMetadataFilePath}");
var fileMetadata = JsonConvert.DeserializeObject<List<ViewableItemImage>>(File.ReadAllText(_gameMetadataFilePath));

if(fileMetadata is not null && fileMetadata.Any())
{
log.Internal($"Loaded {fileMetadata.Count} game metadata items from file.");
return fileMetadata;
}
}
var loadingScreens = Directory.GetFiles(_localLoadingScreenPath);
var screenshots = Directory.GetFiles(_localScreenshotPath);

log.Internal($"Found {loadingScreens.Length} loading screens and {screenshots.Length} screenshots.");

var allScreenMetadata = loadingScreens
.Concat(screenshots)
.ToList()
Expand All @@ -53,11 +57,24 @@ private List<ViewableItemImage> LoadGameMetadata()
.OrderBy(f => f.FileName)
.ToList();

log.Internal($"Mapped {allScreenMetadata.Count} game metadata items.");

if (!Directory.Exists(Path.GetDirectoryName(_gameMetadataFilePath)))
{
log.Internal($"Creating directory for game metadata file: {Path.GetDirectoryName(_gameMetadataFilePath)}");
Directory.CreateDirectory(Path.GetDirectoryName(_gameMetadataFilePath)!);
}
log.Internal($"Writing game metadata file: {_gameMetadataFilePath}");
File.WriteAllText(_gameMetadataFilePath, JsonConvert.SerializeObject(allScreenMetadata));

if(File.Exists(_gameMetadataFilePath))
{
log.InternalSuccess($"Game metadata file written successfully.");
}
else
{
log.InternalError($"Failed to write game metadata file.");
}
return allScreenMetadata;
}

Expand Down

0 comments on commit ff5cf74

Please sign in to comment.