mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
Simply check the file hash value and delete the old pac file
This commit is contained in:
parent
e054d4487d
commit
7cc42ae249
2 changed files with 52 additions and 6 deletions
|
@ -225,15 +225,54 @@ namespace ServiceLib.Common
|
||||||
|
|
||||||
public static string GetMd5(string str)
|
public static string GetMd5(string str)
|
||||||
{
|
{
|
||||||
var byteOld = Encoding.UTF8.GetBytes(str);
|
if (string.IsNullOrEmpty(str))
|
||||||
var byteNew = MD5.HashData(byteOld);
|
|
||||||
StringBuilder sb = new(32);
|
|
||||||
foreach (var b in byteNew)
|
|
||||||
{
|
{
|
||||||
sb.Append(b.ToString("x2"));
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.ToString();
|
try
|
||||||
|
{
|
||||||
|
var byteOld = Encoding.UTF8.GetBytes(str);
|
||||||
|
var byteNew = MD5.HashData(byteOld);
|
||||||
|
StringBuilder sb = new(32);
|
||||||
|
foreach (var b in byteNew)
|
||||||
|
{
|
||||||
|
sb.Append(b.ToString("x2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetFileHash(string filePath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(filePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(filePath))
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var md5 = MD5.Create();
|
||||||
|
using var stream = File.OpenRead(filePath);
|
||||||
|
var hash = md5.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logging.SaveLog(_tag, ex);
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -33,6 +33,13 @@ namespace ServiceLib.Handler
|
||||||
private static async Task InitText()
|
private static async Task InitText()
|
||||||
{
|
{
|
||||||
var path = Path.Combine(_configPath, "pac.txt");
|
var path = Path.Combine(_configPath, "pac.txt");
|
||||||
|
|
||||||
|
// Delete the old pac file
|
||||||
|
if (File.Exists(path) && Utils.GetFileHash(path).Equals("b590c07280f058ef05d5394aa2f927fe"))
|
||||||
|
{
|
||||||
|
File.Delete(path);
|
||||||
|
}
|
||||||
|
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
var pac = EmbedUtils.GetEmbedText(Global.PacFileName);
|
var pac = EmbedUtils.GetEmbedText(Global.PacFileName);
|
||||||
|
|
Loading…
Reference in a new issue