Files
BeWoPlaner/SharedLauncher/Extensions/PlanerFileExtension.cs
2022-09-14 10:57:51 +02:00

83 lines
2.9 KiB
C#

using BS.SharedLauncher.DataContract;
using BS.SharedLauncher.Information;
using BS.SharedLauncher.Update;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace BS.SharedLauncher.Extensions
{
public static class PlanerFileExtension
{
public static List<PlanerFileInfoDC> ToPlanerFileInfoDCList(this List<PlanerFileInfo> planerFileInfos) => planerFileInfos.Select(x => new PlanerFileInfoDC()
{
Checksum = x.Checksum,
Name = x.Name,
RelativePath = x.RelativePath
}).ToList();
public static List<PlanerFileInfo> ToPlanerFileInfoList(this List<PlanerFileInfoDC> planerFileInfos) => planerFileInfos.Select(x => new PlanerFileInfo()
{
Checksum = x.Checksum,
Name = x.Name,
RelativePath = x.RelativePath
}).ToList();
public static void LoadHash(this PlanerFileInfo planerFileInfo)
{
//FileData = File.ReadAllBytes(AbsolutePath);
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(planerFileInfo.AbsolutePath))
{
planerFileInfo.Checksum = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
}
}
}
public static void Copy(this PlanerFileInfo info) => new PlanerFileInfo()
{
Name = info.Name,
AbsolutePath = info.AbsolutePath,
Checksum = info.Checksum,
RelativePath = info.RelativePath
};
public static bool EqualsFile(this PlanerFileInfo file, PlanerFileInfo file2)
{
return (file.Checksum == file2.Checksum) &&
(file.RelativePath == file2.RelativePath) &&
(file.Name == file2.Name);
}
public static bool EqualsFile(this PlanerFileInfoDC file, PlanerFileInfoDC file2)
{
return (file.Checksum == file2.Checksum) &&
(file.RelativePath == file2.RelativePath) &&
(file.Name == file2.Name);
}
public static bool EqualsFile(this PlanerFileInfo file, PlanerFileInfoDC file2)
{
return (file.Checksum == file2.Checksum) &&
(file.RelativePath == file2.RelativePath) &&
(file.Name == file2.Name);
}
public static bool EqualsFile(this PlanerFileInfoDC file, PlanerFileInfo file2)
{
return (file.Checksum == file2.Checksum) &&
(file.RelativePath == file2.RelativePath) &&
(file.Name == file2.Name);
}
public static bool IgnoreToRemove(this PlanerFileInfo file)
{
if (file.Name == BeWoPathFileConfig.LockFileName)
return true;
return false;
}
}
}