private dynamic ParseValue(XElement plistVal)
        {
            switch (plistVal.Name.ToString())
            {
            case "true":
                return(true);

            case "false":
                return(false);

            case "string":
                return(plistVal.Value);

            case "integer":
                return(Convert.ToInt32(plistVal.Value));

            case "real":
                return(Convert.ToSingle(plistVal.Value));

            case "array":
                return(this.ParseArray(plistVal.Elements()));

            case "dict":
                Plist plist = new Plist();
                this.Parse(plist, plistVal.Elements());
                return(plist);
            }
            return(null);
        }
        private void Parse(Plist dict, IEnumerable <XElement> elements)
        {
            for (int i = 0; i < elements.Count(); i += 2)
            {
                var plistVal = elements.ElementAt(i + 1);
                var plistKey = elements.ElementAt(i);

                dict[plistKey.Value] = ParseValue(plistVal);
            }
        }
 private void iDevice_Connected(object sender, ConnectEventArgs e)
 {
     if (new[] { "iPhone1,1", "iPhone1,2", "iPhone2,1", "iPod1,1", "iPod2,1", "iPod3,1" }.Contains(iDevice.DeviceProductType) || iDevice.DeviceProductType.StartsWith("iPad", true, System.Globalization.CultureInfo.CreateSpecificCulture("en")))
     {
         lblPlug.Text = "An iDevice has been plugged in!\r\nHowever, Jaku Theme does not support your device yet!";
     }
     else if (!iDevice.IsJailbreak)
     {
         lblPlug.Text = "Your iDevice must be jailbroken in order to install custom themes!";
     }
     else
     {
         this.Invoke((MethodInvoker) delegate
         {
             lblPlug.Visible     = false;
             wBrowser.Visible    = true;
             btnBrowse.Enabled   = true;
             btnRespring.Enabled = true;
             txtSearch.Enabled   = true;
             // User Apps
             foreach (var dir in iDevice.GetDirectories("/var/mobile/Applications"))
             {
                 foreach (var dir2 in iDevice.GetDirectories("/var/mobile/Applications/" + dir))
                 {
                     if (dir2.EndsWith(".app"))
                     {
                         string finalPath = "/var/mobile/Applications/" + dir + "/" + dir2;
                         getFile(finalPath + "/Info.plist", "tmp\\Info.plist"); // Get Info.plist so we can continue
                         // Use iTunes PlUtil from iTunes Libraries to convert bplist to plist
                         ProcessStartInfo procStartInfo = new ProcessStartInfo(Path.Combine(ApplicationSupportDirectory, "plutil.exe"), @"-convert xml1 """ +
                                                                               Path.Combine(Environment.CurrentDirectory, "tmp\\Info.plist") + @"""")
                         {
                             UseShellExecute        = false,
                             CreateNoWindow         = true,
                             RedirectStandardOutput = true,
                             Verb = "runas"
                         };
                         var p       = new Process();
                         p.StartInfo = procStartInfo;
                         p.Start();
                         string output = p.StandardOutput.ReadToEnd();
                         p.WaitForExit();
                         //MessageBox.Show(output);
                         Plist plist = new Plist();
                         plist.Load("tmp\\Info.plist"); //now load
                         dynamic search;
                         // get icon names, download them until we found perfect 114x114 image size
                         if (plist.ContainsKey("CFBundleIconFiles"))
                         {
                             search = plist["CFBundleIconFiles"];
                         }
                         else
                         {
                             search = plist["CFBundleIcons"]["CFBundlePrimaryIcon"]["CFBundleIconFiles"];
                         }
                         foreach (var item in search)
                         {
                             string appName    = plist["CFBundleDisplayName"];
                             string bundleName = plist["CFBundleIdentifier"];
                             getFile(finalPath + "/" + item, "tmp\\" + appName + ".png");
                             using (Bitmap bitmap = new Bitmap("tmp\\" + appName + ".png"))
                                 if (bitmap.Height == 114)
                                 {
                                     Data.dictIcon[appName] = new string[] { item, bundleName }; //1st: icon name, 2nd: bundle name
                                     break;
                                 }
                         }
                     }
                 }
             }
             // Start iPIN to de-optimize PNGs
             Process p2 = new Process();
             p2.StartInfo.CreateNoWindow = true;
             p2.StartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
             p2.StartInfo.FileName       = "tmp\\ipin.exe";
             p2.Start();
         });
     }
 }