mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-06-20 19:33:42 +00:00
原生文件加密/解密
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -267,7 +268,17 @@ namespace YooAsset
|
||||
return null;
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
var data = FileUtility.ReadAllBytes(filePath);
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"DecryptionServices is Null!");
|
||||
return null;
|
||||
}
|
||||
return DecryptionServices.ReadFileData(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
@@ -278,7 +289,18 @@ namespace YooAsset
|
||||
return null;
|
||||
|
||||
string filePath = GetBuildinFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
var data = FileUtility.ReadAllBytes(filePath);
|
||||
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"DecryptionServices is Null!");
|
||||
return null;
|
||||
}
|
||||
data = DecryptionServices.ReadFileData(data);
|
||||
}
|
||||
return Encoding.UTF8.GetString(data);
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -316,9 +317,19 @@ namespace YooAsset
|
||||
{
|
||||
if (Exists(bundle) == false)
|
||||
return null;
|
||||
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
var data = FileUtility.ReadAllBytes(filePath);
|
||||
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"DecryptionServices is Null!");
|
||||
return null;
|
||||
}
|
||||
return DecryptionServices.ReadFileData(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
public virtual string ReadFileText(PackageBundle bundle)
|
||||
{
|
||||
@@ -326,7 +337,18 @@ namespace YooAsset
|
||||
return null;
|
||||
|
||||
string filePath = GetCacheFileLoadPath(bundle);
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
var data = FileUtility.ReadAllBytes(filePath);
|
||||
|
||||
if (bundle.Encrypted)
|
||||
{
|
||||
if (DecryptionServices == null)
|
||||
{
|
||||
YooLogger.Error($"DecryptionServices is Null!");
|
||||
return null;
|
||||
}
|
||||
data = DecryptionServices.ReadFileData(data);
|
||||
}
|
||||
return Encoding.UTF8.GetString(data);
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
|
||||
@@ -124,13 +124,14 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinRawFileSystemParameters(EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
public static FileSystemParameters CreateDefaultBuildinRawFileSystemParameters(IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
fileSystemParams.AddParameter(FILE_VERIFY_LEVEL, verifyLevel);
|
||||
fileSystemParams.AddParameter(APPEND_FILE_EXTENSION, true);
|
||||
fileSystemParams.AddParameter(RAW_FILE_BUILD_PIPELINE, true);
|
||||
fileSystemParams.AddParameter(DECRYPTION_SERVICES, decryptionServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
@@ -156,7 +157,7 @@ namespace YooAsset
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheRawFileSystemParameters(IRemoteServices remoteServices, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
public static FileSystemParameters CreateDefaultCacheRawFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, EFileVerifyLevel verifyLevel = EFileVerifyLevel.Middle, string rootDirectory = null)
|
||||
{
|
||||
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
|
||||
var fileSystemParams = new FileSystemParameters(fileSystemClass, rootDirectory);
|
||||
@@ -164,6 +165,7 @@ namespace YooAsset
|
||||
fileSystemParams.AddParameter(FILE_VERIFY_LEVEL, verifyLevel);
|
||||
fileSystemParams.AddParameter(APPEND_FILE_EXTENSION, true);
|
||||
fileSystemParams.AddParameter(RAW_FILE_BUILD_PIPELINE, true);
|
||||
fileSystemParams.AddParameter(DECRYPTION_SERVICES, decryptionServices);
|
||||
return fileSystemParams;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,5 +34,12 @@ namespace YooAsset
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream);
|
||||
|
||||
/// <summary>
|
||||
/// 解密字节数据
|
||||
/// </summary>
|
||||
/// <param name="encryptData"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] ReadFileData(byte[] encryptData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user