【热更新】修改热更新配置文件

dev_chengFeng
gaoxin 2021-09-07 18:02:40 +08:00
parent 19e83da85c
commit e04cb9cdb8
2 changed files with 58 additions and 111 deletions

View File

@ -3,6 +3,8 @@ using System.IO;
using UnityEngine;
using UnityEditor;
using GameEditor.Util;
using System.Collections;
public class ClientConfigManager
{
@ -25,6 +27,7 @@ public class ClientConfigManager
private string svnPath = "svn://60.1.1.230/jieling/ClientConfig";
private string localPath = Application.dataPath + "/../ClientConfig";
// 更新svn
public void SVN_Update()
{
if (!Directory.Exists(localPath))
@ -35,6 +38,7 @@ public class ClientConfigManager
ProcessUtil.ProcessCommand(localPath, "svn update");
}
// 获取所有的version文件列表
public string[] GetVersionList()
{
string versionPath = localPath + "/Version";
@ -42,4 +46,25 @@ public class ClientConfigManager
Debug.LogError(list.Length);
return list;
}
// 获取热更新用的配置文件
public Hashtable GetHotFixConfig()
{
string hotfixConfig = localPath + "/HotFixWindow.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()
{
return localPath;
}
}

View File

@ -109,6 +109,7 @@ namespace GameEditor.FrameTool
return size / 1048576;
}
// 写入log
public static void WriteLog(string path, string name, string[] contents)
{
@ -126,6 +127,14 @@ namespace GameEditor.FrameTool
//}
File.WriteAllLines(filePath, contents);
}
// 复制version和config文件
public static void CopyVersionAndConfig(string oPath, string tPath)
{
File.Copy(Path.Combine(oPath, AppConst.GameVersionFile), Path.Combine(tPath, AppConst.GameVersionFile), true);
File.Copy(Path.Combine(oPath, AppConst.GameConfigFile), Path.Combine(tPath, AppConst.GameConfigFile), true);
}
}
class HotFixConfig
@ -155,9 +164,9 @@ namespace GameEditor.FrameTool
}
// 添加配置文件夹
public void AddSetting(string _desc, string _dir_name, string _dir_cdn_setting)
public void AddSetting(string _desc, string _dir_name, string _dir_cdn_setting, string _svn_version)
{
hotFixSettings.Add(new HotFixSetting(_desc, _dir_name, _dir_cdn_setting));
hotFixSettings.Add(new HotFixSetting(_desc, _dir_name, _dir_cdn_setting, _svn_version));
}
// 计算本地到工程的大小
@ -199,6 +208,7 @@ namespace GameEditor.FrameTool
public string cdn_files_path = "";
public string project_files_path = "";
public string local_files_path = "";
public string svn_version_path = "";
public decimal local_cdn_size = 0; // git与cdn比较 热更文件的文件大小
public List<ResourceFile> local_cdn_list; // git与cdn比较 热更文件列表
@ -207,11 +217,12 @@ namespace GameEditor.FrameTool
public VersionTxt cdn_version;
public Hashtable cdn_setting;
public HotFixSetting(string _desc, string _dir_name, string _dir_cdn_setting)
public HotFixSetting(string _desc, string _dir_name, string _dir_cdn_setting, string _svn_version_name)
{
desc = _desc;
dir_name = _dir_name;
dir_cdn_setting = _dir_cdn_setting;
svn_version_path = ClientConfigManager.Instance.GetClientConfigPath() +"/Version/"+ _svn_version_name + "/";
path_cdn_setting = HotfixWindow._HotFixProjectPath + "/Root/" + dir_name + "/" + dir_cdn_setting + "/";
isCalSize = false;
}
@ -263,7 +274,7 @@ namespace GameEditor.FrameTool
public void LoadLocalVersion()
{
// 读取version文件
string json = File.ReadAllText(path_cdn_setting + AppConst.GameVersionFile);
string json = File.ReadAllText(svn_version_path + AppConst.GameVersionFile);
local_version = JsonUtility.FromJson<VersionTxt>(json);
}
@ -295,6 +306,9 @@ namespace GameEditor.FrameTool
// UnityEngine.Debug.Log("未检测到文件改动");
// return;
//}
//
// 拷贝新的version和config文件
HotFixTool.CopyVersionAndConfig(svn_version_path, path_cdn_setting);
// 初始化数据
updateName = dir_name + "_" + dir_cdn_setting + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
changeFileName = updateName.Replace("/", "_");
@ -351,6 +365,9 @@ namespace GameEditor.FrameTool
ProcessUtil.ProcessCommand(path_cdn_setting, "git add .");
ProcessUtil.ProcessCommand(path_cdn_setting, "git commit -m " + commitName);
ProcessUtil.ProcessCommand(path_cdn_setting, "git push");
EditorUtility.DisplayProgressBar("正在提交到SVN", commitName, 1f);
ProcessUtil.ProcessCommand(svn_version_path, "svn add .");
ProcessUtil.ProcessCommand(svn_version_path, "svn commit -m " + commitName);
// git tag
string dir = Application.dataPath.Replace("/Assets", "");
ProcessUtil.ProcessCommand(dir, string.Format("git tag -a {0} -m {1}", tagName, commitName));
@ -366,32 +383,6 @@ namespace GameEditor.FrameTool
//看热更大小
public class HotfixWindow : EditorWindow
{
static string[][] _SettingConfig = new string[][]{
new string[]{ "C轮测试v2", "mht_china/local", "cdn_v2", "china/dev-c" },
new string[]{ "C轮测试v3", "mht_china/local", "cdn_v3", "china/dev-c" },
new string[]{ "灵动-专服-测试", "mht_china/zf", "cdn_mht_zf_test", "china/zf_test" },
new string[]{ "灵动-专服", "mht_china/zf", "cdn_mht_zf_release", "china/zf_test" },
new string[]{ "灵动-Quick", "mht_china/zf", "cdn_mht_zf_quick", "china/zf_test" },
new string[]{ "草花", "mht_china/zf", "cdn_caohua", "china/zf_test" },
new string[]{ "喜扑", "mht_china/zf", "cdn_xipu", "china/zf_test" },
new string[]{ "Quick", "mht_china/zf", "cdn_quick", "china/zf_test" },
new string[]{ "游心", "mht_china/zf", "cdn_youxin", "china/zf_test" },
new string[]{ "动游", "mht_china/zf", "cdn_dongyou", "china/zf_test" },
new string[]{ "灵动-IOS", "mht_china/zf", "cdn_ios", "china/ios" },
new string[]{ "灵动-商务", "mht_china/sw", "cdn_mht_sw", "china/mht_sw" },
new string[]{ "先遣-内网", "mht_china/local", "local12_cn_local", "china/local" },
new string[]{ "先遣-测试跨服", "mht_china/kf", "cdn_xq_kf", "china/test" },
new string[]{ "先遣-测试", "mht_china/xq", "cdn_xq_test", "china/test" },
new string[]{ "先遣-正式", "mht_china/xq", "cdn_xq_release", "china/test" },
};
static Dictionary<string, HotFixConfig> _HotFixConfigDic = new Dictionary<string, HotFixConfig>();
static string benchName = "";
public static string _HotFixProjectPath;
@ -422,12 +413,16 @@ namespace GameEditor.FrameTool
{
_IsGitPull = false;
_HotFixConfigDic.Clear();
foreach (string[] sc in _SettingConfig)
Hashtable config = ClientConfigManager.Instance.GetHotFixConfig();
foreach (string k in config.Keys)
{
string desc = sc[0];
string folder = sc[1];
string setting = sc[2];
string bench = sc[3];
Hashtable ht = config[k] as Hashtable;
string desc = k;
string folder = ht["folder"] as string;
string setting = ht["setting"] as string;
string version = ht["version"] as string;
string bench = ht["bench"] as string;
XDebug.Log.l(desc, folder, setting, version, bench, bench.Equals(benchName));
if (bench.Equals(benchName))
{
HotFixConfig hfc;
@ -437,7 +432,7 @@ namespace GameEditor.FrameTool
hfc = new HotFixConfig(folder);
_HotFixConfigDic.Add(folder, hfc);
}
hfc.AddSetting(desc, folder, setting);
hfc.AddSetting(desc, folder, setting, version);
}
}
}
@ -541,12 +536,12 @@ namespace GameEditor.FrameTool
}
if (GUILayout.Button("编辑Config", GUILayout.Height(30f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + AppConst.GameConfigFile;
string tpath = hfs.svn_version_path + AppConst.GameConfigFile;
ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("编辑Version", GUILayout.Height(30f), GUILayout.Width(100f)))
{
string tpath = hfs.path_cdn_setting + AppConst.GameVersionFile;
string tpath = hfs.svn_version_path + AppConst.GameVersionFile;
ProcessUtil.OpenText(tpath);
}
if (GUILayout.Button("刷新", GUILayout.Height(30f), GUILayout.Width(100f)))
@ -648,79 +643,6 @@ namespace GameEditor.FrameTool
ProcessUtil.ProcessCommand(toPath, "git push");
EditorUtility.ClearProgressBar();
}
//同步工程中的热更文件到git
private static void UpdateUnity3dToCDN(HotFixSetting hfs)
{
string logName;
string updateName;
string changeFileName;
List<ResourceFile> updateList;
List<string> log = new List<string>();
updateList = hfs.local_cdn_list;
if (updateList.Count <= 0)
{
UnityEngine.Debug.Log("未检测到文件改动");
return;
}
// 初始化数据
updateName = hfs.dir_name + "_" + hfs.dir_cdn_setting + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss");
changeFileName = updateName.Replace("/", "_");
logName = changeFileName + "_UpLoad";
EditorUtility.DisplayProgressBar("正在获取数据:", updateName, 0f);
log.Add("热更文件版本:" + updateName);
log.Add("热更大小:" + hfs.local_cdn_size);
// copy unity3d
log.Add("热更文件:");
List<string> changeFile = new List<string>();
foreach (ResourceFile rf in updateList)
{
changeFile.Add(rf.fileName);
log.Add(rf.fileName);
}
changeFile.Add(UpdateConfigs.FILES);
log.Add(UpdateConfigs.FILES);
// write ChangeList
EditorUtility.DisplayProgressBar("正在生成文件变化列表", changeFileName, 1f);
WriteLog(hfs.path_cdn_setting + "/__HotFixLog", changeFileName, changeFile.ToArray());
// upload to cdn
EditorUtility.DisplayProgressBar("正在上传热更文件", changeFileName, 1f);
string setting = File.ReadAllText(hfs.path_cdn_setting + "Setting.txt", System.Text.Encoding.UTF8);
Hashtable info = MiniJSON.jsonDecode(setting) as Hashtable;
if (!info.ContainsKey("cdn_type"))
{
UnityEngine.Debug.LogError("CDN配置错误");
EditorUtility.ClearProgressBar();
return;
}
log.Add("CDN TYPE: "+ info["cdn_type"]);
string toolsDir = _HotFixProjectPath + "/Tools/" + info["cdn_type"];
log.Add("TOOLS DIR: " + toolsDir);
// MAC机器上pathon脚本中使用多线程会导致unity卡死
int isThread = 1;
#if UNITY_IOS
isThread = 0;
#endif
string command = string.Format("python UpLoad.py {0} {1} {2} {3} >>{4}", _HotFixProjectPath + "/Root/" + hfs.dir_name, hfs.dir_cdn_setting, changeFileName, isThread, hfs.path_cdn_setting + "__HotFixLog/" + logName + ".log");
log.Add("UPLOAD COMMAND: " + command);
ProcessUtil.ProcessCommand(toolsDir, command);
string flushCommand = string.Format("python Flush.py {0} >>{1}", hfs.cdn_version.resUrl, hfs.path_cdn_setting + "__HotFixLog/" + logName + ".log");
log.Add("Flush COMMAND: " + flushCommand);
ProcessUtil.ProcessCommand(toolsDir, flushCommand);
// write log
EditorUtility.DisplayProgressBar("正在生成Log文件", logName, 1f);
WriteLog(hfs.path_cdn_setting + "__HotFixLog", logName, log.ToArray());
// git commit
string commitName = hfs.desc + "更新:" + updateName;
UnityEngine.Debug.LogError("git commit -m " + commitName);
EditorUtility.DisplayProgressBar("正在提交到GIT", commitName, 1f);
ProcessUtil.ProcessCommand(hfs.path_cdn_setting, "git add .");
ProcessUtil.ProcessCommand(hfs.path_cdn_setting, "git commit -m " + commitName);
ProcessUtil.ProcessCommand(hfs.path_cdn_setting, "git push");
EditorUtility.ClearProgressBar();
}
private static void WriteLog(string path, string name, string[] contents)
{