diff --git a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs index 2d6895c..736aac9 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Operations/RawFileOperation.cs @@ -146,7 +146,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = e.ToString(); + Error = e.Message; } } } @@ -281,7 +281,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = e.ToString(); + Error = e.Message; } } } @@ -429,7 +429,7 @@ namespace YooAsset { _steps = ESteps.Done; Status = EOperationStatus.Failed; - Error = e.ToString(); + Error = e.Message; } } } diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs index 2618162..5c72672 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/ClearUnusedCacheFilesOperation.cs @@ -57,7 +57,7 @@ namespace YooAsset } catch (System.Exception e) { - YooLogger.Warning($"Failed delete cache file : {filePath} Exception : {e}"); + YooLogger.Warning($"Failed delete cache file : {filePath} ! {e.Message}"); } } _unusedCacheFilePaths.RemoveAt(i); diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs index 1b16bdb..d2b5721 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchBundle.cs @@ -125,31 +125,7 @@ namespace YooAsset /// public void ParseFileName(int nameStype) { - if (nameStype == 1) - { - FileName = FileHash; - } - else if (nameStype == 2) - { - string tempFileExtension = System.IO.Path.GetExtension(BundleName); - FileName = $"{FileHash}{tempFileExtension}"; - } - else if (nameStype == 3) - { - string tempFileExtension = System.IO.Path.GetExtension(BundleName); - string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, ""); - FileName = $"{tempBundleName}_{FileHash}"; - } - else if (nameStype == 4) - { - string tempFileExtension = System.IO.Path.GetExtension(BundleName); - string tempBundleName = BundleName.Replace('/', '_').Replace(tempFileExtension, ""); - FileName = $"{tempBundleName}_{FileHash}{tempFileExtension}"; - } - else - { - throw new NotImplementedException(); - } + FileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash); } /// diff --git a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs index e57d2c1..c1840f8 100644 --- a/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs +++ b/Assets/YooAsset/Runtime/PatchSystem/PatchManifest.cs @@ -308,5 +308,37 @@ namespace YooAsset return patchManifest; } + + /// + /// 生成Bundle文件的正式名称 + /// + public static string CreateBundleFileName(int nameStype, string bundleName, string fileHash) + { + if (nameStype == 1) + { + return fileHash; + } + else if (nameStype == 2) + { + string tempFileExtension = System.IO.Path.GetExtension(bundleName); + return $"{fileHash}{tempFileExtension}"; + } + else if (nameStype == 3) + { + string tempFileExtension = System.IO.Path.GetExtension(bundleName); + string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, ""); + return $"{tempBundleName}_{fileHash}"; + } + else if (nameStype == 4) + { + string tempFileExtension = System.IO.Path.GetExtension(bundleName); + string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, ""); + return $"{tempBundleName}_{fileHash}{tempFileExtension}"; + } + else + { + throw new NotImplementedException(); + } + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index 7daa25e..9e118ab 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -148,6 +148,27 @@ namespace YooAsset } } + /// + /// 创建文件(如果已经存在则删除旧文件) + /// + public static void CreateFile(string filePath, byte[] data) + { + // 删除旧文件 + if (File.Exists(filePath)) + File.Delete(filePath); + + // 创建文件夹路径 + CreateFileDirectory(filePath); + + // 创建新文件 + using (FileStream fs = File.Create(filePath)) + { + fs.Write(data, 0, data.Length); + fs.Flush(); + fs.Close(); + } + } + /// /// 创建文件的文件夹路径 ///