diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs index 556e424..abb174d 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs @@ -61,7 +61,7 @@ namespace YooAsset.Editor File.Delete(savePath); string json = JsonUtility.ToJson(buildReport, true); - FileUtility.CreateFile(savePath, json); + FileUtility.WriteAllText(savePath, json); } public static BuildReport Deserialize(string jsonData) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs index 1299b29..b6d62e8 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs @@ -98,7 +98,7 @@ namespace YooAsset.Editor { string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion); string filePath = $"{packageOutputDirectory}/{fileName}"; - FileUtility.CreateFile(filePath, packageHash); + FileUtility.WriteAllText(filePath, packageHash); BuildLogger.Log($"创建补丁清单哈希文件:{filePath}"); } @@ -106,7 +106,7 @@ namespace YooAsset.Editor { string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName); string filePath = $"{packageOutputDirectory}/{fileName}"; - FileUtility.CreateFile(filePath, buildParameters.PackageVersion); + FileUtility.WriteAllText(filePath, buildParameters.PackageVersion); BuildLogger.Log($"创建补丁清单版本文件:{filePath}"); } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs index ab4e64b..4ca3832 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs @@ -52,7 +52,7 @@ namespace YooAsset.Editor } string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt"; - FileUtility.CreateFile(filePath, encryptResult.EncryptedData); + FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData); bundleInfo.EncryptedFilePath = filePath; bundleInfo.LoadMethod = encryptResult.LoadMethod; BuildLogger.Log($"Bundle文件加密完成:{filePath}"); diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs index 820edeb..6f40be1 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs @@ -278,7 +278,7 @@ namespace YooAsset.Editor string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json"; string fileContent = JsonUtility.ToJson(_currentReport, true); - FileUtility.CreateFile(filePath, fileContent); + FileUtility.WriteAllText(filePath, fileContent); } } private void OnSearchKeyWordChange(ChangeEvent e) diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs index 4f41857..bb66549 100644 --- a/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs +++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/RawFileOperationHandle.cs @@ -86,9 +86,7 @@ namespace YooAsset if (IsValidWithWarning == false) return null; string filePath = Provider.RawFilePath; - if (File.Exists(filePath) == false) - return null; - return File.ReadAllText(filePath, Encoding.UTF8); + return FileUtility.ReadAllText(filePath); } /// diff --git a/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs b/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs index 1494db3..7ae3b36 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/ManifestTools.cs @@ -16,7 +16,7 @@ namespace YooAsset public static void SerializeToJson(string savePath, PackageManifest manifest) { string json = JsonUtility.ToJson(manifest, true); - FileUtility.CreateFile(savePath, json); + FileUtility.WriteAllText(savePath, json); } /// diff --git a/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs b/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs index f21c10f..32c2e66 100644 --- a/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs +++ b/Assets/YooAsset/Runtime/PackageSystem/Operations/InitializationOperation.cs @@ -410,7 +410,7 @@ namespace YooAsset _footPrint = Application.buildGUID; #endif string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath(); - FileUtility.CreateFile(footPrintFilePath, _footPrint); + FileUtility.WriteAllText(footPrintFilePath, _footPrint); YooLogger.Log($"Save application foot print : {_footPrint}"); } } diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index 45a5b56..ddde6dd 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -13,7 +13,7 @@ namespace YooAsset internal static class StringUtility { [ThreadStatic] - private static StringBuilder _cacheBuilder = new StringBuilder(1024); + private static StringBuilder _cacheBuilder = new StringBuilder(2048); public static string Format(string format, object arg0) { @@ -106,46 +106,26 @@ namespace YooAsset } /// - /// 创建文件(如果已经存在则删除旧文件) + /// 写入文本数据(会覆盖指定路径的文件) /// - public static void CreateFile(string filePath, string content) + public static void WriteAllText(string filePath, string content) { - // 删除旧文件 - if (File.Exists(filePath)) - File.Delete(filePath); - // 创建文件夹路径 CreateFileDirectory(filePath); - // 创建新文件 byte[] bytes = Encoding.UTF8.GetBytes(content); - using (FileStream fs = File.Create(filePath)) - { - fs.Write(bytes, 0, bytes.Length); - fs.Flush(); - fs.Close(); - } + File.WriteAllBytes(filePath, bytes); //避免写入BOM标记 } /// - /// 创建文件(如果已经存在则删除旧文件) + /// 写入字节数据(会覆盖指定路径的文件) /// - public static void CreateFile(string filePath, byte[] data) + public static void WriteAllBytes(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(); - } + File.WriteAllBytes(filePath, data); } ///