예제 #1
0
        private static void continueLoading(string projPath, string binsPath)
        {
            if (string.IsNullOrEmpty(binsPath))
            {
                binsPath = projPath;
            }
            bool init = KDZZ.FileTool.Init(projPath);

            ProjectRoot             = projPath;
            Project                 = Path.Combine(projPath, FileTool.project_files_path);
            FileTool.ProjectRootDir = ProjectRoot;
            if (init)
            {
                NumericDialogChoice res = new NumericDialogChoice(-1, string.Empty);
                Console.WriteLine("    - Directory " + Project + " initialized.");
                Console.WriteLine("    - Bins Directory: " + binsPath);
                res = NumericDialog.ShowNumericDialog("Please verify KDZ has been extracted to: " + binsPath, new List <string>()
                {
                    "Continue", "Quit"
                });
                Console.Clear();
                if (res.Choice == 2)
                {
                    Environment.Exit(0);
                }
                List <string>       models   = ScriptBuilder.getModels();
                NumericDialogChoice response = NumericDialog.ShowNumericDialog("Select Device Model", models);
                Console.Clear();
                Console.WriteLine("    - Selected: " + response.Description);
                Console.WriteLine("    - Loading KDZ File List..");
                ModelBins model     = new ModelBins(response.Description);
                bool      binsexist = false;
                while (!binsexist)
                {
                    List <string> bins = new List <string>();
                    bins.AddRange(model.BL);
                    bins.AddRange(model.MPR);
                    bins.AddRange(model.PRI);
                    bins.AddRange(model.DLR);

                    binsexist = FileTool.BinsExist(bins, binsPath);
                    Console.WriteLine("    - Bins Exist: " + binsexist.ToString());
                    if (!binsexist)
                    {
                        NumericDialogChoice binres = NumericDialog.ShowNumericDialog(new List <string>()
                        {
                            "Please extract all KDZ bins and images to", binsPath
                        }, new List <string>()
                        {
                            "Continue", "Quit"
                        });
                        Console.Clear();
                        if (binres.Choice == 2)
                        {
                            Environment.Exit(0);
                        }
                    }
                }
                ModelBins           copied       = FileTool.ProcessBins(model, Project, binsPath);
                NumericDialogChoice buildOptions = NumericDialog.ShowNumericDialog(new List <string>()
                {
                    "What package(s) would you like to build?"
                }, new List <string>()
                {
                    "Bootloader", "Modem", "LAF", "FullStock", "Quit"
                });
                Console.Clear();
                if (buildOptions.Choice == 5)
                {
                    Environment.Exit(0);
                }
                PackageType selectedType = (PackageType)buildOptions.Choice - 1;
                bool        binsMoved    = FileTool.ArrangeFilesForPackage(selectedType);
                if (!binsMoved)
                {
                    Console.WriteLine("    - Unable to prepare package files.");
                    Console.WriteLine("    - Please make sure the source files exist, and you have the proper folder permissions");
                    Console.ReadKey();
                    Environment.Exit(0);
                }
                Console.WriteLine("    - Package File Preparation Complete");
                Console.WriteLine("");

                string pname = string.Empty;
                while (pname.Length < 3)
                {
                    Console.WriteLine("Enter a name for your package");
                    Console.Write(" => ");
                    pname = Console.ReadLine();
                }
                List <string> script  = ScriptBuilder.CreateUpdaterScript(selectedType, pname, copied);
                string        metadir = Path.Combine(ProjectRoot, FileTool.project_files_path, "META-INF");
                string        usdir   = Path.Combine(ProjectRoot, FileTool.project_files_path, "META-INF", "com", "google", "android");
                File.WriteAllText(Path.Combine(usdir, "updater-script"), string.Join("\n", script));
                bool moveMeta = FileTool.MoveDir(metadir, Path.Combine(ProjectRoot, "package", "META-INF"));
                if (!moveMeta)
                {
                    ReturnError("Error moving META-INF Directory");
                }
                string packagepath = FileTool.CreateZipPackage(pname.Replace(" ", "_"), selectedType);
                Console.WriteLine(" ");
                Console.WriteLine("Package Location: " + packagepath);
                Console.WriteLine("Press any key to exit..");
                Console.ReadKey();
            }
        }
예제 #2
0
        public static List <string> CreateUpdaterScript(PackageType packageType, string packageName, ModelBins modelBins)
        {
            Console.WriteLine("    - Building Updater-Script...");
            List <string> sb = new List <string>();

            try
            {
                sb.AddRange(titleLines("Flashing " + packageName + ".."));

                if (packageType == PackageType.Bootloader)
                {
                    // add sha1 checksum methods
                    sb.AddRange(extractBLtoTMP);
                    sb.Add(uiprint("Flashing Bootloader.."));
                    foreach (string s in modelBins.BL)
                    {
                        sb.AddRange(lineExtractFile(@"bootloader/" + s + ".img", modelBins.NOBAK.IndexOf(s) < 0 ? true : false));
                    }
                }
                else if (packageType == PackageType.Modem)
                {
                    sb.Add(uiprint("Flashing Modem.."));
                    foreach (string s in modelBins.MPR)
                    {
                        sb.AddRange(lineExtractFile(s + ".img", modelBins.NOBAK.IndexOf(s) < 0 ? true : false));
                    }
                }
                else if (packageType == PackageType.LAF)
                {
                    sb.Add(uiprint("Flashing LAF.."));
                    foreach (string s in modelBins.DLR)
                    {
                        if (s == "laf")
                        {
                            sb.AddRange(lineExtractFile(s + ".img", modelBins.NOBAK.IndexOf(s) < 0 ? true : false));
                        }
                    }
                }
                else if (packageType == PackageType.FullStock)
                {
                    sb.AddRange(extractBLtoTMP);
                    sb.Add(uiprint("Flashing Bootloader.."));
                    foreach (string s in modelBins.BL)
                    {
                        sb.AddRange(lineExtractFile(@"bootloader/" + s + ".img", modelBins.NOBAK.IndexOf(s) < 0 ? true : false));
                    }
                    sb.Add(uiprint("Flashing Modem.."));
                    foreach (string s in modelBins.MPR)
                    {
                        sb.AddRange(lineExtractFile(s + ".img", modelBins.NOBAK.IndexOf(s) < 0 ? true : false));
                    }
                    sb.Add(uiprint("Flasing Boot and System"));
                    sb.Add(uiprint("This may take a while..."));
                    foreach (string s in modelBins.PRI)
                    {
                        sb.AddRange(lineExtractFile(s + ".img", modelBins.NOBAK.IndexOf(s) < 0 ? true : false));
                    }
                }
                sb.AddRange(endLines(packageName));
                Console.WriteLine("    - Updater Script Created");
            }
            catch (Exception ex)
            {
                KDZZ.Program.ReturnError(ex.Message);
            }
            return(sb);
        }
예제 #3
0
        private static ModelBins ProcessDirectories(string projPath, ModelBins modelBins, List <FileInfo> bins)
        {
            int    bincount     = modelBins.BinCount;
            int    filecount    = bins.Count;
            int    processcount = 0;
            int    copycount    = 0;
            string msg          = "    - Processing File ";

            if (!Directory.Exists(Path.Combine(projPath, "META-INF")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "META-INF"));
            }
            if (!Directory.Exists(Path.Combine(projPath, "META-INF", "com")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "META-INF", "com"));
            }
            if (!Directory.Exists(Path.Combine(projPath, "META-INF", "com", "google")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "META-INF", "com", "google"));
            }
            if (!Directory.Exists(Path.Combine(projPath, "META-INF", "com", "google", "android")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "META-INF", "com", "google", "android"));
            }
            if (!File.Exists(Path.Combine(projPath, "META-INF", "com", "google", "android", "update-binary")))
            {
                string binary    = Path.Combine(KDZZ.Program.Root, "files", "update-binary");
                string binarytgt = Path.Combine(projPath, "META-INF", "com", "google", "android", "update-binary");
                int    bincopied = copy(binary, binarytgt);
                if (bincopied < 1)
                {
                    KDZZ.Program.ReturnError("Unable to copy update-binary");
                }
            }

            if (!Directory.Exists(Path.Combine(projPath, "bootloader")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "bootloader"));
            }
            for (int i = modelBins.BL.Count - 1; i >= 0; i--) //each(string s in modelBins.BL)
            {
                string   s   = modelBins.BL[i];
                FileInfo f   = findByName(s, bins);
                string   tgt = Path.Combine(projPath, "bootloader", s + ".img");
                modelBins.BLPATHS.Add(tgt);
                processcount++;
                displayProgress(msg, f.Name, processcount.ToString() + " of " + bincount.ToString());
                int cr = copy(f.FullName, tgt);
                copycount += cr;
            }
            if (!Directory.Exists(Path.Combine(projPath, "modem")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "modem"));
            }
            foreach (string s in modelBins.MPR)
            {
                FileInfo f   = findByName(s, bins);
                string   tgt = Path.Combine(projPath, "modem", s + ".img");
                modelBins.MPRPATHS.Add(tgt);
                processcount++;
                displayProgress(msg, f.Name, processcount.ToString() + " of " + bincount.ToString());
                int cr = copy(f.FullName, tgt);
                copycount += cr;
            }
            if (!Directory.Exists(Path.Combine(projPath, "dlmode_recov")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "dlmode_recov"));
            }
            foreach (string s in modelBins.DLR)
            {
                FileInfo f   = findByName(s, bins);
                string   tgt = Path.Combine(projPath, "dlmode_recov", s + ".img");
                modelBins.DLRPATHS.Add(tgt);
                processcount++;
                displayProgress(msg, f.Name, processcount.ToString() + " of " + bincount.ToString());
                int cr = copy(f.FullName, tgt);
                copycount += cr;
            }
            if (!Directory.Exists(Path.Combine(projPath, "primary")))
            {
                Directory.CreateDirectory(Path.Combine(projPath, "primary"));
            }
            foreach (string s in modelBins.PRI)
            {
                FileInfo f   = findByName(s, bins);
                string   tgt = Path.Combine(projPath, "primary", s + ".img");
                modelBins.PRIPATHS.Add(tgt);
                processcount++;
                if (f.Name == "system.img")
                {
                    displayProgress("    - Processing System Image (this may take several minutes. do not close console) ", f.Name, processcount.ToString() + " of " + bincount.ToString());
                }
                else
                {
                    displayProgress(msg, f.Name, processcount.ToString() + " of " + bincount.ToString());
                }
                int cr = copy(f.FullName, tgt);
                copycount += cr;
            }
            Console.Clear();
            Console.WriteLine("    - Process Complete");
            return(modelBins);
        }