/// <summary> /// 添加渠道附加资源 /// </summary> private static void addChannelAttachs(ToolSetting toolSet, Cmd.Callback call, String dirSource, String channelAttachDir, String Set_channelId) { // 获取渠道附加目录资源路径 String channelDir = toolSet.chargeAPK_dir + "\\" + Set_channelId; //String channelAttachDir = channelDir + "\\附加资源"; String channelAttachDir2 = channelDir + channelAttachDir; // 复制渠道附加目录中的文件 if (Directory.Exists(channelAttachDir2) && !ApkCombine.isEmptyDirectorty(channelAttachDir2)) { bool isEmptyDir = ApkCombine.isEmptyDirectorty(channelAttachDir); if (!isEmptyDir && call != null) { call("【I】"); } if (!isEmptyDir && call != null) { call("【I】复制," + channelAttachDir); } ApkCombine.CopyFolderTo(channelAttachDir2, dirSource, true, call); if (!isEmptyDir && call != null) { call("【I】复制," + channelAttachDir + "完成"); } } }
/// <summary> /// 添加游戏附加资源 /// </summary> private static void addGameAttachs(ToolSetting toolSet, Cmd.Callback call, String dirTarget, String gameAttachDir, String Set_gameId, String Set_channelId, String tittle = "") { // 获取选中的游戏包所在的目录的附加资源 //toolSet.gameAPK_dir + "\\" + Settings.gameId + "\\" String selectGameDir = toolSet.gameAPK_dir + "\\" + Set_gameId; //String selectVersionDir = Form4.SelectVersionDir; //String[] attachDirs = { selectGameDir + "\\游戏Icon或Logo", selectVersionDir + "\\附加资源" }; //foreach (String gameAttachDir0 in attachDirs) { String gameAttachDir2 = selectGameDir + gameAttachDir; // 生成附加资源路径 // 复制游戏附加目录中的文件 List <String> list_channel = new List <string>(); list_channel.Add("所有渠道"); list_channel.Add(Set_channelId); bool isEmptyDir = ApkCombine.isEmptyDirectorty(gameAttachDir2); if (!isEmptyDir && call != null) { call("【I】"); } if (!isEmptyDir && call != null) { call("【I】复制," + gameAttachDir + (tittle.Equals("") ? "" : ("到" + tittle))); } foreach (String channelId in list_channel) { String Dir = gameAttachDir2 + "\\" + channelId; isEmptyDir = ApkCombine.isEmptyDirectorty(Dir); // 拷贝游戏附加资源目录 if (channelId != null && !channelId.Equals("") && Directory.Exists(Dir) && !ApkCombine.isEmptyDirectorty(Dir)) { if (!isEmptyDir && call != null) { call("【I】复制," + gameAttachDir + "\\" + channelId); } ApkCombine.CopyFolderTo(Dir, dirTarget, true, call); if (!isEmptyDir && call != null) { call("【I】复制," + gameAttachDir + "\\" + channelId + " 完成"); } } } } // 复制游戏Icon、Logo if (gameAttachDir.Equals("\\游戏Icon或Logo") && StartParam.AutoRun && Form4.channelIconDir.ContainsKey(Set_channelId)) { String ICONDIR = Form4.channelIconDir[Set_channelId]; if (!ICONDIR.Equals("") && Directory.Exists(ICONDIR)) { ApkCombine.CopyFolderTo(ICONDIR, dirTarget + @"\res\drawable", true, call); } } }
//从dirTarget目录下获取res资源,重新编译生成public.xml private static bool UpdatePublicXML(String dirTarget, Cmd.Callback call) { ToolSetting settting = ToolSetting.Instance(); // 载入设置信息 if (call != null) { call("【I】- 2.解包Empty.apk"); } String emptyApk = DependentFiles.curDir() + "\\tools\\Empty.apk"; // 空项目资源路径 if (emptyApk.Contains("\\\\")) { emptyApk = emptyApk.Replace("\\\\", "\\"); } String emptyDir = Apktool.unPackage(emptyApk, null, false); // 解包空apk if (emptyDir.Contains("【E】") && call != null) { call("【E】 解包Empty.apk异常"); return(false); } if (call != null) { call("【I】- 复制游戏res资源"); } String Res = emptyDir + "\\res"; ApkCombine.CopyFolderTo(dirTarget + "\\res", Res, true); // 复制Target目录到res目录,到空工程解包路径下 Program.Delay(3000); // 部分机器复制文件,存在异步延时,确保文件复制完成 if (call != null) { call("【I】- 3.使用新的res资源,生成新的Empty.apk"); } String apkFile = Apktool.package(emptyDir, null); // 使用apktool进行打包 if (apkFile.Contains("【E】") && call != null) { call("【E】 打包Empty.apk异常"); call("【E】 异常信息:" + apkFile); return(false); } if (call != null) { call("【I】- 4.解包Empty.apk"); } string unpackDir = Apktool.unPackage(apkFile, null, false); // 使用apktool进行apk的解包,生成新的public.xml if (unpackDir.Contains("【E】") || unpackDir.Trim().Equals("")) { if (call != null) { call("【E】 解包Empty.apk异常"); } return(false); } if (call != null) { call("【I】- 5.复制生成的public.xml文件,到游戏res目录中"); } String relativePath = @"\res\values\public.xml"; File.Copy(unpackDir + relativePath, dirTarget + relativePath, true); // 替换原有public.xml relativePath = @"\res\drawable\empty_ic_launcher.png"; File.Copy(unpackDir + relativePath, dirTarget + relativePath, true); relativePath = @"\res\layout\empty_activity_main.xml"; File.Copy(unpackDir + relativePath, dirTarget + relativePath, true); if (call != null) { call("【I】- 清除Empty.apk相关缓存资源..."); } // 清除缓存资源 Directory.Delete(emptyDir, true); // 删除空项目解包文件 File.Delete(apkFile); // 删除生成的临时文件 Directory.Delete(unpackDir, true); // 删除空工程解包目录 return(true); }