Files
Main/Assets/Plugins/References/FuncellUpdate/UpdateModel/Flow/Flow1TransResourceExOBB.cs
2025-01-25 04:38:09 +08:00

148 lines
4.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
using Thousandto.Update.Enum;
using Thousandto.Update.Log;
using Thousandto.Update.Trans;
namespace Thousandto.Update.Flow
{
/// <summary>
/// 1. 转移obb资源 android only
/// </summary>
public class Flow1TransResourceExOBB : BaseFlow
{
//平台类型
private PlatformType _platformType;
//资源转移功能实例
TransResource _transInstance;
private string _obbFileFullPath = "";
public void SetExternalData(string sourcePath, PlatformType type, Thousandto.Update.Delegate.TransResourceFinishCallback transFinishCallback = null)
{
_platformType = type;
switch (_platformType)
{
case PlatformType.Android:
_transInstance = new TransAndroidResource();
break;
case PlatformType.IOS:
_transInstance = new TransIOSResource();
break;
case PlatformType.Windows:
_transInstance = new TransPCResource();
break;
default:
_transInstance = new TransPCResource();
break;
}
_obbFileFullPath = GetObbFullPath(sourcePath);
UpdateLog.DEBUG_LOG("Obb full path:" + _obbFileFullPath);
//全转移
_transInstance.IsUnZipObb = true;
_transInstance.SetUnzipPath(_obbFileFullPath, _storeDir, transFinishCallback);
}
public void ReInitTransData()
{
if (_transInstance != null)
_transInstance.ReInit();
}
//强制转移资源,因为要更新资源,不管是基础资源还是补丁资源
public void ForceTransWhenNeedUpdate()
{
}
//强制做资源释放, 在ios通过游戏内更新分段资源时调用
public void SetForceUnzip()
{
}
public override void OnEnter(BaseFlow oldFlow)
{
base.OnEnter(oldFlow);
//转移过资源xml就从storePath取。否则从包内取
ChangeLocalXmlPath(HasTransedResource());
}
public override int Work()
{
if (!CheckLastFlowResult()) return LastFlowResult;
int ret = CodeDefine.RET_INIT;
if (!checkNeedTrans())
{
ret = CodeDefine.RET_SUCCESS;
}
else
{
if (!string.IsNullOrEmpty(_obbFileFullPath) && File.Exists(_obbFileFullPath))
{
//转移资源完成后调用
_transInstance.SetInternalCallback(() =>
{
File.Delete(_obbFileFullPath);
});
_transInstance.StartUnzipByThread();
bool success = _transInstance.GetTransReslult();
ret = success ? CodeDefine.RET_SUCCESS : CodeDefine.RET_FAIL_TRANS_FAIL;
_transInstance.CallFinish(success);
}
else
ret = CodeDefine.RET_SUCCESS;
}
return ret;
}
public override void Uninitialize()
{
LocalXml = null;
}
public override void GetCurDownInfo(out string url, out int total, out int downloaded)
{
base.GetCurDownInfo(out url, out total, out downloaded);
url = "";
total = _transInstance.GetTotalValue();
downloaded = _transInstance.GetCurrentProgress();
}
public void TransResourceFinish(bool result)
{
}
//判断是否需要转移资源
private bool checkNeedTrans()
{
bool ret = false;
if (_platformType != PlatformType.Android)
return ret;
return !string.IsNullOrEmpty(_obbFileFullPath) && File.Exists(_obbFileFullPath);
}
private string GetObbFullPath(string storePath)
{
string obbPath = storePath.Replace("/data/", "/obb/").Replace("files/StreamingAssets", "");
UpdateLog.DEBUG_LOG("obb root path:" + obbPath);
if(Directory.Exists(obbPath))
{
var files = Directory.GetFiles(obbPath, "*.obb");
if (files.Length > 0)
return files[0];
}
return null;
}
}
}