49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using BS.SharedLauncher.DataContract;
|
|
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
|
|
};
|
|
}
|
|
}
|