- tweak: rework FileApi for services
- tweak: rework filter think - add: content view button - fix: little fixes in services
This commit is contained in:
45
Nebula.Shared/Services/ContentService.Migration.cs
Normal file
45
Nebula.Shared/Services/ContentService.Migration.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user