Inheritance: System.Windows.Forms.ListViewItem
Esempio n. 1
0
		public async Task RunAsync() {
			var apks = CommandRunner.Instance.GetInstalledPackagesApkInformation ( );
			this.LogDebug("Initializing APK Cache");
			foreach(var item in apks) {
				var lvi = new ApkPackageListViewItem(item);

				// cant uninstall if we dont know the package
				if(string.IsNullOrEmpty(lvi.ApkInformation.Package)) {
					continue;
				}

				string keyName = lvi.ApkInformation.DevicePath;
				if(keyName.StartsWith("/")) {
					keyName = keyName.Substring(1);
				}
				keyName = keyName.Replace("/", ".");

				if(!Program.SystemIcons.ContainsKey(keyName)) {
					// get apk and extract the app icon
					var img = CommandRunner.Instance.GetLocalApkIconImage(item.LocalApk);

					if(img == null) {
						img = DroidExplorer.Resources.Images.package32;
					} else {
						using(System.IO.MemoryStream stream = new System.IO.MemoryStream()) {
							string fileName = System.IO.Path.Combine(System.IO.Path.Combine(CommandRunner.Settings.UserDataDirectory, Cache.APK_IMAGE_CACHE), string.Format("{0}.png", keyName));
							img.Save(stream, ImageFormat.Png);
							stream.Position = 0;
							using(System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write)) {
								byte[] buffer = new byte[2048];
								int readBytes = 0;
								while((readBytes = await stream.ReadAsync(buffer, 0, buffer.Length)) != 0) {
									await fs.WriteAsync(buffer, 0, readBytes);
								}
							}
						}

					}
					//SystemImageListHost.Instance.AddFileTypeImage ( keyName, img, img );

				}
			}
		}
        private void BuildListView( )
        {
            try {
            if ( this.InvokeRequired ) {
              this.Invoke ( new SetControlVisibleDelegate ( SetControlVisible ), new object[ ] { loadingPanel, true } );
              this.Invoke ( new DroidExplorer.UI.GenericDelegate ( packagesList.Items.Clear ) );
            } else {
              SetControlVisible ( loadingPanel, true );
              packagesList.Items.Clear ( );
            }
            List<DroidExplorer.Core.AaptBrandingCommandResult> apks = CommandRunner.Instance.GetInstalledPackagesApkInformation ( );

            foreach ( var item in apks ) {
              ApkPackageListViewItem lvi = new ApkPackageListViewItem ( item );

              // cant uninstall if we dont know the package
              if ( string.IsNullOrEmpty ( lvi.ApkInformation.Package ) ) {
            continue;
              }

              string keyName = lvi.ApkInformation.DevicePath;
              if ( keyName.StartsWith ( "/" ) ) {
            keyName = keyName.Substring ( 1 );
              }
              keyName = keyName.Replace ( "/", "." );

              if ( !Program.SystemIcons.ContainsKey ( keyName ) ) {
            // get apk and extract the app icon
            Image img = CommandRunner.Instance.GetLocalApkIconImage ( item.LocalApk );

            if ( img == null ) {
                            img = DroidExplorer.Resources.Images.package32;
            } else {
              using ( System.IO.MemoryStream stream = new System.IO.MemoryStream ( ) ) {
                                string fileName = System.IO.Path.Combine ( System.IO.Path.Combine ( CommandRunner.Settings.UserDataDirectory, Cache.APK_IMAGE_CACHE ), string.Format ( "{0}.png", keyName ) );
                img.Save ( stream, ImageFormat.Png );
                stream.Position = 0;
                using ( System.IO.FileStream fs = new System.IO.FileStream ( fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write ) ) {
                  byte[] buffer = new byte[ 2048 ];
                  int readBytes = 0;
                  while ( ( readBytes = stream.Read ( buffer, 0, buffer.Length ) ) != 0 ) {
                    fs.Write ( buffer, 0, readBytes );
                  }
                }
              }

            }
                        SystemImageListHost.Instance.AddFileTypeImage ( keyName, img, img );
              }

              if ( this.InvokeRequired ) {
            this.Invoke ( new SetListViewItemImageIndexDelegate ( this.SetListViewItemImageIndex ), new object[ ] { lvi, Program.SystemIcons[ keyName ] } );
            this.Invoke ( new AddListViewItemDelegate ( this.AddListViewItem ), new object[ ] { packagesList, lvi } );
              } else {
            SetListViewItemImageIndex ( lvi, Program.SystemIcons[ keyName ] );
            AddListViewItem ( packagesList, lvi );
              }
            }
              } catch ( Exception ex ) {
            this.LogError( ex.Message,ex );
              } finally {
            if ( this.InvokeRequired ) {
              this.Invoke ( new SetControlVisibleDelegate ( SetControlVisible ), new object[ ] { loadingPanel, false } );
            } else {
              SetControlVisible ( loadingPanel, false );
            }
              }
        }