Inheritance: System.Windows.Forms.ListViewItem
Exemple #1
0
 public int Compare(object x, object y)
 {
     if (x is FileSystemInfoListViewItem && y is FileSystemInfoListViewItem)
     {
         ListViewEx lv = (x as ListViewItem).ListView as ListViewEx;
         FileSystemInfoListViewItem a = x as FileSystemInfoListViewItem;
         FileSystemInfoListViewItem b = y as FileSystemInfoListViewItem;
         if (lv.Sorting == SortOrder.Ascending)
         {
             int diff = a.FileSystemInfo.IsDirectory.CompareTo(b.FileSystemInfo.IsDirectory);
             if (diff != 0)
             {
                 return(-diff);
             }
             return(a.FileSystemInfo.Name.CompareTo(b.FileSystemInfo.Name));
         }
         else
         {
             int diff = a.FileSystemInfo.IsDirectory.CompareTo(b.FileSystemInfo.IsDirectory);
             if (diff != 0)
             {
                 return(diff);
             }
             return(-a.FileSystemInfo.Name.CompareTo(b.FileSystemInfo.Name));
         }
     }
     else
     {
         return(0);
     }
 }
 public FileTypeHandlerToolStripMenuItem( FileSystemInfoListViewItem item, IFileTypeHandler handler )
     : base()
 {
     this.Item = item;
     this.Handler = handler;
     this.Text = string.Format ( CultureInfo.InvariantCulture, "Open with {0}", handler.Text );
     this.Image = handler.Image;
     this.Click += new EventHandler ( FileTypeHandlerToolStripMenuItem_Click );
 }
Exemple #3
0
        private void BuildOpenMenu( FileSystemInfoListViewItem item )
        {
            foreach ( var x in OpenWithItems ) {
                fileListContextMenuStrip.Items.Remove ( x );
            }

            string ext = DroidExplorer.Core.IO.Path.GetExtension ( item.FileSystemInfo.Name );
            if ( FileTypeActionHandlers.ContainsKey ( ext ) ) {
                IFileTypeHandler ifth = FileTypeActionHandlers[ext];
                FileTypeHandlerToolStripMenuItem mi = new FileTypeHandlerToolStripMenuItem ( item, ifth );
                OpenWithItems.Add ( mi );
                int beforeIndex = fileListContextMenuStrip.Items.IndexOf ( openWithContextToolStripMenuItem );
                fileListContextMenuStrip.Items.Insert ( beforeIndex, mi );
            }
        }
Exemple #4
0
        private void BuildListViewItems( List<DroidExplorer.Core.IO.FileSystemInfo> fsiList )
        {
            try {
                if ( this.InvokeRequired ) {
                    this.Invoke ( new SetStatusBarLabelTextDelegate ( this.SetStatusBarLabelText ), new object[] { sizeToolStripStatusLabel, string.Empty } );
                    this.Invoke ( new SetStatusBarLabelTextDelegate ( SetStatusBarLabelText ), new object[] { objectsToolStripStatusLabel, "Scanning for items..." } );
                    this.Invoke ( new SetToolStripItemEnabledDelegate ( SetToolStripItemEnabled ), new object[] { copyToLocalToolStripButton, false } );
                    this.Invoke ( new GenericDelegate ( itemsList.Items.Clear ) );
                } else {
                    SetStatusBarLabelText ( objectsToolStripStatusLabel, "Scanning for items..." );
                    SetStatusBarLabelText ( sizeToolStripStatusLabel, string.Empty );
                    SetToolStripItemEnabled ( copyToLocalToolStripButton, false );
                    itemsList.Items.Clear ( );
                }

                long totalFileSize = 0;
                foreach ( DroidExplorer.Core.IO.FileSystemInfo item in fsiList ) {
                    try {

                        // filesize info
                        totalFileSize += item.Size;
                        string sizeString = String.Format ( new DroidExplorer.Core.IO.FileSizeFormatProvider ( ), "{0:fs}", totalFileSize );
                        if ( this.InvokeRequired ) {
                            this.Invoke ( new SetStatusBarLabelTextDelegate ( this.SetStatusBarLabelText ), new object[] { sizeToolStripStatusLabel, sizeString } );
                        } else {
                            SetStatusBarLabelText ( sizeToolStripStatusLabel, sizeString );
                        }

                        ListViewItem listViewItem = new FileSystemInfoListViewItem ( item );
                        var keyName = Cache.GetCacheKey ( item );
                        if ( !item.IsDirectory ) {
                            string ext = System.IO.Path.GetExtension ( item.Name );
                            keyName = ext.ToLower ( );
                            if ( keyName.StartsWith ( "/" ) ) {
                                keyName = keyName.Substring ( 1 );
                            }
                            keyName = keyName.REReplace ( @"\/\:", "." );
                            if ( !string.IsNullOrEmpty ( ext ) ) {
                                // file type icon handlers
                                if ( this.FileTypeIconHandlers.ContainsKey ( ext ) ) {
                                    var handler = this.FileTypeIconHandlers[ext];
                                    this.LogDebug ( "Loading image from Handler for {0}", ext );
                                    keyName = handler.GetKeyName ( item );
                                    if ( !SystemImageListHost.Instance.SystemIcons.ContainsKey ( keyName ) ) {
                                        var largeImage = handler.GetLargeImage ( item );
                                        var smallImage = largeImage.Resize ( 16, 16 );
                                        SystemImageListHost.Instance.AddFileTypeImage ( keyName, smallImage, largeImage );
                                    }
                                    // get the listview item from the handler
                                    listViewItem = handler.GetListViewItem ( item );
                                    var imageIndex = SystemImageListHost.Instance.SystemIcons[keyName];

                                    if ( this.InvokeRequired ) {
                                        this.Invoke ( (Action)( ( ) => {
                                            SetListViewItemImageIndex ( listViewItem, imageIndex );
                                        } ) );
                                    } else {
                                        SetListViewItemImageIndex ( listViewItem, imageIndex );
                                    }

                                } else {
                                    listViewItem = new FileSystemInfoListViewItem ( item );
                                    if ( !SystemImageListHost.Instance.SystemIcons.ContainsKey ( ext.ToLower ( ) ) ) { // add index and icon
                                        Image sico;
                                        Image lico;
                                        if ( this.InvokeRequired ) {
                                            int iconIndex = (int)this.Invoke ( new GetSystemIconIndexDelegate ( GetSystemIconIndex ), SystemImageListHost.Instance.SmallSystemImageList, item.Name );
                                            sico = (Image)this.Invoke ( new GetSystemBitmapDelegate ( GetSystemBitmap ), SystemImageListHost.Instance.SmallSystemImageList, iconIndex );
                                            lico = (Image)this.Invoke ( new GetSystemBitmapDelegate ( GetSystemBitmap ), SystemImageListHost.Instance.LargeSystemImageList, iconIndex );
                                        } else {
                                            int iconIndex = SystemImageListHost.Instance.SmallSystemImageList.IconIndex ( item.Name, false );
                                            sico = GetSystemBitmap ( SystemImageListHost.Instance.SmallSystemImageList, iconIndex );
                                            lico = GetSystemBitmap ( SystemImageListHost.Instance.LargeSystemImageList, iconIndex );
                                        }
                                        SystemImageListHost.Instance.AddFileTypeImage ( ext.ToLower ( ), sico, lico );
                                    }

                                    if ( this.InvokeRequired ) {
                                        this.Invoke ( new SetListViewItemImageIndexDelegate ( this.SetListViewItemImageIndex ), listViewItem, SystemImageListHost.Instance.SystemIcons[keyName] );
                                    } else {
                                        SetListViewItemImageIndex ( listViewItem, SystemImageListHost.Instance.SystemIcons[keyName] );
                                    }
                                }
                            }
                        }
                        if ( this.InvokeRequired ) {
                            this.Invoke ( new AddListViewItemDelegate ( this.AddListViewItem ), itemsList, listViewItem );
                            int lvCount = (int)this.Invoke ( new GetListViewItemsCountDelegate ( GetListViewItemsCount ), itemsList );
                            this.Invoke ( new SetStatusBarLabelTextDelegate ( SetStatusBarLabelText ), objectsToolStripStatusLabel, string.Format ( "{0} object{1}", lvCount, lvCount != 1 ? "s" : string.Empty ) );
                        } else {
                            AddListViewItem ( itemsList, listViewItem );
                            int lvCount = GetListViewItemsCount ( itemsList );
                            SetStatusBarLabelText ( objectsToolStripStatusLabel, string.Format ( "{0} object{1}", lvCount, lvCount != 1 ? "s" : string.Empty ) );
                        }
                    } catch ( ThreadAbortException taex ) {
                        // Ignore
                    } catch ( Exception ex ) {
                        this.LogError ( ex.Message, ex );
                    }
                }

                if ( this.InvokeRequired ) {
                    int lvCount = (int)this.Invoke ( new GetListViewItemsCountDelegate ( GetListViewItemsCount ), itemsList );
                    if ( lvCount == 0 ) {
                        this.Invoke ( new SetStatusBarLabelTextDelegate ( SetStatusBarLabelText ), objectsToolStripStatusLabel, "0 objects" );
                        this.Invoke ( new AutoResizeColumnsDelegate ( AutoResizeListViewColumnHeaders ), this.itemsList, ColumnHeaderAutoResizeStyle.HeaderSize );
                    } else {
                        this.Invoke ( new AutoResizeColumnsDelegate ( AutoResizeListViewColumnHeaders ), this.itemsList, ColumnHeaderAutoResizeStyle.ColumnContent );
                    }
                } else {
                    int lvCount = GetListViewItemsCount ( itemsList );
                    if ( lvCount == 0 ) {
                        SetStatusBarLabelText ( objectsToolStripStatusLabel, "0 objects" );
                        AutoResizeListViewColumnHeaders ( this.itemsList, ColumnHeaderAutoResizeStyle.HeaderSize );
                    } else {
                        AutoResizeListViewColumnHeaders ( this.itemsList, ColumnHeaderAutoResizeStyle.ColumnContent );
                    }
                }
            } catch ( Exception mex ) {
                this.LogError ( mex.Message, mex );
            }
        }
Exemple #5
0
        private void PrivateNavigate( DroidExplorer.Core.IO.LinuxDirectoryInfo path )
        {
            this.CurrentPath = path;
            string pathName = DroidExplorer.Core.IO.Path.GetDirectoryName ( path.FullName );
            if ( string.IsNullOrEmpty ( pathName ) ) {
                pathName = CommandRunner.Instance.GetSerialNumber ( );
            }
            if ( this.InvokeRequired ) {
                this.Invoke ( new GenericDelegate ( this.files.Items.Clear ) );
                this.Invoke ( new SetComboBoxExDisplayValueDelegate ( this.SetComboBoxExDisplayValue ), this.selectedPath, pathName );
            } else {
                this.files.Items.Clear ( );
                SetComboBoxExDisplayValue ( this.selectedPath, pathName );
            }
            List<DroidExplorer.Core.IO.FileSystemInfo> fsis = CommandRunner.Instance.GetDirectoryContents ( path.FullName );
            foreach ( var item in fsis ) {
                FileSystemInfoListViewItem lvi = new FileSystemInfoListViewItem ( item );
                if ( ( item.IsDirectory && !item.IsPipe && !item.IsSocket ) || ( IsFilterMatch ( item, SelectedFilter ) && !item.IsPipe && !item.IsSocket ) ) {
                    if ( !item.IsDirectory && !item.IsExecutable ) {
                        string ext = System.IO.Path.GetExtension ( lvi.FileSystemInfo.Name );
                        string keyName = ext.ToLower ( );
                        if ( keyName.StartsWith ( "/" ) ) {
                            keyName = keyName.Substring ( 1 );
                        }
                        keyName = keyName.Replace ( "/", "." );

                        if ( !string.IsNullOrEmpty ( ext ) ) {

                            if ( string.Compare ( ext, ".apk", true ) == 0 ) {

                                AaptBrandingCommandResult result = CommandRunner.Instance.GetApkInformation ( item.FullPath );
                                lvi = new ApkFileSystemInfoListViewItem ( item, result );

                                keyName = lvi.FileSystemInfo.FullPath;
                                if ( keyName.StartsWith ( "/" ) ) {
                                    keyName = keyName.Substring ( 1 );
                                }
                                keyName = keyName.Replace ( "/", "." );

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

                                    if ( img == null ) {
                                        img = DroidExplorer.Resources.Images.package32;
                                    } else {
                                        using ( System.IO.MemoryStream stream = new System.IO.MemoryStream ( ) ) {
                                            string lpath = System.IO.Path.GetDirectoryName ( this.GetType ( ).Assembly.Location );
                                            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 ( SetListViewItemImageIndex ), lvi, SystemImageListHost.Instance.SystemIcons[keyName] );
                                } else {
                                    SetListViewItemImageIndex ( lvi, SystemImageListHost.Instance.SystemIcons[keyName] );
                                }
                            } else {
                                if ( !SystemImageListHost.Instance.SystemIcons.ContainsKey ( ext.ToLower ( ) ) ) { // add index and icon
                                    Image sico;
                                    Image lico;
                                    if ( this.InvokeRequired ) {
                                        int iconIndex = (int)this.Invoke ( new GetSystemIconIndexDelegate ( GetSystemIconIndex ), new object[] { SystemImageListHost.Instance.SmallSystemImageList, item.Name } );
                                        sico = (Image)this.Invoke ( new GetSystemBitmapDelegate ( GetSystemBitmap ), new object[] { SystemImageListHost.Instance.SmallSystemImageList, iconIndex } );
                                        lico = (Image)this.Invoke ( new GetSystemBitmapDelegate ( GetSystemBitmap ), new object[] { SystemImageListHost.Instance.LargeSystemImageList, iconIndex } );
                                    } else {
                                        int iconIndex = SystemImageListHost.Instance.SmallSystemImageList.IconIndex ( item.Name, false );
                                        sico = GetSystemBitmap ( SystemImageListHost.Instance.SmallSystemImageList, iconIndex );
                                        lico = GetSystemBitmap ( SystemImageListHost.Instance.LargeSystemImageList, iconIndex );
                                    }
                                    SystemImageListHost.Instance.AddFileTypeImage ( ext.ToLower ( ), sico, lico );
                                }
                            }

                            if ( this.InvokeRequired ) {
                                this.Invoke ( new SetListViewItemImageIndexDelegate ( this.SetListViewItemImageIndex ), new object[] { lvi, SystemImageListHost.Instance.SystemIcons[keyName] } );
                            } else {
                                SetListViewItemImageIndex ( lvi, SystemImageListHost.Instance.SystemIcons[keyName] );
                            }
                        }
                    }
                    if ( this.InvokeRequired ) {
                        this.Invoke ( new AddListViewItemDelegate ( AddListViewItem ), this.files, lvi );
                    } else {
                        AddListViewItem ( this.files, lvi );
                    }
                }
            }

            if ( this.InvokeRequired ) {
                this.Invoke ( new AutoResizeColumnsDelegate ( AutoResizeColumns ), this.files, ColumnHeaderAutoResizeStyle.ColumnContent );
            } else {
                AutoResizeColumns ( this.files, ColumnHeaderAutoResizeStyle.ColumnContent );
            }
        }