Пример #1
0
        public static List <String> generateResTypeList;                  // 混合资源R类型


        // 执行R文件资源id生成逻辑
        public static bool Start(String dirTarget, String dirSource, Cmd.Callback call, bool apktool_yml_process = false, bool R_Process_Game = false)
        {
            if (call != null)
            {
                call("【L】5、R$*smali资源编译,逻辑开始...");
            }
            String GAMEPRE_package = Settings.channel_param["GAMEPRE_package"];     // 游戏原有包名
            String CHANNEL_package = Settings.channel_param["CHANNEL_package"];     // 渠道包原有包名
            String package         = Settings.channel_param["package"];             // 获取包名信息

            // 获取游戏包和渠道包,R资源id信息
            if (call != null)
            {
                call("【I】- 1.获取游戏包和渠道包,R资源id信息");
            }
            R_process.gameResDic    = R_process.getResDic(dirTarget + @"\res\values\public.xml", call);
            R_process.channelResDic = R_process.getResDic(dirSource + @"\res\values\public.xml", call);

            //获取游戏包和渠道包,解包路径下的R文件类型信息
            if (call != null)
            {
                call("【I】-   获取游戏包和渠道包,解包路径下的R文件类型信息");
            }
            R_process.gameResTypeList    = R_process.getRes_typeList(dirTarget, GAMEPRE_package);
            R_process.channelResTypeList = R_process.getRes_typeList(dirSource, CHANNEL_package);


            // 根据现有资源,生成新的R$type.smali文件
            bool R_result = R_process.UpdatePublicXML(dirTarget, call);                                     // 从游戏解包资源生成新的public.xml

            if (!R_result)
            {
                return(false);
            }

            R_process.genrateResDic = R_process.getResDic(dirTarget + @"\res\values\public.xml", call);  // 获取新生成的R资源id信息

            if (call != null)
            {
                call("【I】- 6.根据public.xml中资源id信息,生成新的R$*.smali文件...");
            }
            R_process.rebuidR_smali(genrateResDic, dirTarget + "\\smali", package, call);   // 重新生成包名路径下的R文件
            R_process.generateResTypeList = R_process.getRes_typeList(dirTarget, package);  // 获取新的包名路径下,现有的R文件类型信息

            // 复制原有包名路径和渠道包名路径下,其它R.smali文件到新的包名路径下
            copyR_smali(dirTarget, dirTarget, GAMEPRE_package, package, gameResTypeList, generateResTypeList, gameResDic, genrateResDic, call, true);
            copyR_smali(dirSource, dirTarget, CHANNEL_package, package, channelResTypeList, generateResTypeList, channelResDic, genrateResDic, call);

            R_process.generateResTypeList = R_process.getRes_typeList(dirTarget, package);  // 重新获取新的包名路径下,现有的R文件类型信息
            CreateR_smali(generateResTypeList, dirTarget + "\\smali", package, call);       // 根据现有的R资源类型生成对应R.smali文件

            // 修改smal路径下,原有包名路径信息到新的包名路径信息
            ReplaceSmaliPackagePath(dirTarget, GAMEPRE_package, package);
            ReplaceSmaliPackagePath(dirTarget, CHANNEL_package, package);

            // 修改所有非包名路径下的R文件中的id信息
            if (call != null)
            {
                call("【I】- 7.修改所有非包名路径下的R文件中的id信息");
            }
            //if (call != null) call("【I】- 7.暂时屏蔽");
            updateALL_RIds(dirTarget, package, gameResDic, channelResDic, genrateResDic, call, R_Process_Game);

            if (call != null)
            {
                call("【I】R$*.smali文件处理结束\r\n");
            }

            if (apktool_yml_process)
            {
                appendunknown(dirTarget, call);                         // 修改apktool.yml中的Unknown文件列表
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// 执行apk解包文件混合逻辑
        /// </summary>
        public static void CombineApk(String dirSource, String dirTarget, String signFileName, Cmd.Callback call, bool deletTXT = true)
        {
            if (call != null)
            {
                call("【I】");
            }

            ToolSetting toolSet = ToolSetting.Instance();                                 // 载入配置信息
            String      Set_gameId = Settings.gameId, Set_channelId = Settings.channelId; // 获取游戏id、渠道id

            //-------------------------1
            // 游戏apk解包
            dirTarget = apkUnpack(dirTarget, call /*, true*/);       // 解包游戏包并删除res\values\public.xml文件
            if (dirTarget.Contains("【E】"))
            {
                return;
            }


            //-------------------------2
            // 渠道apk解包
            dirSource = apkUnpack(dirSource, call);
            //ReplaceValues.ReplaceFileContent(dirSource, "0x7f0", "0x7ff");
            //if (call != null) call("【I】替换渠道解包文件下,所有0x7f0 为 0x7ff");
            if (dirSource.Contains("【E】"))
            {
                return;
            }


            // 添加游戏Icon或Logo到游戏解包文件
            addGameAttachs(toolSet, call, dirTarget, "\\游戏Icon或Logo", Set_gameId, Set_channelId, "游戏解包目录");

            // 添加游戏Icon或Logo到渠道解包文件
            addGameAttachs(toolSet, call, dirSource, "\\游戏Icon或Logo", Set_gameId, Set_channelId, "渠道解包目录");

            //-------------------------3
            if (call != null)
            {
                call("【I】");
            }
            if (call != null)
            {
                call("【I】执行apk混合逻辑...");
            }
            if (call != null)
            {
                call("【I】添加" + dirSource + "\r\n到" + dirTarget + "中");
            }

            // 进行apk文件的混合
            ApkCombine.Combine(dirSource, dirTarget, call);
            if (call != null)
            {
                call("【I】apk混合完成!\r\n");
            }

            //-------------------------4
            // 添加渠道附加资源
            addChannelAttachs(toolSet, call, dirTarget, "\\附加资源", Set_channelId);

            // 添加游戏包附加资源
            addGameAttachs(toolSet, call, dirTarget, "\\附加资源", Set_gameId, Set_channelId);

            //-------------------------5
            // 执行R文件修改逻辑
            if (toolSet.R_Process)
            {
                bool R_result = R_process.Start(dirTarget, dirSource, call, toolSet.apktool_yml_Process, toolSet.R_Process_Game);
                if (!R_result)
                {
                    return;
                }
            }

            //String path = R_process.create_publicXML(dirTarget, call);
            //String package = Settings.channel_param["package"];                     // 获取包名信息
            //R_process.rebuidR_smali(path, dirTarget + "\\smali", package, call);    // 重新生成包名路径下的R文件
            //File.Copy(path, dirTarget + @"\res\values\public.xml");                 // 替换原有public.xml

            //-------------------------6
            // apk重新打包
            String result = apkPackage(dirTarget, signFileName, call);

            if (result.Contains("【E】"))
            {
                return;
            }

            // 打包完成后清除缓存中的解包文件
            if (call != null)
            {
                call("【I】清除缓存目录," + dirSource);
            }
            Apktool.DeletDir(dirSource);

            if (call != null)
            {
                call("【I】清除缓存目录," + dirTarget);
            }
            Apktool.DeletDir(dirTarget);

            if (deletTXT)
            {
                if (call != null)
                {
                    call("【I】清除缓存文件," + dirSource + ".txt");
                }
                Apktool.DeletFile(dirSource + ".txt");
            }
        }