Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using Force.Crc32;
|
|
using LANCommander.Server.Services;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace LANCommander.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class CalculateMediaChecksum : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
if (Directory.Exists("Media"))
|
|
{
|
|
var files = Directory.EnumerateFiles("Media");
|
|
|
|
foreach (var file in files)
|
|
{
|
|
try
|
|
{
|
|
uint crc = 0;
|
|
|
|
using (FileStream fs = File.Open(file, FileMode.Open))
|
|
{
|
|
var buffer = new byte[4096];
|
|
|
|
while (true)
|
|
{
|
|
var count = fs.Read(buffer, 0, buffer.Length);
|
|
|
|
if (count == 0)
|
|
break;
|
|
|
|
crc = Crc32Algorithm.Append(crc, buffer, 0, count);
|
|
}
|
|
}
|
|
|
|
migrationBuilder.Sql($"UPDATE Media SET Crc32 = '{crc.ToString("X")}' WHERE FileId = '{file.Replace("Media" + Path.DirectorySeparatorChar, "").ToUpper()}'");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|