From 0c6aa88ac55468da1a774c8f0db2f2986e4db05f Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Fri, 26 Aug 2022 13:50:57 +0800 Subject: [PATCH] Update LoaderUtilities.cs --- .../HotUpdate/Scripts/LoaderUtilities.cs | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/LoaderUtilities.cs b/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/LoaderUtilities.cs index 0581288a..5510c823 100644 --- a/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/LoaderUtilities.cs +++ b/Assets/TEngine/Scripts/Runtime/HotUpdate/Scripts/LoaderUtilities.cs @@ -12,7 +12,6 @@ namespace TEngine.Runtime { public class LoaderUtilities { - /// /// 获取文件的md5码 /// @@ -25,6 +24,7 @@ namespace TEngine.Runtime TLogger.LogWarning($"not exit file,path:{fileName}"); return string.Empty; } + try { using (FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) @@ -36,9 +36,9 @@ namespace TEngine.Runtime { sb.Append(retVal[i].ToString("x2")); } + return sb.ToString(); } - } catch (Exception ex) { @@ -133,6 +133,7 @@ namespace TEngine.Runtime { MonoUtility.StopCoroutine(_coroutine); } + _coroutine = MonoUtility.StartCoroutine(_Response(_msgContent)); } @@ -171,7 +172,8 @@ namespace TEngine.Runtime stream.Close(); stream.Dispose(); var rspResult = webReq.BeginGetResponse(ResponseComplete, webReq); - ThreadPool.RegisterWaitForSingleObject(rspResult.AsyncWaitHandle, TimeoutCallback, result, 2000, true); + ThreadPool.RegisterWaitForSingleObject(rspResult.AsyncWaitHandle, TimeoutCallback, result, 2000, + true); } catch (Exception e) { @@ -265,6 +267,7 @@ namespace TEngine.Runtime Console.WriteLine(e); throw; } + webReq.Abort(); } } @@ -284,6 +287,7 @@ namespace TEngine.Runtime yield return time; callback(); } + #endregion /// @@ -331,7 +335,8 @@ namespace TEngine.Runtime /// public static string HttpGet(string url, string postDataStr = "") { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + (postDataStr == "" ? "" : "?") + postDataStr); + HttpWebRequest request = + (HttpWebRequest)WebRequest.Create(url + (postDataStr == "" ? "" : "?") + postDataStr); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; @@ -363,6 +368,7 @@ namespace TEngine.Runtime { encoding = "UTF-8"; //默认编码 } + StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding)); string retString = reader.ReadToEnd(); return retString; @@ -388,15 +394,17 @@ namespace TEngine.Runtime { fi.Attributes = FileAttributes.Normal; } - LoaderUtilities.DeleteFile(d);//直接删除其中的文件 + + LoaderUtilities.DeleteFile(d); //直接删除其中的文件 } else { DirectoryInfo d1 = new DirectoryInfo(d); if (d1.GetFiles().Length != 0) { - DeleteFolder(d1.FullName);////递归删除子文件夹 + DeleteFolder(d1.FullName); ////递归删除子文件夹 } + Directory.Delete(d, true); } } @@ -465,7 +473,6 @@ namespace TEngine.Runtime { try { - if (string.IsNullOrEmpty(srcPath) || !Directory.Exists(srcPath)) { Debug.LogError("不存在的原目录地址:" + srcPath); @@ -486,6 +493,7 @@ namespace TEngine.Runtime { Directory.CreateDirectory($"{destPath}/{sub_name}"); } + CopyDirectory(i.FullName, $"{destPath}/{sub_name}"); } else @@ -520,6 +528,7 @@ namespace TEngine.Runtime { path = Path.GetDirectoryName(path); } + if (path == null) return; @@ -577,4 +586,4 @@ namespace TEngine.Runtime } } } -} +} \ No newline at end of file