- tweak: rework FileApi for services

- tweak: rework filter think
- add: content view button
- fix: little fixes in services
This commit is contained in:
2025-05-02 20:06:33 +03:00
parent ef8ee5a8d3
commit f066bb1188
18 changed files with 426 additions and 268 deletions

View File

@@ -0,0 +1,45 @@
using Nebula.Shared.FileApis;
using Nebula.Shared.Models;
namespace Nebula.Shared.Services;
public partial class ContentService
{
public bool CheckMigration(ILoadingHandler loadingHandler)
{
debugService.Log("Checking migration...");
var migrationList = ContentFileApi.AllFiles.Where(f => !f.Contains("\\")).ToList();
if(migrationList.Count == 0) return false;
debugService.Log($"Found {migrationList.Count} migration files. Starting migration...");
Task.Run(() => DoMigration(loadingHandler, migrationList));
return true;
}
private void DoMigration(ILoadingHandler loadingHandler, List<string> migrationList)
{
loadingHandler.SetJobsCount(migrationList.Count);
Parallel.ForEach(migrationList, (f,_)=>MigrateFile(f,loadingHandler));
if (loadingHandler is IDisposable disposable)
{
disposable.Dispose();
}
}
private void MigrateFile(string file, ILoadingHandler loadingHandler)
{
if(!ContentFileApi.TryOpen(file, out var stream))
{
loadingHandler.AppendResolvedJob();
return;
}
ContentFileApi.Save(HashApi.GetManifestPath(file), stream);
stream.Dispose();
ContentFileApi.Remove(file);
loadingHandler.AppendResolvedJob();
}
}