diff --git a/Backup/Examples/FileDialog/FileDialog.Designer.cs b/Backup/Examples/FileDialog/FileDialog.Designer.cs new file mode 100644 index 0000000..1bbbcea --- /dev/null +++ b/Backup/Examples/FileDialog/FileDialog.Designer.cs @@ -0,0 +1,209 @@ +namespace FileDialog { + partial class FileDialog { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + System.Windows.Forms.Label filenameLabel; + System.Windows.Forms.Label filetypeLabel; + this.mainLayout = new System.Windows.Forms.TableLayoutPanel(); + this.shellView = new GongSolutions.Shell.ShellView(); + this.openButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.toolbar = new GongSolutions.Shell.FileDialogToolbar(); + this.filterCombo = new GongSolutions.Shell.FileFilterComboBox(); + this.fileNameCombo = new GongSolutions.Shell.FileNameComboBox(); + this.placesToolbar1 = new GongSolutions.Shell.PlacesToolbar(); + filenameLabel = new System.Windows.Forms.Label(); + filetypeLabel = new System.Windows.Forms.Label(); + this.mainLayout.SuspendLayout(); + this.SuspendLayout(); + // + // filenameLabel + // + filenameLabel.AutoSize = true; + filenameLabel.Dock = System.Windows.Forms.DockStyle.Fill; + filenameLabel.Location = new System.Drawing.Point(99, 271); + filenameLabel.Name = "filenameLabel"; + filenameLabel.Size = new System.Drawing.Size(70, 29); + filenameLabel.TabIndex = 0; + filenameLabel.Text = "File &name:"; + filenameLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // filetypeLabel + // + filetypeLabel.AutoSize = true; + filetypeLabel.Dock = System.Windows.Forms.DockStyle.Fill; + filetypeLabel.Location = new System.Drawing.Point(99, 300); + filetypeLabel.Name = "filetypeLabel"; + filetypeLabel.Size = new System.Drawing.Size(70, 29); + filetypeLabel.TabIndex = 2; + filetypeLabel.Text = "Files of &type:"; + filetypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // mainLayout + // + this.mainLayout.BackColor = System.Drawing.Color.Transparent; + this.mainLayout.ColumnCount = 4; + this.mainLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.mainLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.mainLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.mainLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.mainLayout.Controls.Add(this.shellView, 1, 1); + this.mainLayout.Controls.Add(filenameLabel, 1, 2); + this.mainLayout.Controls.Add(filetypeLabel, 1, 3); + this.mainLayout.Controls.Add(this.openButton, 3, 2); + this.mainLayout.Controls.Add(this.cancelButton, 3, 3); + this.mainLayout.Controls.Add(this.toolbar, 0, 0); + this.mainLayout.Controls.Add(this.filterCombo, 2, 3); + this.mainLayout.Controls.Add(this.fileNameCombo, 2, 2); + this.mainLayout.Controls.Add(this.placesToolbar1, 0, 1); + this.mainLayout.Dock = System.Windows.Forms.DockStyle.Fill; + this.mainLayout.Location = new System.Drawing.Point(0, 0); + this.mainLayout.Name = "mainLayout"; + this.mainLayout.Padding = new System.Windows.Forms.Padding(4); + this.mainLayout.RowCount = 4; + this.mainLayout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.mainLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.mainLayout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.mainLayout.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.mainLayout.Size = new System.Drawing.Size(521, 333); + this.mainLayout.TabIndex = 1; + // + // shellView + // + this.mainLayout.SetColumnSpan(this.shellView, 3); + this.shellView.Dock = System.Windows.Forms.DockStyle.Fill; + this.shellView.Location = new System.Drawing.Point(99, 41); + this.shellView.Name = "shellView"; + this.shellView.Size = new System.Drawing.Size(415, 227); + this.shellView.StatusBar = null; + this.shellView.TabIndex = 6; + this.shellView.Text = "shellView1"; + this.shellView.View = GongSolutions.Shell.ShellViewStyle.List; + this.shellView.DoubleClick += new System.EventHandler(this.shellView_DoubleClick); + this.shellView.SelectionChanged += new System.EventHandler(this.shellView_SelectionChanged); + // + // openButton + // + this.openButton.Dock = System.Windows.Forms.DockStyle.Right; + this.openButton.Enabled = false; + this.openButton.Location = new System.Drawing.Point(439, 274); + this.openButton.Name = "openButton"; + this.openButton.Size = new System.Drawing.Size(75, 23); + this.openButton.TabIndex = 4; + this.openButton.Text = "&Open"; + this.openButton.UseVisualStyleBackColor = true; + this.openButton.Click += new System.EventHandler(this.openButton_Click); + // + // cancelButton + // + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Dock = System.Windows.Forms.DockStyle.Right; + this.cancelButton.Location = new System.Drawing.Point(439, 303); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 5; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); + // + // toolbar + // + this.mainLayout.SetColumnSpan(this.toolbar, 4); + this.toolbar.Dock = System.Windows.Forms.DockStyle.Fill; + this.toolbar.Location = new System.Drawing.Point(7, 7); + this.toolbar.Name = "toolbar"; + this.toolbar.ShellView = this.shellView; + this.toolbar.Size = new System.Drawing.Size(507, 28); + this.toolbar.TabIndex = 7; + // + // filterCombo + // + this.filterCombo.Dock = System.Windows.Forms.DockStyle.Fill; + this.filterCombo.FilterItems = "Text Files (*.txt)|*.txt|Video Files|*.avi, *.wmv|All Files (*.*)|*.*"; + this.filterCombo.FormattingEnabled = true; + this.filterCombo.Location = new System.Drawing.Point(175, 303); + this.filterCombo.Name = "filterCombo"; + this.filterCombo.ShellView = this.shellView; + this.filterCombo.Size = new System.Drawing.Size(258, 21); + this.filterCombo.TabIndex = 3; + // + // fileNameCombo + // + this.fileNameCombo.Dock = System.Windows.Forms.DockStyle.Fill; + this.fileNameCombo.FilterControl = this.filterCombo; + this.fileNameCombo.FormattingEnabled = true; + this.fileNameCombo.Location = new System.Drawing.Point(175, 274); + this.fileNameCombo.Name = "fileNameCombo"; + this.fileNameCombo.ShellView = this.shellView; + this.fileNameCombo.Size = new System.Drawing.Size(258, 21); + this.fileNameCombo.TabIndex = 1; + this.fileNameCombo.FileNameEntered += new System.EventHandler(this.fileNameCombo_FilenameEntered); + this.fileNameCombo.TextChanged += new System.EventHandler(this.fileNameCombo_TextChanged); + // + // placesToolbar1 + // + this.placesToolbar1.AutoScrollMargin = new System.Drawing.Size(0, 0); + this.placesToolbar1.AutoScrollMinSize = new System.Drawing.Size(0, 0); + this.placesToolbar1.Dock = System.Windows.Forms.DockStyle.Fill; + this.placesToolbar1.Location = new System.Drawing.Point(7, 41); + this.placesToolbar1.Name = "placesToolbar1"; + this.mainLayout.SetRowSpan(this.placesToolbar1, 3); + this.placesToolbar1.ShellView = this.shellView; + this.placesToolbar1.Size = new System.Drawing.Size(86, 285); + this.placesToolbar1.TabIndex = 8; + // + // FileDialog + // + this.AcceptButton = this.openButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(521, 333); + this.Controls.Add(this.mainLayout); + this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.KeyPreview = true; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "FileDialog"; + this.ShowIcon = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show; + this.Text = "Example File Dialog"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FileDialog_FormClosed); + this.mainLayout.ResumeLayout(false); + this.mainLayout.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel mainLayout; + private GongSolutions.Shell.ShellView shellView; + private System.Windows.Forms.Button cancelButton; + private GongSolutions.Shell.FileDialogToolbar toolbar; + private GongSolutions.Shell.FileFilterComboBox filterCombo; + private GongSolutions.Shell.FileNameComboBox fileNameCombo; + private GongSolutions.Shell.PlacesToolbar placesToolbar1; + private System.Windows.Forms.Button openButton; + } +} diff --git a/Backup/Examples/FileDialog/FileDialog.cs b/Backup/Examples/FileDialog/FileDialog.cs new file mode 100644 index 0000000..9a41c40 --- /dev/null +++ b/Backup/Examples/FileDialog/FileDialog.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using System.Text.RegularExpressions; +using System.Windows.Forms; +using GongSolutions.Shell; + +namespace FileDialog +{ + public partial class FileDialog : Form + { + public FileDialog() + { + InitializeComponent(); + shellView.CurrentFolder = new ShellItem(Properties.Settings.Default.CurrentFolder); + shellView.History.Clear(); + } + + void OnFileSelected(string filename) + { + MessageBox.Show(filename); + } + + void UpdateOpenButtonState() + { + openButton.Enabled = (shellView.SelectedItems.Length > 0) || + (fileNameCombo.Text.Length > 0); + } + + void fileNameCombo_TextChanged(object sender, EventArgs e) + { + UpdateOpenButtonState(); + } + + void shellView_DoubleClick(object sender, EventArgs e) + { + OnFileSelected(shellView.SelectedItems[0].FileSystemPath); + } + + void shellView_SelectionChanged(object sender, EventArgs e) + { + UpdateOpenButtonState(); + } + + void fileNameCombo_FilenameEntered(object sender, EventArgs e) + { + OnFileSelected(fileNameCombo.Text); + } + + void openButton_Click(object sender, EventArgs e) + { + if (!shellView.NavigateSelectedFolder()) + { + ShellItem[] selected = shellView.SelectedItems; + + if (selected.Length > 0) + { + OnFileSelected(selected[0].FileSystemPath); + } + else if (File.Exists(fileNameCombo.Text)) + { + OnFileSelected(fileNameCombo.Text); + } + } + } + + void cancelButton_Click(object sender, EventArgs e) + { + Close(); + } + + void FileDialog_FormClosed(object sender, FormClosedEventArgs e) + { + Properties.Settings.Default.CurrentFolder = shellView.CurrentFolder.ToString(); + Properties.Settings.Default.Save(); + } + } +} diff --git a/Backup/Examples/FileDialog/FileDialog.csproj b/Backup/Examples/FileDialog/FileDialog.csproj new file mode 100644 index 0000000..1306a96 --- /dev/null +++ b/Backup/Examples/FileDialog/FileDialog.csproj @@ -0,0 +1,91 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {6D9343CF-7F87-4C36-ADB8-DD8667F38E51} + WinExe + Properties + FileDialog + FileDialog + + + + + 2.0 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + Form + + + FileDialog.cs + + + + + FileDialog.cs + Designer + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41} + Shell + + + + + \ No newline at end of file diff --git a/Backup/Examples/FileDialog/FileDialog.resx b/Backup/Examples/FileDialog/FileDialog.resx new file mode 100644 index 0000000..7c3f07c --- /dev/null +++ b/Backup/Examples/FileDialog/FileDialog.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + False + + \ No newline at end of file diff --git a/Backup/Examples/FileDialog/Program.cs b/Backup/Examples/FileDialog/Program.cs new file mode 100644 index 0000000..d794e47 --- /dev/null +++ b/Backup/Examples/FileDialog/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace FileDialog +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new FileDialog()); + } + } +} \ No newline at end of file diff --git a/Backup/Examples/FileDialog/Properties/AssemblyInfo.cs b/Backup/Examples/FileDialog/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dccacf3 --- /dev/null +++ b/Backup/Examples/FileDialog/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FileDialog")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FileDialog")] +[assembly: AssemblyCopyright("Copyright © 2006")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("b77e1932-b809-46e0-aaa5-e126de8c05b6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/Examples/FileDialog/Properties/Resources.Designer.cs b/Backup/Examples/FileDialog/Properties/Resources.Designer.cs new file mode 100644 index 0000000..59fcfaf --- /dev/null +++ b/Backup/Examples/FileDialog/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4927 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FileDialog.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FileDialog.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Backup/Examples/FileDialog/Properties/Resources.resx b/Backup/Examples/FileDialog/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Backup/Examples/FileDialog/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Backup/Examples/FileDialog/Properties/Settings.Designer.cs b/Backup/Examples/FileDialog/Properties/Settings.Designer.cs new file mode 100644 index 0000000..4c00113 --- /dev/null +++ b/Backup/Examples/FileDialog/Properties/Settings.Designer.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4927 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FileDialog.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("shell:///Personal")] + public string CurrentFolder { + get { + return ((string)(this["CurrentFolder"])); + } + set { + this["CurrentFolder"] = value; + } + } + } +} diff --git a/Backup/Examples/FileDialog/Properties/Settings.settings b/Backup/Examples/FileDialog/Properties/Settings.settings new file mode 100644 index 0000000..6eec06a --- /dev/null +++ b/Backup/Examples/FileDialog/Properties/Settings.settings @@ -0,0 +1,9 @@ + + + + + + shell:///Personal + + + \ No newline at end of file diff --git a/Backup/Examples/FileDialog/app.config b/Backup/Examples/FileDialog/app.config new file mode 100644 index 0000000..f9d5b83 --- /dev/null +++ b/Backup/Examples/FileDialog/app.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + shell:///Personal + + + + \ No newline at end of file diff --git a/Backup/Examples/ShellExplorer/ExplorerForm.Designer.cs b/Backup/Examples/ShellExplorer/ExplorerForm.Designer.cs new file mode 100644 index 0000000..36c0151 --- /dev/null +++ b/Backup/Examples/ShellExplorer/ExplorerForm.Designer.cs @@ -0,0 +1,238 @@ +namespace ShellExplorer { + partial class ShellExplorer { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShellExplorer)); + this.splitContainer = new System.Windows.Forms.SplitContainer(); + this.treeView = new GongSolutions.Shell.ShellTreeView(); + this.shellView = new GongSolutions.Shell.ShellView(); + this.statusBar = new System.Windows.Forms.StatusBar(); + this.mainMenu = new System.Windows.Forms.MainMenu(this.components); + this.fileMenu = new System.Windows.Forms.MenuItem(); + this.dummyMenuItem = new System.Windows.Forms.MenuItem(); + this.viewMenu = new System.Windows.Forms.MenuItem(); + this.refreshMenu = new System.Windows.Forms.MenuItem(); + this.toolBar = new System.Windows.Forms.ToolBar(); + this.backButton = new System.Windows.Forms.ToolBarButton(); + this.backButtonMenu = new System.Windows.Forms.ContextMenu(); + this.forwardButton = new System.Windows.Forms.ToolBarButton(); + this.forwardButtonMenu = new System.Windows.Forms.ContextMenu(); + this.upButton = new System.Windows.Forms.ToolBarButton(); + this.imageList = new System.Windows.Forms.ImageList(this.components); + this.shellComboBox1 = new GongSolutions.Shell.ShellComboBox(); + this.splitContainer.Panel1.SuspendLayout(); + this.splitContainer.Panel2.SuspendLayout(); + this.splitContainer.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer + // + this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer.Location = new System.Drawing.Point(0, 51); + this.splitContainer.Name = "splitContainer"; + // + // splitContainer.Panel1 + // + this.splitContainer.Panel1.Controls.Add(this.treeView); + // + // splitContainer.Panel2 + // + this.splitContainer.Panel2.Controls.Add(this.shellView); + this.splitContainer.Size = new System.Drawing.Size(610, 224); + this.splitContainer.SplitterDistance = 197; + this.splitContainer.TabIndex = 1; + // + // treeView + // + this.treeView.AllowDrop = true; + this.treeView.Dock = System.Windows.Forms.DockStyle.Fill; + this.treeView.Location = new System.Drawing.Point(0, 0); + this.treeView.Name = "treeView"; + this.treeView.ShellView = this.shellView; + this.treeView.Size = new System.Drawing.Size(197, 224); + this.treeView.TabIndex = 0; + this.treeView.Text = "shellTreeView1"; + // + // shellView + // + this.shellView.Dock = System.Windows.Forms.DockStyle.Fill; + this.shellView.Location = new System.Drawing.Point(0, 0); + this.shellView.Name = "shellView"; + this.shellView.Size = new System.Drawing.Size(409, 224); + this.shellView.StatusBar = this.statusBar; + this.shellView.TabIndex = 0; + this.shellView.Text = "shellView1"; + this.shellView.View = GongSolutions.Shell.ShellViewStyle.Details; + this.shellView.Navigated += new System.EventHandler(this.shellView_Navigated); + // + // statusBar + // + this.statusBar.Location = new System.Drawing.Point(0, 275); + this.statusBar.Name = "statusBar"; + this.statusBar.ShowPanels = true; + this.statusBar.Size = new System.Drawing.Size(610, 22); + this.statusBar.TabIndex = 1; + // + // mainMenu + // + this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.fileMenu, + this.viewMenu}); + // + // fileMenu + // + this.fileMenu.Index = 0; + this.fileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.dummyMenuItem}); + this.fileMenu.Text = "&File"; + this.fileMenu.Popup += new System.EventHandler(this.fileMenu_Popup); + // + // dummyMenuItem + // + this.dummyMenuItem.Index = 0; + this.dummyMenuItem.Text = "Dummy"; + this.dummyMenuItem.Visible = false; + // + // viewMenu + // + this.viewMenu.Index = 1; + this.viewMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { + this.refreshMenu}); + this.viewMenu.Text = "&View"; + // + // refreshMenu + // + this.refreshMenu.Index = 0; + this.refreshMenu.Shortcut = System.Windows.Forms.Shortcut.F5; + this.refreshMenu.Text = "&Refresh"; + this.refreshMenu.Click += new System.EventHandler(this.refreshMenu_Click); + // + // toolBar + // + this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat; + this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { + this.backButton, + this.forwardButton, + this.upButton}); + this.toolBar.DropDownArrows = true; + this.toolBar.ImageList = this.imageList; + this.toolBar.Location = new System.Drawing.Point(0, 0); + this.toolBar.Name = "toolBar"; + this.toolBar.ShowToolTips = true; + this.toolBar.Size = new System.Drawing.Size(610, 28); + this.toolBar.TabIndex = 2; + this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); + // + // backButton + // + this.backButton.DropDownMenu = this.backButtonMenu; + this.backButton.ImageIndex = 0; + this.backButton.Name = "backButton"; + this.backButton.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton; + // + // backButtonMenu + // + this.backButtonMenu.Popup += new System.EventHandler(this.backButton_Popup); + // + // forwardButton + // + this.forwardButton.DropDownMenu = this.forwardButtonMenu; + this.forwardButton.ImageIndex = 1; + this.forwardButton.Name = "forwardButton"; + this.forwardButton.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton; + // + // forwardButtonMenu + // + this.forwardButtonMenu.Popup += new System.EventHandler(this.forwardButton_Popup); + // + // upButton + // + this.upButton.ImageIndex = 2; + this.upButton.Name = "upButton"; + // + // imageList + // + this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream"))); + this.imageList.TransparentColor = System.Drawing.Color.Magenta; + this.imageList.Images.SetKeyName(0, "Back.bmp"); + this.imageList.Images.SetKeyName(1, "Forward.bmp"); + this.imageList.Images.SetKeyName(2, "Up.bmp"); + // + // shellComboBox1 + // + this.shellComboBox1.Dock = System.Windows.Forms.DockStyle.Top; + this.shellComboBox1.Editable = true; + this.shellComboBox1.Location = new System.Drawing.Point(0, 28); + this.shellComboBox1.Name = "shellComboBox1"; + this.shellComboBox1.ShellView = this.shellView; + this.shellComboBox1.Size = new System.Drawing.Size(610, 23); + this.shellComboBox1.TabIndex = 3; + this.shellComboBox1.Text = "shellComboBox1"; + // + // ShellExplorer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(610, 297); + this.Controls.Add(this.splitContainer); + this.Controls.Add(this.shellComboBox1); + this.Controls.Add(this.statusBar); + this.Controls.Add(this.toolBar); + this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Menu = this.mainMenu; + this.MinimumSize = new System.Drawing.Size(600, 200); + this.Name = "ShellExplorer"; + this.Text = "Shell Explorer"; + this.ResizeEnd += new System.EventHandler(this.ShellExplorer_ResizeEnd); + this.splitContainer.Panel1.ResumeLayout(false); + this.splitContainer.Panel2.ResumeLayout(false); + this.splitContainer.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private GongSolutions.Shell.ShellTreeView treeView; + private System.Windows.Forms.SplitContainer splitContainer; + private GongSolutions.Shell.ShellView shellView; + private System.Windows.Forms.StatusBar statusBar; + private System.Windows.Forms.MainMenu mainMenu; + private System.Windows.Forms.MenuItem fileMenu; + private System.Windows.Forms.ToolBar toolBar; + private System.Windows.Forms.ToolBarButton backButton; + private System.Windows.Forms.ToolBarButton forwardButton; + private System.Windows.Forms.ToolBarButton upButton; + private System.Windows.Forms.ImageList imageList; + private System.Windows.Forms.ContextMenu backButtonMenu; + private System.Windows.Forms.ContextMenu forwardButtonMenu; + private System.Windows.Forms.MenuItem dummyMenuItem; + private System.Windows.Forms.MenuItem viewMenu; + private System.Windows.Forms.MenuItem refreshMenu; + private GongSolutions.Shell.ShellComboBox shellComboBox1; + } +} + diff --git a/Backup/Examples/ShellExplorer/ExplorerForm.cs b/Backup/Examples/ShellExplorer/ExplorerForm.cs new file mode 100644 index 0000000..0920ab0 --- /dev/null +++ b/Backup/Examples/ShellExplorer/ExplorerForm.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell; + +namespace ShellExplorer +{ + public partial class ShellExplorer : Form + { + public ShellExplorer() + { + InitializeComponent(); + } + + protected override void WndProc(ref Message m) + { + if ((m_ContextMenu == null) || (!m_ContextMenu.HandleMenuMessage(ref m))) + { + base.WndProc(ref m); + } + } + + void shellView_Navigated(object sender, EventArgs e) + { + backButton.Enabled = shellView.CanNavigateBack; + forwardButton.Enabled = shellView.CanNavigateForward; + upButton.Enabled = shellView.CanNavigateParent; + } + + void fileMenu_Popup(object sender, EventArgs e) + { + ShellItem[] selectedItems = shellView.SelectedItems; + + if (selectedItems.Length > 0) + { + m_ContextMenu = new ShellContextMenu(selectedItems); + } + else + { + m_ContextMenu = new ShellContextMenu(treeView.SelectedFolder); + } + + m_ContextMenu.Populate(fileMenu); + } + + void refreshMenu_Click(object sender, EventArgs e) + { + shellView.RefreshContents(); + treeView.RefreshContents(); + } + + void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) + { + if (e.Button == backButton) + { + shellView.NavigateBack(); + } + else if (e.Button == forwardButton) + { + shellView.NavigateForward(); + } + else if (e.Button == upButton) + { + shellView.NavigateParent(); + } + } + + void backButton_Popup(object sender, EventArgs e) + { + List items = new List(); + + backButtonMenu.MenuItems.Clear(); + foreach (ShellItem f in shellView.History.HistoryBack) + { + MenuItem item = new MenuItem(f.DisplayName); + item.Tag = f; + item.Click += new EventHandler(backButtonMenuItem_Click); + items.Insert(0, item); + } + + backButtonMenu.MenuItems.AddRange(items.ToArray()); + } + + void forwardButton_Popup(object sender, EventArgs e) + { + forwardButtonMenu.MenuItems.Clear(); + foreach (ShellItem f in shellView.History.HistoryForward) + { + MenuItem item = new MenuItem(f.DisplayName); + item.Tag = f; + item.Click += new EventHandler(forwardButtonMenuItem_Click); + forwardButtonMenu.MenuItems.Add(item); + } + } + + void backButtonMenuItem_Click(object sender, EventArgs e) + { + MenuItem item = (MenuItem)sender; + ShellItem folder = (ShellItem)item.Tag; + shellView.NavigateBack(folder); + } + + void forwardButtonMenuItem_Click(object sender, EventArgs e) + { + MenuItem item = (MenuItem)sender; + ShellItem folder = (ShellItem)item.Tag; + shellView.NavigateForward(folder); + } + + void ShellExplorer_ResizeEnd(object sender, EventArgs e) + { + int calculatedWidth = shellView.Width - shellView.GetColumnWidth(1) + - shellView.GetColumnWidth(2) - shellView.GetColumnWidth(3) - 25; + shellView.SetColumnWidth(0, calculatedWidth); + } + + ShellContextMenu m_ContextMenu; + } +} \ No newline at end of file diff --git a/Backup/Examples/ShellExplorer/ExplorerForm.resx b/Backup/Examples/ShellExplorer/ExplorerForm.resx new file mode 100644 index 0000000..b7689ee --- /dev/null +++ b/Backup/Examples/ShellExplorer/ExplorerForm.resx @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 219, 17 + + + 354, 17 + + + 120, 17 + + + + AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w + LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 + ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD4 + EAAAAk1TRnQBSQFMAgEBAwEAAQwBAAEMAQABEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA + AwABEAMAAQEBAAEgBgABEJYAAYEBrwHdAf8BgQGvAd0B/wGjAdYB5QH/AcsB5QHrAf94AAHYAekB7AH/ + AYgBtgGVAf8BfAKBAf8BVAGBAVsB/wFUAYEBWQH/AVIBgQFWAf8BbQGBAXMB/wGBAYkBgQH/Ab4B1QHP + Af8cAAHsAvEB/wGUAbsBmAH/AYACgQH/AVQBgQFbAf8BVAGBAVkB/wFSAYEBVgH/AXABgQFzAf8BgQGN + AYEB/wHPAdwB1AH/FAABgQGvAd0B/wGfAdkB7AH/AWgBpQHWAf8BUgGZAcwB/wF7AakB0gH/AYEBvAHb + Af8BlQHRAeMB/wG+AeAB6QH/ZAABsAHSAcIB/wF9AYgBgQH/AV4BmAF0Af8BYwG2AYEB/wFfAbQBdwH/ + AVsBsgFuAf8BWAGwAWgB/wFTAa4BXQH/AVIBkQFZAf8BYAGBAWUB/wGIAakBlQH/FAABwQHZAcYB/wGB + AYkBgQH/AV4BmAF0Af8BYwG2AYEB/wFfAbQBdwH/AVsBsgFuAf8BWAGwAWgB/wFTAa4BXQH/AVIBkQFZ + Af8BYQGBAWUB/wGUAa4BmAH/EAABgQGvAd0B/wGBAckB5gH/AaAB5gL/AYEB3AL/AYEBzAHyAf8BgQG8 + AeYB/wFiAZwBuQH/AVIBmQHMAf8BbQGjAdEB/wGBAbgB2QH/AZUB0QHjAf9UAAG+AdwBzwH/AWcBiwF0 + Af8BbgG2AYEB/wFtAboBgQH/AWkBuAGBAf8BZAG2AYEB/wGBAcMBgQH/AWwBtwGAAf8BWgGyAW0B/wFW + Aa8BYwH/AVIBrQFbAf8BUgGBAVcB/wGIAakBlQH/DAABzwHjAdQB/wFoAYsBdAH/AW4BtgGBAf8BbQG6 + AYEB/wFpAbgBgQH/AYEBzQGBAf8BgQHVAYgB/wFdAbMBcwH/AVoBsgFtAf8BVgGvAWMB/wFSAa0BWwH/ + AVIBgQFXAf8BlAGuAZgB/wwAAYEBrwHdAf8BgQG8AeYB/wHIAfQC/wGDAegC/wGDAegC/wGDAegC/wFb + AYEBYgH/AXoBjgGBAf8BgQHRAeYB/wGBAcYB7AH/AYEBtQHeAf8BywHlAesB/1AAAYEBnwGBAf8BdQG3 + AYEB/wF2Ab4BgQH/AXMBvQGBAf8BbgG6AYEB/wGBAdMBiAX/AbUB6AG+Af8BYAG0AXgB/wFcAbIBbwH/ + AVkBsQFqAf8BVAGuAV8B/wFgAYEBZQH/Ab4B1QHPAf8IAAGBAaEBgQH/AXUBtwGBAf8BdgG+AYEB/wFz + Ab0BgQH/AW4BugGBAf8B1AHyAdwF/wGmAeQBsQH/AWABtAF4Af8BXAGyAW8B/wFZAbEBagH/AVQBrgFf + Af8BYQGBAWUB/wHPAdwB0wH/CAABgQGvAd0B/wGBAcAB6gH/AcEB6gH1Af8BjAHyAv8BjAHyAv8BjAHy + Av8BgQGsAYEB/wFsAYwBeAH/AWwCgQH/AYEB4AHvAf8BgQHfAfUB/wGIAcsB4QH/TAABowHTAbMB/wFp + AaQBgQH/AYEBwgGBAf8BfgHBAYEB/wF3Ab8BgQH/AYEB1gGVCf8BmgHgAasB/wFlAbYBgQH/AWMBtgGB + Af8BXQGzAXMB/wFbAbIBbgH/AVcBlwFkAf8BgQGGAYEB/wQAAbIB2QG3Af8BaQGkAYEB/wGBAcIBgQH/ + AX4BwQGBAf8BdwG/AYEB/wFuAbsBgQH/AYEB1gGUCf8BpgHkAbEB/wFjAbYBgQH/AV0BswFzAf8BWwGy + AW4B/wFXAZcBZAH/AYEBiQGBAf8IAAGBAa8B3QH/AYMB1AH8Af8BgQHGAeIB/wGsA/8BmQP/AZkD/wGG + AewB3wH/AXABlAGBAf8BgQHFAYEB/wGAAZMBgQH/AakB8gL/AYEBvQHeAf9MAAGBAbgBgQH/AXoBuwGB + Af8BgQHCAYEB/wGBAcIBgQH/AYEB2QGhCf8BrAHmAb8B/wFuAbsBgQH/AWwBugGBAf8BZwG4AYEB/wFk + AbYBgQH/AWEBtQF8Af8BXAGyAW8B/wFvAYEBdwH/BAABgQG8AYEB/wF6AbsBgQH/AYEBwgGBAf8BgQHC + AYEB/wFuAbsBgQH/AW4BuwGBAf8BdwG+AYEB/wGBAdYBlwn/AaYB5AGxAf8BZgG3AYEB/wFhAbUBfAH/ + AVwBsgFvAf8BcgGBAXcB/wgAAYEBrwHdAf8BiQHbAv8BgQG4AeIB/wGrAd8B7wH/AecD/wHZA/8BxgP/ + AWgBgQFzAf8BgQH0AY4B/wFrAYsBdwH/Aa8B5gHfAf8BpAHmAfIB/wGVAdEB4wH/SAABgQGsAYEB/wGB + AcIBgQH/AYEBwgGBAf8BgQHZAaMJ/wHxAfsB9QH/AZIB3wGsAf8BkgHfAawB/wGOAd0BowH/AY0B3QGi + Af8BiwHcAZ0B/wFmAbcBgQH/AWMBtgGBAf8BVwGBAWIB/wQAAYEBrwGBAf8BgQHCAYEB/wGBAdEBkCH/ + AagB5QG2Af8BZgG3AYEB/wFjAbYBgQH/AVcBgQFiAf8IAAGBAa8B3QH/AZUB6gL/AYEB5AH8Af8BgQHV + AfIB/wGBAcIB5gH/AYEBugHfAf8BnwHZAewB/wGBAYwBgQH/AYEB6gGFAf8BgQG+AYEB/wGHAbwBjwH/ + AfID/wGBAcEB3gH/SAABgQGyAYEB/wGBAcIBgQH/AYEBygGBJf8BbQG6AYEB/wFpAbgBgQH/AVwBjQFt + Af8BvgHhAc8B/wGBAbUBgQH/AYEBwgGBAf8BgQHRAZAh/wHVAfMB3gH/AW0BugGBAf8BaQG4AYEB/wFc + AY0BbQH/CAABgQGvAd0B/wGmAfgC/wGTAfkC/wGTAfkC/wGTAfkC/wGTAfkC/wGBAa8B3QH/AVwCgQH/ + AYEB4wGBAf8BgQHYAYEB/wGBAY8BgQH/AYEBrwHdAf8BgQGvAd0B/0gAAYEBtQGBAf8BgQHDAYEB/wGB + AcIBgQH/AYEB2QGjDf8BpAHkAb4B/wGXAeEBtQH/AZcB4QG1Af8BlQHgAbEB/wGSAd8BrAH/AXMBvQGB + Af8BbgG6AYEB/wFZAYEBZQH/AbAB3AHBAf8BgQG4AYEB/wGBAcMBgQH/AYEBwgGBAf8BgQHCAYEB/wGB + AcIBgQH/AYEBwgGBAf8BgQHCAYEB/wGJAd0BrAn/AdcB8wHiAf8BgQHCAYEB/wFzAb0BgQH/AW4BugGB + Af8BWQGBAWUB/wgAAYEBrwHdAf8BxwH+Av8BmQP/AZkD/wG+A/8B0QP/AcYD/wFdAYEBZwH/AYEB2gGB + Af8BgQHjAYEB/wF7AYMBgQH/UAABgQHMAYEB/wGBAcYBgQH/AYEBxwGBAf8BgQHCAYEB/wGBAdkBown/ + AdgB9AHjAf8BgQHGAYEB/wGBAcIBgQH/AYEBwgGBAf8BfgHBAYEB/wF3Ab8BgQH/AXUBvgGBAf8BfgGT + AYEB/wQAAYEB0QGBAf8BgQHGAYEB/wGBAccBgQH/AYEBwgGBAf8BgQHCAYEB/wGBAcIBgQH/AYEBzQGH + Af8B8gH7AfYF/wHYAfQB4wH/AYEBwgGBAf8BfgHBAYEB/wF3Ab8BgQH/AXUBvgGBAf8BgQGVAYEB/wgA + AYEBrwHdAf8BmQHZAewB/wHPAfkB/AH/AbwB9QHvAf8BgQGvAd0B/wGBAa8B3QH/AYEBrwHdAf8BZQGM + AXgB/wGBAdEBgQH/AYEB2gGBAf8BgQGHAYEB/1AAAb4B4wHPAf8BgQG+AYEB/wGBAdUBlQH/AYEBzAGC + Af8BgQHEAYEB/wGBAdkBown/AaQB5AG+Af8BgQHCAYEB/wGBAcIBgQH/AYEBwgGBAf8BgAHCAYEB/wFs + AacBgQH/AYEBuQGGAf8EAAHSAesB1AH/AYEBvgGBAf8BgQHVAZUB/wGBAcwBggH/AYEBxAGBAf8BgQHC + AYEB/wG+AewB0QX/AdgB9AHjAf8BgQHCAYEB/wGBAcIBgQH/AYEBwgGBAf8BgAHCAYEB/wFsAacBgQH/ + AYcBvgGJAf8MAAGBAa8B3QH/AYEBrwHdAf8BgQGvAd0B/wFSAYEBUgH/AVgBgQFdAf8BWgGBAWIB/wFz + Aa0BgQH/AYEBzAGBAf8BgQHRAYEB/wFtAYEBcAH/AVoBgQFiAf8BWgGBAWIB/0wAAYEBzQGBAf8BgQHW + AYMB/wGCAdoBoAH/AYEB0gGOAf8BgQHIAYEB/wGBAdoBpAH/AfIB+wH2Af8BiQHdAawB/wGBAcIBgQH/ + AYEBwgGBAf8BgQHCAYEB/wF9Ab8BgQH/AXABlAF5Af8BywHjAd4B/wgAAYEB0QGBAf8BgQHWAYMB/wGC + AdoBoAH/AYEB0gGOAf8BgQHCAYEB/wGBAcIBgQH/AZcB4QG1Af8BgQHCAYEB/wGBAcIBgQH/AYEBwgGB + Af8BgQHCAYEB/wF9Ab8BgQH/AXMBlQF5Af8B4QHsAeMB/xgAAYEBoAGBAf8BXAGMAWUB/wFsAbMBgQH/ + AXYBvQGBAf8BfQHEAYEB/wGBAcwBgQH/AXABoQGBAf8BVgGBAVkB/wGBAagBgQH/TAABywHnAd4B/wGB + AcUBgQH/AYEB1wGBAf8BmAHgAa0B/wGBAdcBmAH/AYEBzgGGAf8BgQHFAYEB/wGBAcIBgQH/AYEBwgGB + Af8BgQHCAYEB/wF6Ab0BgQH/AWgBngF2Af8BsAHYAcEB/wwAAeEB8AHjAf8BgQHHAYEB/wGBAdcBgQH/ + AZgB4AGtAf8BgQHXAZgB/wGBAc4BhgH/AYEBxQGBAf8BgQHCAYEB/wGBAcIBgQH/AYEBwgGBAf8BegG9 + AYEB/wFpAZ4BdgH/AcMB3wHFAf8cAAHLAeEB3gH/AW4BgQFyAf8BYAGgAW0B/wFsAbMBgQH/AXMBtwGB + Af8BZQGPAXgB/wF7AYEBfgH/AbAB0QHBAf9UAAHLAecB3gH/AYEBzgGBAf8BgQHLAYEB/wGEAdoBkQH/ + AYwB3AGmAf8BgQHTAZEB/wGBAcsBgQH/AYABvwGBAf8BaQGxAYEB/wGBAa8BgQH/AbAB2gHBAf8UAAHh + AfAB4wH/AYEB0gGBAf8BgQHLAYEB/wGEAdoBkQH/AYwB3AGmAf8BgQHTAZEB/wGBAcsBgQH/AYABvwGB + Af8BaQGxAYEB/wGBAbIBgQH/AcMB4QHFAf8kAAGjAcoBsgH/AVUBgQFZAf8BXgGYAWoB/wFjAYEBaAH/ + AYEBsQGFAf9kAAG+AeQBzwH/AYEB0QGBAf8BgQHDAYEB/wGBAb0BgQH/AYEBvAGBAf8BgQHEAYEB/wGj + AdkBsgH/JAAB0wHtAdUB/wGBAdYBgQH/AYEBxgGBAf8BgQHAAYEB/wGBAb8BgQH/AYEByQGBAf8BtgHg + AbYB/zAAAYEBoAGBAf8BgQGHAYEB/wG+AdoBzwH/WAABQgFNAT4HAAE+AwABKAMAAUADAAEQAwABAQEA + AQEFAAGAFwAD/wEABP8BhwH/AgAB4AEPAeABDwGAAX8CAAHAAQcBwAEHAYABDwIAAYABAwGAAQMBgAEH + AgABgAEBAYABAQGAAQcDAAEBAQABAQGAAQcDAAEBAQABAQGAAQMDAAEBAQABAQGAAQMFAAEBAYABAwUA + AQEBgAEPAwABAQEAAQEBgAEPAwABAQEAAQEBwAEDAgABgAEBAYABAQH4AQMCAAGAAQMBgAEDAfgBBwIA + AcABBwHAAQcB/AEfAgAB8AEfAfABHwH+AT8CAAs= + + + \ No newline at end of file diff --git a/Backup/Examples/ShellExplorer/Program.cs b/Backup/Examples/ShellExplorer/Program.cs new file mode 100644 index 0000000..b94ebde --- /dev/null +++ b/Backup/Examples/ShellExplorer/Program.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +namespace ShellExplorer +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new ShellExplorer()); + } + } +} \ No newline at end of file diff --git a/Backup/Examples/ShellExplorer/Properties/AssemblyInfo.cs b/Backup/Examples/ShellExplorer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6f0214a --- /dev/null +++ b/Backup/Examples/ShellExplorer/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShellExplorer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShellExplorer")] +[assembly: AssemblyCopyright("Copyright © 2006")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5e7bf9e9-f32d-4ad3-bf36-0ebf7e75e78a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/Examples/ShellExplorer/Properties/Resources.Designer.cs b/Backup/Examples/ShellExplorer/Properties/Resources.Designer.cs new file mode 100644 index 0000000..a95e5cd --- /dev/null +++ b/Backup/Examples/ShellExplorer/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4927 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShellExplorer.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShellExplorer.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Backup/Examples/ShellExplorer/Properties/Resources.resx b/Backup/Examples/ShellExplorer/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Backup/Examples/ShellExplorer/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Backup/Examples/ShellExplorer/Properties/Settings.Designer.cs b/Backup/Examples/ShellExplorer/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3571542 --- /dev/null +++ b/Backup/Examples/ShellExplorer/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4927 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShellExplorer.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Backup/Examples/ShellExplorer/Properties/Settings.settings b/Backup/Examples/ShellExplorer/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Backup/Examples/ShellExplorer/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Backup/Examples/ShellExplorer/ShellExplorer.csproj b/Backup/Examples/ShellExplorer/ShellExplorer.csproj new file mode 100644 index 0000000..ec49ec8 --- /dev/null +++ b/Backup/Examples/ShellExplorer/ShellExplorer.csproj @@ -0,0 +1,90 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {7258B802-D0E5-4268-9C71-3DCC6AF5C2C1} + WinExe + Properties + ShellExplorer + ShellExplorer + + + + + 2.0 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + Form + + + ExplorerForm.cs + + + + + ExplorerForm.cs + Designer + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41} + Shell + + + + + \ No newline at end of file diff --git a/Backup/GongShell.sln b/Backup/GongShell.sln new file mode 100644 index 0000000..246c033 --- /dev/null +++ b/Backup/GongShell.sln @@ -0,0 +1,38 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDialog", "Examples\FileDialog\FileDialog.csproj", "{6D9343CF-7F87-4C36-ADB8-DD8667F38E51}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShellExplorer", "Examples\ShellExplorer\ShellExplorer.csproj", "{7258B802-D0E5-4268-9C71-3DCC6AF5C2C1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shell", "Shell\Shell.csproj", "{711CCF1F-6B8F-4E97-8D84-0EE679C83B41}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShellTest", "Tests\ShellTest\ShellTest.csproj", "{EA474286-27FB-4DE3-83C6-90142DA951DD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6D9343CF-7F87-4C36-ADB8-DD8667F38E51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D9343CF-7F87-4C36-ADB8-DD8667F38E51}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D9343CF-7F87-4C36-ADB8-DD8667F38E51}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D9343CF-7F87-4C36-ADB8-DD8667F38E51}.Release|Any CPU.Build.0 = Release|Any CPU + {7258B802-D0E5-4268-9C71-3DCC6AF5C2C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7258B802-D0E5-4268-9C71-3DCC6AF5C2C1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7258B802-D0E5-4268-9C71-3DCC6AF5C2C1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7258B802-D0E5-4268-9C71-3DCC6AF5C2C1}.Release|Any CPU.Build.0 = Release|Any CPU + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41}.Debug|Any CPU.Build.0 = Debug|Any CPU + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41}.Release|Any CPU.ActiveCfg = Release|Any CPU + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41}.Release|Any CPU.Build.0 = Release|Any CPU + {EA474286-27FB-4DE3-83C6-90142DA951DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA474286-27FB-4DE3-83C6-90142DA951DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA474286-27FB-4DE3-83C6-90142DA951DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA474286-27FB-4DE3-83C6-90142DA951DD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Backup/Shell/FileDialogToolbar.Designer.cs b/Backup/Shell/FileDialogToolbar.Designer.cs new file mode 100644 index 0000000..e445977 --- /dev/null +++ b/Backup/Shell/FileDialogToolbar.Designer.cs @@ -0,0 +1,230 @@ +namespace GongSolutions.Shell { + partial class FileDialogToolbar { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + System.Windows.Forms.Label lookInLabel; + System.Windows.Forms.ToolStripMenuItem viewThumbnailsMenu; + System.Windows.Forms.ToolStripMenuItem viewTilesMenu; + System.Windows.Forms.ToolStripMenuItem viewIconsMenu; + System.Windows.Forms.ToolStripMenuItem viewListMenu; + System.Windows.Forms.ToolStripMenuItem viewDetailsMenu; + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FileDialogToolbar)); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.toolStrip = new System.Windows.Forms.ToolStrip(); + this.backButton = new System.Windows.Forms.ToolStripButton(); + this.upButton = new System.Windows.Forms.ToolStripButton(); + this.newFolderButton = new System.Windows.Forms.ToolStripButton(); + this.viewMenuButton = new System.Windows.Forms.ToolStripDropDownButton(); + this.shellComboBox = new GongSolutions.Shell.ShellComboBox(); + lookInLabel = new System.Windows.Forms.Label(); + viewThumbnailsMenu = new System.Windows.Forms.ToolStripMenuItem(); + viewTilesMenu = new System.Windows.Forms.ToolStripMenuItem(); + viewIconsMenu = new System.Windows.Forms.ToolStripMenuItem(); + viewListMenu = new System.Windows.Forms.ToolStripMenuItem(); + viewDetailsMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.tableLayoutPanel1.SuspendLayout(); + this.toolStrip.SuspendLayout(); + this.SuspendLayout(); + // + // lookInLabel + // + lookInLabel.AutoSize = true; + lookInLabel.Dock = System.Windows.Forms.DockStyle.Fill; + lookInLabel.Location = new System.Drawing.Point(3, 0); + lookInLabel.Name = "lookInLabel"; + lookInLabel.Size = new System.Drawing.Size(45, 31); + lookInLabel.TabIndex = 10; + lookInLabel.Text = "Look &in:"; + lookInLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + // + // viewThumbnailsMenu + // + viewThumbnailsMenu.Name = "viewThumbnailsMenu"; + viewThumbnailsMenu.Size = new System.Drawing.Size(138, 22); + viewThumbnailsMenu.Tag = "5"; + viewThumbnailsMenu.Text = "Thumbnails"; + viewThumbnailsMenu.Click += new System.EventHandler(this.viewThumbnailsMenu_Click); + // + // viewTilesMenu + // + viewTilesMenu.Name = "viewTilesMenu"; + viewTilesMenu.Size = new System.Drawing.Size(138, 22); + viewTilesMenu.Tag = "6"; + viewTilesMenu.Text = "Tiles"; + viewTilesMenu.Click += new System.EventHandler(this.viewThumbnailsMenu_Click); + // + // viewIconsMenu + // + viewIconsMenu.Name = "viewIconsMenu"; + viewIconsMenu.Size = new System.Drawing.Size(138, 22); + viewIconsMenu.Tag = "1"; + viewIconsMenu.Text = "Icons"; + viewIconsMenu.Click += new System.EventHandler(this.viewThumbnailsMenu_Click); + // + // viewListMenu + // + viewListMenu.Name = "viewListMenu"; + viewListMenu.Size = new System.Drawing.Size(138, 22); + viewListMenu.Tag = "3"; + viewListMenu.Text = "List"; + viewListMenu.Click += new System.EventHandler(this.viewThumbnailsMenu_Click); + // + // viewDetailsMenu + // + viewDetailsMenu.Name = "viewDetailsMenu"; + viewDetailsMenu.Size = new System.Drawing.Size(138, 22); + viewDetailsMenu.Tag = "4"; + viewDetailsMenu.Text = "Details"; + viewDetailsMenu.Click += new System.EventHandler(this.viewThumbnailsMenu_Click); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.AutoSize = true; + this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.tableLayoutPanel1.ColumnCount = 3; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanel1.Controls.Add(lookInLabel, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.toolStrip, 2, 0); + this.tableLayoutPanel1.Controls.Add(this.shellComboBox, 1, 0); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 1; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanel1.Size = new System.Drawing.Size(478, 31); + this.tableLayoutPanel1.TabIndex = 0; + // + // toolStrip + // + this.toolStrip.Dock = System.Windows.Forms.DockStyle.Fill; + this.toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; + this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.backButton, + this.upButton, + this.newFolderButton, + this.viewMenuButton}); + this.toolStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow; + this.toolStrip.Location = new System.Drawing.Point(377, 0); + this.toolStrip.Name = "toolStrip"; + this.toolStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; + this.toolStrip.Size = new System.Drawing.Size(101, 31); + this.toolStrip.TabIndex = 11; + this.toolStrip.TabStop = true; + this.toolStrip.Text = "toolStrip1"; + // + // backButton + // + this.backButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.backButton.Enabled = false; + this.backButton.Image = ((System.Drawing.Image)(resources.GetObject("backButton.Image"))); + this.backButton.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(233)))), ((int)(((byte)(216))))); + this.backButton.Name = "backButton"; + this.backButton.Size = new System.Drawing.Size(23, 28); + this.backButton.Text = "toolStripButton1"; + this.backButton.ToolTipText = "Back"; + this.backButton.Click += new System.EventHandler(this.backButton_Click); + // + // upButton + // + this.upButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.upButton.Enabled = false; + this.upButton.Image = ((System.Drawing.Image)(resources.GetObject("upButton.Image"))); + this.upButton.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(233)))), ((int)(((byte)(216))))); + this.upButton.Name = "upButton"; + this.upButton.Size = new System.Drawing.Size(23, 28); + this.upButton.Text = "toolStripButton2"; + this.upButton.ToolTipText = "Up One Level"; + this.upButton.Click += new System.EventHandler(this.upButton_Click); + // + // newFolderButton + // + this.newFolderButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.newFolderButton.Enabled = false; + this.newFolderButton.Image = ((System.Drawing.Image)(resources.GetObject("newFolderButton.Image"))); + this.newFolderButton.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(233)))), ((int)(((byte)(216))))); + this.newFolderButton.Name = "newFolderButton"; + this.newFolderButton.Size = new System.Drawing.Size(23, 28); + this.newFolderButton.Text = "toolStripButton3"; + this.newFolderButton.ToolTipText = "New Folder"; + this.newFolderButton.Click += new System.EventHandler(this.newFolderButton_Click); + // + // viewMenuButton + // + this.viewMenuButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.viewMenuButton.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + viewThumbnailsMenu, + viewTilesMenu, + viewIconsMenu, + viewListMenu, + viewDetailsMenu}); + this.viewMenuButton.Enabled = false; + this.viewMenuButton.Image = ((System.Drawing.Image)(resources.GetObject("viewMenuButton.Image"))); + this.viewMenuButton.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(236)))), ((int)(((byte)(233)))), ((int)(((byte)(216))))); + this.viewMenuButton.Name = "viewMenuButton"; + this.viewMenuButton.Size = new System.Drawing.Size(29, 28); + this.viewMenuButton.Text = "toolStripDropDownButton1"; + this.viewMenuButton.ToolTipText = "Views"; + // + // shellComboBox + // + this.shellComboBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.shellComboBox.Enabled = false; + this.shellComboBox.Location = new System.Drawing.Point(54, 3); + this.shellComboBox.Name = "shellComboBox"; + this.shellComboBox.Size = new System.Drawing.Size(320, 25); + this.shellComboBox.TabIndex = 9; + this.shellComboBox.Text = "shellComboBox1"; + this.shellComboBox.Changed += new System.EventHandler(this.shellComboBox_Changed); + // + // FileDialogToolbar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.Controls.Add(this.tableLayoutPanel1); + this.Name = "FileDialogToolbar"; + this.Size = new System.Drawing.Size(478, 31); + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.toolStrip.ResumeLayout(false); + this.toolStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.ToolStrip toolStrip; + private System.Windows.Forms.ToolStripButton backButton; + private System.Windows.Forms.ToolStripButton upButton; + private System.Windows.Forms.ToolStripButton newFolderButton; + private System.Windows.Forms.ToolStripDropDownButton viewMenuButton; + private ShellComboBox shellComboBox; + + } +} diff --git a/Backup/Shell/FileDialogToolbar.cs b/Backup/Shell/FileDialogToolbar.cs new file mode 100644 index 0000000..fac3026 --- /dev/null +++ b/Backup/Shell/FileDialogToolbar.cs @@ -0,0 +1,141 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Design; +using System.Data; +using System.Text; +using System.Windows.Forms; + +namespace GongSolutions.Shell +{ + /// + /// Provides a toolbar suitable for use in file Open/Save dialogs. + /// + /// + /// + /// This control provides a toolbar containing a + /// and the various navigation buttons as + /// found in a standard file dialog. By setting the + /// property, the toolbar will automatically + /// control the navigation of a ShellView> control in response to the + /// user's actions. + /// + public partial class FileDialogToolbar : UserControl + { + + /// + /// Initializes a new instance of the FileDialogToolbar control. + /// + public FileDialogToolbar() + { + InitializeComponent(); + Dock = DockStyle.Top; + toolStrip.Renderer = new CustomRenderer(); + } + + /// + /// Gets/sets the root folder displayed in the toolbar's drop-down + /// folder list. + /// + [Editor(typeof(ShellItemEditor), typeof(UITypeEditor))] + public ShellItem RootFolder + { + get { return shellComboBox.RootFolder; } + set { shellComboBox.RootFolder = value; } + } + + + /// + /// Gets/sets the folder currently selected in the toolbar's combo box. + /// + [Editor(typeof(ShellItemEditor), typeof(UITypeEditor))] + public ShellItem SelectedFolder + { + get { return shellComboBox.SelectedFolder; } + set { shellComboBox.SelectedFolder = value; } + } + + /// + /// Gets/sets a whose navigation should be + /// controlled by the toolbar. + /// + [DefaultValue(null), Category("Behaviour")] + public ShellView ShellView + { + get { return shellComboBox.ShellView; } + set + { + shellComboBox.ShellView = value; + shellComboBox.Enabled = viewMenuButton.Enabled = (value != null); + UpdateButtons(); + } + } + + /// + /// Occurs when the needs to know + /// what items it should display in its drop-down list. + /// + public event FilterItemEventHandler FilterItem + { + add { shellComboBox.FilterItem += value; } + remove { shellComboBox.FilterItem -= value; } + } + + bool ShouldSerializeRootFolder() + { + return shellComboBox.ShouldSerializeRootFolder(); + } + + bool ShouldSerializeSelectedFolder() + { + return shellComboBox.ShouldSerializeSelectedFolder(); + } + + void UpdateButtons() + { + if (ShellView != null) + { + backButton.Enabled = ShellView.CanNavigateBack; + upButton.Enabled = ShellView.CanNavigateParent; + newFolderButton.Enabled = ShellView.CanCreateFolder; + } + } + + void shellComboBox_Changed(object sender, EventArgs e) + { + UpdateButtons(); + } + + void shellView_Navigated(object sender, EventArgs e) + { + UpdateButtons(); + } + + void backButton_Click(object sender, EventArgs e) + { + ShellView.NavigateBack(); + } + + void upButton_Click(object sender, EventArgs e) + { + ShellView.NavigateParent(); + } + + void newFolderButton_Click(object sender, EventArgs e) + { + ShellView.CreateNewFolder(); + } + + void viewThumbnailsMenu_Click(object sender, EventArgs e) + { + ToolStripMenuItem item = (ToolStripMenuItem)sender; + ShellView.View = (ShellViewStyle)Convert.ToInt32(item.Tag); + } + + class CustomRenderer : ToolStripSystemRenderer + { + protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { } + } + } +} diff --git a/Backup/Shell/FileDialogToolbar.resx b/Backup/Shell/FileDialogToolbar.resx new file mode 100644 index 0000000..82a52f8 --- /dev/null +++ b/Backup/Shell/FileDialogToolbar.resx @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + False + + + False + + + False + + + False + + + False + + + 17, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAoZJREFUOE+Vk1tI + 03EUx/9LXEtNS6cu3Ay8NtSZVmqzUeCF1UOB9lBIuAKzaVHRZWMQmYVMTGHVcARdHVY0b9PNNfE/NtPC + mQOHl8a0iVK99JBUD/nwbfsP/23THjpwHv6ccz7ne74//gwiJBzLJF5+6yFGV8YJ4re3CIIQsPiEOL6E + OJp5ihHaT38vfLFDOinBEbsYKtcddLrvQuWsR4P9GM5YBCjs46CkRwirq9eLDAnfsHC0ALdm5ejyaKCZ + laFpsgpXR4tx3pZLZ/UwH+mPE2GdC4FIP0hwe+Y6nroa0TZVC8X7MmhdDfi1ugLdfHMQpMaSjV0PdmJh + ye5X4lgiISLzoZ6+gsaJSlx+W4COjzdomeSyNghQbxPg4IskNL1R+HtkExdwdqwMsneHqMbA4aUfc7g2 + doAG1FpzUGXJwAkyDUX3c/wAkaEQF0f2rhv21XzbDYvtVPZ51NB9uoeK4RSUm3lgN7BgdXu9EOkLqeGb + 44fXu7vBm5WZuSg2ccBtjYRjkfQCdH5AqPyfq9+pjb7smG/D8/lWPHK3YN9gPHYbY7FdzvQvrDNJUD3E + pyHPAgy0fNZBPMRDqTkJ+00JyDPGIcuwDcn6SGTIk/2AfmcHirQcCrBmknpGRp/z2vMQ+UY2cr1bU/qj + wNNHIK6diaqmir8nlz4R4vhgGk6S6bRJSuclqoH8akDmQAy1dUcfC9HdYWBLY+CY9t6/Fg43idSWBJQb + eVgzySe3ckQEwWASuPotiO0JR0QXA8xzDKhfKdcbbpvqxR5lNlI1WymTMgaiKbmJvZsR1b0JLBUD7JqY + jYcDX0ttVCJPkYWIujCwasIQXs1Aymku6polwbL/+Vv+Z+EPwOqkYFQINXEAAAAASUVORK5CYII= + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAhNJREFUOE+Nk31o + klEUxicUrbYIQ5LSkIQaSR8EG2Mho7XBCEJY/TGi/jAqRlBRUIibMETWimT+sQYJwQwrGi3WB9EKJxll + K4Vh1MitdB/trUwQZEID6df7vqUwNNuFhwvnnue55znn3rKyEuukx4yxu5axCT+l8oqePXzrpdyyjPXX + VqO2rqXrQfvSRWLTITZ1bETrWUP1Iw1NT/RUuVRs7zQQiNz/v5BUuspZIZP3jWym9eU22sLVGG/oKD+z + HMud04Uin4dqyEHRpqDSugKlbSWN9/Qy+VSkDp1FK8ckLPItEZNRN9mFMVIZX15Iilc5VTL5wsReuaFF + GyYl8us14P4Lv7hHRARZZ6uUyZ2z+9ntMJQQ+HkbFnoXQRKuba+Qyec/NmNyNeSrK7BAoo/sFxvpD8cR + XjQRf2YUbfXT4KynK3GQQ/46XL5usao0scCJwh4weZmZ4UZS8bti0lcRUdmC3q6mZ/4IW65sIC4MkRZu + MhvpKxTIvncwEzwnkgbzvYgnL7Lzqg7zqz0c7d0hXj5AbMRUfISJ561kEgExyZmHfbBZnIKGXXYNqakO + MnEr06FLxQUEXwvMj8I3Rx7Ks6to6dmKEDlGMmgi9riGH3Ohfwi8sYLggU8W0uHDCL56nl5XEnYriHi1 + RIcPFHrPjeLPQ+pn/JZaJrwbMDDpM8uE71NL+Im5Jzw37i1eYom//BvT97UijFkf3wAAAABJRU5ErkJg + gg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAaBJREFUOE+9k0sr + RGEYx/kE8wUkCxsWykJ2bkXZWPgAMkWisbCxYENK41LKZWHDAmEhbNwat8UMZQzGROM2FHKMTA4TR2fm + 533H6MwZ7OTUr9Op9/9/nuf/vCcl5T8fdXWMp+05TDWvPN2cz+aZSG5KL0xFiuX7ta+Rlwm7YSTFsC4Y + FowSDjq527d/M5ViSaQzg2iJhdDh2mcnnwZSHCc6ZvrWl63o1nQ0mxCHnUSCg0Qa0ni35icYhLogCcVT + i+LtIxxwgGsSegrgIBf2c9DaSmMjGR0EWlH3qnjYrUdxN6Ec2NG1W9GJT+AFRw8UW6C9nNfmfKJFFp7n + hwwD3V0TqwbHgg3BgmDGQBmCMzHacEMsRDn/48WOYXC/WICmus1ZJOai9oI6zvVmnSH8WpUM8XqlAt7W + xCF58AeUDlS/jZuj+NyJe5YG974BCPbDXcc3wic2HlwVBJbLzBcosQPt0QMiSIkM83a9mLP5LHxTmfiX + KrnYakG5jO89+ZbJDkInI/in0/FOZ3PqqOZqx/674CcDaRK8iaf6nz/Xn9T6APCsze4CsUFsAAAAAElF + TkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAARtJREFUOE+lk81K + AmEUhp11mxZeSpfRfUTthFa56Dpm185MJGqIFq4KgpBB8W9ARURFIhP8Q1GSXs/76SExhxw98DIzzDzP + d74zM6HQofWS8xC+zAfOY9qDWds6z8C6yAbOcSS7Epy5sKL14BFu2YGc7FI/8tBoBvSmQHsIkPsjsG0X + jNbRdRMMazYXyLZMGv2AAsJ9WVkFXsdHcJt0wGjpNeGvMcw9Jv/pI9icxeQbaEq7HYF5LHeBN9nRe2sH + AWEVKKyC14af4OoUkBA0ez6xTQgWpG1XBsg8V/8REF4XEE63fwVOxUdw/+CA+RjBRIdGmHu/uXNM4sUt + gunqVRFsDZYD05UJp2rAk7SeKAGxwoaAX9U+OfRHNvwCFhF+EPCkEsgAAAAASUVORK5CYII= + + + \ No newline at end of file diff --git a/Backup/Shell/FileFilterComboBox.cs b/Backup/Shell/FileFilterComboBox.cs new file mode 100644 index 0000000..bcca014 --- /dev/null +++ b/Backup/Shell/FileFilterComboBox.cs @@ -0,0 +1,275 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.IO; +using System.Windows.Forms; +using System.Text; +using System.Text.RegularExpressions; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + /// + /// A file-filter combo box suitable for use in open/save file dialogs. + /// + /// + /// + /// + /// This control extends the class to provide + /// automatic filtering of shell items according to wildcard patterns. + /// By setting the control's property, the control + /// will automatically filter items in a ShellView. + /// + /// + /// + /// The property accepts a filter string + /// similar to that accepted by the standard + /// class, for example: + /// "Text files (*.txt)|*.txt|All files (*.*)|*.*" + /// + /// + /// + /// The currently selected filter is selected by the + /// property. This should be set to one of the filter patterns specified + /// in , e.g. "*.txt". + /// + /// + public class FileFilterComboBox : ComboBox + { + + /// + /// Initializes a new instance of the + /// class. + /// + public FileFilterComboBox() + { + DropDownStyle = ComboBoxStyle.DropDownList; + m_Regex = GenerateRegex(m_Filter); + } + + /// + /// Gets or sets the current filter string, which determines the + /// items that appear in the control's . + /// + [Category("Behaviour"), DefaultValue("*.*")] + public string Filter + { + get { return m_Filter; } + set + { + if ((value != null) && (value.Length > 0)) + { + m_Filter = value; + } + else + { + m_Filter = "*.*"; + } + + m_Regex = GenerateRegex(m_Filter); + + foreach (FilterItem item in Items) + { + if (item.Contains(m_Filter)) + { + try + { + m_IgnoreSelectionChange = true; + SelectedItem = item; + } + finally + { + m_IgnoreSelectionChange = false; + } + } + } + + if (m_ShellView != null) + { + m_ShellView.RefreshContents(); + } + } + } + + /// + /// This property does not apply to . + /// + [Browsable(false)] + [DefaultValue(ComboBoxStyle.DropDownList)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [EditorBrowsable(EditorBrowsableState.Never)] + public new ComboBoxStyle DropDownStyle + { + get { return base.DropDownStyle; } + set { base.DropDownStyle = value; } + } + + /// + /// Gets/sets the filter string which determines the choices that + /// appear in the control's drop-down list. + /// + /// + /// + /// + /// For each filtering option, the filter string contains a + /// description of the filter, followed by the vertical bar (|) and + /// the filter pattern. The strings for different filtering options + /// are separated by the vertical bar. + /// + /// + /// + /// If the filter itself does not appear in the description then + /// it will be automatically added when the control is displayed. + /// For example, in the example below the "Video files" entry will + /// be displayed as "Video files (*.avi, *.wmv)". Beacuse the "All + /// files" entry already has the filter string present in its + /// description, it will not be added again. + /// + /// + /// + /// + /// "Video files|*.avi, *.wmv|All files (*.*)|*.*" + /// + /// + /// + [Category("Behaviour")] + public string FilterItems + { + get { return m_FilterItems; } + set + { + int selection; + + Items.Clear(); + Items.AddRange(FilterItem.ParseFilterString(value, m_Filter, + out selection)); + + if (selection != -1) + { + SelectedIndex = selection; + } + else + { + try + { + m_IgnoreSelectionChange = true; + SelectedIndex = Items.Count - 1; + } + finally + { + m_IgnoreSelectionChange = false; + } + } + + m_FilterItems = value; + } + } + + /// + /// This property does not apply to . + /// + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public new ComboBox.ObjectCollection Items + { + get { return base.Items; } + } + + /// + /// Gets/sets the control that the + /// should filter the items of. + /// + [DefaultValue(null)] + [Category("Behaviour")] + public ShellView ShellView + { + get { return m_ShellView; } + set + { + if (m_ShellView != null) + { + m_ShellView.FilterItem -= new FilterItemEventHandler(m_ShellView_FilterItem); + } + + m_ShellView = value; + + if (m_ShellView != null) + { + m_ShellView.FilterItem += new FilterItemEventHandler(m_ShellView_FilterItem); + } + } + } + + /// + /// Generates a object equivalent to the + /// provided wildcard. + /// + /// + /// + /// The wildcard to generate a regex for. + /// + /// + /// + /// A regex equivalent to the wildcard. + /// + public static Regex GenerateRegex(string wildcard) + { + string[] wildcards = wildcard.Split(','); + StringBuilder regexString = new StringBuilder(); + + foreach (string s in wildcards) + { + if (regexString.Length > 0) + { + regexString.Append('|'); + } + + regexString.Append( + Regex.Escape(s). + Replace(@"\*", ".*"). + Replace(@"\?", ".")); + } + + return new Regex(regexString.ToString(), + RegexOptions.IgnoreCase | RegexOptions.Compiled); + } + + /// + /// Raises the event. + /// + /// + /// + /// An EventArgs that contains the event data. + /// + protected override void OnTextChanged(EventArgs e) + { + base.OnTextChanged(e); + + if (!m_IgnoreSelectionChange) + { + if (SelectedItem != null) + { + Filter = ((FilterItem)SelectedItem).Filter; + } + } + } + + void m_ShellView_FilterItem(object sender, FilterItemEventArgs e) + { + // Include items that are present in the filesystem, and are a + // folder, or match the current regex. + if (e.Include) + { + e.Include = (e.Item.IsFileSystem || e.Item.IsFileSystemAncestor) && + (e.Item.IsFolder || m_Regex.IsMatch(e.Item.FileSystemPath)); + } + } + + string m_Filter = "*.*"; + string m_FilterItems = ""; + ShellView m_ShellView; + Regex m_Regex; + bool m_IgnoreSelectionChange; + } +} diff --git a/Backup/Shell/FileNameComboBox.cs b/Backup/Shell/FileNameComboBox.cs new file mode 100644 index 0000000..d72b7c4 --- /dev/null +++ b/Backup/Shell/FileNameComboBox.cs @@ -0,0 +1,265 @@ +using System; +using System.IO; +using System.ComponentModel; +using System.Windows.Forms; + +namespace GongSolutions.Shell +{ + /// + /// A filename combo box suitable for use in file Open/Save dialogs. + /// + /// + /// + /// + /// This control extends the class to provide + /// auto-completion of filenames based on the folder selected in a + /// . The control also automatically navigates + /// the ShellView control when the user types a folder path. + /// + /// + public class FileNameComboBox : ComboBox + { + + /// + /// Initializes a new instance of the + /// class. + /// + [Category("Behaviour")] + [DefaultValue(null)] + public FileFilterComboBox FilterControl + { + get { return m_FilterControl; } + set { m_FilterControl = value; } + } + + /// + /// Gets/sets the control that the + /// should look for auto-completion + /// hints. + /// + [Category("Behaviour")] + [DefaultValue(null)] + public ShellView ShellView + { + get { return m_ShellView; } + set + { + DisconnectEventHandlers(); + m_ShellView = value; + ConnectEventHandlers(); + } + } + + /// + /// Occurs when a file name is entered into the + /// and the Return key pressed. + /// + public event EventHandler FileNameEntered; + + /// + /// Determines whether the specified key is a regular input key or a + /// special key that requires preprocessing. + /// + /// + /// + /// One of the values. + /// + /// + /// + /// true if the specified key is a regular input key; otherwise, false. + /// + protected override bool IsInputKey(Keys keyData) + { + if (keyData == Keys.Enter) + { + return true; + } + else + { + return base.IsInputKey(keyData); + } + } + + /// + /// Raises the event. + /// + /// + /// + /// A that contains the event data. + /// + protected override void OnKeyDown(KeyEventArgs e) + { + base.OnKeyDown(e); + + if (e.KeyCode == Keys.Enter) + { + if ((Text.Length > 0) && (!Open(Text)) && + (m_FilterControl != null)) + { + m_FilterControl.Filter = Text; + } + } + + m_TryAutoComplete = false; + } + + /// + /// Raises the event. + /// + /// + /// + /// A that contains the event data. + /// + protected override void OnKeyPress(KeyPressEventArgs e) + { + base.OnKeyPress(e); + m_TryAutoComplete = char.IsLetterOrDigit(e.KeyChar); + } + + /// + /// Raises the event. + /// + /// + /// + /// An that contains the event data. + /// + protected override void OnTextChanged(EventArgs e) + { + base.OnTextChanged(e); + if (m_TryAutoComplete) + { + try + { + AutoComplete(); + } + catch (Exception) { } + } + } + + void AutoComplete() + { + string path; + string pattern; + string[] matches; + bool rooted = true; + + if ((Text == string.Empty) || + (Text.IndexOfAny(new char[] { '?', '*' }) != -1)) + { + return; + } + + path = Path.GetDirectoryName(Text); + pattern = Path.GetFileName(Text); + + if (((path == null) || (path == string.Empty)) && + ((m_ShellView != null) && + m_ShellView.CurrentFolder.IsFileSystem && + (m_ShellView.CurrentFolder != ShellItem.Desktop))) + { + path = m_ShellView.CurrentFolder.FileSystemPath; + pattern = Text; + rooted = false; + } + + matches = Directory.GetFiles(path, pattern + '*'); + + for (int n = 0; n < 2; ++n) + { + if (matches.Length > 0) + { + int currentLength = Text.Length; + Text = rooted ? matches[0] : Path.GetFileName(matches[0]); + SelectionStart = currentLength; + SelectionLength = Text.Length; + break; + } + else + { + matches = Directory.GetDirectories(path, pattern + '*'); + } + } + } + + void ConnectEventHandlers() + { + if (m_ShellView != null) + { + m_ShellView.SelectionChanged += new EventHandler(m_ShellView_SelectionChanged); + } + } + + void DisconnectEventHandlers() + { + if (m_ShellView != null) + { + m_ShellView.SelectionChanged -= new EventHandler(m_ShellView_SelectionChanged); + } + } + + bool Open(string path) + { + bool result = false; + + if (File.Exists(path)) + { + if (FileNameEntered != null) + { + FileNameEntered(this, EventArgs.Empty); + } + result = true; + } + else if (Directory.Exists(path)) + { + if (m_ShellView != null) + { + m_ShellView.Navigate(path); + Text = string.Empty; + result = true; + } + } + else + { + OpenParentOf(path); + Text = Path.GetFileName(path); + } + + if (!Path.IsPathRooted(path) && + m_ShellView.CurrentFolder.IsFileSystem) + { + result = Open(Path.Combine(m_ShellView.CurrentFolder.FileSystemPath, + path)); + } + + return result; + } + + void OpenParentOf(string path) + { + string parent = Path.GetDirectoryName(path); + + if ((parent != null) && (parent.Length > 0) && + Directory.Exists(parent)) + { + if (m_ShellView != null) + { + m_ShellView.Navigate(parent); + } + } + } + + void m_ShellView_SelectionChanged(object sender, EventArgs e) + { + if ((m_ShellView.SelectedItems.Length > 0) && + (!m_ShellView.SelectedItems[0].IsFolder) && + (m_ShellView.SelectedItems[0].IsFileSystem)) + { + Text = Path.GetFileName(m_ShellView.SelectedItems[0].FileSystemPath); + } + } + + FileFilterComboBox m_FilterControl; + ShellView m_ShellView; + bool m_TryAutoComplete; + } +} diff --git a/Backup/Shell/FilterItem.cs b/Backup/Shell/FilterItem.cs new file mode 100644 index 0000000..c8d2f16 --- /dev/null +++ b/Backup/Shell/FilterItem.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GongSolutions.Shell +{ + internal class FilterItem + { + public FilterItem(string caption, string filter) + { + Caption = caption; + Filter = filter; + } + + public bool Contains(string filter) + { + string[] filters = Filter.Split(','); + + foreach (string s in filters) + { + if (filter == s.Trim()) return true; + } + + return false; + } + + public override string ToString() + { + string filterString = string.Format(" ({0})", Filter); + + if (Caption.EndsWith(filterString)) + { + return Caption; + } + else + { + return Caption + filterString; + } + } + + public static FilterItem[] ParseFilterString(string filterString) + { + int dummy; + return ParseFilterString(filterString, string.Empty, out dummy); + } + + public static FilterItem[] ParseFilterString(string filterString, + string existing, + out int existingIndex) + { + List result = new List(); + string[] items; + + existingIndex = -1; + + if (filterString != string.Empty) + { + items = filterString.Split('|'); + } + else + { + items = new string[0]; + } + + if ((items.Length % 2) != 0) + { + throw new ArgumentException( + "Filter string you provided is not valid. The filter " + + "string must contain a description of the filter, " + + "followed by the vertical bar (|) and the filter pattern." + + "The strings for different filtering options must also be " + + "separated by the vertical bar. Example: " + + "\"Text files|*.txt|All files|*.*\""); + } + + for (int n = 0; n < items.Length; n += 2) + { + FilterItem item = new FilterItem(items[n], items[n + 1]); + result.Add(item); + if (item.Filter == existing) existingIndex = result.Count - 1; + } + + return result.ToArray(); + } + + public string Caption; + public string Filter; + } +} diff --git a/Backup/Shell/Interop/BHID.cs b/Backup/Shell/Interop/BHID.cs new file mode 100644 index 0000000..48b54c8 --- /dev/null +++ b/Backup/Shell/Interop/BHID.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public class BHID + { + public static Guid SFObject + { + get { return m_SFObject; } + } + + public static Guid SFUIObject + { + get { return m_SFUIObject; } + } + + static Guid m_SFObject = new Guid("3981e224-f559-11d3-8e3a-00c04f6837d5"); + static Guid m_SFUIObject = new Guid("3981e225-f559-11d3-8e3a-00c04f6837d5"); + } +} diff --git a/Backup/Shell/Interop/CoClass.cs b/Backup/Shell/Interop/CoClass.cs new file mode 100644 index 0000000..e8a609e --- /dev/null +++ b/Backup/Shell/Interop/CoClass.cs @@ -0,0 +1,20 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public class CoClass + { + [ComImport, Guid("DC1C5A9C-E88A-4dde-A5A1-60F82A20AEF7")] + public class FileOpenDialog + { + } + + [ComImport, Guid("4df0c730-df9d-4ae3-9153-aa6b82e9795a")] + public class KnownFolderManager + { + } + } +} diff --git a/Backup/Shell/Interop/ComCtl32.cs b/Backup/Shell/Interop/ComCtl32.cs new file mode 100644 index 0000000..a9c558d --- /dev/null +++ b/Backup/Shell/Interop/ComCtl32.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public enum ILD + { + NORMAL = 0x00000000, + TRANSPARENT = 0x00000001, + MASK = 0x00000010, + IMAGE = 0x00000020, + ROP = 0x00000040, + BLEND25 = 0x00000002, + BLEND50 = 0x00000004, + OVERLAYMASK = 0x00000F00, + PRESERVEALPHA = 0x00001000, + } + + public class ComCtl32 + { + [DllImport("comctl32")] + public static extern bool ImageList_Draw(IntPtr himl, + int i, IntPtr hdcDst, int x, int y, uint fStyle); + + [DllImport("comctl32")] + public static extern bool ImageList_GetIconSize(IntPtr himl, out int cx, out int cy); + } +} diff --git a/Backup/Shell/Interop/HResult.cs b/Backup/Shell/Interop/HResult.cs new file mode 100644 index 0000000..aa97182 --- /dev/null +++ b/Backup/Shell/Interop/HResult.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public enum HResult + { + DRAGDROP_S_CANCEL = 0x00040101, + DRAGDROP_S_DROP = 0x00040100, + DRAGDROP_S_USEDEFAULTCURSORS = 0x00040102, + DATA_S_SAMEFORMATETC = 0x00040130, + S_OK = 0, + S_FALSE = 1, + E_NOINTERFACE = unchecked((int)0x80004002), + E_NOTIMPL = unchecked((int)0x80004001), + OLE_E_ADVISENOTSUPPORTED = unchecked((int)80040003), + MK_E_NOOBJECT = unchecked((int)0x800401E5), + } +} diff --git a/Backup/Shell/Interop/ICommDlgBrowser.cs b/Backup/Shell/Interop/ICommDlgBrowser.cs new file mode 100644 index 0000000..ab4e066 --- /dev/null +++ b/Backup/Shell/Interop/ICommDlgBrowser.cs @@ -0,0 +1,29 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public enum CDBOSC + { + CDBOSC_SETFOCUS, + CDBOSC_KILLFOCUS, + CDBOSC_SELCHANGE, + CDBOSC_RENAME, + CDBOSC_STATECHANGE, + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214F1-0000-0000-C000-000000000046")] + public interface ICommDlgBrowser + { + [PreserveSig] + HResult OnDefaultCommand(IShellView ppshv); + [PreserveSig] + HResult OnStateChange(IShellView ppshv, CDBOSC uChange); + [PreserveSig] + HResult IncludeObject(IShellView ppshv, IntPtr pidl); + } +} diff --git a/Backup/Shell/Interop/IContextMenu.cs b/Backup/Shell/Interop/IContextMenu.cs new file mode 100644 index 0000000..df59d13 --- /dev/null +++ b/Backup/Shell/Interop/IContextMenu.cs @@ -0,0 +1,114 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [Flags] + public enum CMF : uint + { + NORMAL = 0x00000000, + DEFAULTONLY = 0x00000001, + VERBSONLY = 0x00000002, + EXPLORE = 0x00000004, + NOVERBS = 0x00000008, + CANRENAME = 0x00000010, + NODEFAULT = 0x00000020, + INCLUDESTATIC = 0x00000040, + EXTENDEDVERBS = 0x00000100, + RESERVED = 0xffff0000, + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public struct CMINVOKECOMMANDINFO + { + public int cbSize; + public int fMask; + public IntPtr hwnd; + public string lpVerb; + public string lpParameters; + public string lpDirectory; + public int nShow; + public int dwHotKey; + public IntPtr hIcon; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public struct CMINVOKECOMMANDINFO_ByIndex + { + public int cbSize; + public int fMask; + public IntPtr hwnd; + public int iVerb; + public string lpParameters; + public string lpDirectory; + public int nShow; + public int dwHotKey; + public IntPtr hIcon; + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214e4-0000-0000-c000-000000000046")] + public interface IContextMenu + { + [PreserveSig] + HResult QueryContextMenu(IntPtr hMenu, uint indexMenu, int idCmdFirst, + int idCmdLast, CMF uFlags); + + void InvokeCommand(ref CMINVOKECOMMANDINFO pici); + + [PreserveSig] + HResult GetCommandString(int idcmd, uint uflags, int reserved, + [MarshalAs(UnmanagedType.LPStr)] StringBuilder commandstring, + int cch); + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214f4-0000-0000-c000-000000000046")] + public interface IContextMenu2 : IContextMenu + { + [PreserveSig] + new HResult QueryContextMenu(IntPtr hMenu, uint indexMenu, + int idCmdFirst, int idCmdLast, + CMF uFlags); + + void InvokeCommand(ref CMINVOKECOMMANDINFO_ByIndex pici); + + [PreserveSig] + new HResult GetCommandString(int idcmd, uint uflags, int reserved, + [MarshalAs(UnmanagedType.LPStr)] StringBuilder commandstring, + int cch); + + [PreserveSig] + HResult HandleMenuMsg(int uMsg, IntPtr wParam, IntPtr lParam); + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("bcfce0a0-ec17-11d0-8d10-00a0c90f2719")] + public interface IContextMenu3 : IContextMenu2 + { + [PreserveSig] + new HResult QueryContextMenu(IntPtr hMenu, uint indexMenu, int idCmdFirst, + int idCmdLast, CMF uFlags); + + [PreserveSig] + new HResult InvokeCommand(ref CMINVOKECOMMANDINFO pici); + + [PreserveSig] + new HResult GetCommandString(int idcmd, uint uflags, int reserved, + [MarshalAs(UnmanagedType.LPStr)] StringBuilder commandstring, + int cch); + + [PreserveSig] + new HResult HandleMenuMsg(int uMsg, IntPtr wParam, IntPtr lParam); + + [PreserveSig] + HResult HandleMenuMsg2(int uMsg, IntPtr wParam, IntPtr lParam, + out IntPtr plResult); + } +} diff --git a/Backup/Shell/Interop/IDropSource.cs b/Backup/Shell/Interop/IDropSource.cs new file mode 100644 index 0000000..24103e6 --- /dev/null +++ b/Backup/Shell/Interop/IDropSource.cs @@ -0,0 +1,18 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("00000121-0000-0000-C000-000000000046")] + public interface IDropSource + { + [PreserveSig] + HResult QueryContinueDrag(bool fEscapePressed, int grfKeyState); + [PreserveSig] + HResult GiveFeedback(int dwEffect); + } +} diff --git a/Backup/Shell/Interop/IDropTarget.cs b/Backup/Shell/Interop/IDropTarget.cs new file mode 100644 index 0000000..acfcefa --- /dev/null +++ b/Backup/Shell/Interop/IDropTarget.cs @@ -0,0 +1,22 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("00000122-0000-0000-C000-000000000046")] + public interface IDropTarget + { + void DragEnter(IDataObject pDataObj, int grfKeyState, + Point pt, ref int pdwEffect); + void DragOver(int grfKeyState, Point pt, ref int pdwEffect); + void DragLeave(); + void Drop(IDataObject pDataObj, int grfKeyState, + Point pt, ref int pdwEffect); + } +} diff --git a/Backup/Shell/Interop/IEnumIDList.cs b/Backup/Shell/Interop/IEnumIDList.cs new file mode 100644 index 0000000..2380e29 --- /dev/null +++ b/Backup/Shell/Interop/IEnumIDList.cs @@ -0,0 +1,26 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214F2-0000-0000-C000-000000000046")] + public interface IEnumIDList + { + [PreserveSig] + HResult Next(uint celt, + out IntPtr rgelt, + out uint pceltFetched); + + [PreserveSig] + HResult Skip(uint celt); + + [PreserveSig] + HResult Reset(); + + IEnumIDList Clone(); + } +} diff --git a/Backup/Shell/Interop/IFileDialog.cs b/Backup/Shell/Interop/IFileDialog.cs new file mode 100644 index 0000000..dabd661 --- /dev/null +++ b/Backup/Shell/Interop/IFileDialog.cs @@ -0,0 +1,153 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct COMDLG_FILTERSPEC + { + public string pszName; + public string pszSpec; + } + + public enum FDE_OVERWRITE_RESPONSE + { + FDEOR_DEFAULT = 0, + FDEOR_ACCEPT = 0x1, + FDEOR_REFUSE = 0x2 + } + + public enum FDE_SHAREVIOLATION_RESPONSE + { + FDESVR_DEFAULT = 0, + FDESVR_ACCEPT = 0x1, + FDESVR_REFUSE = 0x2 + } + + public enum FDAP + { + FDAP_BOTTOM = 0, + FDAP_TOP = 0x1 + } + + enum FILEOPENDIALOGOPTIONS + { + FOS_OVERWRITEPROMPT = 0x2, + FOS_STRICTFILETYPES = 0x4, + FOS_NOCHANGEDIR = 0x8, + FOS_PICKFOLDERS = 0x20, + FOS_FORCEFILESYSTEM = 0x40, + FOS_ALLNONSTORAGEITEMS = 0x80, + FOS_NOVALIDATE = 0x100, + FOS_ALLOWMULTISELECT = 0x200, + FOS_PATHMUSTEXIST = 0x800, + FOS_FILEMUSTEXIST = 0x1000, + FOS_CREATEPROMPT = 0x2000, + FOS_SHAREAWARE = 0x4000, + FOS_NOREADONLYRETURN = 0x8000, + FOS_NOTESTFILECREATE = 0x10000, + FOS_HIDEMRUPLACES = 0x20000, + FOS_HIDEPINNEDPLACES = 0x40000, + FOS_NODEREFERENCELINKS = 0x100000, + FOS_DONTADDTORECENT = 0x2000000, + FOS_FORCESHOWHIDDEN = 0x10000000, + FOS_DEFAULTNOMINIMODE = 0x20000000, + FOS_FORCEPREVIEWPANEON = 0x40000000 + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("42f85136-db7e-439c-85f1-e4075d135fc8")] + public interface IFileDialog + { + [PreserveSig] + HResult Show(IntPtr hwndParent); + + void SetFileTypes(uint cFileTypes, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] + COMDLG_FILTERSPEC[] rgFilterSpec); + + void SetFileTypeIndex(uint iFileType); + + uint GetFileTypeIndex(); + + HResult Advise(IFileDialogEvents pfde); + + void Unadvise(ushort dwCookie); + + void SetOptions(ushort fos); + + ushort GetOptions(); + + void SetDefaultFolder(IShellItem psi); + + void SetFolder(IShellItem psi); + + IShellItem GetFolder(); + + IShellItem GetCurrentSelection(); + + void SetFileName(string pszName); + + string GetFileName(); + + void SetTitle(string pszTitle); + + void SetOkButtonLabel(string pszText); + + void SetFileNameLabel(string pszLabel); + + IShellItem GetResult(); + + void AddPlace(IShellItem psi, FDAP fdap); + + void SetDefaultExtension(string pszDefaultExtension); + + void Close(int hr); + + void SetClientGuid(Guid guid); + + void ClearClientData(); + + void SetFilter(IShellItemFilter pFilter); + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("973510db-7d7f-452b-8975-74a85828d354")] + public interface IFileDialogEvents + { + [PreserveSig] + HResult OnFileOk(IFileDialog pfd); + + [PreserveSig] + HResult OnFolderChanging(IFileDialog pfd, IShellItem psiFolder); + + [PreserveSig] + HResult OnFolderChange(IFileDialog pfd); + + [PreserveSig] + HResult OnSelectionChange(IFileDialog pfd); + + [PreserveSig] + HResult OnShareViolation(IFileDialog pfd, IShellItem psi, + out FDE_SHAREVIOLATION_RESPONSE pResponse); + + [PreserveSig] + HResult OnTypeChange(IFileDialog pfd); + + [PreserveSig] + HResult OnOverwrite(IFileDialog pfd, IShellItem psi, out FDE_OVERWRITE_RESPONSE pResponse); + }; + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("2659B475-EEB8-48b7-8F07-B378810F48CF")] + public interface IShellItemFilter + { + int IncludeItem(IShellItem psi); + int GetEnumFlagsForItem(IShellItem psi, out SHCONTF pgrfFlags); + }; +} diff --git a/Backup/Shell/Interop/IKnownFolder.cs b/Backup/Shell/Interop/IKnownFolder.cs new file mode 100644 index 0000000..5a21099 --- /dev/null +++ b/Backup/Shell/Interop/IKnownFolder.cs @@ -0,0 +1,34 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("3AA7AF7E-9B36-420c-A8E3-F77D4674A488")] + public interface IKnownFolder + { + Guid GetId(); + + int GetCategory(); + + IShellItem GetShellItem( + [In] ushort dwFlags, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid rfid); + + string GetPath(ushort dwFlags); + + void SetPath(ushort dwFlags, string pszPath); + + IntPtr GetIDList(ushort dwFlags); + + Guid GetFolderType(); + + uint GetRedirectionCapabilities(); + + KNOWNFOLDER_DEFINITION GetFolderDefinition(); + } +} diff --git a/Backup/Shell/Interop/IKnownFolderManager.cs b/Backup/Shell/Interop/IKnownFolderManager.cs new file mode 100644 index 0000000..bd50851 --- /dev/null +++ b/Backup/Shell/Interop/IKnownFolderManager.cs @@ -0,0 +1,57 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("8BE2D872-86AA-4d47-B776-32CCA40C7018")] + public interface IKnownFolderManager + { + Guid FolderIdFromCsidl(int nCsidl); + + CSIDL FolderIdToCsidl( + [In, MarshalAs(UnmanagedType.LPStruct)] Guid rfid); + + void GetFolderIds( + [Out] out IntPtr ppKFId, + [Out] out uint pCount); + + IKnownFolder GetFolder( + [In, MarshalAs(UnmanagedType.LPStruct)] Guid rfid); + + [PreserveSig] + HResult GetFolderByName( + [In] string pszCanonicalName, + [Out] out IKnownFolder ppkf); + + void RegisterFolder( + [In, MarshalAs(UnmanagedType.LPStruct)] Guid rfid, + [In] IntPtr pKFD); + + void UnregisterFolder( + [In, MarshalAs(UnmanagedType.LPStruct)] Guid rfid); + + [PreserveSig] + HResult FindFolderFromPath( + [In] string pszPath, + [In] FFFP_MODE mode, + [Out] out IKnownFolder ppkf); + + [PreserveSig] + HResult FindFolderFromIDList( + [In] IntPtr pidl, + [Out] out IKnownFolder ppkf); + + string Redirect( + [In, MarshalAs(UnmanagedType.LPStruct)] Guid rfid, + [In] IntPtr hwnd, + [In] int flags, + [In] string pszTargetPath, + [In] uint cFolders, + [In] Guid[] pExclusion); + } +} diff --git a/Backup/Shell/Interop/IOleCommandTarget.cs b/Backup/Shell/Interop/IOleCommandTarget.cs new file mode 100644 index 0000000..9a81f95 --- /dev/null +++ b/Backup/Shell/Interop/IOleCommandTarget.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct OLECMDTEXT + { + public uint cmdtextf; + public uint cwActual; + public uint cwBuf; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)] + public char rgwz; + } + + [StructLayout(LayoutKind.Sequential)] + public struct OLECMD + { + public uint cmdID; + public uint cmdf; + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("b722bccb-4e68-101b-a2bc-00aa00404770")] + public interface IOleCommandTarget + { + void QueryStatus(ref Guid pguidCmdGroup, UInt32 cCmds, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] + OLECMD[] prgCmds, + ref OLECMDTEXT CmdText); + void Exec(ref Guid pguidCmdGroup, uint nCmdId, uint nCmdExecOpt, + ref object pvaIn, ref object pvaOut); + } +} diff --git a/Backup/Shell/Interop/IQueryInfo.cs b/Backup/Shell/Interop/IQueryInfo.cs new file mode 100644 index 0000000..bd5302d --- /dev/null +++ b/Backup/Shell/Interop/IQueryInfo.cs @@ -0,0 +1,19 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [Guid("00021500-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + public interface IQueryInfo + { + [PreserveSig] + void GetInfoTip(int dwFlags, out IntPtr ppwszTip); + + [PreserveSig] + void GetInfoFlags(IntPtr pdwFlags); + } +} diff --git a/Backup/Shell/Interop/IServiceProvider.cs b/Backup/Shell/Interop/IServiceProvider.cs new file mode 100644 index 0000000..d7798fc --- /dev/null +++ b/Backup/Shell/Interop/IServiceProvider.cs @@ -0,0 +1,17 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [Guid("6d5140c1-7436-11ce-8034-00aa006009fa")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + interface IServiceProvider + { + [PreserveSig] + HResult QueryService(ref Guid guidService, ref Guid riid, + out IntPtr ppvObject); + } +} diff --git a/Backup/Shell/Interop/IShellBrowser.cs b/Backup/Shell/Interop/IShellBrowser.cs new file mode 100644 index 0000000..e335a48 --- /dev/null +++ b/Backup/Shell/Interop/IShellBrowser.cs @@ -0,0 +1,82 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public enum FCW + { + FCW_STATUS = 0x0001, + FCW_TOOLBAR = 0x0002, + FCW_TREE = 0x0003, + FCW_INTERNETBAR = 0x0006, + FCW_PROGRESS = 0x0008, + } + + [Flags] + public enum SBSP : uint + { + SBSP_DEFBROWSER = 0x0000, + SBSP_SAMEBROWSER = 0x0001, + SBSP_NEWBROWSER = 0x0002, + SBSP_DEFMODE = 0x0000, + SBSP_OPENMODE = 0x0010, + SBSP_EXPLOREMODE = 0x0020, + SBSP_HELPMODE = 0x0040, + SBSP_NOTRANSFERHIST = 0x0080, + SBSP_ABSOLUTE = 0x0000, + SBSP_RELATIVE = 0x1000, + SBSP_PARENT = 0x2000, + SBSP_NAVIGATEBACK = 0x4000, + SBSP_NAVIGATEFORWARD = 0x8000, + SBSP_ALLOW_AUTONAVIGATE = 0x10000, + SBSP_CALLERUNTRUSTED = 0x00800000, + SBSP_TRUSTFIRSTDOWNLOAD = 0x01000000, + SBSP_UNTRUSTEDFORDOWNLOAD = 0x02000000, + SBSP_NOAUTOSELECT = 0x04000000, + SBSP_WRITENOHISTORY = 0x08000000, + SBSP_TRUSTEDFORACTIVEX = 0x10000000, + SBSP_REDIRECT = 0x40000000, + SBSP_INITIATEDBYHLINKFRAME = 0x80000000, + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214E2-0000-0000-C000-000000000046")] + public interface IShellBrowser + { + [PreserveSig] + HResult GetWindow(out IntPtr phwnd); + [PreserveSig] + HResult ContextSensitiveHelp(bool fEnterMode); + [PreserveSig] + HResult InsertMenusSB(IntPtr IntPtrShared, IntPtr lpMenuWidths); + [PreserveSig] + HResult SetMenuSB(IntPtr IntPtrShared, IntPtr holemenuRes, + IntPtr IntPtrActiveObject); + [PreserveSig] + HResult RemoveMenusSB(IntPtr IntPtrShared); + [PreserveSig] + HResult SetStatusTextSB(IntPtr pszStatusText); + [PreserveSig] + HResult EnableModelessSB(bool fEnable); + [PreserveSig] + HResult TranslateAcceleratorSB(IntPtr pmsg, ushort wID); + + [PreserveSig] + HResult BrowseObject(IntPtr pidl, SBSP wFlags); + [PreserveSig] + HResult GetViewStateStream(uint grfMode, IntPtr ppStrm); + [PreserveSig] + HResult GetControlWindow(FCW id, out IntPtr lpIntPtr); + [PreserveSig] + HResult SendControlMsg(FCW id, MSG uMsg, uint wParam, uint lParam, IntPtr pret); + [PreserveSig] + HResult QueryActiveShellView(out IShellView ppshv); + [PreserveSig] + HResult OnViewWindowActive(IShellView ppshv); + [PreserveSig] + HResult SetToolbarItems(IntPtr lpButtons, uint nButtons, uint uFlags); + } +} diff --git a/Backup/Shell/Interop/IShellFolder.cs b/Backup/Shell/Interop/IShellFolder.cs new file mode 100644 index 0000000..e88907f --- /dev/null +++ b/Backup/Shell/Interop/IShellFolder.cs @@ -0,0 +1,58 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214E6-0000-0000-C000-000000000046")] + public interface IShellFolder + { + void ParseDisplayName( + [In] IntPtr hwnd, + [In] IntPtr pbc, + [In, MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName, + [Out] out uint pchEaten, + [Out] out IntPtr ppidl, + [In, Out] ref uint pdwAttributes); + + [PreserveSig] + HResult EnumObjects( + [In] IntPtr hwnd, + [In] SHCONTF grfFlags, + [Out] out IEnumIDList ppenumIDList); + + void BindToObject(IntPtr pidl, IntPtr pbc, + [MarshalAs(UnmanagedType.LPStruct)] Guid riid, + out IntPtr ppv); + + void BindToStorage(IntPtr pidl, IntPtr pbc, + [MarshalAs(UnmanagedType.LPStruct)] Guid riid, + out IntPtr ppv); + + [PreserveSig] + short CompareIDs(SHCIDS lParam, IntPtr pidl1, IntPtr pidl2); + + IntPtr CreateViewObject(IntPtr hwndOwner, + [MarshalAs(UnmanagedType.LPStruct)] Guid riid); + + void GetAttributesOf(UInt32 cidl, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] + IntPtr[] apidl, + ref SFGAO rgfInOut); + + void GetUIObjectOf(IntPtr hwndOwner, UInt32 cidl, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] + IntPtr[] apidl, + [MarshalAs(UnmanagedType.LPStruct)] Guid riid, + UInt32 rgfReserved, + out IntPtr ppv); + + void GetDisplayNameOf(IntPtr pidl, SHGNO uFlags, out STRRET pName); + + void SetNameOf(IntPtr hwnd, IntPtr pidl, string pszName, + SHCONTF uFlags, out IntPtr ppidlOut); + } +} diff --git a/Backup/Shell/Interop/IShellItem.cs b/Backup/Shell/Interop/IShellItem.cs new file mode 100644 index 0000000..1eda1b2 --- /dev/null +++ b/Backup/Shell/Interop/IShellItem.cs @@ -0,0 +1,27 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")] + public interface IShellItem + { + IntPtr BindToHandler(IntPtr pbc, + [MarshalAs(UnmanagedType.LPStruct)]Guid bhid, + [MarshalAs(UnmanagedType.LPStruct)]Guid riid); + + [PreserveSig] + HResult GetParent(out IShellItem ppsi); + + IntPtr GetDisplayName(SIGDN sigdnName); + + SFGAO GetAttributes(SFGAO sfgaoMask); + + int Compare(IShellItem psi, SICHINT hint); + }; +} diff --git a/Backup/Shell/Interop/IShellItemArray.cs b/Backup/Shell/Interop/IShellItemArray.cs new file mode 100644 index 0000000..10eac22 --- /dev/null +++ b/Backup/Shell/Interop/IShellItemArray.cs @@ -0,0 +1,45 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("b63ea76d-1f85-456f-a19c-48159efa858b")] + public interface IShellItemArray + { + void BindToHandler( + [In] IntPtr pbc, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid bhid, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, + [Out] out IntPtr ppv); + + void GetPropertyStore( + [In] int flags, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, + [Out] out IntPtr ppv); + + void GetPropertyDescriptionList( + [In] int keyType, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, + [Out] out IntPtr ppv); + + void GetAttributes( + [In] int dwAttribFlags, + [In] int sfgaoMask, + [Out] out int psfgaoAttribs); + + void GetCount( + [Out] out ushort pdwNumItems); + + void GetItemAt( + [In] ushort dwIndex, + [Out, MarshalAs(UnmanagedType.Interface)] out IShellItem ppsi); + + void EnumItems( + [Out] out IntPtr ppenumShellItems); + } +} diff --git a/Backup/Shell/Interop/IShellView.cs b/Backup/Shell/Interop/IShellView.cs new file mode 100644 index 0000000..2edea38 --- /dev/null +++ b/Backup/Shell/Interop/IShellView.cs @@ -0,0 +1,49 @@ +using System; +using System.Drawing; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public enum SVGIO : uint + { + SVGIO_BACKGROUND = 0, + SVGIO_SELECTION = 0x1, + SVGIO_ALLVIEW = 0x2, + SVGIO_CHECKED = 0x3, + SVGIO_TYPE_MASK = 0xf, + SVGIO_FLAG_VIEWORDER = 0x80000000, + } + + [ComImport] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + [Guid("000214E3-0000-0000-C000-000000000046")] + public interface IShellView + { + void GetWindow(out IntPtr windowHandle); + void ContextSensitiveHelp(bool fEnterMode); + [PreserveSig] + long TranslateAcceleratorA(IntPtr message); + void EnableModeless(bool enable); + void UIActivate(UInt32 activtionState); + void Refresh(); + void CreateViewWindow( + IShellView previousShellView, + ref FOLDERSETTINGS folderSetting, + IShellBrowser shellBrowser, + ref Rectangle bounds, + out IntPtr handleOfCreatedWindow); + void DestroyViewWindow(); + void GetCurrentInfo(ref FOLDERSETTINGS pfs); + void AddPropertySheetPages([In, MarshalAs(UnmanagedType.U4)] uint reserved, [In]ref IntPtr functionPointer, [In] IntPtr lparam); + void SaveViewState(); + void SelectItem(IntPtr pidlItem, [MarshalAs(UnmanagedType.U4)] SVSI flags); + + [PreserveSig] + int GetItemObject( + [In] SVGIO AspectOfView, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, + [Out] out IntPtr ppv); + } +} diff --git a/Backup/Shell/Interop/Kernel32.cs b/Backup/Shell/Interop/Kernel32.cs new file mode 100644 index 0000000..85ab371 --- /dev/null +++ b/Backup/Shell/Interop/Kernel32.cs @@ -0,0 +1,13 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public class Kernel32 + { + [DllImport("kernel32.dll")] + public static extern IntPtr GlobalLock(IntPtr hMem); + } +} diff --git a/Backup/Shell/Interop/Ole32.cs b/Backup/Shell/Interop/Ole32.cs new file mode 100644 index 0000000..05d295a --- /dev/null +++ b/Backup/Shell/Interop/Ole32.cs @@ -0,0 +1,36 @@ +using System; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using ComTypes = System.Runtime.InteropServices.ComTypes; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public class Ole32 + { + [DllImport("ole32.dll")] + public static extern void CoTaskMemFree(IntPtr pv); + + [DllImport("ole32.dll")] + public static extern int DoDragDrop(ComTypes.IDataObject pDataObject, + IDropSource pDropSource, DragDropEffects dwOKEffect, + out DragDropEffects pdwEffect); + + [DllImport("ole32.dll")] + public static extern int RegisterDragDrop(IntPtr hwnd, IDropTarget pDropTarget); + + [DllImport("ole32.dll")] + public static extern int RevokeDragDrop(IntPtr hwnd); + + public static Guid IID_IDataObject + { + get { return new Guid("0000010e-0000-0000-C000-000000000046"); } + } + + public static Guid IID_IDropTarget + { + get { return new Guid("00000122-0000-0000-C000-000000000046"); } + } + } +} diff --git a/Backup/Shell/Interop/Shell32.cs b/Backup/Shell/Interop/Shell32.cs new file mode 100644 index 0000000..b8aa615 --- /dev/null +++ b/Backup/Shell/Interop/Shell32.cs @@ -0,0 +1,426 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + + public enum CSIDL + { + DESKTOP = 0x0000, + INTERNET = 0x0001, + PROGRAMS = 0x0002, + CONTROLS = 0x0003, + PRINTERS = 0x0004, + PERSONAL = 0x0005, + FAVORITES = 0x0006, + STARTUP = 0x0007, + RECENT = 0x0008, + SENDTO = 0x0009, + BITBUCKET = 0x000a, + STARTMENU = 0x000b, + MYDOCUMENTS = PERSONAL, + MYMUSIC = 0x000d, + MYVIDEO = 0x000e, + DESKTOPDIRECTORY = 0x0010, + DRIVES = 0x0011, + NETWORK = 0x0012, + NETHOOD = 0x0013, + FONTS = 0x0014, + TEMPLATES = 0x0015, + COMMON_STARTMENU = 0x0016, + COMMON_PROGRAMS = 0x0017, + COMMON_STARTUP = 0x0018, + COMMON_DESKTOPDIRECTORY = 0x0019, + APPDATA = 0x001a, + PRINTHOOD = 0x001b, + LOCAL_APPDATA = 0x001c, + ALTSTARTUP = 0x001d, + COMMON_ALTSTARTUP = 0x001e, + COMMON_FAVORITES = 0x001f, + INTERNET_CACHE = 0x0020, + COOKIES = 0x0021, + HISTORY = 0x0022, + COMMON_APPDATA = 0x0023, + WINDOWS = 0x0024, + SYSTEM = 0x0025, + PROGRAM_FILES = 0x0026, + MYPICTURES = 0x0027, + PROFILE = 0x0028, + SYSTEMX86 = 0x0029, + PROGRAM_FILESX86 = 0x002a, + PROGRAM_FILES_COMMON = 0x002b, + PROGRAM_FILES_COMMONX86 = 0x002c, + COMMON_TEMPLATES = 0x002d, + COMMON_DOCUMENTS = 0x002e, + COMMON_ADMINTOOLS = 0x002f, + ADMINTOOLS = 0x0030, + CONNECTIONS = 0x0031, + COMMON_MUSIC = 0x0035, + COMMON_PICTURES = 0x0036, + COMMON_VIDEO = 0x0037, + RESOURCES = 0x0038, + RESOURCES_LOCALIZED = 0x0039, + COMMON_OEM_LINKS = 0x003a, + CDBURN_AREA = 0x003b, + COMPUTERSNEARME = 0x003d, + } + + public enum ERROR + { + SUCCESS, + FILE_EXISTS = 80, + BAD_PATHNAME = 161, + ALREADY_EXISTS = 183, + FILENAME_EXCED_RANGE = 206, + CANCELLED = 1223, + } + + public enum FFFP_MODE + { + EXACTMATCH, + NEARESTPARENTMATCH, + } + + [Flags] + public enum FOLDERFLAGS : uint + { + AUTOARRANGE = 0x1, + ABBREVIATEDNAMES = 0x2, + SNAPTOGRID = 0x4, + OWNERDATA = 0x8, + BESTFITWINDOW = 0x10, + DESKTOP = 0x20, + SINGLESEL = 0x40, + NOSUBFOLDERS = 0x80, + TRANSPARENT = 0x100, + NOCLIENTEDGE = 0x200, + NOSCROLL = 0x400, + ALIGNLEFT = 0x800, + NOICONS = 0x1000, + SHOWSELALWAYS = 0x2000, + NOVISIBLE = 0x4000, + SINGLECLICKACTIVATE = 0x8000, + NOWEBVIEW = 0x10000, + HIDEFILENAMES = 0x20000, + CHECKSELECT = 0x40000 + } + + public enum FOLDERVIEWMODE : uint + { + FIRST = 1, + ICON = 1, + SMALLICON = 2, + LIST = 3, + DETAILS = 4, + THUMBNAIL = 5, + TILE = 6, + THUMBSTRIP = 7, + LAST = 7 + } + + public enum SHCONTF + { + FOLDERS = 0x0020, + NONFOLDERS = 0x0040, + INCLUDEHIDDEN = 0x0080, + INIT_ON_FIRST_NEXT = 0x0100, + NETPRINTERSRCH = 0x0200, + SHAREABLE = 0x0400, + STORAGE = 0x0800 + } + + [Flags] + public enum SFGAO : uint + { + CANCOPY = 0x00000001, + CANMOVE = 0x00000002, + CANLINK = 0x00000004, + STORAGE = 0x00000008, + CANRENAME = 0x00000010, + CANDELETE = 0x00000020, + HASPROPSHEET = 0x00000040, + DROPTARGET = 0x00000100, + CAPABILITYMASK = 0x00000177, + ENCRYPTED = 0x00002000, + ISSLOW = 0x00004000, + GHOSTED = 0x00008000, + LINK = 0x00010000, + SHARE = 0x00020000, + READONLY = 0x00040000, + HIDDEN = 0x00080000, + DISPLAYATTRMASK = 0x000FC000, + STREAM = 0x00400000, + STORAGEANCESTOR = 0x00800000, + VALIDATE = 0x01000000, + REMOVABLE = 0x02000000, + COMPRESSED = 0x04000000, + BROWSABLE = 0x08000000, + FILESYSANCESTOR = 0x10000000, + FOLDER = 0x20000000, + FILESYSTEM = 0x40000000, + HASSUBFOLDER = 0x80000000, + CONTENTSMASK = 0x80000000, + STORAGECAPMASK = 0x70C50008, + } + + [Flags] + public enum SHCIDS : uint + { + ALLFIELDS = 0x80000000, + CANONICALONLY = 0x10000000, + BITMASK = 0xFFFF0000, + COLUMNMASK = 0x0000FFFF, + } + + public enum SHCNE : uint + { + RENAMEITEM = 0x00000001, + CREATE = 0x00000002, + DELETE = 0x00000004, + MKDIR = 0x00000008, + RMDIR = 0x00000010, + MEDIAINSERTED = 0x00000020, + MEDIAREMOVED = 0x00000040, + DRIVEREMOVED = 0x00000080, + DRIVEADD = 0x00000100, + NETSHARE = 0x00000200, + NETUNSHARE = 0x00000400, + ATTRIBUTES = 0x00000800, + UPDATEDIR = 0x00001000, + UPDATEITEM = 0x00002000, + SERVERDISCONNECT = 0x00004000, + UPDATEIMAGE = 0x00008000, + DRIVEADDGUI = 0x00010000, + RENAMEFOLDER = 0x00020000, + FREESPACE = 0x00040000, + EXTENDED_EVENT = 0x04000000, + ASSOCCHANGED = 0x08000000, + DISKEVENTS = 0x0002381F, + GLOBALEVENTS = 0x0C0581E0, + ALLEVENTS = 0x7FFFFFFF, + INTERRUPT = 0x80000000, + } + + public enum SHCNRF + { + InterruptLevel = 0x0001, + ShellLevel = 0x0002, + RecursiveInterrupt = 0x1000, + NewDelivery = 0x8000, + } + + [Flags] + enum SHGFI + { + ICON = 0x000000100, + DISPLAYNAME = 0x000000200, + TYPENAME = 0x000000400, + ATTRIBUTES = 0x000000800, + ICONLOCATION = 0x000001000, + EXETYPE = 0x000002000, + SYSICONINDEX = 0x000004000, + LINKOVERLAY = 0x000008000, + SELECTED = 0x000010000, + ATTR_SPECIFIED = 0x000020000, + LARGEICON = 0x000000000, + SMALLICON = 0x000000001, + OPENICON = 0x000000002, + SHELLICONSIZE = 0x000000004, + PIDL = 0x000000008, + USEFILEATTRIBUTES = 0x000000010, + ADDOVERLAYS = 0x000000020, + OVERLAYINDEX = 0x000000040 + } + + public enum SHGNO + { + NORMAL = 0x0000, + INFOLDER = 0x0001, + FOREDITING = 0x1000, + FORADDRESSBAR = 0x4000, + FORPARSING = 0x8000, + } + + public enum SICHINT : uint + { + DISPLAY = 0x00000000, + CANONICAL = 0x10000000, + ALLFIELDS = 0x80000000 + } + + public enum SIGDN : uint + { + NORMALDISPLAY = 0, + PARENTRELATIVEPARSING = 0x80018001, + PARENTRELATIVEFORADDRESSBAR = 0x8001c001, + DESKTOPABSOLUTEPARSING = 0x80028000, + PARENTRELATIVEEDITING = 0x80031001, + DESKTOPABSOLUTEEDITING = 0x8004c000, + FILESYSPATH = 0x80058000, + URL = 0x80068000 + } + + public enum SVSI : uint + { + SVSI_DESELECT = 0x00000000, + SVSI_SELECT = 0x00000001, + } + + public struct FOLDERSETTINGS + { + public FOLDERVIEWMODE ViewMode; + public FOLDERFLAGS fFlags; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + public struct KNOWNFOLDER_DEFINITION + { + public int category; + public IntPtr pszName; + public IntPtr pszDescription; + public Guid fidParent; + public IntPtr pszRelativePath; + public IntPtr pszParsingName; + public IntPtr pszTooltip; + public IntPtr pszLocalizedName; + public IntPtr pszIcon; + public IntPtr pszSecurity; + public uint dwAttributes; + public int kfdFlags; + public Guid ftidType; + } + + public struct SHChangeNotifyEntry + { + public IntPtr pidl; + public bool fRecursive; + } + + public struct SHFILEINFO + { + public IntPtr hIcon; + public int iIcon; + public uint dwAttributes; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + public string szDisplayName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] + public string szTypeName; + } + + public struct SHNOTIFYSTRUCT + { + public IntPtr dwItem1; + public IntPtr dwItem2; + } + + [StructLayout(LayoutKind.Explicit, Size = 264)] + public struct STRRET + { + [FieldOffset(0)] + public UInt32 uType; + [FieldOffset(4)] + public IntPtr pOleStr; + [FieldOffset(4)] + public IntPtr pStr; + [FieldOffset(4)] + public UInt32 uOffset; + [FieldOffset(4)] + public IntPtr cStr; + } + + class Shell32 + { + [DllImport("shell32.dll", EntryPoint = "#660")] + public static extern bool FileIconInit(bool bFullInit); + + [DllImport("shell32.dll", EntryPoint = "#18")] + public static extern IntPtr ILClone(IntPtr pidl); + + [DllImport("shell32.dll", EntryPoint = "#25")] + public static extern IntPtr ILCombine(IntPtr pidl1, IntPtr pidl2); + + [DllImport("shell32.dll")] + public static extern IntPtr ILCreateFromPath(string pszPath); + + [DllImport("shell32.dll", EntryPoint = "#16")] + public static extern IntPtr ILFindLastID(IntPtr pidl); + + [DllImport("shell32.dll", EntryPoint = "#155")] + public static extern void ILFree(IntPtr pidl); + + [DllImport("shell32.dll", EntryPoint = "#21")] + public static extern bool ILIsEqual(IntPtr pidl1, IntPtr pidl2); + + [DllImport("shell32.dll", EntryPoint = "#23")] + public static extern bool ILIsParent(IntPtr pidl1, IntPtr pidl2, + bool fImmediate); + + [DllImport("shell32.dll", EntryPoint = "#17")] + public static extern bool ILRemoveLastID(IntPtr pidl); + + [DllImport("shell32.dll", EntryPoint = "#71")] + public static extern bool Shell_GetImageLists(out IntPtr lphimlLarge, + out IntPtr lphimlSmall); + + [DllImport("shell32.dll", EntryPoint = "#2")] + public static extern uint SHChangeNotifyRegister(IntPtr hWnd, + SHCNRF fSources, SHCNE fEvents, uint wMsg, int cEntries, + ref SHChangeNotifyEntry pFsne); + + [DllImport("shell32.dll", EntryPoint = "#4")] + public static extern bool SHChangeNotifyUnregister(uint hNotify); + + [DllImport("shell32.dll", EntryPoint = "#165", CharSet = CharSet.Unicode)] + public static extern ERROR SHCreateDirectory(IntPtr hwnd, string pszPath); + + [DllImport("shell32.dll", PreserveSig = false)] + public static extern IShellItem SHCreateItemFromIDList( + [In] IntPtr pidl, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid); + + [DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)] + public static extern IShellItem SHCreateItemFromParsingName( + [In] string pszPath, + [In] IntPtr pbc, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid); + + [DllImport("shell32.dll", CharSet = CharSet.Unicode, PreserveSig = false)] + public static extern IShellItem SHCreateItemWithParent( + [In] IntPtr pidlParent, + [In] IShellFolder psfParent, + [In] IntPtr pidl, + [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid); + + [DllImport("shell32.dll", PreserveSig = false)] + public static extern IShellFolder SHGetDesktopFolder(); + + [DllImport("shell32.dll")] + public static extern IntPtr SHGetFileInfo(IntPtr pszPath, + int dwFileAttributes, out SHFILEINFO psfi, int cbFileInfo, + SHGFI uFlags); + + [DllImport("shfolder.dll")] + public static extern HResult SHGetFolderPath( + [In] IntPtr hwndOwner, + [In] CSIDL nFolder, + [In] IntPtr hToken, + [In] uint dwFlags, + [Out] StringBuilder pszPath); + + [DllImport("shell32.dll", PreserveSig = false)] + public static extern IntPtr SHGetIDListFromObject( + [In, MarshalAs(UnmanagedType.IUnknown)] object punk); + + [DllImport("shell32.dll")] + public static extern bool SHGetPathFromIDList( + [In] IntPtr pidl, + [Out] StringBuilder pszPath); + + [DllImport("shell32.dll")] + public static extern HResult SHGetSpecialFolderLocation(IntPtr hwndOwner, + CSIDL nFolder, out IntPtr ppidl); + } +} diff --git a/Backup/Shell/Interop/ShlWapi.cs b/Backup/Shell/Interop/ShlWapi.cs new file mode 100644 index 0000000..23663d0 --- /dev/null +++ b/Backup/Shell/Interop/ShlWapi.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + public class ShlWapi + { + [DllImport("shlwapi.dll")] + public static extern Int32 StrRetToBuf(ref STRRET pstr, IntPtr pidl, + StringBuilder pszBuf, + UInt32 cchBuf); + } +} diff --git a/Backup/Shell/Interop/User32.cs b/Backup/Shell/Interop/User32.cs new file mode 100644 index 0000000..22e74bd --- /dev/null +++ b/Backup/Shell/Interop/User32.cs @@ -0,0 +1,282 @@ +using System; +using System.Runtime.InteropServices; + +#pragma warning disable 1591 + +namespace GongSolutions.Shell.Interop +{ + [Flags] + public enum LVIF + { + LVIF_TEXT = 0x0001, + LVIF_IMAGE = 0x0002, + LVIF_PARAM = 0x0004, + LVIF_STATE = 0x0008, + LVIF_INDENT = 0x0010, + LVIF_GROUPID = 0x0100, + LVIF_COLUMNS = 0x0200, + LVIF_NORECOMPUTE = 0x0800, + LVIF_DI_SETITEM = 0x1000, + LVIF_COLFMT = 0x00010000, + } + + [Flags] + public enum LVIS + { + LVIS_FOCUSED = 0x0001, + LVIS_SELECTED = 0x0002, + LVIS_CUT = 0x0004, + LVIS_DROPHILITED = 0x0008, + LVIS_ACTIVATING = 0x0020, + LVIS_OVERLAYMASK = 0x0F00, + LVIS_STATEIMAGEMASK = 0xF000, + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public struct LVITEMA + { + public LVIF mask; + public int iItem; + public int iSubItem; + public LVIS state; + public LVIS stateMask; + [MarshalAs(UnmanagedType.LPTStr)] + public string pszText; + public int cchTextMax; + public int iImage; + public int lParam; + } + + public enum LVSIL + { + LVSIL_NORMAL = 0, + LVSIL_SMALL = 1, + LVSIL_STATE = 2, + } + + [StructLayout(LayoutKind.Sequential)] + public struct MENUINFO + { + public int cbSize; + public MIM fMask; + public int dwStyle; + public int cyMax; + public IntPtr hbrBack; + public int dwContextHelpID; + public int dwMenuData; + } + + [StructLayout(LayoutKind.Sequential)] + public struct MENUITEMINFO + { + public int cbSize; + public MIIM fMask; + public uint fType; + public uint fState; + public int wID; + public IntPtr hSubMenu; + public int hbmpChecked; + public int hbmpUnchecked; + public int dwItemData; + public string dwTypeData; + public uint cch; + public int hbmpItem; + } + + public enum MF + { + MF_BYCOMMAND = 0x00000000, + MF_BYPOSITION = 0x00000400, + } + + public enum MIIM : uint + { + MIIM_STATE = 0x00000001, + MIIM_ID = 0x00000002, + MIIM_SUBMENU = 0x00000004, + MIIM_CHECKMARKS = 0x00000008, + MIIM_TYPE = 0x00000010, + MIIM_DATA = 0x00000020, + MIIM_STRING = 0x00000040, + MIIM_BITMAP = 0x00000080, + MIIM_FTYPE = 0x00000100, + } + + public enum MIM : uint + { + MIM_MAXHEIGHT = 0x00000001, + MIM_BACKGROUND = 0x00000002, + MIM_HELPID = 0x00000004, + MIM_MENUDATA = 0x00000008, + MIM_STYLE = 0x00000010, + MIM_APPLYTOSUBMENUS = 0x80000000, + } + + public enum MK + { + MK_LBUTTON = 0x0001, + MK_RBUTTON = 0x0002, + MK_SHIFT = 0x0004, + MK_CONTROL = 0x0008, + MK_MBUTTON = 0x0010, + MK_ALT = 0x1000, + } + + public enum MSG + { + WM_COMMAND = 0x0111, + WM_VSCROLL = 0x0115, + LVM_FIRST = 0x1000, + LVM_SETIMAGELIST = 0x1003, + LVM_GETITEMCOUNT = 0x1004, + LVM_GETITEMA = 0x1005, + LVM_EDITLABEL = 0x1017, + LVM_GETCOLUMNWIDTH = LVM_FIRST + 29, + LVM_SETCOLUMNWIDTH = LVM_FIRST + 30, + TVM_SETIMAGELIST = 4361, + TVM_SETITEMW = 4415 + } + + [Flags] + public enum TPM + { + TPM_LEFTBUTTON = 0x0000, + TPM_RIGHTBUTTON = 0x0002, + TPM_LEFTALIGN = 0x0000, + TPM_CENTERALIGN = 0x000, + TPM_RIGHTALIGN = 0x000, + TPM_TOPALIGN = 0x0000, + TPM_VCENTERALIGN = 0x0010, + TPM_BOTTOMALIGN = 0x0020, + TPM_HORIZONTAL = 0x0000, + TPM_VERTICAL = 0x0040, + TPM_NONOTIFY = 0x0080, + TPM_RETURNCMD = 0x0100, + TPM_RECURSE = 0x0001, + TPM_HORPOSANIMATION = 0x0400, + TPM_HORNEGANIMATION = 0x0800, + TPM_VERPOSANIMATION = 0x1000, + TPM_VERNEGANIMATION = 0x2000, + TPM_NOANIMATION = 0x4000, + TPM_LAYOUTRTL = 0x8000, + } + + [Flags] + public enum TVIF + { + TVIF_TEXT = 0x0001, + TVIF_IMAGE = 0x0002, + TVIF_PARAM = 0x0004, + TVIF_STATE = 0x0008, + TVIF_HANDLE = 0x0010, + TVIF_SELECTEDIMAGE = 0x0020, + TVIF_CHILDREN = 0x0040, + TVIF_INTEGRAL = 0x0080, + } + + [Flags] + public enum TVIS + { + TVIS_SELECTED = 0x0002, + TVIS_CUT = 0x0004, + TVIS_DROPHILITED = 0x0008, + TVIS_BOLD = 0x0010, + TVIS_EXPANDED = 0x0020, + TVIS_EXPANDEDONCE = 0x0040, + TVIS_EXPANDPARTIAL = 0x0080, + TVIS_OVERLAYMASK = 0x0F00, + TVIS_STATEIMAGEMASK = 0xF000, + TVIS_USERMASK = 0xF000, + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + struct TVITEMW + { + public TVIF mask; + public IntPtr hItem; + public TVIS state; + public TVIS stateMask; + public string pszText; + public int cchTextMax; + public int iImage; + public int iSelectedImage; + public int cChildren; + public int lParam; + } + + internal enum GetWindow_Cmd : uint + { + GW_HWNDFIRST = 0, + GW_HWNDLAST = 1, + GW_HWNDNEXT = 2, + GW_HWNDPREV = 3, + GW_OWNER = 4, + GW_CHILD = 5, + GW_ENABLEDPOPUP = 6 + } + + class User32 + { + [DllImport("user32.dll")] + public static extern bool DeleteMenu(IntPtr hMenu, int uPosition, + MF uFlags); + + [DllImport("user32.dll")] + public static extern bool DestroyWindow(IntPtr hWnd); + + [DllImport("user32.dll")] + public static extern bool EnableWindow(IntPtr hWnd, bool bEnable); + + [DllImport("user32.dll")] + public static extern IntPtr EnumChildWindows(IntPtr parentHandle, + Win32Callback callback, IntPtr lParam); + + [DllImport("user32.dll")] + public static extern bool GetMenuInfo(IntPtr hmenu, + ref MENUINFO lpcmi); + + [DllImport("user32.dll")] + public static extern int GetMenuItemCount(IntPtr hMenu); + + [DllImport("user32.dll")] + public static extern bool GetMenuItemInfo(IntPtr hMenu, int uItem, + bool fByPosition, ref MENUITEMINFO lpmii); + + [DllImport("user32.dll", SetLastError = true)] + internal static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd); + + [DllImport("user32.dll")] + public static extern uint RegisterClipboardFormat(string lpszFormat); + + [DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, MSG Msg, + int wParam, int lParam); + + [DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, MSG Msg, + int wParam, ref LVITEMA lParam); + + [DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, MSG Msg, + int wParam, IntPtr lParam); + + [DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, MSG Msg, + int wParam, ref TVITEMW lParam); + + [DllImport("user32.dll")] + public static extern bool SetMenuInfo(IntPtr hmenu, + ref MENUINFO lpcmi); + + [DllImport("user32.dll")] + public static extern bool SetWindowPos(IntPtr hWnd, + IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, + uint uFlags); + + [DllImport("user32.dll")] + public static extern int TrackPopupMenuEx(IntPtr hmenu, + TPM fuFlags, int x, int y, IntPtr hwnd, IntPtr lptpm); + + public delegate bool Win32Callback(IntPtr hwnd, IntPtr lParam); + } +} diff --git a/Backup/Shell/Interop/VistaBridge/ShellItemImpl.cs b/Backup/Shell/Interop/VistaBridge/ShellItemImpl.cs new file mode 100644 index 0000000..76119fa --- /dev/null +++ b/Backup/Shell/Interop/VistaBridge/ShellItemImpl.cs @@ -0,0 +1,159 @@ +using System; +using System.Runtime.InteropServices; +using System.Text; + +namespace GongSolutions.Shell.Interop.VistaBridge +{ + class ShellItemImpl : IDisposable, IShellItem + { + public ShellItemImpl(IntPtr pidl, bool owner) + { + if (owner) + { + m_Pidl = pidl; + } + else + { + m_Pidl = Shell32.ILClone(pidl); + } + } + + ~ShellItemImpl() + { + Dispose(false); + } + + public IntPtr BindToHandler(IntPtr pbc, Guid bhid, Guid riid) + { + if (riid == typeof(IShellFolder).GUID) + { + return Marshal.GetIUnknownForObject(GetIShellFolder()); + } + else + { + throw new InvalidCastException(); + } + } + + public void Dispose() + { + Dispose(true); + } + + public HResult GetParent(out IShellItem ppsi) + { + IntPtr pidl = Shell32.ILClone(m_Pidl); + if (Shell32.ILRemoveLastID(pidl)) + { + ppsi = new ShellItemImpl(pidl, true); + return HResult.S_OK; + } + else + { + ppsi = null; + return HResult.MK_E_NOOBJECT; + } + } + + public IntPtr GetDisplayName(SIGDN sigdnName) + { + if (sigdnName == SIGDN.FILESYSPATH) + { + StringBuilder result = new StringBuilder(512); + if (!Shell32.SHGetPathFromIDList(m_Pidl, result)) + throw new ArgumentException(); + return Marshal.StringToHGlobalUni(result.ToString()); + } + else + { + IShellFolder parentFolder = GetParent().GetIShellFolder(); + IntPtr childPidl = Shell32.ILFindLastID(m_Pidl); + StringBuilder builder = new StringBuilder(512); + STRRET strret = new STRRET(); + + parentFolder.GetDisplayNameOf(childPidl, + (SHGNO)((int)sigdnName & 0xffff), out strret); + ShlWapi.StrRetToBuf(ref strret, childPidl, builder, + (uint)builder.Capacity); + return Marshal.StringToHGlobalUni(builder.ToString()); + } + } + + public SFGAO GetAttributes(SFGAO sfgaoMask) + { + IShellFolder parentFolder = GetParent().GetIShellFolder(); + SFGAO result = sfgaoMask; + + parentFolder.GetAttributesOf(1, + new IntPtr[] { Shell32.ILFindLastID(m_Pidl) }, + ref result); + return result & sfgaoMask; + } + + public int Compare(IShellItem psi, SICHINT hint) + { + ShellItemImpl other = (ShellItemImpl)psi; + ShellItemImpl myParent = GetParent(); + ShellItemImpl theirParent = other.GetParent(); + + if (Shell32.ILIsEqual(myParent.m_Pidl, theirParent.m_Pidl)) + { + return myParent.GetIShellFolder().CompareIDs((SHCIDS)hint, + Shell32.ILFindLastID(m_Pidl), + Shell32.ILFindLastID(other.m_Pidl)); + } + else + { + return 1; + } + } + + public IntPtr Pidl + { + get { return m_Pidl; } + } + + protected void Dispose(bool dispose) + { + Shell32.ILFree(m_Pidl); + } + + ShellItemImpl GetParent() + { + IntPtr pidl = Shell32.ILClone(m_Pidl); + + if (Shell32.ILRemoveLastID(pidl)) + { + return new ShellItemImpl(pidl, true); + } + else + { + return this; + } + } + + IShellFolder GetIShellFolder() + { + IShellFolder desktop = Shell32.SHGetDesktopFolder(); + IntPtr desktopPidl; + + Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.DESKTOP, + out desktopPidl); ; + + if (Shell32.ILIsEqual(m_Pidl, desktopPidl)) + { + return desktop; + } + else + { + IntPtr result; + desktop.BindToObject(m_Pidl, IntPtr.Zero, + typeof(IShellFolder).GUID, out result); + return (IShellFolder)Marshal.GetTypedObjectForIUnknown(result, + typeof(IShellFolder)); + } + } + + IntPtr m_Pidl; + } +} diff --git a/Backup/Shell/KnownFolderManager.cs b/Backup/Shell/KnownFolderManager.cs new file mode 100644 index 0000000..2f73c65 --- /dev/null +++ b/Backup/Shell/KnownFolderManager.cs @@ -0,0 +1,270 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + public class KnownFolderManager : IEnumerable + { + public KnownFolderManager() + { + if (Environment.OSVersion.Version.Major >= 6) + { + m_ComInterface = (IKnownFolderManager) + new CoClass.KnownFolderManager(); + } + else + { + m_NameIndex = new Dictionary(); + m_PathIndex = new Dictionary(); + + AddFolder("Common Desktop", CSIDL.COMMON_DESKTOPDIRECTORY); + AddFolder("Desktop", CSIDL.DESKTOP); + AddFolder("Personal", CSIDL.PERSONAL); + AddFolder("Recent", CSIDL.RECENT); + AddFolder("MyComputerFolder", CSIDL.DRIVES); + AddFolder("My Pictures", CSIDL.MYPICTURES); + AddFolder("ProgramFilesCommon", CSIDL.PROGRAM_FILES_COMMON); + AddFolder("Windows", CSIDL.WINDOWS); + } + } + + public KnownFolder FindNearestParent(ShellItem item) + { + if (m_ComInterface != null) + { + IKnownFolder iKnownFolder; + + if (item.IsFileSystem) + { + if (m_ComInterface.FindFolderFromPath(item.FileSystemPath, + FFFP_MODE.NEARESTPARENTMATCH, out iKnownFolder) + == HResult.S_OK) + { + return CreateFolder(iKnownFolder); + } + } + else + { + if (m_ComInterface.FindFolderFromIDList(item.Pidl, out iKnownFolder) + == HResult.S_OK) + { + return CreateFolder(iKnownFolder); + } + } + } + else + { + if (item.IsFileSystem) + { + foreach (KeyValuePair i in m_PathIndex) + { + if ((i.Key != string.Empty) && + item.FileSystemPath.StartsWith(i.Key)) + { + return i.Value; + } + } + } + else + { + foreach (KeyValuePair i in m_NameIndex) + { + if (item == i.Value.CreateShellItem()) + { + return i.Value; + } + } + } + } + + return null; + } + + public IEnumerator GetEnumerator() + { + IntPtr buffer; + uint count; + KnownFolder[] results; + + if (m_ComInterface != null) + { + m_ComInterface.GetFolderIds(out buffer, out count); + + try + { + results = new KnownFolder[count]; + IntPtr p = buffer; + + for (uint n = 0; n < count; ++n) + { + Guid guid = (Guid)Marshal.PtrToStructure(p, typeof(Guid)); + results[n] = GetFolder(guid); + p = (IntPtr)((int)p + Marshal.SizeOf(typeof(Guid))); + } + } + finally + { + Marshal.FreeCoTaskMem(buffer); + } + + foreach (KnownFolder f in results) + { + yield return f; + } + } + else + { + foreach (KnownFolder f in m_NameIndex.Values) + { + yield return f; + } + } + } + + public KnownFolder GetFolder(Guid guid) + { + return CreateFolder(m_ComInterface.GetFolder(guid)); + } + + public KnownFolder GetFolder(string name) + { + if (m_ComInterface != null) + { + IKnownFolder iKnownFolder; + + if (m_ComInterface.GetFolderByName(name, out iKnownFolder) + == HResult.S_OK) + { + return CreateFolder(iKnownFolder); + } + } + else + { + return m_NameIndex[name]; + } + + throw new InvalidOperationException("Unknown shell folder: " + name); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)this).GetEnumerator(); + } + + void AddFolder(string name, CSIDL csidl) + { + KnownFolder folder = CreateFolder(csidl, name); + + m_NameIndex.Add(folder.Name, folder); + + if (folder.ParsingName != string.Empty) + { + m_PathIndex.Add(folder.ParsingName, folder); + } + } + + static KnownFolder CreateFolder(CSIDL csidl, string name) + { + StringBuilder path = new StringBuilder(512); + + if (Shell32.SHGetFolderPath(IntPtr.Zero, csidl, IntPtr.Zero, 0, path) == HResult.S_OK) + { + return new KnownFolder(csidl, name, path.ToString()); + } + else + { + return new KnownFolder(csidl, name, string.Empty); + } + } + + static KnownFolder CreateFolder(IKnownFolder iface) + { + KNOWNFOLDER_DEFINITION def = iface.GetFolderDefinition(); + + try + { + return new KnownFolder(iface, + Marshal.PtrToStringUni(def.pszName), + Marshal.PtrToStringUni(def.pszParsingName)); + } + finally + { + Marshal.FreeCoTaskMem(def.pszName); + Marshal.FreeCoTaskMem(def.pszDescription); + Marshal.FreeCoTaskMem(def.pszRelativePath); + Marshal.FreeCoTaskMem(def.pszParsingName); + Marshal.FreeCoTaskMem(def.pszTooltip); + Marshal.FreeCoTaskMem(def.pszLocalizedName); + Marshal.FreeCoTaskMem(def.pszIcon); + Marshal.FreeCoTaskMem(def.pszSecurity); + } + } + + struct PathIndexEntry + { + public PathIndexEntry(string name, CSIDL csidl) + { + Name = name; + Csidl = csidl; + } + + public string Name; + public CSIDL Csidl; + } + + IKnownFolderManager m_ComInterface; + Dictionary m_NameIndex; + Dictionary m_PathIndex; + } + + public class KnownFolder + { + public KnownFolder(IKnownFolder iface, string name, string parsingName) + { + m_ComInterface = iface; + m_Name = name; + m_ParsingName = parsingName; + } + + public KnownFolder(CSIDL csidl, string name, string parsingName) + { + m_Csidl = csidl; + m_Name = name; + m_ParsingName = parsingName; + } + + public ShellItem CreateShellItem() + { + if (m_ComInterface != null) + { + return new ShellItem(m_ComInterface.GetShellItem(0, + typeof(IShellItem).GUID)); + } + else + { + return new ShellItem((Environment.SpecialFolder)m_Csidl); + } + } + + public string Name + { + get { return m_Name; } + } + + public string ParsingName + { + get { return m_ParsingName; } + } + + IKnownFolder m_ComInterface; + CSIDL m_Csidl; + string m_Name; + string m_ParsingName; + } +} diff --git a/Backup/Shell/PlacesToolbar.Designer.cs b/Backup/Shell/PlacesToolbar.Designer.cs new file mode 100644 index 0000000..dde4766 --- /dev/null +++ b/Backup/Shell/PlacesToolbar.Designer.cs @@ -0,0 +1,62 @@ +namespace GongSolutions.Shell { + partial class PlacesToolbar { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.toolStrip = new System.Windows.Forms.ToolStrip(); + this.SuspendLayout(); + // + // toolStrip + // + this.toolStrip.CanOverflow = false; + this.toolStrip.Dock = System.Windows.Forms.DockStyle.Fill; + this.toolStrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; + this.toolStrip.ImageScalingSize = new System.Drawing.Size(48, 48); + this.toolStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.VerticalStackWithOverflow; + this.toolStrip.Location = new System.Drawing.Point(0, 0); + this.toolStrip.Name = "toolStrip"; + this.toolStrip.Padding = new System.Windows.Forms.Padding(1); + this.toolStrip.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; + this.toolStrip.Size = new System.Drawing.Size(88, 162); + this.toolStrip.TabIndex = 0; + this.toolStrip.Text = "toolStrip1"; + // + // PlacesToolbar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.Controls.Add(this.toolStrip); + this.Name = "PlacesToolbar"; + this.Size = new System.Drawing.Size(88, 162); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ToolStrip toolStrip; + + } +} diff --git a/Backup/Shell/PlacesToolbar.cs b/Backup/Shell/PlacesToolbar.cs new file mode 100644 index 0000000..b32f413 --- /dev/null +++ b/Backup/Shell/PlacesToolbar.cs @@ -0,0 +1,297 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Text; +using System.Windows.Forms; + +namespace GongSolutions.Shell +{ + /// + /// Provides a toolbar showing common places in the computer's + /// filesystem. + /// + /// + /// + /// Use the control to display a + /// toolbar listing common places in the computer's filesystem, + /// similar to that on the far left-side of the standard file + /// open/save dialogs. + /// + public partial class PlacesToolbar : UserControl + { + + /// + /// Initializes a new instance of the + /// class. + /// + public PlacesToolbar() + { + InitializeComponent(); + AutoSize = true; + toolStrip.Renderer = new Renderer(); + } + + /// + /// Adds a new folder to the toolbar. + /// + /// + /// + /// A representing the folder to be added. + /// + /// + /// + /// true if the item was sucessfully added, false otherwise. + /// + public bool Add(ShellItem folder) + { + bool include = IncludeItem(folder); + + if (include) + { + ToolStripButton button = new ToolStripButton(); + Image image = folder.ShellIcon.ToBitmap(); + + toolStrip.ImageScalingSize = image.Size; + button.AutoSize = false; + button.Image = image; + button.Size = new Size(84, image.Height + 35); + button.Tag = folder; + button.Text = WrapButtonText(button, folder.DisplayName); + button.TextImageRelation = TextImageRelation.ImageAboveText; + button.ToolTipText = folder.ToolTipText; + button.Click += new EventHandler(button_Click); + toolStrip.Items.Add(button); + } + + return include; + } + + /// + /// A that should be automatically + /// navigated when the user clicks on an entry in the toolbar. + /// + [DefaultValue(null)] + public ShellView ShellView + { + get { return m_ShellView; } + set { m_ShellView = value; } + } + + /// + /// Occurs when the control wants to + /// know if it should include an item. + /// + /// + /// + /// This event allows the items displayed in the + /// control to be filtered. + /// + public event FilterItemEventHandler FilterItem; + + #region Hidden Properties + + /// + /// This property does not apply to the + /// class. + /// + [Browsable(false)] + public override bool AllowDrop + { + get { return base.AllowDrop; } + set { base.AllowDrop = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public override bool AutoScroll + { + get { return base.AutoScroll; } + set { base.AutoScroll = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public new Size AutoScrollMargin + { + get { return base.AutoScrollMargin; } + set { base.AutoScrollMargin = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public new Size AutoScrollMinSize + { + get { return base.AutoScrollMinSize; } + set { base.AutoScrollMinSize = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false), DefaultValue(true)] + public override bool AutoSize + { + get { return base.AutoSize; } + set { base.AutoSize = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false), DefaultValue(AutoSizeMode.GrowAndShrink)] + public new AutoSizeMode AutoSizeMode + { + get { return base.AutoSizeMode; } + set { base.AutoSizeMode = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public override AutoValidate AutoValidate + { + get { return base.AutoValidate; } + set { base.AutoValidate = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public override Image BackgroundImage + { + get { return base.BackgroundImage; } + set { base.BackgroundImage = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public override ImageLayout BackgroundImageLayout + { + get { return base.BackgroundImageLayout; } + set { base.BackgroundImageLayout = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public new BorderStyle BorderStyle + { + get { return base.BorderStyle; } + set { base.BorderStyle = value; } + } + + /// + /// This property is not relevant to the + /// class. + /// + [Browsable(false)] + public new bool CausesValidation + { + get { return base.CausesValidation; } + set { base.CausesValidation = value; } + } + + #endregion + + /// + /// Overrides the method. + /// + /// + protected override void OnVisibleChanged(EventArgs e) + { + base.OnVisibleChanged(e); + if (toolStrip.Items.Count == 0) CreateDefaultItems(); + } + + void CreateDefaultItems() + { + const int CSIDL_NETWORK = 0x0012; + Add(new ShellItem(Environment.SpecialFolder.Recent)); + Add(new ShellItem(Environment.SpecialFolder.Desktop)); + Add(new ShellItem(Environment.SpecialFolder.Personal)); + Add(new ShellItem(Environment.SpecialFolder.MyComputer)); + Add(new ShellItem((Environment.SpecialFolder)CSIDL_NETWORK)); + } + + bool IncludeItem(ShellItem item) + { + if (FilterItem != null) + { + FilterItemEventArgs e = new FilterItemEventArgs(item); + FilterItem(this, e); + return e.Include; + } + else + { + return true; + } + } + + string WrapButtonText(ToolStripButton button, string s) + { + Graphics g = Graphics.FromHwnd(toolStrip.Handle); + + if (g.MeasureString(s, button.Font).Width > + button.ContentRectangle.Width) + { + int lastSpace = s.LastIndexOf(' '); + return s.Substring(0, lastSpace) + "\r\n" + + s.Substring(lastSpace + 1); + } + + return s; + } + + void button_Click(object sender, EventArgs e) + { + if (m_ShellView != null) + { + ShellItem folder = (ShellItem)((ToolStripButton)sender).Tag; + m_ShellView.Navigate(folder); + } + } + + class Renderer : ToolStripSystemRenderer + { + protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) + { + Rectangle rect = new Rectangle(0, 0, + e.ToolStrip.Width - 1, e.ToolStrip.Height - 1); + + if (Application.RenderWithVisualStyles) + { + ControlPaint.DrawVisualStyleBorder(e.Graphics, rect); + } + else + { + ControlPaint.DrawBorder3D(e.Graphics, rect, + Border3DStyle.Sunken); + } + } + } + + ShellView m_ShellView; + } +} diff --git a/Backup/Shell/PlacesToolbar.resx b/Backup/Shell/PlacesToolbar.resx new file mode 100644 index 0000000..43accf8 --- /dev/null +++ b/Backup/Shell/PlacesToolbar.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Backup/Shell/Properties/AssemblyInfo.cs b/Backup/Shell/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..358b168 --- /dev/null +++ b/Backup/Shell/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Gong Solutions Shell Library")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Gong Solutions")] +[assembly: AssemblyProduct("GongShell")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a51194d2-1ed9-467b-a9c8-da7af88fdf00")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("0.6.0.*")] +[assembly: AssemblyFileVersion("0.6.0")] diff --git a/Backup/Shell/Properties/Resources.Designer.cs b/Backup/Shell/Properties/Resources.Designer.cs new file mode 100644 index 0000000..1bc8bc2 --- /dev/null +++ b/Backup/Shell/Properties/Resources.Designer.cs @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.4927 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace GongSolutions.Shell.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GongSolutions.Shell.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static System.Drawing.Bitmap Back { + get { + object obj = ResourceManager.GetObject("Back", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap NewFolder { + get { + object obj = ResourceManager.GetObject("NewFolder", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap Up { + get { + object obj = ResourceManager.GetObject("Up", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap Views { + get { + object obj = ResourceManager.GetObject("Views", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Backup/Shell/Properties/Resources.resx b/Backup/Shell/Properties/Resources.resx new file mode 100644 index 0000000..2c2a271 --- /dev/null +++ b/Backup/Shell/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\Back.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\NewFolder.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Up.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Views.bmp;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Backup/Shell/Resources/Back.bmp b/Backup/Shell/Resources/Back.bmp new file mode 100644 index 0000000..ba048cc Binary files /dev/null and b/Backup/Shell/Resources/Back.bmp differ diff --git a/Backup/Shell/Resources/NewFolder.bmp b/Backup/Shell/Resources/NewFolder.bmp new file mode 100644 index 0000000..593b6e5 Binary files /dev/null and b/Backup/Shell/Resources/NewFolder.bmp differ diff --git a/Backup/Shell/Resources/Up.bmp b/Backup/Shell/Resources/Up.bmp new file mode 100644 index 0000000..86cbd8b Binary files /dev/null and b/Backup/Shell/Resources/Up.bmp differ diff --git a/Backup/Shell/Resources/Views.bmp b/Backup/Shell/Resources/Views.bmp new file mode 100644 index 0000000..cae8020 Binary files /dev/null and b/Backup/Shell/Resources/Views.bmp differ diff --git a/Backup/Shell/Shell.csproj b/Backup/Shell/Shell.csproj new file mode 100644 index 0000000..d91438a --- /dev/null +++ b/Backup/Shell/Shell.csproj @@ -0,0 +1,165 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41} + Library + Properties + GongSolutions.Shell + GongShell + + + + + 2.0 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\GongShell.XML + 0419 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + UserControl + + + FileDialogToolbar.cs + + + Component + + + Component + + + + + + + + + + + + + + + + + + + + + + + + + + Code + + + + + + + UserControl + + + PlacesToolbar.cs + + + + True + True + Resources.resx + + + + Component + + + + + + Form + + + ShellItemBrowseForm.cs + + + + Component + + + Component + + + Component + + + + + + + FileDialogToolbar.cs + Designer + + + PlacesToolbar.cs + Designer + + + Designer + ResXFileCodeGenerator + Resources.Designer.cs + + + Designer + ShellItemBrowseForm.cs + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Backup/Shell/ShellBrowser.cs b/Backup/Shell/ShellBrowser.cs new file mode 100644 index 0000000..1bc32f8 --- /dev/null +++ b/Backup/Shell/ShellBrowser.cs @@ -0,0 +1,254 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + class ShellBrowser : IShellBrowser, + IOleCommandTarget, + Interop.IServiceProvider + { + public ShellBrowser(ShellView shellView) + { + m_ShellView = shellView; + } + + public StatusBar StatusBar + { + get { return m_StatusBar; } + set + { + m_StatusBar = value; + if (m_StatusBar != null) + { + m_StatusBar.ShowPanels = true; + } + } + } + + #region IShellBrowser Members + + HResult IShellBrowser.GetWindow(out IntPtr phwnd) + { + phwnd = m_ShellView.Handle; + return HResult.S_OK; + } + + HResult IShellBrowser.ContextSensitiveHelp(bool fEnterMode) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.InsertMenusSB(IntPtr IntPtrShared, IntPtr lpMenuWidths) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.SetMenuSB(IntPtr IntPtrShared, IntPtr holemenuRes, IntPtr IntPtrActiveObject) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.RemoveMenusSB(IntPtr IntPtrShared) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.SetStatusTextSB(IntPtr pszStatusText) + { + if (m_StatusBar != null) + { + m_StatusBar.Panels.Clear(); + m_StatusBar.Panels.Add(Marshal.PtrToStringUni(pszStatusText)); + } + return HResult.S_OK; + } + + HResult IShellBrowser.EnableModelessSB(bool fEnable) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.TranslateAcceleratorSB(IntPtr pmsg, ushort wID) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.BrowseObject(IntPtr pidl, SBSP wFlags) + { + IntPtr result = IntPtr.Zero; + + if ((wFlags & SBSP.SBSP_RELATIVE) != 0) + { + ShellItem child = new ShellItem(m_ShellView.CurrentFolder, pidl); + } + else if ((wFlags & SBSP.SBSP_PARENT) != 0) + { + m_ShellView.NavigateParent(); + } + else if ((wFlags & SBSP.SBSP_NAVIGATEBACK) != 0) + { + m_ShellView.NavigateBack(); + } + else if ((wFlags & SBSP.SBSP_NAVIGATEFORWARD) != 0) + { + m_ShellView.NavigateForward(); + } + else + { + m_ShellView.Navigate(new ShellItem(ShellItem.Desktop, pidl)); + } + return HResult.S_OK; + } + + HResult IShellBrowser.GetViewStateStream(uint grfMode, IntPtr ppStrm) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.GetControlWindow(FCW id, out IntPtr lpIntPtr) + { + if ((id == FCW.FCW_STATUS) && (m_StatusBar != null)) + { + lpIntPtr = m_StatusBar.Handle; + return HResult.S_OK; + } + else + { + lpIntPtr = IntPtr.Zero; + return HResult.E_NOTIMPL; + } + } + + HResult IShellBrowser.SendControlMsg(FCW id, MSG uMsg, uint wParam, + uint lParam, IntPtr pret) + { + int result = 0; + + if ((id == FCW.FCW_STATUS) && (m_StatusBar != null)) + { + result = User32.SendMessage(m_StatusBar.Handle, + uMsg, (int)wParam, (int)lParam); + } + + if (pret != IntPtr.Zero) + { + Marshal.WriteInt32(pret, result); + } + + return HResult.S_OK; + } + + HResult IShellBrowser.QueryActiveShellView(out IShellView ppshv) + { + ppshv = null; + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.OnViewWindowActive(IShellView ppshv) + { + return HResult.E_NOTIMPL; + } + + HResult IShellBrowser.SetToolbarItems(IntPtr lpButtons, uint nButtons, uint uFlags) + { + return HResult.E_NOTIMPL; + } + + #endregion + + #region IOleCommandTarget Members + + void IOleCommandTarget.QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, ref OLECMDTEXT CmdText) + { + throw new NotImplementedException("The method or operation is not implemented."); + } + + void IOleCommandTarget.Exec(ref Guid pguidCmdGroup, uint nCmdId, uint nCmdExecOpt, ref object pvaIn, ref object pvaOut) + { + throw new NotImplementedException("The method or operation is not implemented."); + } + + #endregion + + #region IServiceProvider Members + + HResult Interop.IServiceProvider.QueryService(ref Guid guidService, + ref Guid riid, + out IntPtr ppvObject) + { + if (riid == typeof(IOleCommandTarget).GUID) + { + ppvObject = Marshal.GetComInterfaceForObject(this, + typeof(IOleCommandTarget)); + } + else if (riid == typeof(IShellBrowser).GUID) + { + ppvObject = Marshal.GetComInterfaceForObject(this, + typeof(IShellBrowser)); + } + else + { + ppvObject = IntPtr.Zero; + return HResult.E_NOINTERFACE; + } + + return HResult.S_OK; + } + + #endregion + + protected ShellView m_ShellView; + StatusBar m_StatusBar; + } + + class DialogShellBrowser : ShellBrowser, ICommDlgBrowser + { + public DialogShellBrowser(ShellView shellView) + : base(shellView) { } + + #region ICommDlgBrowser Members + + HResult ICommDlgBrowser.OnDefaultCommand(IShellView ppshv) + { + ShellItem[] selected = m_ShellView.SelectedItems; + + if ((selected.Length > 0) && (selected[0].IsFolder)) + { + try + { + m_ShellView.Navigate(selected[0]); + } + catch (Exception) + { + } + } + else + { + m_ShellView.OnDoubleClick(EventArgs.Empty); + } + + return HResult.S_OK; + } + + HResult ICommDlgBrowser.OnStateChange(IShellView ppshv, CDBOSC uChange) + { + if (uChange == CDBOSC.CDBOSC_SELCHANGE) + { + m_ShellView.OnSelectionChanged(); + } + return HResult.S_OK; + } + + HResult ICommDlgBrowser.IncludeObject(IShellView ppshv, IntPtr pidl) + { + return m_ShellView.IncludeItem(pidl) ? + HResult.S_OK : HResult.S_FALSE; + } + + #endregion + } +} diff --git a/Backup/Shell/ShellComboBox.cs b/Backup/Shell/ShellComboBox.cs new file mode 100644 index 0000000..14d485c --- /dev/null +++ b/Backup/Shell/ShellComboBox.cs @@ -0,0 +1,503 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Design; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + /// + /// Provides a drop-down list displaying the Windows Shell namespace. + /// + /// + /// + /// The class displays a view of the Windows + /// Shell namespace in a drop-down list similar to that displayed in + /// a file open/save dialog. + /// + public class ShellComboBox : Control + { + + /// + /// Initializes a new instance of the class. + /// + public ShellComboBox() + { + m_Combo.Dock = DockStyle.Fill; + m_Combo.DrawMode = DrawMode.OwnerDrawFixed; + m_Combo.DropDownStyle = ComboBoxStyle.DropDownList; + m_Combo.DropDownHeight = 300; + m_Combo.ItemHeight = SystemInformation.SmallIconSize.Height + 1; + m_Combo.Parent = this; + m_Combo.Click += new EventHandler(m_Combo_Click); + m_Combo.DrawItem += new DrawItemEventHandler(m_Combo_DrawItem); + m_Combo.SelectedIndexChanged += new EventHandler(m_Combo_SelectedIndexChanged); + + m_Edit.Anchor = AnchorStyles.Left | AnchorStyles.Top | + AnchorStyles.Right | AnchorStyles.Bottom; + m_Edit.BorderStyle = BorderStyle.None; + m_Edit.Left = 8 + SystemInformation.SmallIconSize.Width; + m_Edit.Top = 4; + m_Edit.Width = Width - m_Edit.Left - 3 - SystemInformation.VerticalScrollBarWidth; + m_Edit.Parent = this; + m_Edit.Visible = false; + m_Edit.GotFocus += new EventHandler(m_Edit_GotFocus); + m_Edit.LostFocus += new EventHandler(m_Edit_LostFocus); + m_Edit.KeyDown += new KeyEventHandler(m_Edit_KeyDown); + m_Edit.MouseDown += new MouseEventHandler(m_Edit_MouseDown); + m_Edit.BringToFront(); + + m_ShellListener.DriveAdded += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.DriveRemoved += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.FolderCreated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.FolderDeleted += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.FolderRenamed += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed); + m_ShellListener.FolderUpdated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.ItemCreated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.ItemDeleted += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.ItemRenamed += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed); + m_ShellListener.ItemUpdated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.SharingChanged += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + + m_SelectedFolder = ShellItem.Desktop; + m_Edit.Text = GetEditString(); + + if (m_Computer == null) + { + m_Computer = new ShellItem(Environment.SpecialFolder.MyComputer); + } + + CreateItems(); + } + + /// + /// Gets/sets a value indicating whether the combo box is editable. + /// + [DefaultValue(false)] + public bool Editable + { + get { return m_Editable; } + set + { + m_Edit.Visible = m_Editable = value; + } + } + + /// + /// Gets/sets a value indicating whether the full file system path + /// should be displayed in the main portion of the control. + /// + [DefaultValue(false)] + public bool ShowFileSystemPath + { + get { return m_ShowFileSystemPath; } + set + { + m_ShowFileSystemPath = value; + m_Combo.Invalidate(); + } + } + + /// + /// Gets/sets the folder that the should + /// display as the root folder. + /// + [Editor(typeof(ShellItemEditor), typeof(UITypeEditor))] + public ShellItem RootFolder + { + get { return m_RootFolder; } + set + { + m_RootFolder = value; + if (!m_RootFolder.IsParentOf(m_SelectedFolder)) + { + m_SelectedFolder = m_RootFolder; + } + CreateItems(); + } + } + + /// + /// Gets/sets the folder currently selected in the + /// . + /// + [Editor(typeof(ShellItemEditor), typeof(UITypeEditor))] + public ShellItem SelectedFolder + { + get { return m_SelectedFolder; } + set + { + if (m_SelectedFolder != value) + { + m_SelectedFolder = value; + CreateItems(); + m_Edit.Text = GetEditString(); + NavigateShellView(); + OnChanged(); + } + } + } + + /// + /// Gets/sets a whose navigation should be + /// controlled by the combo box. + /// + [DefaultValue(null), Category("Behaviour")] + public ShellView ShellView + { + get { return m_ShellView; } + set + { + if (m_ShellView != null) + { + m_ShellView.Navigated -= new EventHandler(m_ShellView_Navigated); + } + + m_ShellView = value; + + if (m_ShellView != null) + { + m_ShellView.Navigated += new EventHandler(m_ShellView_Navigated); + m_ShellView_Navigated(m_ShellView, EventArgs.Empty); + } + } + } + + /// + /// Occurs when the 's + /// property changes. + /// + public event EventHandler Changed; + + /// + /// Occurs when the control wants to know + /// if it should include a folder in its view. + /// + /// + /// + /// This event allows the folders displayed in the + /// control to be filtered. + /// + public event FilterItemEventHandler FilterItem; + + internal bool ShouldSerializeRootFolder() + { + return m_RootFolder != ShellItem.Desktop; + } + + internal bool ShouldSerializeSelectedFolder() + { + return m_SelectedFolder != ShellItem.Desktop; + } + + void CreateItems() + { + if (!m_CreatingItems) + { + try + { + m_CreatingItems = true; + m_Combo.Items.Clear(); + CreateItem(m_RootFolder, 0); + } + finally + { + m_CreatingItems = false; + } + } + } + + void CreateItems(ShellItem folder, int indent) + { + IEnumerator e = folder.GetEnumerator( + SHCONTF.FOLDERS | SHCONTF.INCLUDEHIDDEN); + + while (e.MoveNext()) + { + if (ShouldCreateItem(e.Current)) + { + CreateItem(e.Current, indent); + } + } + } + + void CreateItem(ShellItem folder, int indent) + { + int index = m_Combo.Items.Add(new ComboItem(folder, indent)); + + if (folder == m_SelectedFolder) + { + m_Combo.SelectedIndex = index; + } + + if (ShouldCreateChildren(folder)) + { + CreateItems(folder, indent + 1); + } + } + + bool ShouldCreateItem(ShellItem folder) + { + FilterItemEventArgs e = new FilterItemEventArgs(folder); + ShellItem myComputer = new ShellItem(Environment.SpecialFolder.MyComputer); + + e.Include = false; + + if (ShellItem.Desktop.IsImmediateParentOf(folder) || + m_Computer.IsImmediateParentOf(folder)) + { + e.Include = folder.IsFileSystemAncestor; + } + else if ((folder == m_SelectedFolder) || + folder.IsParentOf(m_SelectedFolder)) + { + e.Include = true; + } + + if (FilterItem != null) + { + FilterItem(this, e); + } + + return e.Include; + } + + bool ShouldCreateChildren(ShellItem folder) + { + return (folder == m_Computer) || + (folder == ShellItem.Desktop) || + folder.IsParentOf(m_SelectedFolder); + } + + string GetEditString() + { + if (m_ShowFileSystemPath && m_SelectedFolder.IsFileSystem) + { + return m_SelectedFolder.FileSystemPath; + } + else + { + return m_SelectedFolder.DisplayName; + } + } + + void NavigateShellView() + { + if ((m_ShellView != null) && !m_ChangingLocation) + { + try + { + m_ChangingLocation = true; + m_ShellView.Navigate(m_SelectedFolder); + } + catch (Exception) + { + SelectedFolder = m_ShellView.CurrentFolder; + } + finally + { + m_ChangingLocation = false; + } + } + } + + void OnChanged() + { + if (Changed != null) + { + Changed(this, EventArgs.Empty); + } + } + + void m_Combo_Click(object sender, EventArgs e) + { + OnClick(e); + } + + void m_Combo_DrawItem(object sender, DrawItemEventArgs e) + { + int iconWidth = SystemInformation.SmallIconSize.Width; + int indent = ((e.State & DrawItemState.ComboBoxEdit) == 0) ? + (iconWidth / 2) : 0; + + if (e.Index != -1) + { + string display; + ComboItem item = (ComboItem)m_Combo.Items[e.Index]; + Color textColor = SystemColors.WindowText; + Rectangle textRect; + int textOffset; + SizeF size; + + if ((e.State & DrawItemState.ComboBoxEdit) != 0) + { + // Don't draw the folder location in the edit box when + // the control is Editable as the edit control will + // take care of that. + display = m_Editable ? string.Empty : GetEditString(); + } + else + { + display = item.Folder.DisplayName; + } + + size = TextRenderer.MeasureText(display, m_Combo.Font); + + textRect = new Rectangle( + e.Bounds.Left + iconWidth + (item.Indent * indent) + 3, + e.Bounds.Y, (int)size.Width, e.Bounds.Height); + textOffset = (int)((e.Bounds.Height - size.Height) / 2); + + // If the text is being drawin in the main combo box edit area, + // draw the text 1 pixel higher - this is how it looks in Windows. + if ((e.State & DrawItemState.ComboBoxEdit) != 0) + { + textOffset -= 1; + } + + if ((e.State & DrawItemState.Selected) != 0) + { + e.Graphics.FillRectangle(SystemBrushes.Highlight, textRect); + textColor = SystemColors.HighlightText; + } + else + { + e.DrawBackground(); + } + + if ((e.State & DrawItemState.Focus) != 0) + { + ControlPaint.DrawFocusRectangle(e.Graphics, textRect); + } + + SystemImageList.DrawSmallImage(e.Graphics, + new Point(e.Bounds.Left + (item.Indent * indent), + e.Bounds.Top), + item.Folder.GetSystemImageListIndex(ShellIconType.SmallIcon, + ShellIconFlags.OverlayIndex), + (e.State & DrawItemState.Selected) != 0); + TextRenderer.DrawText(e.Graphics, display, m_Combo.Font, + new Point(textRect.Left, textRect.Top + textOffset), + textColor); + } + } + + void m_Combo_SelectedIndexChanged(object sender, EventArgs e) + { + if (!m_CreatingItems) + { + SelectedFolder = ((ComboItem)m_Combo.SelectedItem).Folder; + } + } + + void m_Edit_GotFocus(object sender, EventArgs e) + { + m_Edit.SelectAll(); + m_SelectAll = true; + } + + void m_Edit_LostFocus(object sender, EventArgs e) + { + m_SelectAll = false; + } + + void m_Edit_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + string path = m_Edit.Text; + + if ((path == string.Empty) || + (string.Compare(path, "Desktop", true) == 0)) + { + SelectedFolder = ShellItem.Desktop; + return; + } + + if (Directory.Exists(path)) + { + SelectedFolder = new ShellItem(path); + return; + } + + path = Path.Combine(m_SelectedFolder.FileSystemPath, path); + + if (Directory.Exists(path)) + { + SelectedFolder = new ShellItem(path); + return; + } + } + } + + void m_Edit_MouseDown(object sender, MouseEventArgs e) + { + if (m_SelectAll) + { + m_Edit.SelectAll(); + m_SelectAll = false; + } + else + { + m_Edit.SelectionStart = m_Edit.Text.Length; + } + } + + void m_ShellView_Navigated(object sender, EventArgs e) + { + if (!m_ChangingLocation) + { + try + { + m_ChangingLocation = true; + SelectedFolder = m_ShellView.CurrentFolder; + OnChanged(); + } + finally + { + m_ChangingLocation = false; + } + } + } + + void m_ShellListener_ItemRenamed(object sender, ShellItemChangeEventArgs e) + { + CreateItems(); + } + + void m_ShellListener_ItemUpdated(object sender, ShellItemEventArgs e) + { + CreateItems(); + } + + class ComboItem + { + public ComboItem(ShellItem folder, int indent) + { + Folder = folder; + Indent = indent; + } + + public ShellItem Folder; + public int Indent; + } + + ComboBox m_Combo = new ComboBox(); + TextBox m_Edit = new TextBox(); + ShellView m_ShellView; + bool m_Editable; + ShellItem m_RootFolder = ShellItem.Desktop; + ShellItem m_SelectedFolder; + bool m_ChangingLocation; + bool m_ShowFileSystemPath; + bool m_CreatingItems; + bool m_SelectAll; + ShellNotificationListener m_ShellListener = new ShellNotificationListener(); + static ShellItem m_Computer; + } +} diff --git a/Backup/Shell/ShellContextMenu.cs b/Backup/Shell/ShellContextMenu.cs new file mode 100644 index 0000000..adc4627 --- /dev/null +++ b/Backup/Shell/ShellContextMenu.cs @@ -0,0 +1,402 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + /// + /// Provides support for displaying the context menu of a shell item. + /// + /// + /// + /// + /// Use this class to display a context menu for a shell item, either + /// as a popup menu, or as a main menu. + /// + /// + /// + /// To display a popup menu, simply call + /// with the parent control and the position at which the menu should + /// be shown. + /// + /// + /// + /// To display a shell context menu in a Form's main menu, call the + /// method to populate the menu. In addition, + /// you must intercept a number of special messages that will be sent + /// to the menu's parent form. To do this, you must override + /// like so: + /// + /// + /// + /// protected override void WndProc(ref Message m) { + /// if ((m_ContextMenu == null) || (!m_ContextMenu.HandleMenuMessage(ref m))) { + /// base.WndProc(ref m); + /// } + /// } + /// + /// + /// + /// Where m_ContextMenu is the being shown. + /// + /// + /// Standard menu commands can also be invoked from this class, for + /// example and . + /// + public class ShellContextMenu + { + + /// + /// Initialises a new instance of the + /// class. + /// + /// + /// + /// The item to which the context menu should refer. + /// + public ShellContextMenu(ShellItem item) + { + Initialize(new ShellItem[] { item }); + } + + /// + /// Initialises a new instance of the + /// class. + /// + /// + /// + /// The items to which the context menu should refer. + /// + public ShellContextMenu(ShellItem[] items) + { + Initialize(items); + } + + /// + /// Handles context menu messages when the + /// is displayed on a Form's main menu bar. + /// + /// + /// + /// + /// To display a shell context menu in a Form's main menu, call the + /// method to populate the menu with the shell + /// item's menu items. In addition, you must intercept a number of + /// special messages that will be sent to the menu's parent form. To + /// do this, you must override like so: + /// + /// + /// + /// protected override void WndProc(ref Message m) { + /// if ((m_ContextMenu == null) || (!m_ContextMenu.HandleMenuMessage(ref m))) { + /// base.WndProc(ref m); + /// } + /// } + /// + /// + /// + /// Where m_ContextMenu is the being shown. + /// + /// + /// + /// + /// The message to handle. + /// + /// + /// + /// if the message was a Shell Context Menu + /// message, if not. If the method returns false, + /// then the message should be passed down to the base class's + /// method. + /// + public bool HandleMenuMessage(ref Message m) + { + if ((m.Msg == (int)MSG.WM_COMMAND) && ((int)m.WParam >= m_CmdFirst)) + { + InvokeCommand((int)m.WParam - m_CmdFirst); + return true; + } + else + { + if (m_ComInterface3 != null) + { + IntPtr result; + if (m_ComInterface3.HandleMenuMsg2(m.Msg, m.WParam, m.LParam, + out result) == HResult.S_OK) + { + m.Result = result; + return true; + } + } + else if (m_ComInterface2 != null) + { + if (m_ComInterface2.HandleMenuMsg(m.Msg, m.WParam, m.LParam) + == HResult.S_OK) + { + m.Result = IntPtr.Zero; + return true; + } + } + } + return false; + } + + /// + /// Invokes the Copy command on the shell item(s). + /// + public void InvokeCopy() + { + InvokeVerb("copy"); + } + + /// + /// Invokes the Copy command on the shell item(s). + /// + public void InvokeCut() + { + InvokeVerb("cut"); + } + + /// + /// Invokes the Delete command on the shell item(s). + /// + public void InvokeDelete() + { + try + { + InvokeVerb("delete"); + } + catch (COMException e) + { + // Ignore the exception raised when the user cancels + // a delete operation. + if (e.ErrorCode != unchecked((int)0x800704C7) && + e.ErrorCode != unchecked((int)0x80270000)) + { + throw; + } + } + } + + /// + /// Invokes the Paste command on the shell item(s). + /// + public void InvokePaste() + { + InvokeVerb("paste"); + } + + /// + /// Invokes the Rename command on the shell item. + /// + public void InvokeRename() + { + InvokeVerb("rename"); + } + + /// + /// Invokes the specified verb on the shell item(s). + /// + public void InvokeVerb(string verb) + { + CMINVOKECOMMANDINFO invoke = new CMINVOKECOMMANDINFO(); + invoke.cbSize = Marshal.SizeOf(invoke); + invoke.lpVerb = verb; + m_ComInterface.InvokeCommand(ref invoke); + } + + /// + /// Populates a with the context menu items for + /// a shell item. + /// + /// + /// + /// If this method is being used to populate a Form's main menu + /// then you need to call in the + /// Form's message handler. + /// + /// + /// + /// The menu to populate. + /// + public void Populate(Menu menu) + { + RemoveShellMenuItems(menu); + m_ComInterface.QueryContextMenu(menu.Handle, 0, + m_CmdFirst, int.MaxValue, CMF.EXPLORE); + } + + /// + /// Shows a context menu for a shell item. + /// + /// + /// + /// The parent control. + /// + /// + /// + /// The position on that the menu + /// should be displayed at. + /// + public void ShowContextMenu(Control control, Point pos) + { + using (ContextMenu menu = new ContextMenu()) + { + pos = control.PointToScreen(pos); + Populate(menu); + int command = User32.TrackPopupMenuEx(menu.Handle, + TPM.TPM_RETURNCMD, pos.X, pos.Y, m_MessageWindow.Handle, + IntPtr.Zero); + if (command > 0) + { + InvokeCommand(command - m_CmdFirst); + } + } + } + + /// + /// Gets the underlying COM interface. + /// + public IContextMenu ComInterface + { + get { return m_ComInterface; } + set { m_ComInterface = value; } + } + + void Initialize(ShellItem[] items) + { + IntPtr[] pidls = new IntPtr[items.Length]; + ShellItem parent = null; + IntPtr result; + + for (int n = 0; n < items.Length; ++n) + { + pidls[n] = Shell32.ILFindLastID(items[n].Pidl); + + if (parent == null) + { + if (items[n] == ShellItem.Desktop) + { + parent = ShellItem.Desktop; + } + else + { + parent = items[n].Parent; + + } + } + else + { + if (items[n].Parent != parent) + { + throw new Exception("All shell items must have the same parent"); + } + } + } + + parent.GetIShellFolder().GetUIObjectOf(IntPtr.Zero, + (uint)pidls.Length, pidls, + typeof(IContextMenu).GUID, 0, out result); + m_ComInterface = (IContextMenu) + Marshal.GetTypedObjectForIUnknown(result, + typeof(IContextMenu)); + m_ComInterface2 = m_ComInterface as IContextMenu2; + m_ComInterface3 = m_ComInterface as IContextMenu3; + m_MessageWindow = new MessageWindow(this); + } + + void InvokeCommand(int index) + { + const int SW_SHOWNORMAL = 1; + CMINVOKECOMMANDINFO_ByIndex invoke = new CMINVOKECOMMANDINFO_ByIndex(); + invoke.cbSize = Marshal.SizeOf(invoke); + invoke.iVerb = index; + invoke.nShow = SW_SHOWNORMAL; + m_ComInterface2.InvokeCommand(ref invoke); + } + + void TagManagedMenuItems(Menu menu, int tag) + { + MENUINFO info = new MENUINFO(); + + info.cbSize = Marshal.SizeOf(info); + info.fMask = MIM.MIM_MENUDATA; + info.dwMenuData = tag; + + foreach (MenuItem item in menu.MenuItems) + { + User32.SetMenuInfo(item.Handle, ref info); + } + } + + void RemoveShellMenuItems(Menu menu) + { + const int tag = 0xAB; + List remove = new List(); + int count = User32.GetMenuItemCount(menu.Handle); + MENUINFO menuInfo = new MENUINFO(); + MENUITEMINFO itemInfo = new MENUITEMINFO(); + + menuInfo.cbSize = Marshal.SizeOf(menuInfo); + menuInfo.fMask = MIM.MIM_MENUDATA; + itemInfo.cbSize = Marshal.SizeOf(itemInfo); + itemInfo.fMask = MIIM.MIIM_ID | MIIM.MIIM_SUBMENU; + + // First, tag the managed menu items with an arbitary + // value (0xAB). + TagManagedMenuItems(menu, tag); + + for (int n = 0; n < count; ++n) + { + User32.GetMenuItemInfo(menu.Handle, n, true, ref itemInfo); + + if (itemInfo.hSubMenu == IntPtr.Zero) + { + // If the item has no submenu we can't get the tag, so + // check its ID to determine if it was added by the shell. + if (itemInfo.wID >= m_CmdFirst) remove.Add(n); + } + else + { + User32.GetMenuInfo(itemInfo.hSubMenu, ref menuInfo); + if (menuInfo.dwMenuData != tag) remove.Add(n); + } + } + + // Remove the unmanaged menu items. + remove.Reverse(); + foreach (int position in remove) + { + User32.DeleteMenu(menu.Handle, position, MF.MF_BYPOSITION); + } + } + + class MessageWindow : Control + { + public MessageWindow(ShellContextMenu parent) + { + m_Parent = parent; + } + + protected override void WndProc(ref Message m) + { + if (!m_Parent.HandleMenuMessage(ref m)) + { + base.WndProc(ref m); + } + } + + ShellContextMenu m_Parent; + } + + MessageWindow m_MessageWindow; + IContextMenu m_ComInterface; + IContextMenu2 m_ComInterface2; + IContextMenu3 m_ComInterface3; + const int m_CmdFirst = 0x8000; + } +} diff --git a/Backup/Shell/ShellHistory.cs b/Backup/Shell/ShellHistory.cs new file mode 100644 index 0000000..53a60ec --- /dev/null +++ b/Backup/Shell/ShellHistory.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Text; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + /// + /// Holds a 's navigation history. + /// + public class ShellHistory + { + + /// + /// Clears the shell history. + /// + public void Clear() + { + ShellItem current = null; + + if (m_History.Count > 0) + { + current = Current; + } + + m_History.Clear(); + + if (current != null) + { + Add(current); + } + } + + /// + /// Gets the list of folders in the 's + /// Back history. + /// + public ShellItem[] HistoryBack + { + get + { + return m_History.GetRange(0, m_Current).ToArray(); + } + } + + /// + /// Gets the list of folders in the 's + /// Forward history. + /// + public ShellItem[] HistoryForward + { + get + { + if (CanNavigateForward) + { + return m_History.GetRange(m_Current + 1, + m_History.Count - (m_Current + 1)).ToArray(); + } + else + { + return new ShellItem[0]; + } + } + } + + internal ShellHistory() + { + m_History = new List(); + } + + internal void Add(ShellItem folder) + { + while (m_Current < m_History.Count - 1) + { + m_History.RemoveAt(m_Current + 1); + } + + m_History.Add(folder); + m_Current = m_History.Count - 1; + } + + internal ShellItem MoveBack() + { + if (m_Current == 0) + { + throw new InvalidOperationException("Cannot navigate back"); + } + return m_History[--m_Current]; + } + + internal void MoveBack(ShellItem folder) + { + int index = m_History.IndexOf(folder); + + if ((index == -1) || (index >= m_Current)) + { + throw new Exception( + "The requested folder could not be located in the " + + "'back' shell history"); + } + + m_Current = index; + } + + internal ShellItem MoveForward() + { + if (m_Current == m_History.Count - 1) + { + throw new InvalidOperationException("Cannot navigate forward"); + } + return m_History[++m_Current]; + } + + internal void MoveForward(ShellItem folder) + { + int index = m_History.IndexOf(folder, m_Current + 1); + + if (index == -1) + { + throw new Exception( + "The requested folder could not be located in the " + + "'forward' shell history"); + } + + m_Current = index; + } + + internal bool CanNavigateBack + { + get { return m_Current > 0; } + } + + internal bool CanNavigateForward + { + get { return m_Current < m_History.Count - 1; } + } + + internal ShellItem Current + { + get { return m_History[m_Current]; } + } + + List m_History; + int m_Current; + } +} diff --git a/Backup/Shell/ShellItem.cs b/Backup/Shell/ShellItem.cs new file mode 100644 index 0000000..877470c --- /dev/null +++ b/Backup/Shell/ShellItem.cs @@ -0,0 +1,969 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.Design.Serialization; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Text; +using System.Runtime.InteropServices; +using ComTypes = System.Runtime.InteropServices.ComTypes; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + /// + /// Represents an item in the Windows Shell namespace. + /// + [TypeConverter(typeof(ShellItemConverter))] + public class ShellItem : IEnumerable + { + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// Takes a containing the location of the ShellItem. + /// This constructor accepts URIs using two schemes: + /// + /// - file: A file or folder in the computer's filesystem, e.g. + /// file:///D:/Folder + /// - shell: A virtual folder, or a file or folder referenced from + /// a virtual folder, e.g. shell:///Personal/file.txt + /// + /// + /// + /// A containing the location of the ShellItem. + /// + public ShellItem(Uri uri) + { + Initialize(uri); + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// Takes a containing the location of the ShellItem. + /// This constructor accepts URIs using two schemes: + /// + /// - file: A file or folder in the computer's filesystem, e.g. + /// file:///D:/Folder + /// - shell: A virtual folder, or a file or folder referenced from + /// a virtual folder, e.g. shell:///Personal/file.txt + /// + /// + /// + /// A string containing a Uri with the location of the ShellItem. + /// + public ShellItem(string path) + { + Initialize(new Uri(path)); + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// Takes an containing the + /// location of the folder. + /// + /// + /// + /// An containing the + /// location of the folder. + /// + public ShellItem(Environment.SpecialFolder folder) + { + IntPtr pidl; + + if (Shell32.SHGetSpecialFolderLocation(IntPtr.Zero, + (CSIDL)folder, out pidl) == HResult.S_OK) + { + try + { + m_ComInterface = CreateItemFromIDList(pidl); + } + finally + { + Shell32.ILFree(pidl); + } + } + else + { + // SHGetSpecialFolderLocation does not support many common + // CSIDL values on Windows 98, but SHGetFolderPath in + // ShFolder.dll does, so fall back to it if necessary. We + // try SHGetSpecialFolderLocation first because it returns + // a PIDL which is preferable to a path as it can express + // virtual folder locations. + StringBuilder path = new StringBuilder(); + Marshal.ThrowExceptionForHR((int)Shell32.SHGetFolderPath( + IntPtr.Zero, (CSIDL)folder, IntPtr.Zero, 0, path)); + m_ComInterface = CreateItemFromParsingName(path.ToString()); + } + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// Creates a ShellItem which is a named child of . + /// + /// + /// + /// The parent folder of the item. + /// + /// + /// + /// The name of the child item. + /// + public ShellItem(ShellItem parent, string name) + { + if (parent.IsFileSystem) + { + // If the parent folder is in the file system, our best + // chance of success is to use the FileSystemPath to + // create the new item. Folders other than Desktop don't + // seem to implement ParseDisplayName properly. + m_ComInterface = CreateItemFromParsingName( + Path.Combine(parent.FileSystemPath, name)); + } + else + { + IShellFolder folder = parent.GetIShellFolder(); + uint eaten; + IntPtr pidl; + uint attributes = 0; + + folder.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, + name, out eaten, out pidl, ref attributes); + + try + { + m_ComInterface = CreateItemFromIDList(pidl); + } + finally + { + Shell32.ILFree(pidl); + } + } + } + + internal ShellItem(IntPtr pidl) + { + m_ComInterface = CreateItemFromIDList(pidl); + } + + internal ShellItem(ShellItem parent, IntPtr pidl) + { + m_ComInterface = CreateItemWithParent(parent, pidl); + } + + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// An representing the folder. + /// + public ShellItem(IShellItem comInterface) + { + m_ComInterface = comInterface; + } + + /// + /// Compares two s. The comparison is carried + /// out by display order. + /// + /// + /// + /// The item to compare. + /// + /// + /// + /// 0 if the two items are equal. A negative number if + /// is before in + /// display order. A positive number if + /// comes after in + /// display order. + /// + public int Compare(ShellItem item) + { + int result = m_ComInterface.Compare(item.ComInterface, + SICHINT.DISPLAY); + return result; + } + + /// + /// Determines whether two s refer to + /// the same shell folder. + /// + /// + /// + /// The item to compare. + /// + /// + /// + /// if the two objects refer to the same + /// folder, otherwise. + /// + public override bool Equals(object obj) + { + if (obj is ShellItem) + { + ShellItem otherItem = (ShellItem)obj; + bool result = m_ComInterface.Compare(otherItem.ComInterface, + SICHINT.DISPLAY) == 0; + + // Sometimes, folders are reported as being unequal even when + // they refer to the same folder, so double check by comparing + // the file system paths. (This was showing up on Windows XP in + // the SpecialFolders() test) + if (!result) + { + result = IsFileSystem && otherItem.IsFileSystem && + (FileSystemPath == otherItem.FileSystemPath); + } + + return result; + } + else + { + return false; + } + } + + /// + /// Returns the name of the item in the specified style. + /// + /// + /// + /// The style of display name to return. + /// + /// + /// + /// A string containing the display name of the item. + /// + public string GetDisplayName(SIGDN sigdn) + { + IntPtr resultPtr = m_ComInterface.GetDisplayName(sigdn); + string result = Marshal.PtrToStringUni(resultPtr); + Marshal.FreeCoTaskMem(resultPtr); + return result; + } + + /// + /// Returns an enumerator detailing the child items of the + /// . + /// + /// + /// + /// This method returns all child item including hidden + /// items. + /// + /// + /// + /// An enumerator over all child items. + /// + public IEnumerator GetEnumerator() + { + return GetEnumerator(SHCONTF.FOLDERS | SHCONTF.INCLUDEHIDDEN | + SHCONTF.NONFOLDERS); + } + + /// + /// Returns an enumerator detailing the child items of the + /// . + /// + /// + /// + /// A filter describing the types of child items to be included. + /// + /// + /// + /// An enumerator over all child items. + /// + public IEnumerator GetEnumerator(SHCONTF filter) + { + IShellFolder folder = GetIShellFolder(); + IEnumIDList enumId = GetIEnumIDList(folder, filter); + uint count; + IntPtr pidl; + HResult result; + + if (enumId == null) + { + yield break; + } + + result = enumId.Next(1, out pidl, out count); + while (result == HResult.S_OK) + { + yield return new ShellItem(this, pidl); + Shell32.ILFree(pidl); + result = enumId.Next(1, out pidl, out count); + } + + if (result != HResult.S_FALSE) + { + Marshal.ThrowExceptionForHR((int)result); + } + + yield break; + } + + /// + /// Returns an enumerator detailing the child items of the + /// . + /// + /// + /// + /// This method returns all child item including hidden + /// items. + /// + /// + /// + /// An enumerator over all child items. + /// + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Returns an representing the + /// item. This object is used in drag and drop operations. + /// + public ComTypes.IDataObject GetIDataObject() + { + IntPtr result = m_ComInterface.BindToHandler(IntPtr.Zero, + BHID.SFUIObject, typeof(ComTypes.IDataObject).GUID); + return (ComTypes.IDataObject)Marshal.GetTypedObjectForIUnknown(result, + typeof(ComTypes.IDataObject)); + } + + /// + /// Returns an representing the + /// item. This object is used in drag and drop operations. + /// + public IDropTarget GetIDropTarget(System.Windows.Forms.Control control) + { + IntPtr result = GetIShellFolder().CreateViewObject(control.Handle, + typeof(IDropTarget).GUID); + return (IDropTarget)Marshal.GetTypedObjectForIUnknown(result, + typeof(IDropTarget)); + } + + /// + /// Returns an representing the + /// item. + /// + public IShellFolder GetIShellFolder() + { + IntPtr result = m_ComInterface.BindToHandler(IntPtr.Zero, + BHID.SFObject, typeof(IShellFolder).GUID); + return (IShellFolder)Marshal.GetTypedObjectForIUnknown(result, + typeof(IShellFolder)); + } + + /// + /// Gets the index in the system image list of the icon representing + /// the item. + /// + /// + /// + /// The type of icon to retrieve. + /// + /// + /// + /// Flags detailing additional information to be conveyed by the icon. + /// + /// + /// + public int GetSystemImageListIndex(ShellIconType type, ShellIconFlags flags) + { + SHFILEINFO info = new SHFILEINFO(); + IntPtr result = Shell32.SHGetFileInfo(Pidl, 0, out info, + Marshal.SizeOf(info), + SHGFI.ICON | SHGFI.SYSICONINDEX | SHGFI.OVERLAYINDEX | SHGFI.PIDL | + (SHGFI)type | (SHGFI)flags); + + if (result == IntPtr.Zero) + { + throw new Exception("Error retreiving shell folder icon"); + } + + return info.iIcon; + } + + /// + /// Tests whether the is the immediate parent + /// of another item. + /// + /// + /// + /// The potential child item. + /// + public bool IsImmediateParentOf(ShellItem item) + { + return IsFolder && Shell32.ILIsParent(Pidl, item.Pidl, true); + } + + /// + /// Tests whether the is the parent of + /// another item. + /// + /// + /// + /// The potential child item. + /// + public bool IsParentOf(ShellItem item) + { + return IsFolder && Shell32.ILIsParent(Pidl, item.Pidl, false); + } + + /// + /// Returns a string representation of the . + /// + public override string ToString() + { + return ToUri().ToString(); + } + + /// + /// Returns a URI representation of the . + /// + public Uri ToUri() + { + KnownFolderManager manager = new KnownFolderManager(); + StringBuilder path = new StringBuilder("shell:///"); + KnownFolder knownFolder = manager.FindNearestParent(this); + + if (knownFolder != null) + { + List folders = new List(); + ShellItem knownFolderItem = knownFolder.CreateShellItem(); + ShellItem item = this; + + while (item != knownFolderItem) + { + folders.Add(item.GetDisplayName(SIGDN.PARENTRELATIVEPARSING)); + item = item.Parent; + } + + folders.Reverse(); + path.Append(knownFolder.Name); + foreach (string s in folders) + { + path.Append('/'); + path.Append(s); + } + + return new Uri(path.ToString()); + } + else + { + return new Uri(FileSystemPath); + } + } + + /// + /// Gets a child item. + /// + /// + /// + /// The name of the child item. + /// + public ShellItem this[string name] + { + get + { + return new ShellItem(this, name); + } + } + + /// + /// Tests if two s refer to the same folder. + /// + /// + /// + /// The first folder. + /// + /// + /// + /// The second folder. + /// + public static bool operator !=(ShellItem a, ShellItem b) + { + if (object.ReferenceEquals(a, null)) + { + return !object.ReferenceEquals(b, null); + } + else + { + return !a.Equals(b); + } + } + + /// + /// Tests if two s refer to the same folder. + /// + /// + /// + /// The first folder. + /// + /// + /// + /// The second folder. + /// + public static bool operator ==(ShellItem a, ShellItem b) + { + if (object.ReferenceEquals(a, null)) + { + return object.ReferenceEquals(b, null); + } + else + { + return a.Equals(b); + } + } + + /// + /// Gets the underlying COM interface. + /// + public IShellItem ComInterface + { + get { return m_ComInterface; } + } + + /// + /// Gets the normal display name of the item. + /// + public string DisplayName + { + get { return GetDisplayName(SIGDN.NORMALDISPLAY); } + } + + /// + /// Gets the file system path of the item. + /// + public string FileSystemPath + { + get { return GetDisplayName(SIGDN.FILESYSPATH); } + } + + /// + /// Gets a value indicating whether the item has subfolders. + /// + public bool HasSubFolders + { + get { return m_ComInterface.GetAttributes(SFGAO.HASSUBFOLDER) != 0; } + } + + /// + /// Gets a value indicating whether the item is a file system item. + /// + public bool IsFileSystem + { + get { return m_ComInterface.GetAttributes(SFGAO.FILESYSTEM) != 0; } + } + + /// + /// Gets a value indicating whether the item is a file system item + /// or the child of a file system item. + /// + public bool IsFileSystemAncestor + { + get { return m_ComInterface.GetAttributes(SFGAO.FILESYSANCESTOR) != 0; } + } + + /// + /// Gets a value indicating whether the item is a folder. + /// + public bool IsFolder + { + get { return m_ComInterface.GetAttributes(SFGAO.FOLDER) != 0; } + } + + /// + /// Gets a value indicating whether the item is read-only. + /// + public bool IsReadOnly + { + get { return m_ComInterface.GetAttributes(SFGAO.READONLY) != 0; } + } + + /// + /// Gets the item's parent. + /// + public ShellItem Parent + { + get + { + IShellItem item; + HResult result = m_ComInterface.GetParent(out item); + + if (result == HResult.S_OK) + { + return new ShellItem(item); + } + else if (result == HResult.MK_E_NOOBJECT) + { + return null; + } + else + { + Marshal.ThrowExceptionForHR((int)result); + return null; + } + } + } + + /// + /// Gets the item's parsing name. + /// + public string ParsingName + { + get { return GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING); } + } + + /// + /// Gets a PIDL representing the item. + /// + public IntPtr Pidl + { + get { return GetIDListFromObject(m_ComInterface); } + } + + /// + /// Gets the item's shell icon. + /// + public Icon ShellIcon + { + get + { + SHFILEINFO info = new SHFILEINFO(); + IntPtr result = Shell32.SHGetFileInfo(Pidl, 0, out info, + Marshal.SizeOf(info), + SHGFI.ADDOVERLAYS | SHGFI.ICON | + SHGFI.SHELLICONSIZE | SHGFI.PIDL); + + if (result == IntPtr.Zero) + { + throw new Exception("Error retreiving shell folder icon"); + } + + return Icon.FromHandle(info.hIcon); + } + } + + /// + /// Gets the item's tooltip text. + /// + public string ToolTipText + { + get + { + IntPtr result; + IQueryInfo queryInfo; + IntPtr infoTipPtr; + string infoTip; + + try + { + IntPtr relativePidl = Shell32.ILFindLastID(Pidl); + Parent.GetIShellFolder().GetUIObjectOf(IntPtr.Zero, 1, + new IntPtr[] { relativePidl }, + typeof(IQueryInfo).GUID, 0, out result); + } + catch (Exception) + { + return string.Empty; + } + + queryInfo = (IQueryInfo) + Marshal.GetTypedObjectForIUnknown(result, + typeof(IQueryInfo)); + queryInfo.GetInfoTip(0, out infoTipPtr); + infoTip = Marshal.PtrToStringUni(infoTipPtr); + Ole32.CoTaskMemFree(infoTipPtr); + return infoTip; + } + } + + /// + /// Gets the Desktop folder. + /// + public static ShellItem Desktop + { + get + { + if (m_Desktop == null) + { + IShellItem item; + IntPtr pidl; + + Shell32.SHGetSpecialFolderLocation( + IntPtr.Zero, (CSIDL)Environment.SpecialFolder.Desktop, + out pidl); + + try + { + item = CreateItemFromIDList(pidl); + } + finally + { + Shell32.ILFree(pidl); + } + + m_Desktop = new ShellItem(item); + } + return m_Desktop; + } + } + + internal static bool RunningVista + { + get { return Environment.OSVersion.Version.Major >= 6; } + } + + void Initialize(Uri uri) + { + if (uri.Scheme == "file") + { + m_ComInterface = CreateItemFromParsingName(uri.LocalPath); + } + else if (uri.Scheme == "shell") + { + InitializeFromShellUri(uri); + } + else + { + throw new InvalidOperationException("Invalid uri scheme"); + } + } + + void InitializeFromShellUri(Uri uri) + { + KnownFolderManager manager = new KnownFolderManager(); + string path = uri.GetComponents(UriComponents.Path, UriFormat.Unescaped); + string knownFolder; + string restOfPath; + int separatorIndex = path.IndexOf('/'); + + if (separatorIndex != -1) + { + knownFolder = path.Substring(0, separatorIndex); + restOfPath = path.Substring(separatorIndex + 1); + } + else + { + knownFolder = path; + restOfPath = string.Empty; + } + + m_ComInterface = manager.GetFolder(knownFolder).CreateShellItem().ComInterface; + + if (restOfPath != string.Empty) + { + m_ComInterface = this[restOfPath.Replace('/', '\\')].ComInterface; + } + } + + static IShellItem CreateItemFromIDList(IntPtr pidl) + { + if (RunningVista) + { + return Shell32.SHCreateItemFromIDList(pidl, + typeof(IShellItem).GUID); + } + else + { + return new Interop.VistaBridge.ShellItemImpl( + pidl, false); + } + } + + static IShellItem CreateItemFromParsingName(string path) + { + if (RunningVista) + { + return Shell32.SHCreateItemFromParsingName(path, IntPtr.Zero, + typeof(IShellItem).GUID); + } + else + { + IShellFolder desktop = Desktop.GetIShellFolder(); + uint attributes = 0; + uint eaten; + IntPtr pidl; + + desktop.ParseDisplayName(IntPtr.Zero, IntPtr.Zero, + path, out eaten, out pidl, ref attributes); + return new Interop.VistaBridge.ShellItemImpl( + pidl, true); + } + } + + static IShellItem CreateItemWithParent(ShellItem parent, IntPtr pidl) + { + if (RunningVista) + { + return Shell32.SHCreateItemWithParent(IntPtr.Zero, + parent.GetIShellFolder(), pidl, typeof(IShellItem).GUID); + } + else + { + Interop.VistaBridge.ShellItemImpl impl = + (Interop.VistaBridge.ShellItemImpl)parent.ComInterface; + return new Interop.VistaBridge.ShellItemImpl( + Shell32.ILCombine(impl.Pidl, pidl), true); + } + } + + static IntPtr GetIDListFromObject(IShellItem item) + { + if (RunningVista) + { + return Shell32.SHGetIDListFromObject(item); + } + else + { + return ((Interop.VistaBridge.ShellItemImpl)item).Pidl; + } + } + + static IEnumIDList GetIEnumIDList(IShellFolder folder, SHCONTF flags) + { + IEnumIDList result; + + if (folder.EnumObjects(IntPtr.Zero, flags, out result) == HResult.S_OK) + { + return result; + } + else + { + return null; + } + } + + IShellItem m_ComInterface; + static ShellItem m_Desktop; + } + + class ShellItemConverter : TypeConverter + { + public override bool CanConvertFrom(ITypeDescriptorContext context, + Type sourceType) + { + if (sourceType == typeof(string)) + { + return true; + } + else + { + return base.CanConvertFrom(context, sourceType); + } + } + + public override bool CanConvertTo(ITypeDescriptorContext context, + Type destinationType) + { + if (destinationType == typeof(InstanceDescriptor)) + { + return true; + } + else + { + return base.CanConvertTo(context, destinationType); + } + } + + public override object ConvertFrom(ITypeDescriptorContext context, + CultureInfo culture, + object value) + { + if (value is string) + { + string s = (string)value; + + if (s.Length == 0) + { + return ShellItem.Desktop; + } + else + { + return new ShellItem(s); + } + } + else + { + return base.ConvertFrom(context, culture, value); + } + } + + public override object ConvertTo(ITypeDescriptorContext context, + CultureInfo culture, + object value, + Type destinationType) + { + if (value is ShellItem) + { + Uri uri = ((ShellItem)value).ToUri(); + + if (destinationType == typeof(string)) + { + if (uri.Scheme == "file") + { + return uri.LocalPath; + } + else + { + return uri.ToString(); + } + } + else if (destinationType == typeof(InstanceDescriptor)) + { + return new InstanceDescriptor( + typeof(ShellItem).GetConstructor(new Type[] { typeof(string) }), + new object[] { uri.ToString() }); + } + } + return base.ConvertTo(context, culture, value, destinationType); + } + } + + /// + /// Enumerates the types of shell icons. + /// + public enum ShellIconType + { + /// The system large icon type + LargeIcon = SHGFI.LARGEICON, + + /// The system shell icon type + ShellIcon = SHGFI.SHELLICONSIZE, + + /// The system small icon type + SmallIcon = SHGFI.SMALLICON, + } + + /// + /// Enumerates the optional styles that can be applied to shell icons. + /// + [Flags] + public enum ShellIconFlags + { + /// The icon is displayed opened. + OpenIcon = SHGFI.OPENICON, + + /// Get the overlay for the icon as well. + OverlayIndex = SHGFI.OVERLAYINDEX + } +} diff --git a/Backup/Shell/ShellItemBrowseForm.Designer.cs b/Backup/Shell/ShellItemBrowseForm.Designer.cs new file mode 100644 index 0000000..cb19166 --- /dev/null +++ b/Backup/Shell/ShellItemBrowseForm.Designer.cs @@ -0,0 +1,169 @@ +namespace GongSolutions.Shell { + partial class ShellItemBrowseForm { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Common", System.Windows.Forms.HorizontalAlignment.Left); + System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("All", System.Windows.Forms.HorizontalAlignment.Left); + this.tabControl = new System.Windows.Forms.TabControl(); + this.knownFoldersPage = new System.Windows.Forms.TabPage(); + this.knownFolderList = new System.Windows.Forms.ListView(); + this.allFilesPage = new System.Windows.Forms.TabPage(); + this.allFilesView = new GongSolutions.Shell.ShellView(); + this.allFilesToolbar = new GongSolutions.Shell.FileDialogToolbar(); + this.okButton = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.tabControl.SuspendLayout(); + this.knownFoldersPage.SuspendLayout(); + this.allFilesPage.SuspendLayout(); + this.SuspendLayout(); + // + // tabControl + // + this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl.Controls.Add(this.knownFoldersPage); + this.tabControl.Controls.Add(this.allFilesPage); + this.tabControl.Location = new System.Drawing.Point(12, 12); + this.tabControl.Name = "tabControl"; + this.tabControl.SelectedIndex = 0; + this.tabControl.Size = new System.Drawing.Size(622, 402); + this.tabControl.TabIndex = 0; + this.tabControl.Selected += new System.Windows.Forms.TabControlEventHandler(this.tabControl_Selected); + // + // knownFoldersPage + // + this.knownFoldersPage.Controls.Add(this.knownFolderList); + this.knownFoldersPage.Location = new System.Drawing.Point(4, 22); + this.knownFoldersPage.Name = "knownFoldersPage"; + this.knownFoldersPage.Padding = new System.Windows.Forms.Padding(3); + this.knownFoldersPage.Size = new System.Drawing.Size(614, 376); + this.knownFoldersPage.TabIndex = 0; + this.knownFoldersPage.Text = "Known Folders"; + this.knownFoldersPage.UseVisualStyleBackColor = true; + // + // knownFolderList + // + this.knownFolderList.Dock = System.Windows.Forms.DockStyle.Fill; + listViewGroup1.Header = "Common"; + listViewGroup1.Name = "common"; + listViewGroup2.Header = "All"; + listViewGroup2.Name = "all"; + this.knownFolderList.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { + listViewGroup1, + listViewGroup2}); + this.knownFolderList.Location = new System.Drawing.Point(3, 3); + this.knownFolderList.Name = "knownFolderList"; + this.knownFolderList.Size = new System.Drawing.Size(608, 370); + this.knownFolderList.TabIndex = 0; + this.knownFolderList.UseCompatibleStateImageBehavior = false; + this.knownFolderList.View = System.Windows.Forms.View.Tile; + this.knownFolderList.DoubleClick += new System.EventHandler(this.knownFolderList_DoubleClick); + this.knownFolderList.SelectedIndexChanged += new System.EventHandler(this.knownFolderList_SelectedIndexChanged); + // + // allFilesPage + // + this.allFilesPage.Controls.Add(this.allFilesView); + this.allFilesPage.Controls.Add(this.allFilesToolbar); + this.allFilesPage.Location = new System.Drawing.Point(4, 22); + this.allFilesPage.Name = "allFilesPage"; + this.allFilesPage.Padding = new System.Windows.Forms.Padding(3); + this.allFilesPage.Size = new System.Drawing.Size(614, 376); + this.allFilesPage.TabIndex = 1; + this.allFilesPage.Text = "All Files"; + this.allFilesPage.UseVisualStyleBackColor = true; + // + // allFilesView + // + this.allFilesView.Dock = System.Windows.Forms.DockStyle.Fill; + this.allFilesView.Location = new System.Drawing.Point(3, 31); + this.allFilesView.Name = "allFilesView"; + this.allFilesView.Size = new System.Drawing.Size(608, 342); + this.allFilesView.StatusBar = null; + this.allFilesView.TabIndex = 1; + this.allFilesView.Text = "shellView1"; + this.allFilesView.SelectionChanged += new System.EventHandler(this.fileBrowseView_SelectionChanged); + // + // allFilesToolbar + // + this.allFilesToolbar.Dock = System.Windows.Forms.DockStyle.Top; + this.allFilesToolbar.Location = new System.Drawing.Point(3, 3); + this.allFilesToolbar.Name = "allFilesToolbar"; + this.allFilesToolbar.ShellView = this.allFilesView; + this.allFilesToolbar.Size = new System.Drawing.Size(608, 28); + this.allFilesToolbar.TabIndex = 0; + // + // okButton + // + this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.okButton.Enabled = false; + this.okButton.Location = new System.Drawing.Point(478, 420); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 23); + this.okButton.TabIndex = 0; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.okButton_Click); + // + // cancelButton + // + this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.cancelButton.Location = new System.Drawing.Point(559, 420); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 1; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + // + // ShellItemBrowseForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(646, 455); + this.Controls.Add(this.okButton); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.tabControl); + this.MinimizeBox = false; + this.Name = "ShellItemBrowseForm"; + this.Text = "Browse for ShellItem"; + this.tabControl.ResumeLayout(false); + this.knownFoldersPage.ResumeLayout(false); + this.allFilesPage.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.TabControl tabControl; + private System.Windows.Forms.TabPage knownFoldersPage; + private System.Windows.Forms.TabPage allFilesPage; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.ListView knownFolderList; + private ShellView allFilesView; + private FileDialogToolbar allFilesToolbar; + } +} \ No newline at end of file diff --git a/Backup/Shell/ShellItemBrowseForm.cs b/Backup/Shell/ShellItemBrowseForm.cs new file mode 100644 index 0000000..c6909a0 --- /dev/null +++ b/Backup/Shell/ShellItemBrowseForm.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace GongSolutions.Shell +{ + partial class ShellItemBrowseForm : Form + { + public ShellItemBrowseForm() + { + InitializeComponent(); + + KnownFolderManager manager = new KnownFolderManager(); + + SystemImageList.UseSystemImageList(knownFolderList); + foreach (KnownFolder knownFolder in manager) + { + try + { + ShellItem shellItem = knownFolder.CreateShellItem(); + ListViewItem item = knownFolderList.Items.Add(knownFolder.Name, + shellItem.GetSystemImageListIndex(ShellIconType.LargeIcon, 0)); + + item.Tag = knownFolder; + + if (item.Text == "Personal") + { + item.Text = "Personal (My Documents)"; + item.Group = knownFolderList.Groups["common"]; + } + else if ((item.Text == "Desktop") || + (item.Text == "Downloads") || + (item.Text == "MyComputerFolder")) + { + item.Group = knownFolderList.Groups["common"]; + } + else + { + item.Group = knownFolderList.Groups["all"]; + } + } + catch (Exception) + { + } + } + } + + public ShellItem SelectedItem + { + get { return m_SelectedItem; } + } + + void SaveSelection() + { + if (tabControl.SelectedTab == knownFoldersPage) + { + m_SelectedItem = ((KnownFolder)knownFolderList.SelectedItems[0].Tag) + .CreateShellItem(); + } + else + { + m_SelectedItem = allFilesView.SelectedItems[0]; + } + } + + void knownFolderList_DoubleClick(object sender, EventArgs e) + { + if (knownFolderList.SelectedItems.Count > 0) + { + SaveSelection(); + DialogResult = DialogResult.OK; + } + } + + void knownFolderList_SelectedIndexChanged(object sender, EventArgs e) + { + okButton.Enabled = knownFolderList.SelectedItems.Count > 0; + } + + void fileBrowseView_SelectionChanged(object sender, EventArgs e) + { + okButton.Enabled = allFilesView.SelectedItems.Length > 0; + } + + void tabControl_Selected(object sender, TabControlEventArgs e) + { + if (e.TabPage == knownFoldersPage) + { + okButton.Enabled = knownFolderList.SelectedItems.Count > 0; + } + else if (e.TabPage == allFilesPage) + { + okButton.Enabled = allFilesView.SelectedItems.Length > 0; + } + } + + void okButton_Click(object sender, EventArgs e) + { + SaveSelection(); + DialogResult = DialogResult.OK; + } + + ShellItem m_SelectedItem; + } +} \ No newline at end of file diff --git a/Backup/Shell/ShellItemBrowseForm.resx b/Backup/Shell/ShellItemBrowseForm.resx new file mode 100644 index 0000000..19dc0dd --- /dev/null +++ b/Backup/Shell/ShellItemBrowseForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Backup/Shell/ShellItemEditor.cs b/Backup/Shell/ShellItemEditor.cs new file mode 100644 index 0000000..0d4fd34 --- /dev/null +++ b/Backup/Shell/ShellItemEditor.cs @@ -0,0 +1,27 @@ +using System; +using System.ComponentModel; +using System.Drawing.Design; +using System.Windows.Forms; + +namespace GongSolutions.Shell +{ + class ShellItemEditor : UITypeEditor + { + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) + { + return UITypeEditorEditStyle.Modal; + } + + public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) + { + ShellItemBrowseForm f = new ShellItemBrowseForm(); + + if (f.ShowDialog() == DialogResult.OK) + { + return f.SelectedItem; + } + + return value; + } + } +} diff --git a/Backup/Shell/ShellNotificationListener.cs b/Backup/Shell/ShellNotificationListener.cs new file mode 100644 index 0000000..38f6f93 --- /dev/null +++ b/Backup/Shell/ShellNotificationListener.cs @@ -0,0 +1,350 @@ +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + /// + /// Listens for notifications of changes in the Windows Shell Namespace. + /// + public class ShellNotificationListener : Component + { + + /// + /// Initializes a new instance of the + /// class. + /// + public ShellNotificationListener() + { + m_Window = new NotificationWindow(this); + } + + /// + /// Initializes a new instance of the + /// class. + /// + public ShellNotificationListener(IContainer container) + { + container.Add(this); + m_Window = new NotificationWindow(this); + } + + /// + /// Occurs when a drive is added. + /// + public event ShellItemEventHandler DriveAdded; + + /// + /// Occurs when a drive is removed. + /// + public event ShellItemEventHandler DriveRemoved; + + /// + /// Occurs when a folder is created. + /// + public event ShellItemEventHandler FolderCreated; + + /// + /// Occurs when a folder is deleted. + /// + public event ShellItemEventHandler FolderDeleted; + + /// + /// Occurs when a folder is renamed. + /// + public event ShellItemChangeEventHandler FolderRenamed; + + /// + /// Occurs when a folder's contents are updated. + /// + public event ShellItemEventHandler FolderUpdated; + + /// + /// Occurs when a non-folder item is created. + /// + public event ShellItemEventHandler ItemCreated; + + /// + /// Occurs when a non-folder item is deleted. + /// + public event ShellItemEventHandler ItemDeleted; + + /// + /// Occurs when a non-folder item is renamed. + /// + public event ShellItemChangeEventHandler ItemRenamed; + + /// + /// Occurs when a non-folder item is updated. + /// + public event ShellItemEventHandler ItemUpdated; + + /// + /// Occurs when the shared state for a folder changes. + /// + public event ShellItemEventHandler SharingChanged; + + /// + /// Overrides the method. + /// + /// + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + m_Window.Dispose(); + } + + class NotificationWindow : Control + { + public NotificationWindow(ShellNotificationListener parent) + { + SHChangeNotifyEntry notify = new SHChangeNotifyEntry(); + notify.pidl = ShellItem.Desktop.Pidl; + notify.fRecursive = true; + m_NotifyId = Shell32.SHChangeNotifyRegister(this.Handle, + SHCNRF.InterruptLevel | SHCNRF.ShellLevel, + SHCNE.ALLEVENTS, WM_SHNOTIFY, 1, ref notify); + m_Parent = parent; + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + Shell32.SHChangeNotifyUnregister(m_NotifyId); + } + + protected override void WndProc(ref Message m) + { + if (m.Msg == WM_SHNOTIFY) + { + SHNOTIFYSTRUCT notify = (SHNOTIFYSTRUCT) + Marshal.PtrToStructure(m.WParam, + typeof(SHNOTIFYSTRUCT)); + + switch ((SHCNE)m.LParam) + { + case SHCNE.CREATE: + if (m_Parent.ItemCreated != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.ItemCreated(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.DELETE: + if (m_Parent.ItemDeleted != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.ItemDeleted(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.DRIVEADD: + if (m_Parent.DriveAdded != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.DriveAdded(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.DRIVEREMOVED: + if (m_Parent.DriveRemoved != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.DriveRemoved(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.MKDIR: + if (m_Parent.FolderCreated != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.FolderCreated(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.RMDIR: + if (m_Parent.FolderDeleted != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.FolderDeleted(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.UPDATEDIR: + if (m_Parent.FolderUpdated != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.FolderUpdated(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.UPDATEITEM: + if (m_Parent.ItemUpdated != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.ItemUpdated(m_Parent, + new ShellItemEventArgs(item)); + } + break; + + case SHCNE.RENAMEFOLDER: + if (m_Parent.FolderRenamed != null) + { + ShellItem item1 = new ShellItem(notify.dwItem1); + ShellItem item2 = new ShellItem(notify.dwItem2); + m_Parent.FolderRenamed(m_Parent, + new ShellItemChangeEventArgs(item1, item2)); + } + break; + + case SHCNE.RENAMEITEM: + if (m_Parent.ItemRenamed != null) + { + ShellItem item1 = new ShellItem(notify.dwItem1); + ShellItem item2 = new ShellItem(notify.dwItem2); + m_Parent.ItemRenamed(m_Parent, + new ShellItemChangeEventArgs(item1, item2)); + } + break; + + case SHCNE.NETSHARE: + case SHCNE.NETUNSHARE: + if (m_Parent.SharingChanged != null) + { + ShellItem item = new ShellItem(notify.dwItem1); + m_Parent.SharingChanged(m_Parent, + new ShellItemEventArgs(item)); + } + break; + } + } + else + { + base.WndProc(ref m); + } + } + + uint m_NotifyId; + ShellNotificationListener m_Parent; + const int WM_SHNOTIFY = 0x401; + } + + NotificationWindow m_Window; + } + + /// + /// Provides information of changes in the Windows Shell Namespace. + /// + public class ShellItemEventArgs : EventArgs + { + + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// + /// The ShellItem that has changed. + /// + public ShellItemEventArgs(ShellItem item) + { + m_Item = item; + } + + /// + /// The ShellItem that has changed. + /// + public ShellItem Item + { + get { return m_Item; } + } + + ShellItem m_Item; + } + + /// + /// Provides information of changes in the Windows Shell Namespace. + /// + public class ShellItemChangeEventArgs : EventArgs + { + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// + /// The ShellItem before the change + /// + /// + /// + /// The ShellItem after the change + /// + public ShellItemChangeEventArgs(ShellItem oldItem, + ShellItem newItem) + { + m_OldItem = oldItem; + m_NewItem = newItem; + } + + /// + /// The ShellItem before the change. + /// + public ShellItem OldItem + { + get { return m_OldItem; } + } + + /// + /// The ShellItem after the change. + /// + public ShellItem NewItem + { + get { return m_NewItem; } + } + + ShellItem m_OldItem; + ShellItem m_NewItem; + } + + /// + /// Represents the method that handles change notifications from + /// + /// + /// + /// + /// The source of the event. + /// + /// + /// + /// A that contains the data + /// for the event. + /// + public delegate void ShellItemEventHandler(object sender, + ShellItemEventArgs e); + + /// + /// Represents the method that handles change notifications from + /// + /// + /// + /// + /// The source of the event. + /// + /// + /// + /// A that contains the data + /// for the event. + /// + public delegate void ShellItemChangeEventHandler(object sender, + ShellItemChangeEventArgs e); +} diff --git a/Backup/Shell/ShellTreeView.cs b/Backup/Shell/ShellTreeView.cs new file mode 100644 index 0000000..ea7fe1d --- /dev/null +++ b/Backup/Shell/ShellTreeView.cs @@ -0,0 +1,859 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Design; +using System.IO; +using System.Runtime.InteropServices; +using System.Windows.Forms; +using Microsoft.Win32; +using GongSolutions.Shell.Interop; +using Interop = GongSolutions.Shell.Interop; +using ComTypes = System.Runtime.InteropServices.ComTypes; + +namespace GongSolutions.Shell +{ + /// + /// Provides a tree view of a computer's folders. + /// + /// + /// + /// + /// The control allows you to embed Windows + /// Explorer functionality in your Windows Forms applications. The + /// control provides a tree view of the computer's folders, as it would + /// appear in the left-hand pane in Explorer. + /// + /// + public class ShellTreeView : Control, Interop.IDropSource, Interop.IDropTarget + { + + /// + /// Initializes a new instance of the class. + /// + public ShellTreeView() + { + m_TreeView = new TreeView(); + m_TreeView.Dock = DockStyle.Fill; + m_TreeView.HideSelection = false; + m_TreeView.HotTracking = true; + m_TreeView.Parent = this; + m_TreeView.ShowRootLines = false; + m_TreeView.AfterSelect += new TreeViewEventHandler(m_TreeView_AfterSelect); + m_TreeView.BeforeExpand += new TreeViewCancelEventHandler(m_TreeView_BeforeExpand); + m_TreeView.ItemDrag += new ItemDragEventHandler(m_TreeView_ItemDrag); + m_TreeView.MouseDown += new MouseEventHandler(m_TreeView_MouseDown); + m_TreeView.MouseUp += new MouseEventHandler(m_TreeView_MouseUp); + m_ScrollTimer.Interval = 250; + m_ScrollTimer.Tick += new EventHandler(m_ScrollTimer_Tick); + Size = new Size(120, 100); + SystemImageList.UseSystemImageList(m_TreeView); + + m_ShellListener.DriveAdded += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.DriveRemoved += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.FolderCreated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.FolderDeleted += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.FolderRenamed += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed); + m_ShellListener.FolderUpdated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.ItemCreated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.ItemDeleted += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.ItemRenamed += new ShellItemChangeEventHandler(m_ShellListener_ItemRenamed); + m_ShellListener.ItemUpdated += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + m_ShellListener.SharingChanged += new ShellItemEventHandler(m_ShellListener_ItemUpdated); + + // Setting AllowDrop to true then false makes sure OleInitialize() + // is called for the thread: it must be called before we can use + // RegisterDragDrop. There is probably a neater way of doing this. + m_TreeView.AllowDrop = true; + m_TreeView.AllowDrop = false; + + CreateItems(); + } + + /// + /// Refreses the contents of the . + /// + public void RefreshContents() + { + RefreshItem(m_TreeView.Nodes[0]); + } + + /// + /// Gets/sets a value indicating whether drag/drop operations are + /// allowed on the control. + /// + [DefaultValue(false)] + public override bool AllowDrop + { + get { return m_AllowDrop; } + set + { + if (value != m_AllowDrop) + { + m_AllowDrop = value; + + if (m_AllowDrop) + { + Marshal.ThrowExceptionForHR( + Ole32.RegisterDragDrop(m_TreeView.Handle, this)); + } + else + { + Marshal.ThrowExceptionForHR( + Ole32.RevokeDragDrop(m_TreeView.Handle)); + } + } + } + } + + /// + /// Gets or sets a value indicating whether a tree node label takes on + /// the appearance of a hyperlink as the mouse pointer passes over it. + /// + [DefaultValue(true)] + [Category("Appearance")] + public bool HotTracking + { + get { return m_TreeView.HotTracking; } + set { m_TreeView.HotTracking = value; } + } + + /// + /// Gets or sets the root folder that is displayed in the + /// . + /// + [Category("Appearance")] + public ShellItem RootFolder + { + get { return m_RootFolder; } + set + { + m_RootFolder = value; + CreateItems(); + } + } + + /// + /// Gets/sets a whose navigation should be + /// controlled by the treeview. + /// + [DefaultValue(null), Category("Behaviour")] + public ShellView ShellView + { + get { return m_ShellView; } + set + { + if (m_ShellView != null) + { + m_ShellView.Navigated -= new EventHandler(m_ShellView_Navigated); + } + + m_ShellView = value; + + if (m_ShellView != null) + { + m_ShellView.Navigated += new EventHandler(m_ShellView_Navigated); + m_ShellView_Navigated(m_ShellView, EventArgs.Empty); + } + } + } + + /// + /// Gets or sets the selected folder in the + /// . + /// + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Editor(typeof(ShellItemEditor), typeof(UITypeEditor))] + public ShellItem SelectedFolder + { + get { return (ShellItem)m_TreeView.SelectedNode.Tag; } + set { SelectItem(value); } + } + + /// + /// Gets or sets a value indicating whether hidden folders should + /// be displayed in the tree. + /// + [DefaultValue(ShowHidden.System), Category("Appearance")] + public ShowHidden ShowHidden + { + get { return m_ShowHidden; } + set + { + m_ShowHidden = value; + RefreshContents(); + } + } + + /// + /// Occurs when the property changes. + /// + public event EventHandler SelectionChanged; + + #region IDropSource Members + + HResult IDropSource.QueryContinueDrag(bool fEscapePressed, int grfKeyState) + { + if (fEscapePressed) + { + return HResult.DRAGDROP_S_CANCEL; + } + else if ((grfKeyState & (int)(MK.MK_LBUTTON | MK.MK_RBUTTON)) == 0) + { + return HResult.DRAGDROP_S_DROP; + } + else + { + return HResult.S_OK; + } + } + + HResult IDropSource.GiveFeedback(int dwEffect) + { + return HResult.DRAGDROP_S_USEDEFAULTCURSORS; + } + + #endregion + + #region IDropTarget Members + + void Interop.IDropTarget.DragEnter(ComTypes.IDataObject pDataObj, + int grfKeyState, Point pt, + ref int pdwEffect) + { + Point clientLocation = m_TreeView.PointToClient(pt); + TreeNode node = m_TreeView.HitTest(clientLocation).Node; + + DragTarget.Data = pDataObj; + m_TreeView.HideSelection = true; + + if (node != null) + { + m_DragTarget = new DragTarget(node, grfKeyState, pt, + ref pdwEffect); + } + else + { + pdwEffect = 0; + } + } + + void Interop.IDropTarget.DragOver(int grfKeyState, Point pt, + ref int pdwEffect) + { + Point clientLocation = m_TreeView.PointToClient(pt); + TreeNode node = m_TreeView.HitTest(clientLocation).Node; + + CheckDragScroll(clientLocation); + + if (node != null) + { + if ((m_DragTarget == null) || + (node != m_DragTarget.Node)) + { + + if (m_DragTarget != null) + { + m_DragTarget.Dispose(); + } + + m_DragTarget = new DragTarget(node, grfKeyState, + pt, ref pdwEffect); + } + else + { + m_DragTarget.DragOver(grfKeyState, pt, ref pdwEffect); + } + } + else + { + pdwEffect = 0; + } + } + + void Interop.IDropTarget.DragLeave() + { + if (m_DragTarget != null) + { + m_DragTarget.Dispose(); + m_DragTarget = null; + } + m_TreeView.HideSelection = false; + } + + void Interop.IDropTarget.Drop(ComTypes.IDataObject pDataObj, + int grfKeyState, Point pt, + ref int pdwEffect) + { + if (m_DragTarget != null) + { + m_DragTarget.Drop(pDataObj, grfKeyState, pt, + ref pdwEffect); + m_DragTarget.Dispose(); + m_DragTarget = null; + } + } + + #endregion + + #region Hidden Properties + + /// + /// This property does not apply to the + /// class. + /// + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public override string Text + { + get { return base.Text; } + set { base.Text = value; } + } + + #endregion + + void CreateItems() + { + m_TreeView.BeginUpdate(); + + try + { + m_TreeView.Nodes.Clear(); + CreateItem(null, m_RootFolder); + m_TreeView.Nodes[0].Expand(); + m_TreeView.SelectedNode = m_TreeView.Nodes[0]; + } + finally + { + m_TreeView.EndUpdate(); + } + } + + void CreateItem(TreeNode parent, ShellItem folder) + { + string displayName = folder.DisplayName; + TreeNode node; + + if (parent != null) + { + node = InsertNode(parent, folder, displayName); + } + else + { + node = m_TreeView.Nodes.Add(displayName); + } + + if (folder.HasSubFolders) + { + node.Nodes.Add(""); + } + + node.Tag = folder; + SetNodeImage(node); + } + + void CreateChildren(TreeNode node) + { + if ((node.Nodes.Count == 1) && (node.Nodes[0].Tag == null)) + { + ShellItem folder = (ShellItem)node.Tag; + IEnumerator e = GetFolderEnumerator(folder); + + node.Nodes.Clear(); + while (e.MoveNext()) + { + CreateItem(node, e.Current); + } + } + } + + void RefreshItem(TreeNode node) + { + ShellItem folder = (ShellItem)node.Tag; + node.Text = folder.DisplayName; + SetNodeImage(node); + + if (NodeHasChildren(node)) + { + IEnumerator e = GetFolderEnumerator(folder); + ArrayList nodesToRemove = new ArrayList(node.Nodes); + + while (e.MoveNext()) + { + TreeNode childNode = FindItem(e.Current, node); + + if (childNode != null) + { + RefreshItem(childNode); + nodesToRemove.Remove(childNode); + } + else + { + CreateItem(node, e.Current); + } + } + + foreach (TreeNode n in nodesToRemove) + { + n.Remove(); + } + } + else if (node.Nodes.Count == 0) + { + if (folder.HasSubFolders) + { + node.Nodes.Add(""); + } + } + } + + TreeNode InsertNode(TreeNode parent, ShellItem folder, string displayName) + { + ShellItem parentFolder = (ShellItem)parent.Tag; + IntPtr folderRelPidl = Shell32.ILFindLastID(folder.Pidl); + TreeNode result = null; + + foreach (TreeNode child in parent.Nodes) + { + ShellItem childFolder = (ShellItem)child.Tag; + IntPtr childRelPidl = Shell32.ILFindLastID(childFolder.Pidl); + short compare = parentFolder.GetIShellFolder().CompareIDs(0, + folderRelPidl, childRelPidl); + + if (compare < 0) + { + result = parent.Nodes.Insert(child.Index, displayName); + break; + } + } + + if (result == null) + { + result = parent.Nodes.Add(displayName); + } + + return result; + } + + bool ShouldShowHidden() + { + if (m_ShowHidden == ShowHidden.System) + { + RegistryKey reg = Registry.CurrentUser.OpenSubKey( + @"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced"); + + if (reg != null) + { + return ((int)reg.GetValue("Hidden", 2)) == 1; + } + else + { + return false; + } + } + else + { + return m_ShowHidden == ShowHidden.True; + } + } + + IEnumerator GetFolderEnumerator(ShellItem folder) + { + SHCONTF filter = SHCONTF.FOLDERS; + if (ShouldShowHidden()) filter |= SHCONTF.INCLUDEHIDDEN; + return folder.GetEnumerator(filter); + } + + void SetNodeImage(TreeNode node) + { + TVITEMW itemInfo = new TVITEMW(); + ShellItem folder = (ShellItem)node.Tag; + + // We need to set the images for the item by sending a + // TVM_SETITEMW message, as we need to set the overlay images, + // and the .Net TreeView API does not support overlays. + itemInfo.mask = TVIF.TVIF_IMAGE | TVIF.TVIF_SELECTEDIMAGE | + TVIF.TVIF_STATE; + itemInfo.hItem = node.Handle; + itemInfo.iImage = folder.GetSystemImageListIndex( + ShellIconType.SmallIcon, ShellIconFlags.OverlayIndex); + itemInfo.iSelectedImage = folder.GetSystemImageListIndex( + ShellIconType.SmallIcon, ShellIconFlags.OpenIcon); + itemInfo.state = (TVIS)(itemInfo.iImage >> 16); + itemInfo.stateMask = TVIS.TVIS_OVERLAYMASK; + User32.SendMessage(m_TreeView.Handle, MSG.TVM_SETITEMW, + 0, ref itemInfo); + } + + void SelectItem(ShellItem value) + { + TreeNode node = m_TreeView.Nodes[0]; + ShellItem folder = (ShellItem)node.Tag; + + if (folder == value) + { + m_TreeView.SelectedNode = node; + } + else + { + SelectItem(node, value); + } + } + + void SelectItem(TreeNode node, ShellItem value) + { + CreateChildren(node); + + foreach (TreeNode child in node.Nodes) + { + ShellItem folder = (ShellItem)child.Tag; + + if (folder == value) + { + m_TreeView.SelectedNode = child; + child.EnsureVisible(); + child.Expand(); + return; + } + else if (folder.IsParentOf(value)) + { + SelectItem(child, value); + return; + } + } + } + + TreeNode FindItem(ShellItem item, TreeNode parent) + { + if ((ShellItem)parent.Tag == item) + { + return parent; + } + + foreach (TreeNode node in parent.Nodes) + { + if ((ShellItem)node.Tag == item) + { + return node; + } + else + { + TreeNode found = FindItem(item, node); + if (found != null) return found; + } + } + return null; + } + + bool NodeHasChildren(TreeNode node) + { + return (node.Nodes.Count > 0) && (node.Nodes[0].Tag != null); + } + + void ScrollTreeView(ScrollDirection direction) + { + User32.SendMessage(m_TreeView.Handle, MSG.WM_VSCROLL, + (int)direction, 0); + } + + void CheckDragScroll(Point location) + { + int scrollArea = (int)(m_TreeView.Nodes[0].Bounds.Height * 1.5); + ScrollDirection scroll = ScrollDirection.None; + + if (location.Y < scrollArea) + { + scroll = ScrollDirection.Up; + } + else if (location.Y > m_TreeView.ClientRectangle.Height - scrollArea) + { + scroll = ScrollDirection.Down; + } + + if (scroll != ScrollDirection.None) + { + if (m_ScrollDirection == ScrollDirection.None) + { + ScrollTreeView(scroll); + m_ScrollTimer.Enabled = true; + } + } + else + { + m_ScrollTimer.Enabled = false; + } + + m_ScrollDirection = scroll; + } + + ShellItem[] ParseShellIDListArray(ComTypes.IDataObject pDataObj) + { + List result = new List(); + ComTypes.FORMATETC format = new ComTypes.FORMATETC(); + ComTypes.STGMEDIUM medium = new ComTypes.STGMEDIUM(); + + format.cfFormat = (short)User32.RegisterClipboardFormat("Shell IDList Array"); + format.dwAspect = ComTypes.DVASPECT.DVASPECT_CONTENT; + format.lindex = 0; + format.ptd = IntPtr.Zero; + format.tymed = ComTypes.TYMED.TYMED_HGLOBAL; + + pDataObj.GetData(ref format, out medium); + Kernel32.GlobalLock(medium.unionmember); + + try + { + ShellItem parentFolder = null; + int count = Marshal.ReadInt32(medium.unionmember); + int offset = 4; + + for (int n = 0; n <= count; ++n) + { + int pidlOffset = Marshal.ReadInt32(medium.unionmember, offset); + int pidlAddress = (int)medium.unionmember + pidlOffset; + + if (n == 0) + { + parentFolder = new ShellItem(new IntPtr(pidlAddress)); + } + else + { + result.Add(new ShellItem(parentFolder, new IntPtr(pidlAddress))); + } + + offset += 4; + } + } + finally + { + Marshal.FreeHGlobal(medium.unionmember); + } + + return result.ToArray(); + } + + bool ShouldSerializeRootFolder() + { + return m_RootFolder != ShellItem.Desktop; + } + + void m_TreeView_AfterSelect(object sender, TreeViewEventArgs e) + { + if ((m_ShellView != null) && (!m_Navigating)) + { + m_Navigating = true; + try + { + m_ShellView.CurrentFolder = SelectedFolder; + } + catch (Exception) + { + SelectedFolder = m_ShellView.CurrentFolder; + } + finally + { + m_Navigating = false; + } + } + + if (SelectionChanged != null) + { + SelectionChanged(this, EventArgs.Empty); + } + } + + void m_TreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) + { + try + { + CreateChildren(e.Node); + } + catch (Exception) + { + e.Cancel = true; + } + } + + void m_TreeView_ItemDrag(object sender, ItemDragEventArgs e) + { + TreeNode node = (TreeNode)e.Item; + ShellItem folder = (ShellItem)node.Tag; + DragDropEffects effect; + + Ole32.DoDragDrop(folder.GetIDataObject(), this, + DragDropEffects.All, out effect); + } + + void m_TreeView_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + m_RightClickNode = m_TreeView.GetNodeAt(e.Location); + } + } + + void m_TreeView_MouseUp(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + TreeNode node = m_TreeView.GetNodeAt(e.Location); + + if ((node != null) && (node == m_RightClickNode)) + { + ShellItem folder = (ShellItem)node.Tag; + new ShellContextMenu(folder).ShowContextMenu(m_TreeView, e.Location); + } + } + } + + void m_ScrollTimer_Tick(object sender, EventArgs e) + { + ScrollTreeView(m_ScrollDirection); + } + + void m_ShellListener_ItemRenamed(object sender, ShellItemChangeEventArgs e) + { + TreeNode node = FindItem(e.OldItem, m_TreeView.Nodes[0]); + if (node != null) RefreshItem(node); + } + + void m_ShellListener_ItemUpdated(object sender, ShellItemEventArgs e) + { + TreeNode parent = FindItem(e.Item.Parent, m_TreeView.Nodes[0]); + if (parent != null) RefreshItem(parent); + } + + void m_ShellView_Navigated(object sender, EventArgs e) + { + if (!m_Navigating) + { + m_Navigating = true; + SelectedFolder = m_ShellView.CurrentFolder; + m_Navigating = false; + } + } + + enum ScrollDirection + { + None = -1, Up, Down + } + + class DragTarget : IDisposable + { + public DragTarget(TreeNode node, + int keyState, Point pt, + ref int effect) + { + m_Node = node; + m_Node.BackColor = SystemColors.Highlight; + m_Node.ForeColor = SystemColors.HighlightText; + + m_DragExpandTimer = new Timer(); + m_DragExpandTimer.Interval = 1000; + m_DragExpandTimer.Tick += new EventHandler(m_DragExpandTimer_Tick); + m_DragExpandTimer.Start(); + + try + { + m_DropTarget = Folder.GetIDropTarget(node.TreeView); + m_DropTarget.DragEnter(m_Data, keyState, pt, ref effect); + } + catch (Exception) + { + } + } + + public void Dispose() + { + m_Node.BackColor = m_Node.TreeView.BackColor; + m_Node.ForeColor = m_Node.TreeView.ForeColor; + m_DragExpandTimer.Dispose(); + + if (m_DropTarget != null) + { + m_DropTarget.DragLeave(); + } + } + + public void DragOver(int keyState, Point pt, ref int effect) + { + if (m_DropTarget != null) + { + m_DropTarget.DragOver(keyState, pt, ref effect); + } + else + { + effect = 0; + } + } + + public void Drop(ComTypes.IDataObject data, int keyState, + Point pt, ref int effect) + { + m_DropTarget.Drop(data, keyState, pt, ref effect); + } + + public ShellItem Folder + { + get { return (ShellItem)m_Node.Tag; } + } + + public TreeNode Node + { + get { return m_Node; } + } + + public static ComTypes.IDataObject Data + { + get { return m_Data; } + set { m_Data = value; } + } + + void m_DragExpandTimer_Tick(object sender, EventArgs e) + { + m_Node.Expand(); + m_DragExpandTimer.Stop(); + } + + TreeNode m_Node; + Interop.IDropTarget m_DropTarget; + Timer m_DragExpandTimer; + static ComTypes.IDataObject m_Data; + } + + TreeView m_TreeView; + TreeNode m_RightClickNode; + DragTarget m_DragTarget; + Timer m_ScrollTimer = new Timer(); + ScrollDirection m_ScrollDirection = ScrollDirection.None; + ShellItem m_RootFolder = ShellItem.Desktop; + ShellView m_ShellView; + ShowHidden m_ShowHidden = ShowHidden.System; + bool m_Navigating; + bool m_AllowDrop; + ShellNotificationListener m_ShellListener = new ShellNotificationListener(); + } + + /// Describes whether hidden files/folders should be displayed in a + /// control. + public enum ShowHidden + { + /// + /// Hidden files/folders should not be displayed. + /// + False, + + /// + /// Hidden files/folders should be displayed. + /// + True, + + /// + /// The Windows Explorer "Show hidden files" setting should be used + /// to determine whether to show hidden files/folders. + /// + System + } +} \ No newline at end of file diff --git a/Backup/Shell/ShellView.cs b/Backup/Shell/ShellView.cs new file mode 100644 index 0000000..fa5d700 --- /dev/null +++ b/Backup/Shell/ShellView.cs @@ -0,0 +1,1176 @@ +using System; +using System.CodeDom; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.Design.Serialization; +using System.Drawing; +using System.Drawing.Design; +using System.IO; +using System.Runtime.InteropServices; +using System.Runtime.InteropServices.ComTypes; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell.Interop; +using ComTypes = System.Runtime.InteropServices.ComTypes; + +namespace GongSolutions.Shell +{ + /// + /// Specifies how list items are displayed in a + /// control. + /// + public enum ShellViewStyle + { + /// + /// Each item appears as a full-sized icon with a label below it. + /// + LargeIcon = 1, + + /// + /// Each item appears as a small icon with a label to its right. + /// + SmallIcon, + + /// + /// Each item appears as a small icon with a label to its right. + /// Items are arranged in columns with no column headers. + /// + List, + + /// + /// Each item appears on a separate line with further information + /// about each item arranged in columns. The left-most column + /// contains a small icon and label. + /// + Details, + + /// + /// Each item appears with a thumbnail picture of the file's content. + /// + Thumbnail, + + /// + /// Each item appears as a full-sized icon with the item label and + /// file information to the right of it. + /// + Tile, + + /// + /// Each item appears in a thumbstrip at the bottom of the control, + /// with a large preview of the seleted item appearing above. + /// + Thumbstrip, + } + + /// + /// Provides a view of a computer's files and folders. + /// + /// + /// + /// + /// The control allows you to embed Windows + /// Explorer functionality in your Windows Forms applications. The + /// control provides a view of a single folder's contents, as it would + /// appear in the right-hand pane in Explorer. + /// + /// + /// + /// When a new control is added to a form, + /// it displays the contents of the Desktop folder. Other folders + /// can be displayed by calling one of the Navigate methods or setting + /// the property. + /// + /// + public class ShellView : Control, INotifyPropertyChanged + { + /// + /// Constant passed to which causes a column to be auto-sized. + /// + public const int ColumnAutoSize = -1; + + /// + /// Constant passed to which causes a column to be auto-sized + /// to fit the column header text width. + /// + public const int ColumnAutoSizeToHeader = -2; + + /// + /// Initializes a new instance of the class. + /// + public ShellView() + { + m_History = new ShellHistory(); + m_MultiSelect = true; + m_View = ShellViewStyle.LargeIcon; + Size = new Size(250, 200); + Navigate(ShellItem.Desktop); + } + + /// + /// Copies the currently selected items to the clipboard. + /// + public void CopySelectedItems() + { + ShellContextMenu contextMenu = new ShellContextMenu(SelectedItems); + contextMenu.InvokeCopy(); + } + + /// + /// Cuts the currently selected items. + /// + public void CutSelectedItems() + { + ShellContextMenu contextMenu = new ShellContextMenu(SelectedItems); + contextMenu.InvokeCut(); ; + } + + /// + /// Creates a new folder in the folder currently being browsed. + /// + public void CreateNewFolder() + { + string name = "New Folder"; + int suffix = 0; + + do + { + name = string.Format("{0}\\New Folder ({1})", + CurrentFolder.FileSystemPath, ++suffix); + } while (Directory.Exists(name) || File.Exists(name)); + + ERROR result = Shell32.SHCreateDirectory(m_ShellViewWindow, name); + + switch (result) + { + case ERROR.FILE_EXISTS: + case ERROR.ALREADY_EXISTS: + throw new IOException("The directory already exists"); + case ERROR.BAD_PATHNAME: + throw new IOException("Bad pathname"); + case ERROR.FILENAME_EXCED_RANGE: + throw new IOException("The filename is too long"); + } + } + + /// + /// Deletes the currently selected items. + /// + public void DeleteSelectedItems() + { + ShellContextMenu contextMenu = new ShellContextMenu(SelectedItems); + contextMenu.InvokeDelete(); + } + + /// + /// Navigates to the specified . + /// + /// + /// + /// The folder to navigate to. + /// + public void Navigate(ShellItem folder) + { + NavigatingEventArgs e = new NavigatingEventArgs(folder); + + if (Navigating != null) + { + Navigating(this, e); + } + + if (!e.Cancel) + { + ShellItem previous = m_CurrentFolder; + m_CurrentFolder = folder; + + try + { + RecreateShellView(); + m_History.Add(folder); + OnNavigated(); + } + catch (Exception) + { + m_CurrentFolder = previous; + RecreateShellView(); + throw; + } + } + } + + /// + /// Navigates to the specified filesystem directory. + /// + /// + /// + /// The path of the directory to navigate to. + /// + /// + /// + /// is not a valid folder. + /// + public void Navigate(string path) + { + Navigate(new ShellItem(path)); + } + + /// + /// Navigates to the specified standard location. + /// + /// + /// + /// The to which to navigate. + /// + /// + /// + /// Standard locations are virtual folders which may be located in + /// different places in different versions of Windows. For example + /// the "My Documents" folder is normally located at C:\My Documents + /// on Windows 98, but is located in the user's "Documents and + /// Settings" folder in Windows XP. Using a standard + /// to refer to such folders + /// ensures that your application will behave correctly on all + /// versions of Windows. + /// + public void Navigate(Environment.SpecialFolder location) + { + + // CSIDL_MYDOCUMENTS was introduced in Windows XP but doesn't work + // even on that platform. Use CSIDL_PERSONAL instead. + if (location == Environment.SpecialFolder.MyDocuments) + { + location = Environment.SpecialFolder.Personal; + } + + Navigate(new ShellItem(location)); + } + + /// + /// Navigates the control to the previous folder + /// in the navigation history. + /// + /// + /// + /// + /// The WebBrowser control maintains a history list of all the folders + /// visited during a session. You can use the + /// method to implement a Back button similar to the one in + /// Windows Explorer, which will allow your users to return to a + /// previous folder in the navigation history. + /// + /// + /// + /// Use the property to determine whether + /// the navigation history is available and contains a previous page. + /// This property is useful, for example, to change the enabled state + /// of a Back button when the ShellView control navigates to or leaves + /// the beginning of the navigation history. + /// + /// + /// + /// + /// There is no history to navigate backwards through. + /// + public void NavigateBack() + { + m_CurrentFolder = m_History.MoveBack(); + RecreateShellView(); + OnNavigated(); + } + + /// + /// Navigates the control backwards to the + /// requested folder in the navigation history. + /// + /// + /// + /// The WebBrowser control maintains a history list of all the folders + /// visited during a session. You can use the + /// method to implement a drop-down menu on a Back button similar + /// to the one in Windows Explorer, which will allow your users to return + /// to a previous folder in the navigation history. + /// + /// + /// + /// The folder to navigate to. + /// + /// + /// + /// The requested folder is not present in the + /// 's 'back' history. + /// + public void NavigateBack(ShellItem folder) + { + m_History.MoveBack(folder); + m_CurrentFolder = folder; + RecreateShellView(); + OnNavigated(); + } + + /// + /// Navigates the control to the next folder + /// in the navigation history. + /// + /// + /// + /// + /// The WebBrowser control maintains a history list of all the folders + /// visited during a session. You can use the + /// method to implement a Forward button similar to the one + /// in Windows Explorer, allowing your users to return to the next + /// folder in the navigation history after navigating backward. + /// + /// + /// + /// Use the property to determine + /// whether the navigation history is available and contains a folder + /// located after the current one. This property is useful, for + /// example, to change the enabled state of a Forward button + /// when the ShellView control navigates to or leaves the end of the + /// navigation history. + /// + /// + /// + /// + /// There is no history to navigate forwards through. + /// + public void NavigateForward() + { + m_CurrentFolder = m_History.MoveForward(); + RecreateShellView(); + OnNavigated(); + } + + /// + /// Navigates the control forwards to the + /// requested folder in the navigation history. + /// + /// + /// + /// The WebBrowser control maintains a history list of all the folders + /// visited during a session. You can use the + /// method to implement a drop-down menu + /// on a Forward button similar to the one in Windows Explorer, + /// which will allow your users to return to a folder in the 'forward' + /// navigation history. + /// + /// + /// + /// The folder to navigate to. + /// + /// + /// + /// The requested folder is not present in the + /// 's 'forward' history. + /// + public void NavigateForward(ShellItem folder) + { + m_History.MoveForward(folder); + m_CurrentFolder = folder; + RecreateShellView(); + OnNavigated(); + } + + /// + /// Navigates to the parent of the currently displayed folder. + /// + public void NavigateParent() + { + Navigate(m_CurrentFolder.Parent); + } + + /// + /// Navigates to the folder currently selected in the + /// . + /// + /// + /// + /// If the 's + /// property is set, and more than one item is selected in the + /// ShellView, the first Folder found will be navigated to. + /// + /// + /// + /// if a selected folder could be + /// navigated to, otherwise. + /// + public bool NavigateSelectedFolder() + { + ShellItem[] selected = SelectedItems; + + if (selected.Length > 0) + { + foreach (ShellItem i in selected) + { + if (i.IsFolder) + { + Navigate(i); + return true; + } + } + } + + return false; + } + + /// + /// Pastes the contents of the clipboard into the current folder. + /// + public void PasteClipboard() + { + ShellContextMenu contextMenu = new ShellContextMenu(m_CurrentFolder); + contextMenu.InvokePaste(); + } + + /// + /// Refreshes the contents of the . + /// + public void RefreshContents() + { + if (m_ComInterface != null) m_ComInterface.Refresh(); + } + + /// + /// Begins a rename on the item currently selected in the + /// . + /// + public void RenameSelectedItem() + { + User32.EnumChildWindows(m_ShellViewWindow, RenameCallback, IntPtr.Zero); + } + + /// + /// Gets the width of the specified column. + /// + /// The column. + /// Width in pixel + public int GetColumnWidth(int column) + { + IntPtr wnd = User32.GetWindow(m_ShellViewWindow,GetWindow_Cmd.GW_CHILD);// Get listview + return User32.SendMessage(wnd, MSG.LVM_GETCOLUMNWIDTH,column,0); + } + + /// + /// Resizes the specified column. + /// + /// The column. + /// + /// The width (in pixels) of the column or a special value : , + /// + /// + public void SetColumnWidth(int column, int width) + { + IntPtr wnd = User32.GetWindow(m_ShellViewWindow, GetWindow_Cmd.GW_CHILD);// Get listview + User32.SendMessage(wnd, MSG.LVM_SETCOLUMNWIDTH, column, width); + } + + /// + /// Selects all items in the . + /// + public void SelectAll() + { + foreach (ShellItem item in ShellItem) + { + m_ComInterface.SelectItem(Shell32.ILFindLastID(item.Pidl), SVSI.SVSI_SELECT); + } + } + + /// + /// Gets a value indicating whether a new folder can be created in + /// the folder currently being browsed by th . + /// + [Browsable(false)] + public bool CanCreateFolder + { + get + { + return m_CurrentFolder.IsFileSystem && !m_CurrentFolder.IsReadOnly; + } + } + + /// + /// Gets a value indicating whether a previous page in navigation + /// history is available, which allows the + /// method to succeed. + /// + [Browsable(false)] + public bool CanNavigateBack + { + get { return m_History.CanNavigateBack; } + } + + /// + /// Gets a value indicating whether a subsequent page in navigation + /// history is available, which allows the + /// method to succeed. + /// + [Browsable(false)] + public bool CanNavigateForward + { + get { return m_History.CanNavigateForward; } + } + + /// + /// Gets a value indicating whether the folder currently being browsed + /// by the has parent folder which can be + /// navigated to by calling . + /// + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public bool CanNavigateParent + { + get + { + return m_CurrentFolder != ShellItem.Desktop; + } + } + + /// + /// Gets the control's underlying COM IShellView interface. + /// + [Browsable(false)] + public IShellView ComInterface + { + get { return m_ComInterface; } + } + + /// + /// Gets/sets a describing the folder + /// currently being browsed by the . + /// + [Editor(typeof(ShellItemEditor), typeof(UITypeEditor))] + public ShellItem CurrentFolder + { + get { return m_CurrentFolder; } + set + { + if (value != m_CurrentFolder) + { + Navigate(value); + } + } + } + + /// + /// Gets the 's navigation history. + /// + [Browsable(false)] + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public ShellHistory History + { + get { return m_History; } + } + + /// + /// Gets a list of the items currently selected in the + /// + /// + /// + /// + /// A array detailing the items currently + /// selected in the control. If no items are currently selected, + /// an empty array is returned. + /// + [Browsable(false)] + public ShellItem[] SelectedItems + { + get + { + uint CFSTR_SHELLIDLIST = + User32.RegisterClipboardFormat("Shell IDList Array"); + ComTypes.IDataObject selection = GetSelectionDataObject(); + + if (selection != null) + { + FORMATETC format = new FORMATETC(); + STGMEDIUM storage = new STGMEDIUM(); + + format.cfFormat = (short)CFSTR_SHELLIDLIST; + format.dwAspect = DVASPECT.DVASPECT_CONTENT; + format.lindex = 0; + format.tymed = TYMED.TYMED_HGLOBAL; + + if (selection.QueryGetData(ref format) == 0) + { + selection.GetData(ref format, out storage); + + int itemCount = Marshal.ReadInt32(storage.unionmember); + ShellItem[] result = new ShellItem[itemCount]; + + for (int n = 0; n < itemCount; ++n) + { + int offset = Marshal.ReadInt32(storage.unionmember, + 8 + (n * 4)); + result[n] = new ShellItem( + m_CurrentFolder, + (IntPtr)((int)storage.unionmember + offset)); + } + + GlobalFree(storage.unionmember); + return result; + } + } + return new ShellItem[0]; + } + } + + /// + /// Gets/sets a value indicating whether multiple items can be selected + /// by the user. + /// + [DefaultValue(true), Category("Behaviour")] + public bool MultiSelect + { + get { return m_MultiSelect; } + set + { + m_MultiSelect = value; + RecreateShellView(); + OnNavigated(); + } + } + + /// + /// Gets/sets a value indicating whether a "WebView" is displayed on + /// the left of the control. + /// + /// + /// + /// The WebView is a strip of HTML that appears to the left of a + /// Windows Explorer window when the window has no Explorer Bar. + /// It displays general system tasks and locations, as well as + /// information about the items selected in the window. + /// + /// + /// Important: When is set to + /// , the + /// event will not occur. This is due to a limitation in the + /// underlying windows control. + /// + /// + [DefaultValue(false), Category("Appearance")] + public bool ShowWebView + { + get { return m_ShowWebView; } + set + { + if (value != m_ShowWebView) + { + m_ShowWebView = value; + m_Browser = null; + RecreateShellView(); + OnNavigated(); + } + } + } + + /// + /// Gets/sets a control that the + /// should use to display folder details. + /// + public StatusBar StatusBar + { + get { return ((ShellBrowser)GetShellBrowser()).StatusBar; } + set { ((ShellBrowser)GetShellBrowser()).StatusBar = value; } + } + + /// + /// Gets or sets how items are displayed in the control. + /// + [DefaultValue(ShellViewStyle.LargeIcon), Category("Appearance")] + public ShellViewStyle View + { + get { return m_View; } + set + { + m_View = value; + RecreateShellView(); + OnNavigated(); + } + } + + /// + /// Occurs when the control wants to know + /// if it should include an item in its view. + /// + /// + /// + /// This event allows the items displayed in the + /// control to be filtered. You may want to to only list files with + /// a certain extension, for example. + /// + public event FilterItemEventHandler FilterItem; + + /// + /// Occurs when the control navigates to a + /// new folder. + /// + public event EventHandler Navigated; + + /// + /// Occurs when the control is about to + /// navigate to a new folder. + /// + public event NavigatingEventHandler Navigating; + + /// + /// Occurs when the 's current selection + /// changes. + /// + /// + /// + /// Important: When is set to + /// , this event will not occur. This is due to + /// a limitation in the underlying windows control. + /// + public event EventHandler SelectionChanged; + + #region Hidden Inherited Properties + + /// + /// This property does not apply to . + /// + [Browsable(false)] + public override Color BackColor + { + get { return base.BackColor; } + set { base.BackColor = value; } + } + + /// + /// This property does not apply to . + /// + [Browsable(false)] + public override Image BackgroundImage + { + get { return base.BackgroundImage; } + set { base.BackgroundImage = value; } + } + + /// + /// This property does not apply to . + /// + [Browsable(false)] + public override ImageLayout BackgroundImageLayout + { + get { return base.BackgroundImageLayout; } + set { base.BackgroundImageLayout = value; } + } + + #endregion + + #region INotifyPropertyChanged Members + + event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged + { + add { m_PropertyChanged += value; } + remove { m_PropertyChanged -= value; } + } + + #endregion + + /// + /// Overrides + /// + /// + /// + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (m_ShellViewWindow != IntPtr.Zero) + { + User32.DestroyWindow(m_ShellViewWindow); + m_ShellViewWindow = IntPtr.Zero; + } + } + base.Dispose(disposing); + } + + /// + /// Creates the actual shell view control. + /// + protected override void OnCreateControl() + { + base.OnCreateControl(); + CreateShellView(); + OnNavigated(); + } + + /// + /// Overrides . + /// + /// + /// + /// + protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e) + { + if ((e.KeyData == Keys.Up) || (e.KeyData == Keys.Down) || + (e.KeyData == Keys.Left) || (e.KeyData == Keys.Right) || + (e.KeyData == Keys.Enter) || (e.KeyData == Keys.Delete)) + e.IsInputKey = true; + + if (e.KeyCode == Keys.Delete) DeleteSelectedItems(); + if (e.KeyCode == Keys.F2) RenameSelectedItem(); + if (e.Control && e.KeyCode == Keys.A) SelectAll(); + if (e.Control && e.KeyCode == Keys.C) CopySelectedItems(); + if (e.Control && e.KeyCode == Keys.V) PasteClipboard(); + if (e.Control && e.KeyCode == Keys.X) CutSelectedItems(); + + base.OnPreviewKeyDown(e); + } + + /// + /// Overrides . + /// + /// + /// + protected override void OnResize(EventArgs eventargs) + { + base.OnResize(eventargs); + User32.SetWindowPos(m_ShellViewWindow, IntPtr.Zero, 0, 0, + ClientRectangle.Width, ClientRectangle.Height, 0); + } + + /// + /// Overrides + /// + /// + protected override void WndProc(ref Message m) + { + const int CWM_GETISHELLBROWSER = 0x407; + + // Windows 9x sends the CWM_GETISHELLBROWSER message and expects + // the IShellBrowser for the window to be returned or an Access + // Violation occurs. This is pseudo-documented in knowledge base + // article Q157247. + if (m.Msg == CWM_GETISHELLBROWSER) + { + m.Result = Marshal.GetComInterfaceForObject(m_Browser, + typeof(IShellBrowser)); + } + else + { + base.WndProc(ref m); + } + } + + internal bool IncludeItem(IntPtr pidl) + { + if (FilterItem != null) + { + FilterItemEventArgs e = new FilterItemEventArgs( + new ShellItem(m_CurrentFolder, pidl)); + FilterItem(this, e); + return e.Include; + } + else + { + return true; + } + } + + internal new void OnDoubleClick(EventArgs e) + { + base.OnDoubleClick(e); + } + + internal void OnSelectionChanged() + { + if (SelectionChanged != null) + { + SelectionChanged(this, EventArgs.Empty); + } + } + + internal ShellItem ShellItem + { + get { return m_CurrentFolder; } + } + + void CreateShellView() + { + IShellView previous = m_ComInterface; + Rectangle bounds = ClientRectangle; + FOLDERSETTINGS folderSettings = new FOLDERSETTINGS(); + + // Create an IShellView object. + m_ComInterface = CreateViewObject(m_CurrentFolder, Handle); + + // Set the FOLDERSETTINGS. + folderSettings.ViewMode = (FOLDERVIEWMODE)m_View; + + if (!m_ShowWebView) + { + folderSettings.fFlags |= FOLDERFLAGS.NOWEBVIEW; + } + + if (!m_MultiSelect) + { + folderSettings.fFlags |= FOLDERFLAGS.SINGLESEL; + } + + // Tell the IShellView object to create a view window and + // activate it. + try + { + m_ComInterface.CreateViewWindow(previous, ref folderSettings, + GetShellBrowser(), ref bounds, + out m_ShellViewWindow); + } + catch (COMException ex) + { + // If the operation was cancelled by the user (for example + // because an empty removable media drive was selected, + // then "Cancel" pressed in the resulting dialog) convert + // the exception into something more meaningfil. + if (ex.ErrorCode == unchecked((int)0x800704C7U)) + { + throw new UserAbortException(ex); + } + } + + m_ComInterface.UIActivate(1); + + // Disable the window if in design mode, so that user input is + // passed onto the designer. + if (DesignMode) + { + User32.EnableWindow(m_ShellViewWindow, false); + } + + // Destroy the previous view window. + if (previous != null) previous.DestroyViewWindow(); + } + + void RecreateShellView() + { + if (m_ComInterface != null) + { + CreateShellView(); + OnNavigated(); + } + + if (m_PropertyChanged != null) + { + m_PropertyChanged(this, + new PropertyChangedEventArgs("CurrentFolder")); + } + } + + bool RenameCallback(IntPtr hwnd, IntPtr lParam) + { + int itemCount = User32.SendMessage(hwnd, + MSG.LVM_GETITEMCOUNT, 0, 0); + + for (int n = 0; n < itemCount; ++n) + { + LVITEMA item = new LVITEMA(); + item.mask = LVIF.LVIF_STATE; + item.iItem = n; + item.stateMask = LVIS.LVIS_SELECTED; + User32.SendMessage(hwnd, MSG.LVM_GETITEMA, + 0, ref item); + + if (item.state != 0) + { + User32.SendMessage(hwnd, MSG.LVM_EDITLABEL, n, 0); + return false; + } + } + + return true; + } + + ComTypes.IDataObject GetSelectionDataObject() + { + IntPtr result; + + if (m_ComInterface == null) + { + return null; + } + + m_ComInterface.GetItemObject(SVGIO.SVGIO_SELECTION, + typeof(ComTypes.IDataObject).GUID, out result); + + if (result != IntPtr.Zero) + { + ComTypes.IDataObject wrapped = + (ComTypes.IDataObject) + Marshal.GetTypedObjectForIUnknown(result, + typeof(ComTypes.IDataObject)); + return wrapped; + } + else + { + return null; + } + } + + IShellBrowser GetShellBrowser() + { + if (m_Browser == null) + { + if (m_ShowWebView) + { + m_Browser = new ShellBrowser(this); + } + else + { + m_Browser = new DialogShellBrowser(this); + } + } + return m_Browser; + } + + void OnNavigated() + { + if (Navigated != null) + { + Navigated(this, EventArgs.Empty); + } + } + + bool ShouldSerializeCurrentFolder() + { + return m_CurrentFolder != ShellItem.Desktop; + } + + static IShellView CreateViewObject(ShellItem folder, IntPtr hwndOwner) + { + IntPtr result = folder.GetIShellFolder().CreateViewObject(hwndOwner, + typeof(IShellView).GUID); + return (IShellView) + Marshal.GetTypedObjectForIUnknown(result, + typeof(IShellView)); + } + + [DllImport("kernel32.dll")] + static extern IntPtr GlobalFree(IntPtr hMem); + + bool m_MultiSelect; + ShellHistory m_History; + ShellBrowser m_Browser; + ShellItem m_CurrentFolder; + IShellView m_ComInterface; + IntPtr m_ShellViewWindow; + bool m_ShowWebView; + ShellViewStyle m_View; + PropertyChangedEventHandler m_PropertyChanged; + } + + /// + /// Provides information for FilterItem events. + /// + public class FilterItemEventArgs : EventArgs + { + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// + /// The item to be filtered. + /// + internal FilterItemEventArgs(ShellItem item) + { + m_Item = item; + } + + /// + /// Gets/sets a value which will determine whether the item will be + /// included in the . + /// + public bool Include + { + get { return m_Include; } + set { m_Include = value; } + } + + /// + /// The item to be filtered. + /// + public ShellItem Item + { + get { return m_Item; } + } + + ShellItem m_Item; + bool m_Include = true; + } + + /// + /// Provides information for the + /// event. + /// + public class NavigatingEventArgs : EventArgs + { + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// + /// The folder being navigated to. + /// + public NavigatingEventArgs(ShellItem folder) + { + m_Folder = folder; + } + + /// + /// Gets/sets a value indicating whether the navigation should be + /// cancelled. + /// + public bool Cancel + { + get { return m_Cancel; } + set { m_Cancel = value; } + } + + /// + /// The folder being navigated to. + /// + public ShellItem Folder + { + get { return m_Folder; } + set { m_Folder = value; } + } + + bool m_Cancel; + ShellItem m_Folder; + } + + /// + /// Exception raised when a user aborts a Shell operation. + /// + public class UserAbortException : ExternalException + { + + /// + /// Initializes a new instance of the + /// class. + /// + /// + /// + /// The inner exception. + /// + public UserAbortException(Exception e) + : base("User aborted", e) + { + } + } + + /// + /// Represents the method that will handle FilterItem events. + /// + public delegate void FilterItemEventHandler(object sender, + FilterItemEventArgs e); + + /// + /// Represents the method that will handle the + /// event. + /// + public delegate void NavigatingEventHandler(object sender, + NavigatingEventArgs e); +} diff --git a/Backup/Shell/SystemImageList.cs b/Backup/Shell/SystemImageList.cs new file mode 100644 index 0000000..2940724 --- /dev/null +++ b/Backup/Shell/SystemImageList.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell.Interop; + +namespace GongSolutions.Shell +{ + class SystemImageList + { + public static void DrawSmallImage(Graphics g, Point point, + int imageIndex, bool selected) + { + uint flags = (uint)(imageIndex >> 16); + IntPtr hdc = g.GetHdc(); + + try + { + if (selected) flags |= (int)ILD.BLEND50; + ComCtl32.ImageList_Draw(SmallImageList, imageIndex & 0xffff, + hdc, point.X, point.Y, flags); + } + finally + { + g.ReleaseHdc(); + } + } + + public static void UseSystemImageList(ListView control) + { + IntPtr large, small; + int x, y; + + if (control.LargeImageList == null) + { + control.LargeImageList = new ImageList(); + } + + if (control.SmallImageList == null) + { + control.SmallImageList = new ImageList(); + } + + Shell32.FileIconInit(true); + if (!Shell32.Shell_GetImageLists(out large, out small)) + { + throw new Exception("Failed to get system image list"); + } + + ComCtl32.ImageList_GetIconSize(large, out x, out y); + control.LargeImageList.ImageSize = new Size(x, y); + ComCtl32.ImageList_GetIconSize(small, out x, out y); + control.SmallImageList.ImageSize = new Size(x, y); + + User32.SendMessage(control.Handle, MSG.LVM_SETIMAGELIST, + (int)LVSIL.LVSIL_NORMAL, LargeImageList); + User32.SendMessage(control.Handle, MSG.LVM_SETIMAGELIST, + (int)LVSIL.LVSIL_SMALL, SmallImageList); + } + + public static void UseSystemImageList(TreeView control) + { + User32.SendMessage(control.Handle, MSG.TVM_SETIMAGELIST, + 0, SmallImageList); + } + + static void InitializeImageLists() + { + Shell32.FileIconInit(true); + if (!Shell32.Shell_GetImageLists(out m_LargeImageList, + out m_SmallImageList)) + { + throw new Exception("Failed to get system image list"); + } + } + + static IntPtr SmallImageList + { + get + { + if (m_SmallImageList == IntPtr.Zero) + { + InitializeImageLists(); + } + return m_SmallImageList; + } + } + + static IntPtr LargeImageList + { + get + { + if (m_LargeImageList == IntPtr.Zero) + { + InitializeImageLists(); + } + return m_LargeImageList; + } + } + + static IntPtr m_SmallImageList; + static IntPtr m_LargeImageList; + } +} diff --git a/Backup/Tests/ShellTest/Program.cs b/Backup/Tests/ShellTest/Program.cs new file mode 100644 index 0000000..320edb1 --- /dev/null +++ b/Backup/Tests/ShellTest/Program.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Windows.Forms; +using GongSolutions.Shell; +using GongSolutions.Shell.Interop; +using NUnit.Framework; + +namespace ShellTest +{ + public class Program + { + static void Main(string[] args) + { + RunTests(); + } + + static void RunTests() + { + ShellItemTest test = new ShellItemTest(); + + test.SetUp(); + + try + { + test.Names(); + test.EnumerateChildren(); + test.SpecialFolders(); + test.Attributes(); + test.Compare(); + test.Uri(); + test.Pidl(); + } + finally + { + test.TearDown(); + } + } + } + + [TestFixture] + public class ShellItemTest + { + [TestFixtureSetUp] + public void SetUp() + { + Directory.CreateDirectory(Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + "GongShellTestFolder")); + Directory.CreateDirectory(Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + "GongShellTestFolder\\Nested")); + } + + [TestFixtureTearDown] + public void TearDown() + { + Directory.Delete(Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), + "GongShellTestFolder"), + true); + } + + [Test] + public void Names() + { + string location = @"C:\Program Files"; + string displayName = @"Program Files"; + ShellItem item = new ShellItem(location); + Assert.AreEqual(displayName, item.DisplayName); + Assert.AreEqual(location, item.FileSystemPath); + Assert.AreEqual( + Environment.GetFolderPath(Environment.SpecialFolder.Desktop), + ShellItem.Desktop.FileSystemPath); + } + + [Test] + public void EnumerateChildren() + { + string location = @"C:\Program Files"; + ShellItem item = new ShellItem(location); + List children = new List(); + + children.AddRange(Directory.GetFiles(location)); + children.AddRange(Directory.GetDirectories(location)); + + // The shell does not include desktop.ini in its enumeration. + children.Remove(Path.Combine(location, "desktop.ini")); + + foreach (ShellItem child in item) + { + children.Remove(child.FileSystemPath); + } + + Assert.IsEmpty(children); + } + + [Test] + public void SpecialFolders() + { + Environment.SpecialFolder myComputerFolder = + Environment.SpecialFolder.MyComputer; + Environment.SpecialFolder myPicturesFolder = + Environment.SpecialFolder.MyPictures; + ShellItem myComputer = new ShellItem(myComputerFolder); + ShellItem myComputer2 = new ShellItem(myComputer.ToUri()); + ShellItem myPictures = new ShellItem(myPicturesFolder); + ShellItem myPictures2 = new ShellItem(myPictures.ToUri()); + + Assert.IsTrue(myComputer.Equals(myComputer2)); + Assert.AreEqual(Environment.GetFolderPath(myPicturesFolder), myPictures.FileSystemPath); + Assert.AreEqual(myPictures, myPictures2); + + try + { + string path = myComputer.FileSystemPath; + Assert.Fail("FileSystemPath from virtual folder should throw exception"); + } + catch (ArgumentException) + { + } + catch (Exception) + { + Assert.Fail("FileSystemPath from virtual folder should throw ArgumentException"); + } + } + + [Test] + public void Attributes() + { + ShellItem cDrive = new ShellItem(@"C:\"); + ShellItem myComputer = + new ShellItem(Environment.SpecialFolder.MyComputer); + ShellItem file = new ShellItem(Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.System), + "kernel32.dll")); + + Assert.IsTrue(cDrive.IsFolder); + Assert.IsTrue(myComputer.IsFolder); + Assert.IsFalse(file.IsFolder); + } + + [Test] + public void Compare() + { + ShellItem desktop1 = ShellItem.Desktop; + ShellItem desktop2 = new ShellItem("shell:///Desktop"); + ShellItem item1 = new ShellItem(@"C:\Program Files"); + ShellItem item2 = item1.Parent[@"Program Files"]; + + Assert.IsTrue(desktop1.Equals(desktop2)); + Assert.AreEqual(item1.FileSystemPath, item2.FileSystemPath); + Assert.IsTrue(item1 == item2); + Assert.IsFalse(item1 != item2); + } + + [Test] + public void Uri() + { + string desktopExpected = "shell:///Desktop"; + string myComputerExpected = "shell:///MyComputerFolder"; + string myDocumentsExpected = "shell:///Personal"; + ShellItem desktop1 = ShellItem.Desktop; + ShellItem desktop2 = new ShellItem(desktopExpected); + ShellItem myComputer = new ShellItem(myComputerExpected); + ShellItem myDocuments = new ShellItem(Environment.SpecialFolder.MyDocuments); + ShellItem myDocumentsChild = myDocuments["GongShellTestFolder"]; + ShellItem myDocumentsChild2 = new ShellItem(myDocumentsExpected + "/GongShellTestFolder"); + ShellItem myDocumentsChild3 = new ShellItem(myDocumentsExpected + "/GongShellTestFolder/Nested"); + ShellItem cDrive = new ShellItem(@"C:\"); + ShellItem controlPanel = new ShellItem((Environment.SpecialFolder)CSIDL.CONTROLS); + + Assert.AreEqual(desktopExpected, desktop1.ToString()); + Assert.AreEqual(desktopExpected, desktop2.ToString()); + Assert.AreEqual(myComputerExpected, myComputer.ToString()); + Assert.AreEqual(myDocumentsExpected, myDocuments.ToString()); + Assert.AreEqual(myDocumentsExpected + "/GongShellTestFolder", + myDocumentsChild.ToString()); + Assert.AreEqual("file:///C:/", cDrive.ToString()); + Assert.IsTrue(myDocumentsChild.Equals(myDocumentsChild2)); + Assert.AreEqual(myDocumentsExpected + "/GongShellTestFolder/Nested", + myDocumentsChild3.ToString()); + } + + [Test] + public void Pidl() + { + ShellItem myDocuments = new ShellItem(Environment.SpecialFolder.MyDocuments); + IntPtr pidl = myDocuments.Pidl; + } + } +} diff --git a/Backup/Tests/ShellTest/Properties/AssemblyInfo.cs b/Backup/Tests/ShellTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f83c7f9 --- /dev/null +++ b/Backup/Tests/ShellTest/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShellFolderTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShellFolderTest")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fd50bb33-2c54-4380-841e-379df28cfa4a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Backup/Tests/ShellTest/ShellTest.csproj b/Backup/Tests/ShellTest/ShellTest.csproj new file mode 100644 index 0000000..c547048 --- /dev/null +++ b/Backup/Tests/ShellTest/ShellTest.csproj @@ -0,0 +1,63 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {EA474286-27FB-4DE3-83C6-90142DA951DD} + Exe + Properties + ShellTest + ShellTest + + + + + 2.0 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + C:\Program Files\NUnit 2.4.1\bin\nunit.framework.dll + + + + + + + + + + + + + {711CCF1F-6B8F-4E97-8D84-0EE679C83B41} + Shell + + + + + \ No newline at end of file diff --git a/Examples/FileDialog/FileDialog.csproj b/Examples/FileDialog/FileDialog.csproj index 1306a96..17ee2c2 100644 --- a/Examples/FileDialog/FileDialog.csproj +++ b/Examples/FileDialog/FileDialog.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -13,7 +14,8 @@ - 2.0 + 3.5 + v2.0 true diff --git a/Examples/FileDialog/Properties/Resources.Designer.cs b/Examples/FileDialog/Properties/Resources.Designer.cs index 59fcfaf..907bfbe 100644 --- a/Examples/FileDialog/Properties/Resources.Designer.cs +++ b/Examples/FileDialog/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.4927 +// Runtime Version:4.0.30319.34003 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,7 +19,7 @@ namespace FileDialog.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/Examples/FileDialog/Properties/Settings.Designer.cs b/Examples/FileDialog/Properties/Settings.Designer.cs index 4c00113..b2f98d9 100644 --- a/Examples/FileDialog/Properties/Settings.Designer.cs +++ b/Examples/FileDialog/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.4927 +// Runtime Version:4.0.30319.34003 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,7 +12,7 @@ namespace FileDialog.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Examples/FileDialog/bin/Debug/FileDialog.exe.config b/Examples/FileDialog/bin/Debug/FileDialog.exe.config new file mode 100644 index 0000000..f9d5b83 --- /dev/null +++ b/Examples/FileDialog/bin/Debug/FileDialog.exe.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + shell:///Personal + + + + \ No newline at end of file diff --git a/Examples/FileDialog/bin/Debug/FileDialog.vshost.exe b/Examples/FileDialog/bin/Debug/FileDialog.vshost.exe new file mode 100644 index 0000000..01b91bc Binary files /dev/null and b/Examples/FileDialog/bin/Debug/FileDialog.vshost.exe differ diff --git a/Examples/FileDialog/bin/Debug/FileDialog.vshost.exe.config b/Examples/FileDialog/bin/Debug/FileDialog.vshost.exe.config new file mode 100644 index 0000000..f9d5b83 --- /dev/null +++ b/Examples/FileDialog/bin/Debug/FileDialog.vshost.exe.config @@ -0,0 +1,15 @@ + + + + +
+ + + + + + shell:///Personal + + + + \ No newline at end of file diff --git a/Examples/FileDialog/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Examples/FileDialog/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..e580cf9 Binary files /dev/null and b/Examples/FileDialog/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Examples/FileDialog/obj/Debug/FileDialog.csproj.FileListAbsolute.txt b/Examples/FileDialog/obj/Debug/FileDialog.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..558cc1f --- /dev/null +++ b/Examples/FileDialog/obj/Debug/FileDialog.csproj.FileListAbsolute.txt @@ -0,0 +1 @@ +D:\projects\gong-shell\Examples\FileDialog\bin\Debug\FileDialog.exe.config diff --git a/Examples/ShellExplorer/Properties/Resources.Designer.cs b/Examples/ShellExplorer/Properties/Resources.Designer.cs index a95e5cd..91df2f3 100644 --- a/Examples/ShellExplorer/Properties/Resources.Designer.cs +++ b/Examples/ShellExplorer/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.4927 +// Runtime Version:4.0.30319.34003 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,7 +19,7 @@ namespace ShellExplorer.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/Examples/ShellExplorer/Properties/Settings.Designer.cs b/Examples/ShellExplorer/Properties/Settings.Designer.cs index 3571542..94f3daa 100644 --- a/Examples/ShellExplorer/Properties/Settings.Designer.cs +++ b/Examples/ShellExplorer/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.4927 +// Runtime Version:4.0.30319.34003 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -12,7 +12,7 @@ namespace ShellExplorer.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/Examples/ShellExplorer/ShellExplorer.csproj b/Examples/ShellExplorer/ShellExplorer.csproj index ec49ec8..cf41eb6 100644 --- a/Examples/ShellExplorer/ShellExplorer.csproj +++ b/Examples/ShellExplorer/ShellExplorer.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -13,7 +14,8 @@ - 2.0 + 3.5 + v2.0 true diff --git a/Examples/ShellExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Examples/ShellExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..7922f73 Binary files /dev/null and b/Examples/ShellExplorer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/GongShell.sln b/GongShell.sln index 246c033..f58b8fa 100644 --- a/GongShell.sln +++ b/GongShell.sln @@ -1,6 +1,8 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileDialog", "Examples\FileDialog\FileDialog.csproj", "{6D9343CF-7F87-4C36-ADB8-DD8667F38E51}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShellExplorer", "Examples\ShellExplorer\ShellExplorer.csproj", "{7258B802-D0E5-4268-9C71-3DCC6AF5C2C1}" diff --git a/GongShell.v12.suo b/GongShell.v12.suo new file mode 100644 index 0000000..7257a35 Binary files /dev/null and b/GongShell.v12.suo differ diff --git a/Shell/Properties/Resources.Designer.cs b/Shell/Properties/Resources.Designer.cs index 1bc8bc2..bdf067b 100644 --- a/Shell/Properties/Resources.Designer.cs +++ b/Shell/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.4927 +// Runtime Version:4.0.30319.34003 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -19,7 +19,7 @@ namespace GongSolutions.Shell.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -60,6 +60,9 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap Back { get { object obj = ResourceManager.GetObject("Back", resourceCulture); @@ -67,6 +70,9 @@ internal static System.Drawing.Bitmap Back { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap NewFolder { get { object obj = ResourceManager.GetObject("NewFolder", resourceCulture); @@ -74,6 +80,9 @@ internal static System.Drawing.Bitmap NewFolder { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap Up { get { object obj = ResourceManager.GetObject("Up", resourceCulture); @@ -81,6 +90,9 @@ internal static System.Drawing.Bitmap Up { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// internal static System.Drawing.Bitmap Views { get { object obj = ResourceManager.GetObject("Views", resourceCulture); diff --git a/Shell/Shell.csproj b/Shell/Shell.csproj index d91438a..0e3d937 100644 --- a/Shell/Shell.csproj +++ b/Shell/Shell.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -13,7 +14,8 @@ - 2.0 + 3.5 + v2.0 true diff --git a/Shell/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Shell/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..82523c5 Binary files /dev/null and b/Shell/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Shell/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll b/Shell/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll new file mode 100644 index 0000000..0dc9863 Binary files /dev/null and b/Shell/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll differ diff --git a/Tests/ShellTest/ShellTest.csproj b/Tests/ShellTest/ShellTest.csproj index c547048..ea9468a 100644 --- a/Tests/ShellTest/ShellTest.csproj +++ b/Tests/ShellTest/ShellTest.csproj @@ -1,4 +1,5 @@ - + + Debug AnyCPU @@ -13,7 +14,8 @@ - 2.0 + 3.5 + v2.0 true diff --git a/Tests/ShellTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Tests/ShellTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..3b71870 Binary files /dev/null and b/Tests/ShellTest/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ