Update runtime code

pull/51/head
hevinci 2022-11-01 23:02:20 +08:00
parent bdc8285255
commit b5f2174ed0
5 changed files with 58 additions and 29 deletions

View File

@ -146,7 +146,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = e.ToString(); Error = e.Message;
} }
} }
} }
@ -281,7 +281,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = e.ToString(); Error = e.Message;
} }
} }
} }
@ -429,7 +429,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = e.ToString(); Error = e.Message;
} }
} }
} }

View File

@ -57,7 +57,7 @@ namespace YooAsset
} }
catch (System.Exception e) 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); _unusedCacheFilePaths.RemoveAt(i);

View File

@ -125,31 +125,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void ParseFileName(int nameStype) public void ParseFileName(int nameStype)
{ {
if (nameStype == 1) FileName = PatchManifest.CreateBundleFileName(nameStype, BundleName, FileHash);
{
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();
}
} }
/// <summary> /// <summary>

View File

@ -308,5 +308,37 @@ namespace YooAsset
return patchManifest; return patchManifest;
} }
/// <summary>
/// 生成Bundle文件的正式名称
/// </summary>
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();
}
}
} }
} }

View File

@ -148,6 +148,27 @@ namespace YooAsset
} }
} }
/// <summary>
/// 创建文件(如果已经存在则删除旧文件)
/// </summary>
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();
}
}
/// <summary> /// <summary>
/// 创建文件的文件夹路径 /// 创建文件的文件夹路径
/// </summary> /// </summary>