85 lines
2.8 KiB
C#
85 lines
2.8 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 bool ContainsPlanerFile(this List<UpdateFileDC> files, UpdateFileDC file2)
|
|
{
|
|
return files.FirstOrDefault(file => file.RelativePath == file2.RelativePath) is object;
|
|
}
|
|
public static bool ContainsPlanerFileWithHash(this List<UpdateFileDC> files, UpdateFileDC file2)
|
|
{
|
|
return files.FirstOrDefault(file => file.RelativePath == file2.RelativePath && file.Checksum == file2.Checksum) is object;
|
|
}
|
|
public static void LoadHash(this UpdateFileDC planerFileInfo)
|
|
{
|
|
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 UpdateFileDC info) => new UpdateFileDC()
|
|
{
|
|
Name = info.Name,
|
|
AbsolutePath = info.AbsolutePath,
|
|
Checksum = info.Checksum,
|
|
RelativePath = info.RelativePath
|
|
};
|
|
public static bool EqualsFile(this UpdateFileDC file, UpdateFileDC file2)
|
|
{
|
|
return (file.Checksum == file2.Checksum) &&
|
|
(file.RelativePath == file2.RelativePath) &&
|
|
(file.Name == file2.Name);
|
|
}
|
|
public static string GetExtensionType(this UpdateFileDC file)
|
|
{
|
|
return Path.GetExtension(file.AbsolutePath);
|
|
}
|
|
public static bool IsLockFile(this UpdateFileDC file)
|
|
{
|
|
return file.Name == BeWoPathFileConfig.LockFileName;
|
|
}
|
|
public static bool IsPackageInfo(this UpdateFileDC file)
|
|
{
|
|
return file.GetExtensionType() == BeWoPathFileConfig.DotBeWoInfo;
|
|
}
|
|
public static bool IgnoreFile(this UpdateFileDC file)
|
|
{
|
|
// Lock File Ignorieren
|
|
if (file.IsLockFile())
|
|
return true;
|
|
|
|
// Package Info Ignorieren
|
|
if (file.IsPackageInfo())
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
public static bool IgnoreToRemove(this UpdateFileDC file)
|
|
{
|
|
if (file.Name == BeWoPathFileConfig.LockFileName)
|
|
return true;
|
|
|
|
if (file.GetExtensionType() == BeWoPathFileConfig.DotBeWoInfo)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|