encrypt
parent
6a817f1b01
commit
2d73b2d13a
|
@ -241,6 +241,7 @@ public class AutoPack : EditorWindow
|
||||||
ExportAS(i);
|
ExportAS(i);
|
||||||
ReplaceFromProject(i);
|
ReplaceFromProject(i);
|
||||||
ReplaceConfigAndVersion(i);
|
ReplaceConfigAndVersion(i);
|
||||||
|
EncryptAB(i);
|
||||||
GitUpdate(i);
|
GitUpdate(i);
|
||||||
CreateLogFile(i);
|
CreateLogFile(i);
|
||||||
StartGradleBuild(i);
|
StartGradleBuild(i);
|
||||||
|
@ -249,6 +250,7 @@ public class AutoPack : EditorWindow
|
||||||
case 1: // 只替换AB
|
case 1: // 只替换AB
|
||||||
ReplaceFromAB(i);
|
ReplaceFromAB(i);
|
||||||
ReplaceConfigAndVersion(i);
|
ReplaceConfigAndVersion(i);
|
||||||
|
EncryptAB(i);
|
||||||
GitUpdate(i);
|
GitUpdate(i);
|
||||||
CreateLogFile(i);
|
CreateLogFile(i);
|
||||||
StartGradleBuild(i);
|
StartGradleBuild(i);
|
||||||
|
@ -416,6 +418,34 @@ public class AutoPack : EditorWindow
|
||||||
Debug.Log(PackConfig[index].name + ":替换AB包完成");
|
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)
|
private static void ReplaceConfigAndVersion(int index)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace GameLogic {
|
||||||
|
|
||||||
if (key == null || key == "")
|
if (key == null || key == "")
|
||||||
{
|
{
|
||||||
rb = crypt(data, key);
|
rb = data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb = crypt(data, key);
|
rb = crypt(data, key);
|
||||||
|
@ -55,41 +55,62 @@ namespace GameLogic {
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
// 文件加密
|
||||||
|
public static void EncyptAB(string path, string key)
|
||||||
[MenuItem("Build/TEST")]
|
|
||||||
static void load()
|
|
||||||
{
|
{
|
||||||
byte[] a = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
|
// 闪屏先不加密了
|
||||||
string s = "";
|
if (Path.GetFileName(path).Equals("splashpanel.unity3d"))
|
||||||
for(int i = 0;i < a.Length; i++)
|
|
||||||
{
|
{
|
||||||
s += a[i];
|
return;
|
||||||
}
|
}
|
||||||
XDebug.Log.l("a = " + s);
|
if (key == null || key == "")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
byte[] b = crypt(a, "key");
|
|
||||||
s = "";
|
|
||||||
for (int i = 0; i < b.Length; i++)
|
|
||||||
{
|
{
|
||||||
s += b[i];
|
return;
|
||||||
}
|
}
|
||||||
XDebug.Log.l("b = " + s);
|
if (!File.Exists(path))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
byte[] c = crypt(b, "key");
|
|
||||||
s = "";
|
|
||||||
for (int i = 0; i < c.Length; i++)
|
|
||||||
{
|
{
|
||||||
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("");
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -248,6 +248,7 @@ namespace GameEditor.FrameTool {
|
||||||
public string packageVersion;
|
public string packageVersion;
|
||||||
public string version;
|
public string version;
|
||||||
public string serverUrl;
|
public string serverUrl;
|
||||||
|
public string EncyptKey;
|
||||||
//public string noticeChannel;
|
//public string noticeChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,10 @@ namespace GameEditor.FrameTool
|
||||||
}
|
}
|
||||||
|
|
||||||
//遍历内部unity3d数据
|
//遍历内部unity3d数据
|
||||||
public static List<ResourceFile> GetFilesList(string filesPath)
|
public static List<ResourceFile> GetFilesList(string filesPath, string encryptKey = null)
|
||||||
{
|
{
|
||||||
if(!File.Exists(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));
|
||||||
return null;
|
|
||||||
}
|
|
||||||
UnityEngine.AssetBundle bundle = UnityEngine.AssetBundle.LoadFromFile(filesPath + UpdateConfigs.FILES);
|
|
||||||
ResourceFiles files = bundle.LoadAsset<ResourceFiles>("game");
|
ResourceFiles files = bundle.LoadAsset<ResourceFiles>("game");
|
||||||
bundle.Unload(true);
|
bundle.Unload(true);
|
||||||
return files.files;
|
return files.files;
|
||||||
|
@ -73,8 +70,6 @@ namespace GameEditor.FrameTool
|
||||||
{
|
{
|
||||||
List<ResourceFile> diffList = new List<ResourceFile>();
|
List<ResourceFile> diffList = new List<ResourceFile>();
|
||||||
Dictionary<string, ResourceFile> exDataDic = new Dictionary<string, ResourceFile>();
|
Dictionary<string, ResourceFile> exDataDic = new Dictionary<string, ResourceFile>();
|
||||||
if (exDataList != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < exDataList.Count; i++)
|
for (int i = 0; i < exDataList.Count; i++)
|
||||||
{
|
{
|
||||||
if (!exDataDic.ContainsKey(exDataList[i].fileName))
|
if (!exDataDic.ContainsKey(exDataList[i].fileName))
|
||||||
|
@ -86,11 +81,7 @@ namespace GameEditor.FrameTool
|
||||||
exDataDic[exDataList[i].fileName] = exDataList[i];
|
exDataDic[exDataList[i].fileName] = exDataList[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
XDebug.Log.error("exDataList is null!!!");
|
|
||||||
}
|
|
||||||
if(inDataList != null)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < inDataList.Count; i++)
|
for (int i = 0; i < inDataList.Count; i++)
|
||||||
{
|
{
|
||||||
if (!exDataDic.ContainsKey(inDataList[i].fileName))
|
if (!exDataDic.ContainsKey(inDataList[i].fileName))
|
||||||
|
@ -105,11 +96,6 @@ namespace GameEditor.FrameTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
XDebug.Log.error("inDataList is null!!!");
|
|
||||||
}
|
|
||||||
return diffList;
|
return diffList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +248,7 @@ namespace GameEditor.FrameTool
|
||||||
LoadCDN();
|
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);
|
local_cdn_size = HotFixTool.GetDiffSize(local_cdn_list);
|
||||||
|
@ -343,6 +329,24 @@ namespace GameEditor.FrameTool
|
||||||
}
|
}
|
||||||
changeFile.Add(UpdateConfigs.FILES);
|
changeFile.Add(UpdateConfigs.FILES);
|
||||||
log.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
|
// write ChangeList
|
||||||
EditorUtility.DisplayProgressBar("正在生成文件变化列表", changeFileName, 1f);
|
EditorUtility.DisplayProgressBar("正在生成文件变化列表", changeFileName, 1f);
|
||||||
HotFixTool.WriteLog(logPath, changeFileName, changeFile.ToArray());
|
HotFixTool.WriteLog(logPath, changeFileName, changeFile.ToArray());
|
||||||
|
|
Loading…
Reference in New Issue