【配置】打包和同步校验服修改到配置文件工程中

dev_chengFeng
gaoxin 2021-09-17 19:22:45 +08:00
parent cb4c81b420
commit 071e7db748
3 changed files with 124 additions and 68 deletions

View File

@ -4,36 +4,30 @@ using System.IO;
using System;
using GameEditor.FrameTool;
using GameEditor.Util;
using System.Collections;
using System.Collections.Generic;
public class PackConfig
{
public string name;
public string scene;
public string project;
public string version;
public string bench;
public PackConfig(string _name, string _scene, string _project, string _version, string _bench)
{
name = _name;
scene = _scene;
project = _project;
version= _version;
bench = _bench;
}
}
public class AutoPack : EditorWindow
{
static string[][] PackConfig = new string[][]
{
// 内网包
new string[]{ "内网包", "Logo_gm_nosdk", "TCX_LOCAL", "china/local"},
// 专服
new string[]{ "C轮v2", "Logo_gm_nosdk", "TCX_TEST_C_V2", "china/zf_test"},
new string[]{ "灵动专服-测试", "Logo_gn_zf_test", "MHT_GN_ZF_TEST" , "china/zf_test"},
new string[]{ "灵动专服-正式1", "Logo_gn_zf_release", "MHT_GN_ZF_RELEASE" , "china/zf_test"},
new string[]{ "灵动专服-正式2", "Logo_gn_zf_release", "MHT_GN_ZF_RELEASE2" , "china/zf_test"},
new string[]{ "灵动专服-正式3", "Logo_gn_zf_release", "MHT_GN_ZF_RELEASE3" , "china/zf_test"},
new string[]{ "喜扑", "Logo_cn_xipu", "MHT_CN_XIPU", "china/zf_test"},
new string[]{ "草花", "Logo_cn_caohua", "MHT_CN_MIDDLE_WARE" , "china/zf_test"},
new string[]{ "游心", "Logo_cn_youxin", "MHT_CN_YOUXIN", "china/zf_test"},
new string[]{ "动游", "Logo_cn_dongyou", "MHT_CN_DONGYOU", "china/zf_test"},
new string[]{ "渠道-MHT", "Logo_gn_zf_quick", "MHT_GN_ZF_QUICK", "china/zf_test"},
new string[]{ "渠道-Quick", "Logo_cn_quick", "MHT_CN_QUICK" , "china/zf_test"},
// 灵动商务
new string[]{ "灵动商务", "Logo_mht_sw", "MHT_GN_SW" , "china/mht_sw"},
//先遣
new string[]{ "跨服", "LogoChinaXQCS", "MHT_GN_KUAFU", "china/xq"},
new string[]{ "先遣-测试", "LogoChinaXQCS", "MHT_GN_XQ_TEST", "china/xq"},
new string[]{ "先遣", "LogoChinaXQ", "MHT_GN_XQ", "china/xq"},
};
static List<PackConfig> PackConfig = new List<PackConfig>();
#if UNITY_ANDROID
static string Platform = "Android";
@ -77,7 +71,25 @@ public class AutoPack : EditorWindow
ScenePath = Application.dataPath + "/LuaFramework/Scenes/";
ABPath = Application.dataPath + "/../BuildABs/" + Platform + "/";
ExportType = 2;
Chooser = new bool[PackConfig.Length];
// 加载配置
LoadConfig();
}
static void LoadConfig()
{
Hashtable config = ClientConfigManager.Instance.GetAutoPackConfig();
foreach (string k in config.Keys)
{
Hashtable ht = config[k] as Hashtable;
string name = k;
string scene = ht["scene"] as string;
string project = ht["project"] as string;
string version = ht["version"] as string;
string bench = ht["bench"] as string;
PackConfig.Add(new PackConfig(name, scene, project, version, bench));
}
Chooser = new bool[PackConfig.Count];
}
/// <summary>
@ -139,31 +151,31 @@ public class AutoPack : EditorWindow
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.LabelField("请选择要打的包:");
for(int i = 0; i < PackConfig.Length; i++)
for(int i = 0; i < PackConfig.Count; i++)
{
if (PackConfig[i][3].Equals(benchName))
if (PackConfig[i].bench.Equals(benchName))
{
EditorGUILayout.BeginVertical();
Chooser[i] = EditorGUILayout.ToggleLeft(PackConfig[i][0], Chooser[i]);
Chooser[i] = EditorGUILayout.ToggleLeft(PackConfig[i].name, Chooser[i]);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("编辑Config", GUILayout.Height(20f)))
{
string tpath = _MomPackPath + PackConfig[i][2] + "/Config/" + ConfigFileName;
string tpath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[i].version + "/" + ConfigFileName;
GameEditor.Util.ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("编辑Version", GUILayout.Height(20f)))
{
string tpath = _MomPackPath + PackConfig[i][2] + "/Config/" + VersionFileName;
string tpath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[i].version + "/" + VersionFileName;
GameEditor.Util.ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("编辑Gradle", GUILayout.Height(20f)))
{
string tpath = _MomPackPath + PackConfig[i][2] + "/build.gradle";
string tpath = _MomPackPath + PackConfig[i].project + "/build.gradle";
GameEditor.Util.ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("更新蓝鲸SDK", GUILayout.Height(20f)))
{
File.Copy(_MomPackPath + "BlueWhaleJar/app/build/outputs/aar/app-release.aar", _MomPackPath + PackConfig[i][2] + "/libs/BlueWhale.aar", true);
File.Copy(_MomPackPath + "BlueWhaleJar/app/build/outputs/aar/app-release.aar", _MomPackPath + PackConfig[i].project + "/libs/BlueWhale.aar", true);
Debug.Log("更新完成");
}
EditorGUILayout.EndHorizontal();
@ -197,16 +209,16 @@ public class AutoPack : EditorWindow
for (int i = 0; i < Chooser.Length; i++)
{
if (!Chooser[i]) continue;
string sceneFilePath = ScenePath + PackConfig[i][1];
string sceneFilePath = ScenePath + PackConfig[i].scene;
if (!File.Exists(sceneFilePath + ".unity"))
{
Debug.LogError(PackConfig[i][0] + " 未找到场景:" + sceneFilePath);
Debug.LogError(PackConfig[i].name + " 未找到场景:" + sceneFilePath);
check_result = true;
}
string momPath = _MomPackPath + PackConfig[i][2];
string momPath = _MomPackPath + PackConfig[i].project;
if (!Directory.Exists(momPath))
{
Debug.LogError(PackConfig[i][0] + " 未找到母包:" + momPath);
Debug.LogError(PackConfig[i].name + " 未找到母包:" + momPath);
check_result = true;
}
}
@ -252,7 +264,7 @@ public class AutoPack : EditorWindow
public static void CreateLogFile(int index)
{
APKPath = _MomPackPath + PackConfig[index][2] + "/APK/";
APKPath = _MomPackPath + PackConfig[index].project + "/APK/";
if (!Directory.Exists(APKPath))
{
Directory.CreateDirectory(APKPath);
@ -268,7 +280,7 @@ public class AutoPack : EditorWindow
// 导出android 工程
public static void ExportAS(int index)
{
string pName = PackConfig[index][1] + "__" + PackConfig[index][2];
string pName = PackConfig[index].scene + "__" + PackConfig[index].project;
PlayerSettings.productName = pName;
PlayerSettings.Android.useAPKExpansionFiles = isObb;
if (isObb)
@ -287,8 +299,8 @@ public class AutoPack : EditorWindow
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
// 设置需要打包的场景
string launchScene = "Assets/LuaFramework/Scenes/" + PackConfig[index][1] + ".unity";
Debug.Log(PackConfig[index][0] + ":打包场景:" + launchScene);
string launchScene = "Assets/LuaFramework/Scenes/" + PackConfig[index].scene + ".unity";
Debug.Log(PackConfig[index].name + ":打包场景:" + launchScene);
BuildPlayerOptions bpo = new BuildPlayerOptions();
bpo.locationPathName = ExportPackPath;
bpo.options = BuildOptions.None;
@ -297,8 +309,8 @@ public class AutoPack : EditorWindow
bpo.target = BuildTarget.Android;
// 调用开始打包
BuildPipeline.BuildPlayer(bpo);
Debug.Log(PackConfig[index][0] + "android工程导出路径" + ExportPackPath + "/" + pName);
Debug.Log(PackConfig[index][0] + "android工程导出完成");
Debug.Log(PackConfig[index].name + "android工程导出路径" + ExportPackPath + "/" + pName);
Debug.Log(PackConfig[index].name + "android工程导出完成");
}
static string[] ReplaceDir = new string[]
@ -314,8 +326,8 @@ public class AutoPack : EditorWindow
// 从工程中替换
private static void ReplaceFromProject(int index)
{
string fromPath = ExportPackPath + "/" + PackConfig[index][1] + "__" + PackConfig[index][2];
string toPath = _MomPackPath + PackConfig[index][2];
string fromPath = ExportPackPath + "/" + PackConfig[index].scene + "__" + PackConfig[index].project;
string toPath = _MomPackPath + PackConfig[index].project;
for (int i = 0; i < ReplaceDir.Length; i++)
{
string dir = ReplaceDir[i];
@ -336,13 +348,13 @@ public class AutoPack : EditorWindow
});
EditorUtility.ClearProgressBar();
}
Debug.Log(PackConfig[index][0] + ":母包工程资源替换完成");
Debug.Log(PackConfig[index].name + ":母包工程资源替换完成");
// 替换build-id
EditorUtility.DisplayProgressBar("重写AndroidManifest", "", 0.5f);
RewriteManifest(fromPath + "/src/main/AndroidManifest.xml", toPath + "/src/main/AndroidManifest.xml");
Debug.Log(PackConfig[index][0] + "母包Manifest修改完成");
Debug.Log(PackConfig[index].name + "母包Manifest修改完成");
EditorUtility.ClearProgressBar();
}
private static void RewriteManifest(string f, string t)
@ -389,7 +401,7 @@ public class AutoPack : EditorWindow
// 从AB包替换
private static void ReplaceFromAB(int index)
{
string toPath = _MomPackPath + PackConfig[index][2] + "/src/main/assets/Android";
string toPath = _MomPackPath + PackConfig[index].project + "/src/main/assets/Android";
if (Directory.Exists(toPath)) Directory.Delete(toPath, true);
Directory.CreateDirectory(toPath);
GameCore.FileUtils.ReplaceDir(ABPath, toPath, (string dirName, string fileName, float progress) =>
@ -397,18 +409,23 @@ public class AutoPack : EditorWindow
EditorUtility.DisplayProgressBar("正在复制:" + dirName, fileName, progress);
});
EditorUtility.ClearProgressBar();
Debug.Log(PackConfig[index][0] + "替换AB包完成");
Debug.Log(PackConfig[index].name + "替换AB包完成");
}
// 替换配置文件
private static void ReplaceConfigAndVersion(int index)
{
EditorUtility.DisplayProgressBar("替换配置文件", "", 0.5f);
string toPath = _MomPackPath + PackConfig[index][2] + "/src/main/assets/Android/";
string fromPath = _MomPackPath + PackConfig[index][2] + "/Config/";
EditorUtility.DisplayProgressBar("替换配置文件1", "", 0.5f);
string fromPath = ClientConfigManager.Instance.GetClientConfigPath() + "/Version/" + PackConfig[index].version + "/";
string toPath = _MomPackPath + PackConfig[index].project + "/Config/";
File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true);
File.Copy(fromPath + VersionFileName, toPath + VersionFileName, true);
Debug.Log(PackConfig[index][0]+":配置文件替换完成");
EditorUtility.DisplayProgressBar("替换配置文件2", "", 0.5f);
fromPath = toPath;
toPath = _MomPackPath + PackConfig[index].project + "/src/main/assets/Android/";
File.Copy(fromPath + ConfigFileName, toPath + ConfigFileName, true);
File.Copy(fromPath + VersionFileName, toPath + VersionFileName, true);
Debug.Log(PackConfig[index].name+":配置文件替换完成");
EditorUtility.ClearProgressBar();
}
@ -416,17 +433,17 @@ public class AutoPack : EditorWindow
private static void StartGradleBuild(int index)
{
EditorUtility.DisplayProgressBar("正在生成APK", "", 0f);
GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], "gradlew assembleRelease>>" + APKPath + "/_log.txt");
GameEditor.Util.ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index].project, "gradlew assembleRelease>>" + APKPath + "/_log.txt");
EditorUtility.DisplayProgressBar("正在导出APK", "", 1f);
string versionStr = GetAPKVersionStr(PackConfig[index][2]);
string apkFilePath = _MomPackPath + PackConfig[index][2] + "/build/outputs/apk/release/" + PackConfig[index][2] + "-release.apk";
string versionStr = GetAPKVersionStr(PackConfig[index].project);
string apkFilePath = _MomPackPath + PackConfig[index].project + "/build/outputs/apk/release/" + PackConfig[index].project + "-release.apk";
if (File.Exists(apkFilePath))
{
File.Copy(apkFilePath, APKPath + "/" + PackConfig[index][0] +"_"+ PackConfig[index][2] + "_" + versionStr + "_" + PackTime + ".apk");
File.Copy(apkFilePath, APKPath + "/" + PackConfig[index].name +"_"+ PackConfig[index].project + "_" + versionStr + "_" + PackTime + ".apk");
}
Debug.Log(PackConfig[index][0] + ":打包完成");
Debug.Log(PackConfig[index].name + ":打包完成");
EditorUtility.ClearProgressBar();
}
@ -460,17 +477,17 @@ public class AutoPack : EditorWindow
{
if (CommitToGit)
{
string versionStr = GetAPKVersionStr(PackConfig[index][2]);
string versionStr = GetAPKVersionStr(PackConfig[index].project);
EditorUtility.DisplayProgressBar("正在提交修改", "", 0f);
string printlog = ">>" + APKPath + "/_log.txt";
string[] commands = new string[]{
"echo git add ." + printlog,
"git add ." + printlog,
"echo git commit -m 'AutoPack" + PackConfig[index][0] +"_"+ PackConfig[index][2] + "_" + versionStr + "_" + PackTime + ".apk'" + printlog,
"git commit -m 'AutoPack" + PackConfig[index][0] +"_"+ PackConfig[index][2] + "_" + versionStr + "_" + PackTime + ".apk'" + printlog,
"echo git commit -m 'AutoPack" + PackConfig[index].name +"_"+ PackConfig[index].project + "_" + versionStr + "_" + PackTime + ".apk'" + printlog,
"git commit -m 'AutoPack" + PackConfig[index].name +"_"+ PackConfig[index].project + "_" + versionStr + "_" + PackTime + ".apk'" + printlog,
"git push",
};
ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index][2], commands);
ProcessUtil.ProcessCommand(_MomPackPath + PackConfig[index].project, commands);
EditorUtility.ClearProgressBar();
}

View File

@ -61,6 +61,31 @@ public class ClientConfigManager
return config;
}
// 获取打包工具配置文件
public Hashtable GetAutoPackConfig()
{
string hotfixConfig = localPath + "/AutoPack.txt";
Hashtable config = null;
if (File.Exists(hotfixConfig))
{
string s = File.ReadAllText(hotfixConfig);
config = MiniJSON.jsonDecode(s) as Hashtable;
}
return config;
}
// 获取校验服同步工程配置文件
public Hashtable GetFightServerConfig()
{
string hotfixConfig = localPath + "/FightServer.txt";
Hashtable config = null;
if (File.Exists(hotfixConfig))
{
string s = File.ReadAllText(hotfixConfig);
config = MiniJSON.jsonDecode(s) as Hashtable;
}
return config;
}
// 获取svn工程根目录路径
public string GetClientConfigPath()
{

View File

@ -1,6 +1,7 @@
using GameCore;
using GameEditor.Util;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@ -33,10 +34,8 @@ namespace GameEditor.Core.DataConfig
[MenuItem("Data Config/Export")]
private static void ShowConfigWin()
{
ServerBattleConfig.Clear();
ServerBattleConfig.Add("china/dev", "test");
ServerBattleConfig.Add("china/xq", "master_zh_test");
ServerBattleConfig.Add("china/zf_test", "master_zh_online_special");
// 加载配置文件
LoadConfig();
m_CurGitBench = GitUtil.GetCurBenchName();
ServerBattleConfig.TryGetValue(m_CurGitBench, out m_CurServerBattlePath);
@ -52,6 +51,21 @@ namespace GameEditor.Core.DataConfig
win.titleContent = new GUIContent("Export");
win.Show();
}
// 加载配置文件
static void LoadConfig()
{
ServerBattleConfig.Clear();
Hashtable config = ClientConfigManager.Instance.GetFightServerConfig();
foreach (string k in config.Keys)
{
Hashtable ht = config[k] as Hashtable;
string folder = ht["folder"] as string;
string bench = ht["bench"] as string;
XDebug.Log.l(folder, bench);
ServerBattleConfig.Add(bench, folder);
}
}
//提供给打包工具调用的一键导表接口
public static void PyCallBuildData()
{