initial commit
This commit is contained in:
commit
68ae9540ad
23
.gitignore
vendored
Normal file
23
.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# Build results
|
||||
[Bb]in/
|
||||
.bin/
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
[Oo]bj/
|
||||
[Oo]ut/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
[Pp]ublish/
|
||||
|
||||
# IDE files
|
||||
.vs/
|
||||
.vscode/
|
||||
.vshistory/
|
||||
.idea/
|
||||
с/
|
||||
.editorconfig
|
||||
*.user
|
||||
|
||||
#backups
|
||||
.old*/
|
||||
13
ParadoxSaveParser.Lib/ParadoxSaveParser.Lib.csproj
Normal file
13
ParadoxSaveParser.Lib/ParadoxSaveParser.Lib.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
27
ParadoxSaveParser.Lib/Parser.cs
Normal file
27
ParadoxSaveParser.Lib/Parser.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace ParadoxSaveParser.Lib;
|
||||
|
||||
public abstract class Parser
|
||||
{
|
||||
protected Stream _saveFile;
|
||||
|
||||
protected Parser(Stream savefile)
|
||||
{
|
||||
_saveFile = savefile;
|
||||
}
|
||||
|
||||
protected enum TokenType
|
||||
{
|
||||
Invalid, String, Equals, BracketOpen, BracketClose,
|
||||
}
|
||||
|
||||
protected struct Token
|
||||
{
|
||||
public TokenType type;
|
||||
public string? value;
|
||||
}
|
||||
|
||||
protected void BuildAST()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
8
ParadoxSaveParser.Lib/ParserEU4.cs
Normal file
8
ParadoxSaveParser.Lib/ParserEU4.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace ParadoxSaveParser.Lib;
|
||||
|
||||
public class ParserEU4 : Parser
|
||||
{
|
||||
public ParserEU4(Stream savefile) : base(savefile)
|
||||
{
|
||||
}
|
||||
}
|
||||
14
ParadoxSaveParser.WebAPI/ParadoxSaveParser.WebAPI.csproj
Normal file
14
ParadoxSaveParser.WebAPI/ParadoxSaveParser.WebAPI.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ParadoxSaveParser.Lib\ParadoxSaveParser.Lib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
ParadoxSaveParser.WebAPI/ParadoxSaveParser.WebAPI.http
Normal file
6
ParadoxSaveParser.WebAPI/ParadoxSaveParser.WebAPI.http
Normal file
@ -0,0 +1,6 @@
|
||||
@ParadoxSaveParser.WebAPI_HostAddress = http://localhost:5226
|
||||
|
||||
GET {{ParadoxSaveParser.WebAPI_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
76
ParadoxSaveParser.WebAPI/Program.cs
Normal file
76
ParadoxSaveParser.WebAPI/Program.cs
Normal file
@ -0,0 +1,76 @@
|
||||
global using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ParadoxSaveParser.Lib;
|
||||
|
||||
namespace ParadoxSaveParser.WebAPI;
|
||||
|
||||
public enum SaveFileProcessingStatus
|
||||
{
|
||||
NotFound, Uploading, Parsing, SavingResults, Done, Error
|
||||
}
|
||||
|
||||
public class SaveFileMetadata
|
||||
{
|
||||
public required string guid;
|
||||
public required SaveFileProcessingStatus status { get; set; }
|
||||
}
|
||||
|
||||
public class Program
|
||||
{
|
||||
private const string DATA_DIR = "data";
|
||||
private static string SAVES_DIR = Path.Join(DATA_DIR, "saves");
|
||||
private static ConcurrentDictionary<string, SaveFileMetadata> _saveMetadataStorage = new();
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
var app = builder.Build();
|
||||
|
||||
foreach (var metaFilePath in Directory.GetFiles(SAVES_DIR, "*.meta.json", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
using var metaFile = File.Open(metaFilePath, FileMode.Open, FileAccess.Read);
|
||||
var meta = JsonSerializer.Deserialize<SaveFileMetadata>(metaFile) ?? throw new NullReferenceException(metaFilePath);
|
||||
if (meta.status != SaveFileProcessingStatus.Done)
|
||||
{
|
||||
app.Logger.Log(LogLevel.Warning, $"metadata file '{metaFilePath}' status has invalid status {meta.status}"));
|
||||
}
|
||||
|
||||
if(!_saveMetadataStorage.TryAdd(meta.guid, meta))
|
||||
throw new Exception("Guid collision!");
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.MapPost("/parse/eu4", async httpContext =>
|
||||
{
|
||||
var remoteFile = httpContext.Request.Form.Files.FirstOrDefault();
|
||||
if(remoteFile is null)
|
||||
return;
|
||||
string save_id = Guid.NewGuid().ToString();
|
||||
string meta_file_path = Path.Join(SAVES_DIR, save_id + ".meta.json");
|
||||
// string save_file_path = Path.Join(SAVES_DIR, save_id + ".eu4");
|
||||
// await using var metaFile = File.Open(meta_file_path, FileMode.CreateNew, FileAccess.Write);
|
||||
if (File.Exists(meta_file_path))
|
||||
{
|
||||
httpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
throw new Exception($"Guid collision! file {meta_file_path} already exists.")
|
||||
}
|
||||
|
||||
await using var saveFile =
|
||||
await remoteFile.OpenReadStream().CopyToAsync();
|
||||
var parser = new ParserEU4(stream);
|
||||
|
||||
|
||||
});
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
41
ParadoxSaveParser.WebAPI/Properties/launchSettings.json
Normal file
41
ParadoxSaveParser.WebAPI/Properties/launchSettings.json
Normal file
@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:38396",
|
||||
"sslPort": 44312
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "/",
|
||||
"applicationUrl": "http://localhost:5226",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "/",
|
||||
"applicationUrl": "https://localhost:7032;http://localhost:5226",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "/",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
ParadoxSaveParser.WebAPI/appsettings.Development.json
Normal file
8
ParadoxSaveParser.WebAPI/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
ParadoxSaveParser.WebAPI/appsettings.json
Normal file
9
ParadoxSaveParser.WebAPI/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
22
ParadoxSaveParser.sln
Normal file
22
ParadoxSaveParser.sln
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParadoxSaveParser.WebAPI", "ParadoxSaveParser.WebAPI\ParadoxSaveParser.WebAPI.csproj", "{7D377558-CE40-4D7E-B0B1-FB33C475AE6A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParadoxSaveParser.Lib", "ParadoxSaveParser.Lib\ParadoxSaveParser.Lib.csproj", "{53ED0135-9513-4DE2-9187-CF2899F179B3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7D377558-CE40-4D7E-B0B1-FB33C475AE6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7D377558-CE40-4D7E-B0B1-FB33C475AE6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D377558-CE40-4D7E-B0B1-FB33C475AE6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D377558-CE40-4D7E-B0B1-FB33C475AE6A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{53ED0135-9513-4DE2-9187-CF2899F179B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{53ED0135-9513-4DE2-9187-CF2899F179B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{53ED0135-9513-4DE2-9187-CF2899F179B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{53ED0135-9513-4DE2-9187-CF2899F179B3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Loading…
Reference in New Issue
Block a user