182 lines
6.0 KiB
C#
182 lines
6.0 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace BF
|
|
{
|
|
/// <summary>
|
|
/// todo 对首包和ab_config.bytes简单加密
|
|
/// </summary>
|
|
public abstract class GameLaunchProcessorBase
|
|
{
|
|
protected const string ASSETS_FIRST_AB = "first/first.ab";
|
|
|
|
protected static string ABConfigFileName { get { return GameLaunchUtils.ABCONFIG_FILE_NAME; } }
|
|
protected static string StreamingAbccPath { get; private set; }
|
|
protected static string PersistentAbccPath { get; private set; }
|
|
protected static string UpdateDirPath { get; private set; } // 热更目录
|
|
protected static string TempUpdateDirPath { get; private set; } // 下载文件临时目录
|
|
|
|
protected GameLaunchProcessorBase nextProcessor;
|
|
|
|
static GameLaunchProcessorBase()
|
|
{
|
|
StreamingAbccPath = Path.Combine(Application.streamingAssetsPath, GameLaunchUtils.ABCONFIG_FILE_NAME);
|
|
PersistentAbccPath = Path.Combine(Application.persistentDataPath, GameLaunchUtils.ABCONFIG_FILE_NAME);
|
|
UpdateDirPath = Path.Combine(Application.persistentDataPath, "update");
|
|
TempUpdateDirPath = Path.Combine(Application.persistentDataPath, "temp");
|
|
}
|
|
|
|
public GameLaunchProcessorBase() { }
|
|
|
|
public GameLaunchProcessorBase(GameLaunchProcessorBase nextProcessor)
|
|
{
|
|
this.nextProcessor = nextProcessor;
|
|
}
|
|
|
|
public virtual void Process(LaunchRequester lr)
|
|
{
|
|
BFMain.Instance.GameLaunchMgr.SetCurrentProcessor(this);
|
|
}
|
|
|
|
public virtual void Update() { }
|
|
|
|
protected void NextProcess(LaunchRequester lr)
|
|
{
|
|
if (nextProcessor != null)
|
|
{
|
|
nextProcessor.Process(lr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 包内版本号大于热更目录的版本号说明更了新包
|
|
/// </summary>
|
|
public bool IsPersistentLessThanPackageVersion(string packageVersion, string persistentVersion)
|
|
{
|
|
if (string.IsNullOrEmpty(persistentVersion) || string.IsNullOrEmpty(packageVersion))
|
|
{
|
|
return false;
|
|
}
|
|
var persistentNums = persistentVersion.Split('.');
|
|
var packageNums = packageVersion.Split('.');
|
|
if (persistentNums.Length < 3 || packageNums.Length < 3)
|
|
{
|
|
return false;
|
|
}
|
|
var persistentNums1 = int.Parse(persistentNums[0]);
|
|
var packageNums1 = int.Parse(packageNums[0]);
|
|
if(persistentNums1 < packageNums1)
|
|
{
|
|
return false;
|
|
}
|
|
else if(persistentNums1 == packageNums1)
|
|
{
|
|
if(int.Parse(persistentNums[1]) < int.Parse(packageNums[1]))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 低于最低要求版本则需强更
|
|
/// </summary>
|
|
public bool IsClientBiggerThanMinVersion(string minVersion, string clientVersion)
|
|
{
|
|
if (string.IsNullOrEmpty(minVersion) || string.IsNullOrEmpty(clientVersion))
|
|
{
|
|
return false;
|
|
}
|
|
var minNums = minVersion.Split('.');
|
|
var clientNums = clientVersion.Split('.');
|
|
if (minNums.Length < 3 || clientNums.Length < 3)
|
|
{
|
|
return false;
|
|
}
|
|
var clientNums1 = int.Parse(clientNums[0]);
|
|
var minNums1 = int.Parse(minNums[0]);
|
|
if(clientNums1 < minNums1)
|
|
{
|
|
return false;
|
|
}
|
|
else if(clientNums1 == minNums1)
|
|
{
|
|
if(int.Parse(clientNums[1]) < int.Parse(minNums[1]))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 低于推荐版本则提示更新
|
|
/// </summary>
|
|
public bool IsClientBiggerThanLatestVersion(string latestVersion, string clientVersion)
|
|
{
|
|
if (string.IsNullOrEmpty(latestVersion) || string.IsNullOrEmpty(clientVersion))
|
|
{
|
|
return true;
|
|
}
|
|
var latestNums = latestVersion.Split('.');
|
|
var clientNums = clientVersion.Split('.');
|
|
if (latestNums.Length < 3 || clientNums.Length < 3)
|
|
{
|
|
return true;
|
|
}
|
|
var clientNums1 = int.Parse(clientNums[0]);
|
|
var latestNums1 = int.Parse(latestNums[0]);
|
|
if (clientNums1 < latestNums1)
|
|
{
|
|
return false;
|
|
}
|
|
else if (clientNums1 == latestNums1)
|
|
{
|
|
if (int.Parse(clientNums[1]) < int.Parse(latestNums[1]))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected string GetFileMD5(string filePath)
|
|
{
|
|
return GameLaunchUtils.GetFileMD5(filePath);
|
|
}
|
|
|
|
protected string GetFileMD5(byte[] content)
|
|
{
|
|
return GameLaunchUtils.GetFileMD5(content);
|
|
}
|
|
|
|
protected void GetBytesAsync(string path, Action<byte[]> onComplete)
|
|
{
|
|
byte[] result;
|
|
#if UNITY_EDITOR || UNITY_IOS
|
|
result = File.ReadAllBytes(path);
|
|
onComplete(result);
|
|
#elif UNITY_ANDROID
|
|
BFMain.Instance.WebRequestMgr.Get(path, (EDownloadCode code, UnityEngine.Networking.UnityWebRequest request) => {
|
|
if (code == EDownloadCode.SUCCESS)
|
|
{
|
|
result = request.downloadHandler.data;
|
|
onComplete(result);
|
|
}
|
|
else
|
|
{
|
|
onComplete(null);
|
|
Debug.LogWarning("GetBytesAsync Failed " + request.responseCode);
|
|
}
|
|
});
|
|
#endif
|
|
}
|
|
|
|
protected void QuitGame()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
}
|
|
} |