This commit is contained in:
Lani Aung
2024-02-10 23:35:35 -07:00
parent 262bce4549
commit 70c85d0e18
5 changed files with 13 additions and 20 deletions
+3 -4
View File
@@ -59,14 +59,15 @@ namespace fxl.codes.kisekae.Services
public async void StoreToDatabase(IFormFile file) public async void StoreToDatabase(IFormFile file)
{ {
var memoryStream = await GetAsMemoryStream(file); var memoryStream = await GetAsMemoryStream(file);
var checksum = Convert.ToBase64String(SHA256.Create().ComputeHash(memoryStream.GetBuffer())); var checksum = Convert.ToBase64String(SHA256.HashData(memoryStream.GetBuffer()));
memoryStream.Position = 0; // Reset for re-read memoryStream.Position = 0; // Reset for re-read
await using var context = await _contextFactory.CreateDbContextAsync(); await using var context = await _contextFactory.CreateDbContextAsync();
var existing = await context.KisekaeSets var existing = await context.KisekaeSets
.FirstOrDefaultAsync(x => string.Equals(x.FileName, file.FileName) .FirstOrDefaultAsync(x => string.Equals(x.FileName, file.FileName)
|| string.Equals(x.CheckSum, checksum)); || string.Equals(x.CheckSum, checksum));
if (existing != null) return; if (existing != null) context.KisekaeSets.Remove(existing);
await context.SaveChangesAsync();
_fileParserService.UnzipLzh(file, memoryStream); _fileParserService.UnzipLzh(file, memoryStream);
var directory = Path.GetFileNameWithoutExtension(file.FileName); var directory = Path.GetFileNameWithoutExtension(file.FileName);
@@ -96,8 +97,6 @@ namespace fxl.codes.kisekae.Services
await context.AddAsync(kisekae); await context.AddAsync(kisekae);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
//_storage.DeleteDirectory(directory);
} }
private async Task SetInnerFiles(Kisekae kisekae, string directory, IEnumerable<string> filenames) private async Task SetInnerFiles(Kisekae kisekae, string directory, IEnumerable<string> filenames)
+2 -5
View File
@@ -5,7 +5,6 @@ using System.IO;
using System.IO.IsolatedStorage; using System.IO.IsolatedStorage;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text;
using fxl.codes.kisekae.Entities; using fxl.codes.kisekae.Entities;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -16,7 +15,7 @@ namespace fxl.codes.kisekae.Services
{ {
public class FileParserService public class FileParserService
{ {
private static readonly byte[] KissHeader = Encoding.ASCII.GetBytes("KiSS"); private static readonly byte[] KissHeader = "KiSS"u8.ToArray();
private static readonly Color Transparent = Color.Black.WithAlpha(0); private static readonly Color Transparent = Color.Black.WithAlpha(0);
private readonly ILogger<FileParserService> _logger; private readonly ILogger<FileParserService> _logger;
@@ -57,7 +56,6 @@ namespace fxl.codes.kisekae.Services
} }
_storage.CreateDirectory(directory); _storage.CreateDirectory(directory);
var process = new Process var process = new Process
{ {
StartInfo = new ProcessStartInfo StartInfo = new ProcessStartInfo
@@ -167,11 +165,10 @@ namespace fxl.codes.kisekae.Services
for (var row = 0; row < height; row++) for (var row = 0; row < height; row++)
{ {
var span = bitmap.GetPixelRowSpan(row);
for (var column = 0; column < width; column++) for (var column = 0; column < width; column++)
{ {
var value = values[index]; var value = values[index];
span[column] = value == 0 || value >= palette.Colors.Count ? Transparent : Color.ParseHex(palette.Colors[value].Hex); bitmap[row, column] = value == 0 || value >= palette.Colors.Count ? Transparent : Color.ParseHex(palette.Colors[value].Hex);
index++; index++;
} }
-3
View File
@@ -5,7 +5,6 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Npgsql.Logging;
namespace fxl.codes.kisekae namespace fxl.codes.kisekae
{ {
@@ -37,8 +36,6 @@ namespace fxl.codes.kisekae
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
NpgsqlLogManager.Provider = new ConsoleLoggingProvider();
NpgsqlLogManager.IsParameterLoggingEnabled = true;
} }
else else
{ {
+7 -7
View File
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory> <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
<LangVersion>latestmajor</LangVersion> <LangVersion>latestmajor</LangVersion>
</PropertyGroup> </PropertyGroup>
@@ -15,15 +15,15 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Npgsql" Version="6.0.0" /> <PackageReference Include="Npgsql" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" /> <PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"sdk": { "sdk": {
"version": "6.0.0", "version": "8.0.0",
"rollForward": "latestMajor", "rollForward": "latestMajor",
"allowPrerelease": false "allowPrerelease": false
} }