Beispiel #1
0
        // 从resDic中的id信息生成R*smali文件
        public static void rebuidR_smali(Dictionary <String, List <xmlNode> > resDic, String TargetDir, String packageName, Cmd.Callback call)
        {
            if (resDic == null || resDic.Count == 0)
            {
                return;
            }

            // 创建包名对应的路径
            String TargetPath = TargetDir + "\\" + packageName.Trim('.').Replace('.', '\\');    // 形如 com\ltsdk_56_base\leshi

            DependentFiles.checkDir(TargetPath);

            // 按照res中的type类型,生成对应的R$type.smali文件资源到指定的包名、路径下
            foreach (String typeName in resDic.Keys)
            {
                if (typeName.Equals("AllType"))
                {
                    continue;
                }

                List <xmlNode> typeList = resDic[typeName];
                createSmali(TargetPath, packageName, typeName, typeList, call);
            }

            // 生成BuildConfig.smali
            createBuildConfig(TargetPath, packageName, call);
        }
Beispiel #2
0
        // 根据type类型从Src拷贝仅存在与Src中的项到Target目录下
        private static void copyR_smali(String source, String target, String pNameSrc, String pNameTar, List <String> typeListSrc, List <String> typeListTar, Dictionary <String, List <xmlNode> > DicSrc, Dictionary <String, List <xmlNode> > DicTar, Cmd.Callback call, bool delet = false)
        {
            String SourcePath = source + "\\smali\\" + pNameSrc.Trim('.').Replace('.', '\\');    // 形如 com\ltsdk_56_base\leshi
            String TargetPath = target + "\\smali\\" + pNameTar.Trim('.').Replace('.', '\\');

            DependentFiles.checkDir(TargetPath);

            foreach (String type in typeListSrc)
            {
                String name       = "R$" + type + ".smali";
                String fileSource = SourcePath + "\\" + name;          // 获取type类型对应的smali文件
                String fileTarget = TargetPath + "\\" + name;
                if (File.Exists(fileSource))
                {
                    if (!typeListTar.Contains(type))                   // 该smali文件之前未曾生成,则自动复制
                    {
                        List <xmlNode> listSrc = new List <xmlNode>();
                        List <xmlNode> listTar = new List <xmlNode>();

                        if (DicSrc.ContainsKey(type))
                        {
                            listSrc = DicSrc[type];
                        }
                        else
                        {
                            listSrc = DicSrc["AllType"];
                        }
                        //{
                        //    if (call != null) call("【I】" + SourcePath + "对应的public.xml不含有type类型:" + type);
                        //    //listSrc = ToListNode(DicSrc);   // 获取DicSrc中所有节点id信息
                        //}

                        if (DicTar.ContainsKey(type))
                        {
                            listTar = DicTar[type];
                        }
                        else
                        {
                            listTar = DicTar["AllType"];
                        }
                        //{
                        //    if (call != null) call("【I】" + TargetPath + "对应的public.xml不含有type类型:" + type);
                        //    //listTar = ToListNode(DicTar);   // 获取DicTar中所有节点id信息
                        //}

                        if (call != null)
                        {
                            call("【I】复制" + name + "从" + SourcePath + "->" + TargetPath);
                        }
                        //File.Copy(fileSource, fileTarget, true);
                        MoveR_smali(fileSource, fileTarget, pNameSrc, pNameTar, listSrc, listTar, call, delet);
                    }
                    else if (delet && !fileSource.Equals(fileTarget)) // 原文件与目标文件不是相同文件,则删除
                    {
                        File.Delete(fileSource);
                        if (call != null)
                        {
                            call("【I】删除文件," + fileSource);
                        }
                    }
                }
                else if (call != null)
                {
                    call("【I】文件丢失," + fileSource + "...");
                }
            }

            if (delet) // 删除原有的R.smali
            {
                String fileSource = SourcePath + "\\R.smali";
                if (File.Exists(fileSource))
                {
                    File.Delete(fileSource);
                    if (call != null)
                    {
                        call("【I】删除文件," + fileSource);
                    }
                }
            }
        }