示例#1
0
        private void UnPack_Logic()
        {
            OutPut("【I】");

            if (Apktool.isApkFile(file.Text))       // 解包
            {
                OutPut("【I】apk解包开始...");
                String result = Apktool.unPackage(file.Text, OutPut, false, false);   // 使用apktool进行apk的解包
                if (result.Contains("【E】"))
                {
                    return;
                }
                OutPut("【I】apk解包结束!\r\n");
            }
            else if (Apktool.isApkDir(file.Text))   // 打包
            {
                OutPut("【I】apk打包开始...");
                String result = Apktool.package(file.Text, OutPut);     // 使用apktool进行打包
                if (result.Contains("【E】"))
                {
                    return;
                }
                OutPut("【I】apk未签名文件已生成!\r\n");

                // 若有签名文件,则进行签名
                if (!comboBox_sign.Text.Equals(""))
                {
                    OutPut("【I】apk签名中...");
                    String apkName = file.Text + "..apk";
                    String pem     = SinPath() + "\\" + comboBox_sign.Text + ".x509.pem";
                    String pk8     = SinPath() + "\\" + comboBox_sign.Text + ".pk8";
                    String psw     = "letang123";
                    result = Apktool.Sign(apkName, pem, pk8, psw, OutPut);
                    if (result.Contains("【E】"))
                    {
                        return;
                    }
                    OutPut("【I】apk签名、对齐 完成!\r\n");

                    // 删除打包生成的未签名文件
                    if (System.IO.File.Exists(apkName))
                    {
                        System.IO.File.Delete(apkName);
                    }
                }

                OutPut("【I】apk打包结束!\r\n");
            }
            else
            {
                Cmd.Run(file.Text, OutPut); // 执行cmd命令
            }
        }
示例#2
0
        //==========================
        // apk解包打包逻辑封装

        /// <summary>
        /// 若为apk文件,则先行解包
        /// </summary>
        public static String apkUnpack(String apkFile, Cmd.Callback call, bool deletPublicXML = false)
        {
            // 若输入的为apk文件,则自动进行解包
            if (Apktool.isApkFile(apkFile))
            {
                if (call != null)
                {
                    call("【I】" + Path.GetFileName(apkFile));
                }
                if (call != null)
                {
                    call("【I】apk解包开始...");
                }

                string dir = Apktool.unPackage(apkFile, call, deletPublicXML);   // 使用apktool进行apk的解包
                if (dir.Contains("【E】"))
                {
                    return(dir);
                }

                if (call != null)
                {
                    call("【I】apk解包结束!\r\n");
                }

                // 拷贝apk目录下的配置文件到解包文件所在目录
                String configTxt  = apkFile.Replace(".apk", ".txt");
                String configTxt2 = apkFile.Replace(".apk", "-" + Settings.gameId + ".txt");    // 可按游戏获取游戏id对应的配置文件
                if (File.Exists(configTxt2) && !File.Exists(dir + ".txt"))
                {
                    File.Copy(configTxt2, dir + ".txt", false);
                }
                else if (File.Exists(configTxt) && !File.Exists(dir + ".txt"))
                {
                    File.Copy(configTxt, dir + ".txt", false);
                }

                if (File.Exists(dir + ".txt"))
                {
                    // 添加游戏附加配置信息到渠道包,打包配置中
                    String gameAttachConfig = ToolSetting.Instance().serverRoot + "游戏附加配置\\" + Settings.gameId + ".txt";
                    Settings.AppendSettingsTo(gameAttachConfig, dir + ".txt");
                }

                return(dir);
            }
            else
            {
                return(apkFile);
            }
        }
示例#3
0
        //从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);
        }