102 lines
4.0 KiB
C#
102 lines
4.0 KiB
C#
using BS.SharedLauncher.DataContract;
|
|
using BS.SharedLauncher.Update;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BS.SharedLauncher.Extensions
|
|
{
|
|
public static class PlanerPackageExtension
|
|
{
|
|
public static PlanerPackageInfoDC ToPlanerPackageInfoDC(this PlanerPackageInfo planerFileInfo) => new PlanerPackageInfoDC()
|
|
{
|
|
Created = planerFileInfo.Created,
|
|
DefaultVersion = planerFileInfo.DefaultVersion,
|
|
Files = planerFileInfo.Files.ToPlanerFileInfoDCList(),
|
|
TenantVersion = planerFileInfo.TenantVersion
|
|
};
|
|
public static PlanerPackageInfo ToPlanerPackageInfo(this PlanerPackageInfoDC planerFileInfo) => new PlanerPackageInfo()
|
|
{
|
|
Created = planerFileInfo.Created,
|
|
DefaultVersion = planerFileInfo.DefaultVersion,
|
|
Files = planerFileInfo.Files.ToPlanerFileInfoList(),
|
|
TenantVersion = planerFileInfo.TenantVersion
|
|
};
|
|
|
|
public static bool ContainsPlanerFile(this PlanerPackageInfo planerPackageInfo, string rel, string checksum)
|
|
{
|
|
return planerPackageInfo.Files.FirstOrDefault(file => file.RelativePath == rel && file.Checksum == checksum) is object;
|
|
}
|
|
public static bool AnyFile(this PlanerPackageInfo planerPackageInfo)
|
|
{
|
|
if (planerPackageInfo.Files is null)
|
|
return false;
|
|
|
|
return planerPackageInfo.Files.Any();
|
|
}
|
|
|
|
public static PlanerFileInfo FindPlanerFile(this PlanerPackageInfo planerFileInfo, string relative)
|
|
{
|
|
return planerFileInfo.Files.Find(x => x.RelativePath == relative);
|
|
}
|
|
public static PlanerFileInfo FirstOrDefaultPlanerFile(this PlanerPackageInfo planerFileInfo, string relative)
|
|
{
|
|
return planerFileInfo.Files.FirstOrDefault(x => x.RelativePath == relative);
|
|
}
|
|
|
|
public static void InitFiles(this PlanerPackageInfo planerFileInfo, List<PlanerFileInfo> files)
|
|
{
|
|
planerFileInfo.Files = new List<PlanerFileInfo>();
|
|
planerFileInfo.Files.AddRange(files);
|
|
}
|
|
private static void OverrideFile(this PlanerPackageInfo planerFileInfo, PlanerFileInfo newFile)
|
|
{
|
|
var oldFile = planerFileInfo.FindPlanerFile(newFile.RelativePath);
|
|
|
|
oldFile.AbsolutePath = newFile.AbsolutePath;
|
|
//oldFile.Source = newFile.Source;
|
|
}
|
|
public static void OverrideFiles(this PlanerPackageInfo planerFileInfo, List<PlanerFileInfo> files)
|
|
{
|
|
files.ForEach(x => planerFileInfo.OverrideFile(x));
|
|
}
|
|
public static void RemoveFile(this PlanerPackageInfo planerFileInfo, string subtrahend)
|
|
{
|
|
var minuend = planerFileInfo.FirstOrDefaultPlanerFile(subtrahend);
|
|
|
|
if (minuend is PlanerFileInfo)
|
|
{
|
|
planerFileInfo.RemoveFile(minuend);
|
|
}
|
|
}
|
|
public static void RemoveFile(this PlanerPackageInfo planerFileInfo, PlanerFileInfo file)
|
|
{
|
|
planerFileInfo.Files.Remove(file);
|
|
}
|
|
public static void RemoveFileAt(this PlanerPackageInfo planerFileInfo, int index)
|
|
{
|
|
planerFileInfo.Files.RemoveAt(index);
|
|
}
|
|
public static void SubstractFiles(this PlanerPackageInfo planerPackageInfo, List<PlanerFileInfo> files)
|
|
{
|
|
files.ForEach(f => planerPackageInfo.RemoveFile(f.RelativePath));
|
|
}
|
|
|
|
public static void LoadHash(this PlanerPackageInfo planer) => planer.Files.ForEach(file => file.LoadHash());
|
|
public static PlanerPackageInfo Copy(this PlanerPackageInfo pp) => new PlanerPackageInfo()
|
|
{
|
|
Created = pp.Created,
|
|
DefaultVersion = pp.DefaultVersion,
|
|
TenantVersion = pp.TenantVersion,
|
|
Files = pp.Files.Select(file => file.Copy()).ToList()
|
|
};
|
|
|
|
public static void Apply(this PlanerPackageInfo planer)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|