public void PrepareMainOperatingSystemFirmwarePackage()
        {
            if (OperatingSystemsArray[0] == null)
            {
                return;
            }
            OperatingSystemsArray[0].FirmwarePackage = new IPSWlib.Editor(OperatingSystemsArray[0].FilePathIPSW, WorkingDirectory);
            for (int i = 1; i < OperatingSystemsArray.Length; i++)
            {
                if (OperatingSystemsArray[i] != null)
                {
                    OperatingSystemsArray[i].ImagesToFlash   = new List <string>();
                    OperatingSystemsArray[i].FirmwarePackage = new IPSWlib.Editor(OperatingSystemsArray[i].FilePathIPSW, WorkingDirectory);

                    addOperatingSystemFirmwareImagesToFlash(OperatingSystemsArray[i]);

                    DecryptFirmwareImages(OperatingSystemsArray[i].FirmwarePackage.getFileNameIPSW(), OperatingSystemsArray[i].ImagesToFlash);

                    PatchFirmwareImages(OperatingSystemsArray[i].FirmwarePackage.getFileNameIPSW(), OperatingSystemsArray[i].ImagesToFlash);

                    OperatingSystemsArray[i].LocalWorkingDirectory = WorkingDirectory + OperatingSystemsArray[i].SystemBuildNumber + "_" + OperatingSystemsArray[i].InstanceID;

                    string   ImageFileName         = Path.GetFileName(OperatingSystemsArray[i].LowLevelBootloader);
                    string[] SplittedImageFileName = ImageFileName.Split('.');
                    string   UpdatedImageFileName  = "";
                    SplittedImageFileName[0] = SplittedImageFileName[0] + OperatingSystemsArray[i].SystemID;
                    UpdatedImageFileName     = SplittedImageFileName[0] + "." + SplittedImageFileName[1] + "." + SplittedImageFileName[2] + "." + SplittedImageFileName[3];
                    File.Copy(OperatingSystemsArray[i].LowLevelBootloader, OperatingSystemsArray[i].LocalWorkingDirectory + "\\" + UpdatedImageFileName);
                    OperatingSystemsArray[i].LowLevelBootloader = OperatingSystemsArray[i].LocalWorkingDirectory + "\\" + UpdatedImageFileName;

                    string DecryptedRootFileSystemImagePath = DecryptRootFileSystemImage(OperatingSystemsArray[i].FirmwarePackage.getFileNameIPSW(), OperatingSystemsArray[i].FirmwarePackage.getRootFileSystemImagePath());
                    File.Move(DecryptedRootFileSystemImagePath, OperatingSystemsArray[i].LocalWorkingDirectory + "\\" + "RootFileSystem.dmg");
                    OperatingSystemsArray[i].RootFileSystem = OperatingSystemsArray[i].LocalWorkingDirectory + "\\" + "RootFileSystem.dmg";

                    for (int j = 0; j < OperatingSystemsArray[i].FirmwarePackage.getAllFilesIPSW().Length; j++)
                    {
                        if (OperatingSystemsArray[i].FirmwarePackage.getAllFilesIPSW()[j].Contains("kernel"))
                        {
                            File.Copy(OperatingSystemsArray[i].FirmwarePackage.getAllFilesIPSW()[j], OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + Path.GetFileName(OperatingSystemsArray[i].FirmwarePackage.getAllFilesIPSW()[j]));
                            OperatingSystemsArray[1].KernelCache = OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + Path.GetFileName(OperatingSystemsArray[i].FirmwarePackage.getAllFilesIPSW()[j]);
                        }
                    }

                    for (int j = 0; j < OperatingSystemsArray[i].ImagesToFlash.Count; j++)
                    {
                        OperatingSystemsArray[i].ImagesToFlash[j] = OperatingSystemsArray[0].FirmwarePackage.AddToAllFlashFolder(OperatingSystemsArray[i].ImagesToFlash[j], OperatingSystemsArray[i].InstanceID);
                    }

                    for (int j = 0; j < OperatingSystemsArray[i].ImagesToFlash.Count; j++)
                    {
                        OperatingSystemsArray[0].FirmwarePackage.AddToFlashManifest(OperatingSystemsArray[i].ImagesToFlash[j]);
                    }
                }
            }
            OperatingSystemsArray[0].FirmwarePackage.RebuildIPSW(WorkingDirectory + OperatingSystemsArray[0].FirmwarePackage.getFileNameIPSW(), WorkingDirectory + OperatingSystemsArray[0].FirmwarePackage.getFileNameIPSW() + ".ipsw");
            ToolsManagerLib.iDeviceRestore iDeviceRestore = new ToolsManagerLib.iDeviceRestore();
            iDeviceRestore.EraseRestore(WorkingDirectory + OperatingSystemsArray[0].FirmwarePackage.getFileNameIPSW() + ".ipsw");
        }
        public void PrepareMainOperatingSystemIPSW()
        {
            IPSWlib.Editor MainOperatingSystemIPSW;
            List <string>  ImagesToFlashSecondaryOS = new List <string>();

            if (MainOperatingSystemSelected == true)
            {
                MainOperatingSystemIPSW = new IPSWlib.Editor(MainOperatingSystemPathIPSW, WorkingDirectory);
            }
            else
            {
                MainOperatingSystemIPSW = null;
            }

            if (SecondaryOperatingSystemSelected == true)
            {
                IPSWlib.Editor SecondaryOperatingSystemIPSW = new IPSWlib.Editor(SecondaryOperatingSystemPathIPSW, WorkingDirectory);
                OperatingSystemsArray[1].FileNameIPSW = SecondaryOperatingSystemIPSW.getFileNameIPSW();
                OperatingSystemsArray[1].SystemID     = 'B';
                ImagesToFlashSecondaryOS = addSecondaryOperatingSystemImagesToFlash(SecondaryOperatingSystemIPSW, ImagesToFlashSecondaryOS);

                DecryptFirmwareImages(SecondaryOperatingSystemIPSW.getFileNameIPSW(), ImagesToFlashSecondaryOS);
                PatchFirmwareImages(SecondaryOperatingSystemIPSW.getFileNameIPSW(), ImagesToFlashSecondaryOS);

                OperatingSystemsArray[1].LocalWorkingDirectory = WorkingDirectory + SecondaryOperatingSystemIPSW.getBuildNumber() + "_Secondary";
                string   ImageFileName         = Path.GetFileName(OperatingSystemsArray[1].LowLevelBootloader);
                string[] SplittedImageFileName = ImageFileName.Split('.');
                string   UpdatedImageFileName  = "";
                SplittedImageFileName[0] = SplittedImageFileName[0] + "B";
                UpdatedImageFileName     = SplittedImageFileName[0] + "." + SplittedImageFileName[1] + "." + SplittedImageFileName[2] + "." + SplittedImageFileName[3];
                File.Copy(OperatingSystemsArray[1].LowLevelBootloader, OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + UpdatedImageFileName);
                OperatingSystemsArray[1].LowLevelBootloader = OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + UpdatedImageFileName;

                string DecryptedRootFileSystemImagePath = DecryptRootFileSystemImage(SecondaryOperatingSystemIPSW.getFileNameIPSW(), SecondaryOperatingSystemIPSW.getRootFileSystemImagePath());
                File.Move(DecryptedRootFileSystemImagePath, OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + "RootFileSystem.dmg");
                OperatingSystemsArray[1].RootFileSystem = OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + "RootFileSystem.dmg";

                for (int i = 0; i < SecondaryOperatingSystemIPSW.getAllFilesIPSW().Length; i++)
                {
                    if (SecondaryOperatingSystemIPSW.getAllFilesIPSW()[i].Contains("kernel"))
                    {
                        File.Copy(SecondaryOperatingSystemIPSW.getAllFilesIPSW()[i], OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + Path.GetFileName(SecondaryOperatingSystemIPSW.getAllFilesIPSW()[i]));
                        OperatingSystemsArray[1].KernelCache = OperatingSystemsArray[1].LocalWorkingDirectory + "\\" + Path.GetFileName(SecondaryOperatingSystemIPSW.getAllFilesIPSW()[i]);
                    }
                }

                for (int i = 0; i < ImagesToFlashSecondaryOS.Count; i++)
                {
                    ImagesToFlashSecondaryOS[i] = MainOperatingSystemIPSW.AddToAllFlashFolder(ImagesToFlashSecondaryOS[i], "Secondary");
                }

                for (int i = 0; i < ImagesToFlashSecondaryOS.Count; i++)
                {
                    MainOperatingSystemIPSW.AddToFlashManifest(ImagesToFlashSecondaryOS[i]);
                }
            }

            MainOperatingSystemIPSW.RebuildIPSW(WorkingDirectory + MainOperatingSystemIPSW.getFileNameIPSW(), WorkingDirectory + MainOperatingSystemIPSW.getFileNameIPSW() + ".ipsw");
            ToolsManagerLib.iDeviceRestore iDeviceRestore = new ToolsManagerLib.iDeviceRestore();
            iDeviceRestore.EraseRestore(WorkingDirectory + MainOperatingSystemIPSW.getFileNameIPSW() + ".ipsw");
        }