update logic code

优化了创建文件的方式。
main
hevinci 2023-06-09 18:12:03 +08:00
parent f6e94c9514
commit 895dde1cc8
8 changed files with 15 additions and 37 deletions

View File

@ -61,7 +61,7 @@ namespace YooAsset.Editor
File.Delete(savePath); File.Delete(savePath);
string json = JsonUtility.ToJson(buildReport, true); string json = JsonUtility.ToJson(buildReport, true);
FileUtility.CreateFile(savePath, json); FileUtility.WriteAllText(savePath, json);
} }
public static BuildReport Deserialize(string jsonData) public static BuildReport Deserialize(string jsonData)
{ {

View File

@ -98,7 +98,7 @@ namespace YooAsset.Editor
{ {
string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion); string fileName = YooAssetSettingsData.GetPackageHashFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}"; string filePath = $"{packageOutputDirectory}/{fileName}";
FileUtility.CreateFile(filePath, packageHash); FileUtility.WriteAllText(filePath, packageHash);
BuildLogger.Log($"创建补丁清单哈希文件:{filePath}"); BuildLogger.Log($"创建补丁清单哈希文件:{filePath}");
} }
@ -106,7 +106,7 @@ namespace YooAsset.Editor
{ {
string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName); string fileName = YooAssetSettingsData.GetPackageVersionFileName(buildParameters.PackageName);
string filePath = $"{packageOutputDirectory}/{fileName}"; string filePath = $"{packageOutputDirectory}/{fileName}";
FileUtility.CreateFile(filePath, buildParameters.PackageVersion); FileUtility.WriteAllText(filePath, buildParameters.PackageVersion);
BuildLogger.Log($"创建补丁清单版本文件:{filePath}"); BuildLogger.Log($"创建补丁清单版本文件:{filePath}");
} }
} }

View File

@ -52,7 +52,7 @@ namespace YooAsset.Editor
} }
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt"; string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
FileUtility.CreateFile(filePath, encryptResult.EncryptedData); FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData);
bundleInfo.EncryptedFilePath = filePath; bundleInfo.EncryptedFilePath = filePath;
bundleInfo.LoadMethod = encryptResult.LoadMethod; bundleInfo.LoadMethod = encryptResult.LoadMethod;
BuildLogger.Log($"Bundle文件加密完成{filePath}"); BuildLogger.Log($"Bundle文件加密完成{filePath}");

View File

@ -278,7 +278,7 @@ namespace YooAsset.Editor
string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json"; string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json";
string fileContent = JsonUtility.ToJson(_currentReport, true); string fileContent = JsonUtility.ToJson(_currentReport, true);
FileUtility.CreateFile(filePath, fileContent); FileUtility.WriteAllText(filePath, fileContent);
} }
} }
private void OnSearchKeyWordChange(ChangeEvent<string> e) private void OnSearchKeyWordChange(ChangeEvent<string> e)

View File

@ -86,9 +86,7 @@ namespace YooAsset
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return null; return null;
string filePath = Provider.RawFilePath; string filePath = Provider.RawFilePath;
if (File.Exists(filePath) == false) return FileUtility.ReadAllText(filePath);
return null;
return File.ReadAllText(filePath, Encoding.UTF8);
} }
/// <summary> /// <summary>

View File

@ -16,7 +16,7 @@ namespace YooAsset
public static void SerializeToJson(string savePath, PackageManifest manifest) public static void SerializeToJson(string savePath, PackageManifest manifest)
{ {
string json = JsonUtility.ToJson(manifest, true); string json = JsonUtility.ToJson(manifest, true);
FileUtility.CreateFile(savePath, json); FileUtility.WriteAllText(savePath, json);
} }
/// <summary> /// <summary>

View File

@ -410,7 +410,7 @@ namespace YooAsset
_footPrint = Application.buildGUID; _footPrint = Application.buildGUID;
#endif #endif
string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath(); string footPrintFilePath = PersistentTools.GetAppFootPrintFilePath();
FileUtility.CreateFile(footPrintFilePath, _footPrint); FileUtility.WriteAllText(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}"); YooLogger.Log($"Save application foot print : {_footPrint}");
} }
} }

View File

@ -13,7 +13,7 @@ namespace YooAsset
internal static class StringUtility internal static class StringUtility
{ {
[ThreadStatic] [ThreadStatic]
private static StringBuilder _cacheBuilder = new StringBuilder(1024); private static StringBuilder _cacheBuilder = new StringBuilder(2048);
public static string Format(string format, object arg0) public static string Format(string format, object arg0)
{ {
@ -106,46 +106,26 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 创建文件(如果已经存在则删除旧文件) /// 写入文本数据(会覆盖指定路径的文件)
/// </summary> /// </summary>
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); CreateFileDirectory(filePath);
// 创建新文件
byte[] bytes = Encoding.UTF8.GetBytes(content); byte[] bytes = Encoding.UTF8.GetBytes(content);
using (FileStream fs = File.Create(filePath)) File.WriteAllBytes(filePath, bytes); //避免写入BOM标记
{
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
}
} }
/// <summary> /// <summary>
/// 创建文件(如果已经存在则删除旧文件) /// 写入字节数据(会覆盖指定路径的文件)
/// </summary> /// </summary>
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); CreateFileDirectory(filePath);
// 创建新文件 File.WriteAllBytes(filePath, data);
using (FileStream fs = File.Create(filePath))
{
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
}
} }
/// <summary> /// <summary>