Пример #1
0
        /// <summary>
        /// Method to create the <see cref="StackPanel"/> title container.
        /// </summary>
        /// <returns>A <see cref="StackPanel"/> as title container.</returns>
        private static StackPanel GetTitle(DriveInfo di)
        {
            // Get the icon image of the Drive.
            BitmapImage icon  = Win32Icon.IconFromHandle(di.Name).ToBitmap().ToBitmapImage();
            StackPanel  title = title = new StackPanel
            {
                Orientation = Orientation.Horizontal,
                Height      = 20,
                Children    =
                {
                    new Border()
                    {
                        Child = new Image
                        {
                            Width  = icon.Width,
                            Height = icon.Height,
                            Source = icon
                        }
                    }
                }
            };

            try
            {
                TextBlock volName = null;

                if (di.IsReady)
                {
                    volName = new TextBlock
                    {
                        Text   = $"{di.VolumeLabel} ({di.Name.ToString()})",
                        Margin = new Thickness(5, 0, 0, 0)
                    };
                }
                else
                {
                    volName = new TextBlock
                    {
                        Text       = $"Volume not ready ! ({di.Name.ToString()})",
                        Margin     = new Thickness(5, 0, 0, 0),
                        Foreground = Brushes.Red
                    };
                }

                title.Children.Add(volName);
            }

            catch (IOException io)
            {
                log.Debug(io.Output());
                MessageBoxs.Error(io);

                title.Children.Add(
                    new TextBlock
                {
                    Text       = $"Volume not ready ! ({di.Name.ToString()})",
                    Margin     = new Thickness(5, 0, 0, 0),
                    Foreground = Brushes.Red
                }
                    );

                title.ToolTip = io.Message;
            }

            catch (Exception e)
            {
                log.Debug(e.Output());
                MessageBoxs.Fatal(e);
            }

            return(title);
        }
Пример #2
0
		/// <summary>
		/// Reads the icon resource from a provided <B>.ICO</B> file stream.
		/// </summary>
		/// <param name="stream">The input stream.</param>
		/// <exception cref="InvalidDataException">The icon has an invalid format.</exception>
		private void ReadFromIcoFile(Stream/*!*/ stream)
		{
			icons = null;

			long max_length = (stream.CanSeek) ? stream.Length : Int32.MaxValue;

			using (BinaryReader r = new BinaryReader(stream))
			{
				int idReserved = r.ReadInt16();
				int idType = r.ReadInt16();
				if (idReserved != 0 || idType != 1)
				{
					throw new ArgumentException("Invalid .ICO file format", "stream");
				}
				long count = r.ReadInt16();

				icons = new Win32Icon[count];

				for (int i = 0; i < count; i++)
				{
					Win32Icon icon = new Win32Icon();

					icon.bWidth = r.ReadByte();
					icon.bHeight = r.ReadByte();
					icon.bColorCount = r.ReadByte();
					icon.bReserved = r.ReadByte();
					icon.wPlanes = r.ReadUInt16();
					icon.wBitCount = r.ReadUInt16();
					icon.id = (ushort)(i + 1);

					int length = r.ReadInt32();
					int offset = r.ReadInt32();

					// prevents allocation boom when the length or possions are invalid:
					if (length > max_length || offset > max_length)
						throw new InvalidDataException(CoreResources.GetString("invalid_icon_format"));

					icon.image = new byte[length];
					long pos = stream.Position;
					stream.Position = offset;
					stream.Read(icon.image, 0, length);
					stream.Position = pos;

					// The wPlanes and wBitCount members in the ICONDIRENTRY structure can be 0,
					// so we set them from the BITMAPINFOHEADER structure that follows
					if (icon.wPlanes == 0) icon.wPlanes = (ushort)(icon.image[12] | (icon.image[13] << 8));
					if (icon.wBitCount == 0) icon.wBitCount = (ushort)(icon.image[14] | (icon.image[15] << 8));

					icons[i] = icon;
				}
			}
		}
Пример #3
0
        /// <summary>
        /// Class Fotootof Components Server Browser Layouts Helper Tree View Item Directory Info Constructor.
        /// </summary>
        /// <param name="di">A <see cref="DirectoryInfo"/> create as <see cref="TreeViewItem"/>.</param>
        public TreeViewItemDirectoryInfo(DirectoryInfo di)
        {
            // Get the icon image of the Drive.
            BitmapImage icon = Win32Icon.IconFromHandle(di.FullName).ToBitmap().ToBitmapImage();

            double opacity = 1;

            if ((di.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
            {
                opacity = 0.5;
            }

            // Create the main content Grid.
            Grid header = new Grid();

            header.Height = 20;
            ColumnDefinition gr1 = new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            };

            header.ColumnDefinitions.Add(gr1);
            header.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });

            // Create the Title.
            StackPanel title = new StackPanel
            {
                Orientation = Orientation.Horizontal,
                Height      = 20,
                Children    =
                {
                    new Border()
                    {
                        Child = new Image
                        {
                            Width  = icon.Width,
                            Height = icon.Height,
                            Source = icon
                        }
                    },

                    new TextBlock
                    {
                        Text   = di.Name.ToString(),
                        Margin = new Thickness(5, 0, 0, 0)
                    }
                },
                Opacity = opacity
            };

            // Create Drive special informations.
            string inf = "NaN";

            try
            {
                inf = di.GetFiles().Length.ToString();
                inf = $"{inf}/{di.GetDirectories().Length.ToString()}";
            }
            catch (Exception e)
            {
                log.Debug(e.Output(), e);
                log.Debug($"{GetType().Name}.{MethodBase.GetCurrentMethod().Name} : {di?.Name}");
            }

            // Create TextBlock for the special informations.
            TextBlock count = new TextBlock
            {
                Text      = inf,
                Margin    = new Thickness(0, 0, 10, 0),
                FontStyle = FontStyles.Italic,
                FontSize  = 10
            };

            Grid.SetColumn(title, 0);
            Grid.SetColumn(count, 1);
            header.Children.Add(title);
            header.Children.Add(count);

            Header = header;
            HorizontalAlignment = HorizontalAlignment.Stretch;
            Tag   = di;
            Style = Application.Current.Resources["TreeViewItemStyle"] as Style;

            Items.Add("Loading...");
        }