using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using IFix.Core;
|
using UnityEngine;
|
|
/// <summary>
|
/// 脚本补丁加载器
|
/// </summary>
|
public class PatchLoader
|
{
|
private static List<AssetVersion> patchAssets;
|
|
//使用本地的版本文件加载,editor测试用
|
public static void InitLocalPatchAsset()
|
{
|
patchAssets = new List<AssetVersion>();
|
var path = StringUtility.Contact(ResourcesPath.Instance.StreamingAssetPath, "AssetsVersion.txt");
|
if (AssetSource.patchFromEditor || !File.Exists(path))
|
return;
|
var lines = File.ReadAllLines(path);
|
for (int i = 0; i < lines.Length; i++)
|
{
|
var assetVersion = new AssetVersion(lines[i]);
|
if (assetVersion.GetAssetCategory() == AssetVersion.AssetCategory.Patch)
|
patchAssets.Add(assetVersion);
|
}
|
}
|
|
//初始化补丁资源列表
|
public static void InitPatchAsset(List<AssetVersion> list)
|
{
|
patchAssets = list;
|
}
|
|
//加载补丁
|
public static void LoadPatch()
|
{
|
try
|
{
|
if (AssetSource.patchFromEditor)
|
{
|
if (!Directory.Exists(ResourcesPath.PATCH_EDITOR))
|
return;
|
var dic = new DirectoryInfo(ResourcesPath.PATCH_EDITOR);
|
foreach (var file in dic.GetFiles())
|
{
|
if (file.Exists)
|
{
|
PatchManager.Load(new FileStream(file.FullName, FileMode.Open));
|
DebugEx.LogFormat("已加载补丁:{0}", file.FullName);
|
}
|
}
|
return;
|
}
|
if (patchAssets == null)
|
return;
|
foreach (var asset in patchAssets)
|
{
|
var patchPath = AssetVersionUtility.GetAssetFilePath(asset.relativePath);
|
if (File.Exists(patchPath))
|
{
|
PatchManager.Load(new FileStream(patchPath, FileMode.Open));
|
DebugEx.LogFormat("已加载补丁:{0}", patchPath);
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
DebugEx.LogError(e);
|
}
|
}
|
|
}
|