JD2022-TU1/main/tools/apps/DataFileAnalyzer/FileLibrary/DependenciesUpdateOperation.cs

99 lines
3.8 KiB
C#

using System;
using System.Collections.Generic;
using UAF;
namespace DataFileAnalyzer
{
/// <summary>
/// Compute the dependencies of a data file
/// </summary>
public class DependenciesUpdateOperation : UpdateOperation
{
protected DateTime m_lastCheckTime = DateTimeExtensions.Invalid;
List<string> m_dependencies = new List<string>();
/// <summary>
/// Constructor
/// </summary>
public DependenciesUpdateOperation(FileUpdater _updater, string _filePath)
: base(_updater, _filePath)
{
}
/// <summary>
/// Use the cookerWrapper to compute the dependencies
/// </summary>
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions()]
public override void Run()
{
SetProgress(States.Running);
m_lastCheckTime = DateTime.UtcNow;
try
{
m_updater.CookerWrapper.getTopLevelDependencies(Platform.PC.Name, NormalizedFilePath, m_dependencies, true);
m_updater.CookerWrapper.getTopLevelDependencies(Platform.WII.Name, NormalizedFilePath, m_dependencies, true);
m_updater.CookerWrapper.getTopLevelDependencies(Platform.WIIU.Name, NormalizedFilePath, m_dependencies, true);
m_updater.CookerWrapper.getTopLevelDependencies(Platform.X360.Name, NormalizedFilePath, m_dependencies, true);
m_updater.CookerWrapper.getTopLevelDependencies(Platform.DURANGO.Name, NormalizedFilePath, m_dependencies, true);
m_updater.CookerWrapper.getTopLevelDependencies(Platform.PS3.Name, NormalizedFilePath, m_dependencies, true);
m_updater.CookerWrapper.getTopLevelDependencies(Platform.ORBIS.Name, NormalizedFilePath, m_dependencies, true);
SetProgress(States.WaitUpdate);
}
catch (System.Exception ex)
{
m_logger.Error(LogCategories.Get("DataFileAnalyzer"), "Failed to compute dependencies on file {0}", NormalizedFilePath);
m_logger.Exception(ex);
SetProgress(States.WaitUpdate | States.Error);
}
}
/// <summary>
/// Update the library with the computed dependencies
/// </summary>
public override void UpdateLibrary()
{
bool skipped = (State & States.Skipped) != States.None;
bool error = (State & States.Error) != States.None;
DataFile dataFile = m_library.GetFile(NormalizedFilePath);
if (skipped || error)
{
if (error && dataFile != null)
{
dataFile.AddError(DataFileError.Codes.ErrorComputingDependencies);
}
SetProgress(States.Finished);
return;
}
SetProgress(States.Updating);
if (dataFile == null)
{
m_logger.Error("Computed the dependencies of a non-existing file: " + FilePath);
State |= States.Error;
}
else
{
if (!m_library.SetDataFileDependencies(dataFile, m_dependencies, Platform.PC)) // todo, set the correct platform?
{
State |= States.Error;
}
else
{
dataFile.RemoveWarning(DataFileError.Codes.NeedDependencies);
dataFile.LastDependenciesCheckTime = m_lastCheckTime;
}
m_updater.AskForOrphanDetectionUpdate(dataFile.FilePath);
}
SetProgress(States.Finished);
//m_logger.Message("[Basic Update] Updated {0}", NormalizedFilePath);
}
}
}