diff --git a/KamihamaWeb/KamihamaWeb.csproj b/KamihamaWeb/KamihamaWeb.csproj
index c364386..63dbd22 100644
--- a/KamihamaWeb/KamihamaWeb.csproj
+++ b/KamihamaWeb/KamihamaWeb.csproj
@@ -9,6 +9,7 @@
+
diff --git a/KamihamaWeb/Services/DiskCacheService.cs b/KamihamaWeb/Services/DiskCacheService.cs
index adb42a0..a0dcd60 100644
--- a/KamihamaWeb/Services/DiskCacheService.cs
+++ b/KamihamaWeb/Services/DiskCacheService.cs
@@ -38,13 +38,13 @@ namespace KamihamaWeb.Services
public async Task Get(string cacheItem, string versionMd5, bool forceOrigin = false)
{
+ // Remember: don't allow directory traversal attacks...
var filename = CryptUtil.CalculateSha256(cacheItem + "?" + versionMd5);
-
var filePath = Path.Combine(CacheDirectory, filename);
if (!forceOrigin && cacheItem.StartsWith("scenario/json/general"))
{
- var generalJson = Path.Combine(CacheDirectory, cacheItem + versionMd5);
+ var generalJson = Path.Combine(ScenarioCacheDirectory, filename);
if (File.Exists(generalJson))
{
return new DiskCacheItem()
@@ -110,7 +110,8 @@ namespace KamihamaWeb.Services
{
case StoreType.ScenarioGeneral:
var md5 = CryptUtil.CalculateMd5Bytes(storeContents);
- storePath = Path.Combine(CacheDirectory, filepath + md5);
+ var filename = CryptUtil.CalculateSha256(filepath + "?" + md5);
+ storePath = Path.Combine(ScenarioCacheDirectory, filename);
await File.WriteAllBytesAsync(storePath, storeContents);
break;
default:
diff --git a/KamihamaWeb/Services/MasterService.cs b/KamihamaWeb/Services/MasterService.cs
index b38d24e..ae42aba 100644
--- a/KamihamaWeb/Services/MasterService.cs
+++ b/KamihamaWeb/Services/MasterService.cs
@@ -63,6 +63,8 @@ namespace KamihamaWeb.Services
public async Task UpdateMasterLists()
{
Log.Information("Updating master lists.");
+ UpdateIsRunning = true;
+
var workGamedataAssets = new Dictionary>();
foreach (var assetToMod in ModdedAssetLists)
{
@@ -78,12 +80,10 @@ namespace KamihamaWeb.Services
workGamedataAssets.Add(assetToMod, masterJson);
}
- IsReady = false;
- GamedataAssets.Clear();
-
Log.Information("Configuring master list...");
var postProcessingGeneralScenario = new Dictionary();
+ var newGamedataAssets = new Dictionary>();
long counterReplace = 0;
long counterSkip = 0;
@@ -123,7 +123,7 @@ namespace KamihamaWeb.Services
counterNew++;
}
}
- GamedataAssets.Add(assetType.Key, readyAssets);
+ newGamedataAssets.Add(assetType.Key, readyAssets);
}
Log.Information($"Finished setting up. {counterReplace} replaced assets, {counterSkip} duplicate assets, {counterNew} new assets, {counterPost} assets for post processing.");
@@ -135,7 +135,7 @@ namespace KamihamaWeb.Services
var split = asset.Key.Split("/").Last();
var scenario = split[0..^5]; // Trim .json from end
//Log.Debug($"Adding script {scenario}.");
- GamedataAssets.Add($"asset_scenario_{scenario}", new Dictionary()
+ newGamedataAssets.Add($"asset_scenario_{scenario}", new Dictionary()
{
{scenario,asset.Value}
});
@@ -147,9 +147,13 @@ namespace KamihamaWeb.Services
{
var builtJson = await _builder.BuildScenarioGeneralJson(asset.Value, EnglishMasterAssets);
- GamedataAssets["asset_main"].Add(builtJson.Path, builtJson);
+ newGamedataAssets["asset_main"].Add(builtJson.Path, builtJson);
}
+
+ IsReady = false;
+ GamedataAssets = newGamedataAssets;
IsReady = true;
+ UpdateIsRunning = false;
return true;
}
@@ -193,6 +197,7 @@ namespace KamihamaWeb.Services
}
public bool IsReady { get; set; } = false;
+ public bool UpdateIsRunning { get; set; } = false;
public long AssetsCurrentVersion { get; set; }
public Dictionary EnglishMasterAssets { get; set; }
public Dictionary> GamedataAssets { get; set; }
@@ -210,6 +215,11 @@ namespace KamihamaWeb.Services
}
}
+ public async Task RunUpdate()
+ {
+ return true;
+ }
+
public async Task ProvideJson(string which)
{
if (which == "asset_config")