Support both json and compressed files
Bump versions
This commit is contained in:
parent
fd9d1a95ab
commit
55ed7a8df8
@ -19,6 +19,7 @@ public static class Constants
|
|||||||
public const string DEFAULT_DB_NAME = "taiko.db3";
|
public const string DEFAULT_DB_NAME = "taiko.db3";
|
||||||
|
|
||||||
public const string MUSIC_ATTRIBUTE_FILE_NAME = "music_attribute.json";
|
public const string MUSIC_ATTRIBUTE_FILE_NAME = "music_attribute.json";
|
||||||
|
public const string MUSIC_ATTRIBUTE_COMPRESSED_FILE_NAME = "music_attribute.bin";
|
||||||
|
|
||||||
public const string DAN_DATA_FILE_NAME = "dan_data.json";
|
public const string DAN_DATA_FILE_NAME = "dan_data.json";
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using ICSharpCode.SharpZipLib.GZip;
|
||||||
using SharedProject.Models;
|
using SharedProject.Models;
|
||||||
using Swan.Mapping;
|
using Swan.Mapping;
|
||||||
using Throw;
|
using Throw;
|
||||||
@ -53,6 +54,10 @@ public class GameDataService : IGameDataService
|
|||||||
var danDataPath = Path.Combine(dataPath, Constants.DAN_DATA_FILE_NAME);
|
var danDataPath = Path.Combine(dataPath, Constants.DAN_DATA_FILE_NAME);
|
||||||
var songIntroDataPath = Path.Combine(dataPath, Constants.INTRO_DATA_FILE_NAME);
|
var songIntroDataPath = Path.Combine(dataPath, Constants.INTRO_DATA_FILE_NAME);
|
||||||
|
|
||||||
|
if (!File.Exists(musicAttributePath))
|
||||||
|
{
|
||||||
|
TryDecompressMusicAttribute();
|
||||||
|
}
|
||||||
await using var musicAttributeFile = File.OpenRead(musicAttributePath);
|
await using var musicAttributeFile = File.OpenRead(musicAttributePath);
|
||||||
await using var danDataFile = File.OpenRead(danDataPath);
|
await using var danDataFile = File.OpenRead(danDataPath);
|
||||||
await using var songIntroDataFile = File.OpenRead(songIntroDataPath);
|
await using var songIntroDataFile = File.OpenRead(songIntroDataPath);
|
||||||
@ -68,6 +73,18 @@ public class GameDataService : IGameDataService
|
|||||||
InitializeIntroData(introData);
|
InitializeIntroData(introData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void TryDecompressMusicAttribute()
|
||||||
|
{
|
||||||
|
var dataPath = PathHelper.GetDataPath();
|
||||||
|
var musicAttributePath = Path.Combine(dataPath, Constants.MUSIC_ATTRIBUTE_FILE_NAME);
|
||||||
|
var compressedMusicAttributePath = Path.Combine(dataPath, Constants.MUSIC_ATTRIBUTE_COMPRESSED_FILE_NAME);
|
||||||
|
|
||||||
|
using var compressed = File.Open(compressedMusicAttributePath, FileMode.Open);
|
||||||
|
using var output = File.Create(musicAttributePath);
|
||||||
|
|
||||||
|
GZip.Decompress(compressed, output, true);
|
||||||
|
}
|
||||||
|
|
||||||
private void InitializeIntroData(List<SongIntroductionData>? introData)
|
private void InitializeIntroData(List<SongIntroductionData>? introData)
|
||||||
{
|
{
|
||||||
introData.ThrowIfNull("Shouldn't happen!");
|
introData.ThrowIfNull("Shouldn't happen!");
|
||||||
|
@ -12,10 +12,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-preview.7.22376.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.0-rc.1.22426.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-preview.7.22376.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-rc.1.22426.7" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0-preview.7.22376.2">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0-rc.1.22426.7">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@ -23,7 +23,7 @@
|
|||||||
<PackageReference Include="protobuf-net.AspNetCore" Version="3.1.17" />
|
<PackageReference Include="protobuf-net.AspNetCore" Version="3.1.17" />
|
||||||
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0-dev-00281" />
|
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0-dev-00281" />
|
||||||
<PackageReference Include="Serilog.Expressions" Version="3.4.1-dev-00095" />
|
<PackageReference Include="Serilog.Expressions" Version="3.4.1-dev-00095" />
|
||||||
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
<PackageReference Include="SharpZipLib" Version="1.4.0" />
|
||||||
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
||||||
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
|
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
@ -38,9 +38,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="wwwroot\data\music_attribute.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Update="wwwroot\data\dan_data.json">
|
<Content Update="wwwroot\data\dan_data.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.Json;
|
||||||
|
using ICSharpCode.SharpZipLib.GZip;
|
||||||
using Swan.Mapping;
|
using Swan.Mapping;
|
||||||
using TaikoWebUI.Shared.Models;
|
using TaikoWebUI.Shared.Models;
|
||||||
|
|
||||||
@ -27,16 +30,12 @@ public class GameDataService : IGameDataService
|
|||||||
|
|
||||||
public async Task InitializeAsync(string dataBaseUrl)
|
public async Task InitializeAsync(string dataBaseUrl)
|
||||||
{
|
{
|
||||||
var musicInfo = await client.GetFromJsonAsync<MusicInfo>($"{dataBaseUrl}/data/musicinfo.json");
|
var musicInfo = await GetData<MusicInfo>(dataBaseUrl, Constants.MUSIC_INFO_BASE_NAME);
|
||||||
var wordList = await client.GetFromJsonAsync<WordList>($"{dataBaseUrl}/data/wordlist.json");
|
var wordList = await GetData<WordList>(dataBaseUrl, Constants.WORD_LIST_BASE_NAME);
|
||||||
var musicOrder = await client.GetFromJsonAsync<MusicOrder>($"{dataBaseUrl}/data/music_order.json");
|
var musicOrder = await GetData<MusicOrder>(dataBaseUrl, Constants.MUSIC_ORDER_BASE_NAME);
|
||||||
var danData = await client.GetFromJsonAsync<List<DanData>>($"{dataBaseUrl}/data/dan_data.json");
|
var danData = await client.GetFromJsonAsync<List<DanData>>($"{dataBaseUrl}/data/dan_data.json");
|
||||||
|
|
||||||
musicInfo.ThrowIfNull();
|
|
||||||
wordList.ThrowIfNull();
|
|
||||||
musicOrder.ThrowIfNull();
|
|
||||||
danData.ThrowIfNull();
|
danData.ThrowIfNull();
|
||||||
|
|
||||||
danMap = danData.ToImmutableDictionary(data => data.DanId);
|
danMap = danData.ToImmutableDictionary(data => data.DanId);
|
||||||
|
|
||||||
// To prevent duplicate entries in wordlist
|
// To prevent duplicate entries in wordlist
|
||||||
@ -52,6 +51,36 @@ public class GameDataService : IGameDataService
|
|||||||
await Task.Run(() => InitializeTitles(dict));
|
await Task.Run(() => InitializeTitles(dict));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<T> GetData<T>(string dataBaseUrl, string fileBaseName) where T : notnull
|
||||||
|
{
|
||||||
|
T? data;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
data = await client.GetFromJsonAsync<T>($"{dataBaseUrl}/data/{fileBaseName}.json");
|
||||||
|
data.ThrowIfNull();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
catch (HttpRequestException e)
|
||||||
|
{
|
||||||
|
if (e.StatusCode != HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
await using var compressed = await client.GetStreamAsync($"{dataBaseUrl}/data/{fileBaseName}.bin");
|
||||||
|
await using var gZipInputStream = new GZipInputStream(compressed);
|
||||||
|
using var decompressed = new MemoryStream();
|
||||||
|
|
||||||
|
// Decompress
|
||||||
|
await gZipInputStream.CopyToAsync(decompressed);
|
||||||
|
|
||||||
|
// Reset stream for reading
|
||||||
|
decompressed.Position = 0;
|
||||||
|
data = await JsonSerializer.DeserializeAsync<T>(decompressed);
|
||||||
|
data.ThrowIfNull();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetMusicNameBySongId(uint songId)
|
public string GetMusicNameBySongId(uint songId)
|
||||||
{
|
{
|
||||||
return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.SongName : string.Empty;
|
return musicMap.TryGetValue(songId, out var musicDetail) ? musicDetail.SongName : string.Empty;
|
||||||
|
@ -9,4 +9,8 @@ public static class Constants
|
|||||||
public const int COSTUME_PUCHI_MAX = 129;
|
public const int COSTUME_PUCHI_MAX = 129;
|
||||||
public const int COSTUME_COLOR_MAX = 63;
|
public const int COSTUME_COLOR_MAX = 63;
|
||||||
public const int PLAYER_TITLE_MAX = 750;
|
public const int PLAYER_TITLE_MAX = 750;
|
||||||
|
|
||||||
|
public const string MUSIC_INFO_BASE_NAME = "musicinfo";
|
||||||
|
public const string WORD_LIST_BASE_NAME = "wordlist";
|
||||||
|
public const string MUSIC_ORDER_BASE_NAME = "music_order";
|
||||||
}
|
}
|
@ -8,9 +8,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Autocomplete.Clients" Version="1.1.0" />
|
<PackageReference Include="Autocomplete.Clients" Version="1.1.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.9" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.9" PrivateAssets="all" />
|
||||||
<PackageReference Include="MudBlazor" Version="6.0.15" />
|
<PackageReference Include="MudBlazor" Version="6.0.15" />
|
||||||
|
<PackageReference Include="SharpZipLib" Version="1.4.0" />
|
||||||
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@ -22,15 +23,6 @@
|
|||||||
<Content Update="wwwroot\appsettings.json">
|
<Content Update="wwwroot\appsettings.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Content Update="wwwroot\data\musicinfo.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Update="wwwroot\data\wordlist.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
<Content Update="wwwroot\data\music_order.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
||||||
</Content>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user