dev_chengFeng
zhangshanxue 2021-12-01 21:32:16 +08:00
parent 6a817f1b01
commit 2d73b2d13a
4 changed files with 119 additions and 63 deletions

View File

@ -241,6 +241,7 @@ public class AutoPack : EditorWindow
ExportAS(i);
ReplaceFromProject(i);
ReplaceConfigAndVersion(i);
EncryptAB(i);
GitUpdate(i);
CreateLogFile(i);
StartGradleBuild(i);
@ -249,6 +250,7 @@ public class AutoPack : EditorWindow
case 1: // 只替换AB
ReplaceFromAB(i);
ReplaceConfigAndVersion(i);
EncryptAB(i);
GitUpdate(i);
CreateLogFile(i);
StartGradleBuild(i);
@ -416,6 +418,34 @@ public class AutoPack : EditorWindow
Debug.Log(PackConfig[index].name + "替换AB包完成");
}
// 加密AB包
private static void EncryptAB(int index)
{
string toPath = _MomPackPath + PackConfig[index].project + "/src/main/assets/Android";
string json = File.ReadAllText(toPath + "/"+ VersionFileName);
VersionTxt version = JsonUtility.FromJson<VersionTxt>(json);
if (version.EncyptKey != null && version.EncyptKey != "")
{
string[] pathList = Directory.GetFiles(toPath, "*.unity3d", SearchOption.AllDirectories);
float i = 0f;
Debug.Log("文件数量;" + pathList.Length);
foreach (string path in pathList)
{
GameLogic.MEncyptUtil.EncyptAB(path, version.EncyptKey);
EditorUtility.DisplayProgressBar("正在加密:", path, i++ / pathList.Length);
}
EditorUtility.ClearProgressBar();
Debug.Log(PackConfig[index].name + "加密AB包完成");
}
else {
Debug.Log(PackConfig[index].name + ":无需加密");
}
}
// 替换配置文件
private static void ReplaceConfigAndVersion(int index)
{

View File

@ -43,7 +43,7 @@ namespace GameLogic {
if (key == null || key == "")
{
rb = crypt(data, key);
rb = data;
}
else {
rb = crypt(data, key);
@ -55,41 +55,62 @@ namespace GameLogic {
}
return r;
}
[MenuItem("Build/TEST")]
static void load()
// 文件加密
public static void EncyptAB(string path, string key)
{
byte[] a = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
string s = "";
for(int i = 0;i < a.Length; i++)
// 闪屏先不加密了
if (Path.GetFileName(path).Equals("splashpanel.unity3d"))
{
s += a[i];
return;
}
XDebug.Log.l("a = " + s);
byte[] b = crypt(a, "key");
s = "";
for (int i = 0; i < b.Length; i++)
if (key == null || key == "")
{
s += b[i];
return;
}
XDebug.Log.l("b = " + s);
byte[] c = crypt(b, "key");
s = "";
for (int i = 0; i < c.Length; i++)
if (!File.Exists(path))
{
s += c[i];
return;
}
byte[] data = File.ReadAllBytes(path);
byte[] rb = crypt(data, key);
File.WriteAllBytes(path, rb);
}
XDebug.Log.l("c = " + s);
//File.ReadAllBytes("");
}
//[MenuItem("Build/TEST")]
//static void load()
//{
// byte[] a = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
// string s = "";
// for(int i = 0;i < a.Length; i++)
// {
// s += a[i];
// }
// XDebug.Log.l("a = " + s);
// byte[] b = crypt(a, "key");
// s = "";
// for (int i = 0; i < b.Length; i++)
// {
// s += b[i];
// }
// XDebug.Log.l("b = " + s);
// byte[] c = crypt(b, "key");
// s = "";
// for (int i = 0; i < c.Length; i++)
// {
// s += c[i];
// }
// XDebug.Log.l("c = " + s);
// //File.ReadAllBytes("");
//}
}
}

View File

@ -248,6 +248,7 @@ namespace GameEditor.FrameTool {
public string packageVersion;
public string version;
public string serverUrl;
public string EncyptKey;
//public string noticeChannel;
}

View File

@ -56,13 +56,10 @@ namespace GameEditor.FrameTool
}
//遍历内部unity3d数据
public static List<ResourceFile> GetFilesList(string filesPath)
public static List<ResourceFile> GetFilesList(string filesPath, string encryptKey = null)
{
if(!File.Exists(filesPath + UpdateConfigs.FILES))
{
return null;
}
UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromFile(filesPath + UpdateConfigs.FILES);
//UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromFile(filesPath + UpdateConfigs.FILES);
UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromMemory(GameLogic.MEncyptUtil.DecyptAB(File.ReadAllBytes(filesPath + UpdateConfigs.FILES), encryptKey, 0));
ResourceFiles files = bundle.LoadAsset<ResourceFiles>("game");
bundle.Unload(true);
return files.files;
@ -73,8 +70,6 @@ namespace GameEditor.FrameTool
{
List<ResourceFile> diffList = new List<ResourceFile>();
Dictionary<string, ResourceFile> exDataDic = new Dictionary<string, ResourceFile>();
if (exDataList != null)
{
for (int i = 0; i < exDataList.Count; i++)
{
if (!exDataDic.ContainsKey(exDataList[i].fileName))
@ -86,11 +81,7 @@ namespace GameEditor.FrameTool
exDataDic[exDataList[i].fileName] = exDataList[i];
}
}
} else {
XDebug.Log.error("exDataList is null!!!");
}
if(inDataList != null)
{
for (int i = 0; i < inDataList.Count; i++)
{
if (!exDataDic.ContainsKey(inDataList[i].fileName))
@ -105,11 +96,6 @@ namespace GameEditor.FrameTool
}
}
}
}
else
{
XDebug.Log.error("inDataList is null!!!");
}
return diffList;
}
@ -262,7 +248,7 @@ namespace GameEditor.FrameTool
LoadCDN();
// 计算差异文件
local_cdn_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(local_files_path), HotFixTool.GetFilesList(cdn_files_path));
local_cdn_list = HotFixTool.GetDiffList(HotFixTool.GetFilesList(local_files_path), HotFixTool.GetFilesList(cdn_files_path, local_version.EncyptKey));
// 计算大小
local_cdn_size = HotFixTool.GetDiffSize(local_cdn_list);
@ -343,6 +329,24 @@ namespace GameEditor.FrameTool
}
changeFile.Add(UpdateConfigs.FILES);
log.Add(UpdateConfigs.FILES);
// 复制热更文件
string cpPath = path_cdn_setting + "/" + AppConst.PlatformPath + "/";
int fileIndex = 0;
foreach (string file in changeFile)
{
EditorUtility.DisplayProgressBar("正在复制热更文件:", file, fileIndex++/changeFile.Count);
string dirName = Path.GetDirectoryName(cpPath + file);
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}
File.Copy(local_files_path + file, cpPath + file, true);
if (local_version.EncyptKey != null && local_version.EncyptKey != "")
{
MEncyptUtil.EncyptAB(cpPath + file, local_version.EncyptKey);
}
}
// write ChangeList
EditorUtility.DisplayProgressBar("正在生成文件变化列表", changeFileName, 1f);
HotFixTool.WriteLog(logPath, changeFileName, changeFile.ToArray());