mirror of https://github.com/tuyoogame/YooAsset
added RawFile can support encryption
parent
80188ae6e6
commit
6da7a8cff2
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_RFBP : TaskEncryption, IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4401997215a8ab040893fbf62435db93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -32,6 +32,7 @@ namespace YooAsset.Editor
|
|||
new TaskPrepare_RFBP(),
|
||||
new TaskGetBuildMap_RFBP(),
|
||||
new TaskBuilding_RFBP(),
|
||||
new TaskEncryption_RFBP(),
|
||||
new TaskUpdateBundleInfo_RFBP(),
|
||||
new TaskCreateManifest_RFBP(),
|
||||
new TaskCreateReport_RFBP(),
|
||||
|
|
|
@ -64,7 +64,6 @@ namespace YooAsset
|
|||
this.ReleaseInternal();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取原生文件的二进制数据
|
||||
/// </summary>
|
||||
|
@ -73,7 +72,11 @@ namespace YooAsset
|
|||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
if (Provider.RawFileInfo == null ||
|
||||
Provider.RawFileInfo.Bundle.Encrypted == false)
|
||||
return FileUtility.ReadAllBytes(filePath);
|
||||
else
|
||||
return Provider.RawFileInfo.LoadRawFile(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -84,7 +87,11 @@ namespace YooAsset
|
|||
if (IsValidWithWarning == false)
|
||||
return null;
|
||||
string filePath = Provider.RawFilePath;
|
||||
if (Provider.RawFileInfo == null ||
|
||||
Provider.RawFileInfo.Bundle.Encrypted == false)
|
||||
return FileUtility.ReadAllText(filePath);
|
||||
else
|
||||
return FileUtility.BytesToText(Provider.RawFileInfo.LoadRawFile(filePath));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace YooAsset
|
|||
if (_steps == ESteps.Checking)
|
||||
{
|
||||
RawFilePath = OwnerBundle.FileLoadPath;
|
||||
RawFileInfo = OwnerBundle.MainBundleInfo;
|
||||
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public string RawFilePath { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 原生文件信息
|
||||
/// </summary>
|
||||
public BundleInfo RawFileInfo { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
|
|
|
@ -14,6 +14,27 @@ namespace YooAsset
|
|||
_delivery = delivery;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载原生数据对象
|
||||
/// </summary>
|
||||
/// <param name="bundleInfo"></param>
|
||||
/// <param name="fileLoadPath"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] LoadRawFile(BundleInfo bundleInfo, string fileLoadPath)
|
||||
{
|
||||
if (_decryption == null)
|
||||
{
|
||||
YooLogger.Error($"{nameof(IDecryptionServices)} is null ! when load raw file {bundleInfo.Bundle.BundleName}!");
|
||||
return null;
|
||||
}
|
||||
|
||||
DecryptFileInfo fileInfo = new DecryptFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.Bundle.BundleName;
|
||||
fileInfo.FileLoadPath = fileLoadPath;
|
||||
fileInfo.ConentCRC = bundleInfo.Bundle.UnityCRC;
|
||||
return _decryption.LoadRawFileData(fileInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步加载资源包对象
|
||||
/// </summary>
|
||||
|
|
|
@ -146,6 +146,13 @@ namespace YooAsset
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region RawFile
|
||||
internal byte[] LoadRawFile(string fileLoadPath)
|
||||
{
|
||||
return _assist.Loader.LoadRawFile(this, fileLoadPath);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AssetBundle
|
||||
internal AssetBundle LoadAssetBundle(string fileLoadPath, out Stream managedStream)
|
||||
{
|
||||
|
|
|
@ -40,5 +40,12 @@ namespace YooAsset
|
|||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream);
|
||||
|
||||
/// <summary>
|
||||
/// 同步方式获取解密原生文件的二进制数据
|
||||
/// </summary>
|
||||
/// <param name="fileInfo"></param>
|
||||
/// <returns></returns>
|
||||
byte[] LoadRawFileData(DecryptFileInfo fileInfo);
|
||||
}
|
||||
}
|
|
@ -115,6 +115,18 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
internal static class FileUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// 字节数据转换成文本数据
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string BytesToText(byte[] data)
|
||||
{
|
||||
UTF8Encoding utf8 = new UTF8Encoding();
|
||||
string txt = utf8.GetString(data);
|
||||
return txt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取文件的文本数据
|
||||
/// </summary>
|
||||
|
|
Loading…
Reference in New Issue