diff --git a/v2rayN/ServiceLib/Common/FileManager.cs b/v2rayN/ServiceLib/Common/FileManager.cs index 70b093146a8..b98b165526e 100644 --- a/v2rayN/ServiceLib/Common/FileManager.cs +++ b/v2rayN/ServiceLib/Common/FileManager.cs @@ -1,4 +1,5 @@ -using System.IO.Compression; +using System.Formats.Tar; +using System.IO.Compression; using System.Text; namespace ServiceLib.Common @@ -19,7 +20,7 @@ public static bool ByteArrayToFile(string fileName, byte[] content) return false; } - public static void UncompressedFile(string fileName, byte[] content) + public static void DecompressFile(string fileName, byte[] content) { try { @@ -33,7 +34,7 @@ public static void UncompressedFile(string fileName, byte[] content) } } - public static void UncompressedFile(string fileName, string toPath, string? toName) + public static void DecompressFile(string fileName, string toPath, string? toName) { try { @@ -49,6 +50,20 @@ public static void UncompressedFile(string fileName, string toPath, string? toNa } } + public static void DecompressTarFile(string fileName, string toPath) + { + try + { + using var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); + using var gz = new GZipStream(fs, CompressionMode.Decompress, leaveOpen: true); + TarFile.ExtractToDirectory(gz, toPath, overwriteFiles: true); + } + catch (Exception ex) + { + Logging.SaveLog(ex.Message, ex); + } + } + public static string NonExclusiveReadAllText(string path) { return NonExclusiveReadAllText(path, Encoding.Default); @@ -139,7 +154,7 @@ public static bool CreateFromDirectory(string sourceDirectoryName, string destin return true; } - public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, string ignoredName) + public static void CopyDirectory(string sourceDir, string destinationDir, bool recursive, string? ignoredName) { // Get information about the source directory var dir = new DirectoryInfo(sourceDir); @@ -166,7 +181,7 @@ public static void CopyDirectory(string sourceDir, string destinationDir, bool r continue; } var targetFilePath = Path.Combine(destinationDir, file.Name); - file.CopyTo(targetFilePath); + file.CopyTo(targetFilePath, true); } // If recursive and copying subdirectories, recursively call this method diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index f25548ce687..09f103fa238 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -107,7 +107,7 @@ public async Task CheckUpdateCore(ECoreType type, Config config, Action t.CoreType == item.CoreType); - if (found != null) - { - var itemCopy = JsonUtils.DeepCopy(found); - itemCopy.Remarks = item.Remarks; - _checkUpdateItem.Replace(found, itemCopy); - } + if (found == null) return; + var itemCopy = JsonUtils.DeepCopy(found); + itemCopy.Remarks = item.Remarks; + _checkUpdateItem.Replace(found, itemCopy); } } } \ No newline at end of file