123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Threading;
- using System.Diagnostics;
- using System.IO;
- using System.Runtime.InteropServices;
- namespace LYFZ.NeroDiscBurn.NET
- {
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。 UpdateSuccess
- /// </summary>
- [STAThread]
- static void Main(string[] args)
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new LYFZ.NeroDiscBurn.NET.BrunAPP.frmMain());
- }
-
- }
- //创建一个委托,是为访问DataGridVie控件服务的。
- public delegate void UpdateControl();
- public class ItemValue
- {
- private string _text = string.Empty;
- public string Text
- {
- get
- {
- if (this._text != null)
- {
- return this._text;
- }
- return string.Empty;
- }
- set { _text = value; }
- }
- private object _value = string.Empty;
- public object Value
- {
- get { return this._value; }
- set { this._value = value; }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="_value"></param>
- /// <param name="_text"></param>
- public ItemValue(object value, string text)
- {
- this._value = value;
- this._text = text;
- }
- public override string ToString()
- {
- return this._text;
- }
- }
- [StructLayout(LayoutKind.Sequential)]
- public struct SHFILEINFO
- {
- public IntPtr hIcon;
- public IntPtr iIcon;
- public uint dwAttributes;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
- public string szDisplayName;
- [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
- public string szTypeName;
- };
- class Win32
- {
- public const uint SHGFI_ICON = 0x100;
- public const uint SHGFI_LARGEICON = 0x0; // Large icon
- public const uint SHGFI_SMALLICON = 0x1; // Small icon
- [DllImport("shell32.dll")]
- public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
- [DllImport("user32.dll")]
- public static extern bool DestroyIcon(IntPtr handle);
- public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
- public const uint STGM_DELETEONRELEASE = 0x04000000;
- public const uint STGM_SHARE_DENY_WRITE = 0x00000020;
- public const uint STGM_SHARE_DENY_NONE = 0x00000040;
- public const uint STGM_READ = 0x00000000;
- [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false, EntryPoint = "SHCreateStreamOnFileW")]
- public static extern void SHCreateStreamOnFile(string fileName, uint mode, ref System.Runtime.InteropServices.ComTypes.IStream stream);
- }
- /// <summary>
- ///
- /// </summary>
- public class FileItem : IMediaItem
- {
- private const Int64 SECTOR_SIZE = 2048;
- private Int64 m_fileLength = 0;
- public FileItem(string path)
- {
- if (!File.Exists(path))
- {
- throw new FileNotFoundException("未发现加入的FileItem文件!", path);
- }
- filePath = path;
- FileInfo fileInfo = new FileInfo(filePath);
- displayName = fileInfo.Name;
- m_fileLength = fileInfo.Length;
- //
- // Get the File icon
- //
- SHFILEINFO shinfo = new SHFILEINFO();
- IntPtr hImg = Win32.SHGetFileInfo(filePath, 0, ref shinfo,
- (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
- if (shinfo.hIcon != null)
- {
- //The icon is returned in the hIcon member of the shinfo struct
- System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter();
- System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
- try
- {
- fileIconImage = (System.Drawing.Image)
- imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
- }
- catch (NotSupportedException)
- {
- }
- Win32.DestroyIcon(shinfo.hIcon);
- }
- }
- /// <summary>
- ///
- /// </summary>
- public Int64 SizeOnDisc
- {
- get
- {
- if (m_fileLength > 0)
- {
- return ((m_fileLength / SECTOR_SIZE) + 1) * SECTOR_SIZE;
- }
- return 0;
- }
- }
- /// <summary>
- ///
- /// </summary>
- public string Path
- {
- get
- {
- return filePath;
- }
- }
- private string filePath;
- /// <summary>
- ///
- /// </summary>
- public System.Drawing.Image FileIconImage
- {
- get
- {
- return fileIconImage;
- }
- }
- private System.Drawing.Image fileIconImage = null;
- /// <summary>
- ///
- /// </summary>
- public override string ToString()
- {
- return displayName;
- }
- private string displayName;
- /* public bool AddToFileSystem(IFsiDirectoryItem rootItem)
- {
- System.Runtime.InteropServices.ComTypes.IStream stream = null;
- try
- {
- Win32.SHCreateStreamOnFile(filePath, Win32.STGM_READ | Win32.STGM_SHARE_DENY_WRITE, ref stream);
- if (stream != null)
- {
- rootItem.AddFile(displayName, stream);
- return true;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "文件添加错误",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- if (stream != null)
- {
- Marshal.FinalReleaseComObject(stream);
- }
- }
- return false;
- }*/
- }
- interface IMediaItem
- {
- /// <summary>
- /// Returns the full path of the file or directory
- /// </summary>
- string Path { get; }
- /// <summary>
- /// Returns the size of the file or directory to the next largest sector
- /// </summary>
- Int64 SizeOnDisc { get; }
- /// <summary>
- /// Returns the Icon of the file or directory
- /// </summary>
- System.Drawing.Image FileIconImage { get; }
- }
- /// <summary>
- ///
- /// </summary>
- public class DirectoryItem : IMediaItem
- {
- private List<IMediaItem> mediaItems = new List<IMediaItem>();
- /// <summary>
- ///
- /// </summary>
- /// <param name="directoryPath"></param>
- public DirectoryItem(string directoryPath)
- {
- if (!Directory.Exists(directoryPath))
- {
- throw new FileNotFoundException("加入DirectoryItem目录未找到!", directoryPath);
- }
- if (directoryPath.Length <= 3)
- {
- throw new FileNotFoundException("目录不能直接为驱动盘本身!", directoryPath);
- }
- m_directoryPath = directoryPath;
- FileInfo fileInfo = new FileInfo(m_directoryPath);
- displayName = fileInfo.Name;
- //
- // Get all the files in the directory
- //
- string[] files = Directory.GetFiles(m_directoryPath);
- foreach (string file in files)
- {
- mediaItems.Add(new FileItem(file));
- }
- //
- // Get all the subdirectories
- //
- string[] directories = Directory.GetDirectories(m_directoryPath);
- foreach (string directory in directories)
- {
- mediaItems.Add(new DirectoryItem(directory));
- }
- //
- // Get the Directory icon
- //
- SHFILEINFO shinfo = new SHFILEINFO();
- IntPtr hImg = Win32.SHGetFileInfo(m_directoryPath, 0, ref shinfo,
- (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);
- if (shinfo.hIcon != null)
- {
- //The icon is returned in the hIcon member of the shinfo struct
- System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter();
- System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
- try
- {
- fileIconImage = (System.Drawing.Image)
- imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
- }
- catch (NotSupportedException)
- {
- }
- Win32.DestroyIcon(shinfo.hIcon);
- }
- }
- /// <summary>
- ///
- /// </summary>
- public string Path
- {
- get
- {
- return m_directoryPath;
- }
- }
- private string m_directoryPath;
- /// <summary>
- ///
- /// </summary>
- public override string ToString()
- {
- return displayName;
- }
- private string displayName;
- /// <summary>
- ///
- /// </summary>
- public Int64 SizeOnDisc
- {
- get
- {
- Int64 totalSize = 0;
- foreach (IMediaItem mediaItem in mediaItems)
- {
- totalSize += mediaItem.SizeOnDisc;
- }
- return totalSize;
- }
- }
- /// <summary>
- ///
- /// </summary>
- public System.Drawing.Image FileIconImage
- {
- get
- {
- return fileIconImage;
- }
- }
- private System.Drawing.Image fileIconImage = null;
-
- }
- }
|