.


:




:

































 

 

 

 


 

 

1 # .Net. .: , 2003

2 .. . -.: , 2006

3 . #. . . .: , 2008

4 .. . .: -, 2002

5 .. CASE-. . .: , 1999

6 . UML2 .: -, 2007

7 2.106-96. .

8 19.401-2000. .


 

()

 

using System;

using System.ComponentModel;

using System.Drawing;

using System.Windows.Forms;

using System.IO;

using System.Runtime.InteropServices;

 

namespace DramaShellSolution

{

public partial class MainForm: Form

{

#region

private const uint SHGFI_ICON = 0x100; // get icon

private const uint SHGFI_LINKOVERLAY = 0x8000; // put a link overlay on icon

private const uint SHGFI_SELECTED = 0x10000; // show icon in selected state

private const uint SHGFI_LARGEICON = 0x0; // get large icon

private const uint SHGFI_SMALLICON = 0x1; // get small icon

private const uint SHGFI_OPENICON = 0x2; // get open icon

private const uint SHGFI_SHELLICONSIZE = 0x4; // get shell size icon

private const uint SHGFI_USEFILEATTRIBUTES = 0x10; // use passed dwFileAttribute

private const uint SHGFI_TYPENAME = 0x400;

 

private const string DEFAULT_PATH = @"C:\";

#endregion

 

// ,

[StructLayout(LayoutKind.Sequential)]

private struct SHFILEINFO

{

public IntPtr hIcon;

public IntPtr iIcon;

public uint dwAttributes;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]

public string szDisplayName;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]

public string szTypeName;

};

 

// Win32 <shell32.dll>

[DllImport("shell32.dll")]

private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);

 

// Win32 <user32.dll>

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public extern static bool DestroyIcon(IntPtr handle);

 

//

public enum IconSize { Large, Small, Shell };

 

//

private ImageList fileIcons = new ImageList();

 

public static string szPath = "";

private string szPathToAction = "";

 

private bool bActIsCopy = false,

bActIsMove = false;

 

CreateFolder createFolder = new CreateFolder();

CreateFile createFile = new CreateFile();

 

public MainForm()

{

InitializeComponent();

}

 

private void MainForm_Load(object sender, EventArgs e)

{

szPath = DEFAULT_PATH; // - (C:\)

fileBrowser.LargeImageList = fileIcons; //

Navigate(); //

}

 

private static void Add(string pszPath, ImageList imageList, uint uFlags)

{

SHFILEINFO SHInfo = new SHFILEINFO();

//

IntPtr hImg = SHGetFileInfo(pszPath, 0, ref SHInfo, (uint)Marshal.SizeOf(SHInfo), SHGFI_ICON | uFlags);

imageList.Images.Add(Icon.FromHandle(SHInfo.hIcon)); //

DestroyIcon(SHInfo.hIcon); //

}

 

public static void AddIconOfFile(string fileName, IconSize iconSize, bool selectedState, bool openState, bool linkOverlay, ImageList destinationImagelist)

{

// ,

uint uFlags = ((iconSize == IconSize.Large)? SHGFI_LARGEICON: 0) |

((iconSize == IconSize.Small)? SHGFI_SMALLICON: 0) |

((iconSize == IconSize.Shell)? SHGFI_SHELLICONSIZE: 0) |

((selectedState)? SHGFI_SELECTED: 0) |

((openState)? SHGFI_OPENICON: 0) |

((linkOverlay)? SHGFI_LINKOVERLAY: 0);

 

Add(fileName, destinationImagelist, uFlags); //

}

 

public void Navigate(string path)

{

szPath = path;

Navigate();

}

 

public void Navigate()

{

ReleaseNavigate();

}

 

private void ReleaseNavigate()

//

{

if (!DesignMode)

//

{

try

{

try

{

if (!Directory.Exists(szPath))

//

{

MessageBox.Show(" !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

return;

}

} //try

catch (UnauthorizedAccessException)

//

{

UpOnOneDirectory(); //

MessageBox.Show(" !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

return;

} //catch (UnauthorizedAccessException)

 

fileBrowser.BeginUpdate(); //

this.fileBrowser.Items.Clear(); //

if (fileIcons.Images.Count > 0) fileIcons.Images.Clear(); //

 

DirectoryInfo dInfo = new DirectoryInfo(szPath);

fileIcons.ColorDepth = ColorDepth.Depth32Bit;

fileIcons.ImageSize = new Size(32, 32);

 

foreach (DirectoryInfo di in dInfo.GetDirectories())

{

AddIconOfFile(di.FullName, IconSize.Large, false, false, false, fileIcons);

fileBrowser.Items.Add(di.Name, fileIcons.Images.Count - 1);

} //foreach (DirectoryInfo di in dInfo.GetDirectories())

 

foreach (FileInfo fi in dInfo.GetFiles())

{

AddIconOfFile(fi.FullName, IconSize.Large, false, false, false, fileIcons);

fileBrowser.Items.Add(fi.Name, fileIcons.Images.Count - 1);

} //foreach (FileInfo fi in dInfo.GetFiles())

 

} //try

finally

{

fileBrowser.EndUpdate();

curPathBox.Text = szPath;

}

} //if (!DesignMode)

}

 

private void DirectoryCopy(string pathSource, string pathTo)

{

if (pathSource == null || pathSource == String.Empty ||!Directory.Exists(pathSource))

throw new ArgumentException();

if (pathTo == null || pathTo == String.Empty)

throw new ArgumentException();

if (!Directory.Exists(Path.Combine(pathTo, Path.GetFileName(pathSource))))

Directory.CreateDirectory(Path.Combine(pathTo, Path.GetFileName(pathSource)));

foreach (FileInfo fi in (new DirectoryInfo(pathSource)).GetFiles())

fi.CopyTo(Path.Combine(pathTo, Path.GetFileName(pathSource)) + Path.DirectorySeparatorChar + fi.Name, true);

foreach (DirectoryInfo di in (new DirectoryInfo(pathSource)).GetDirectories())

DirectoryCopy(Path.Combine(pathSource, di.Name), Path.Combine(pathTo, Path.GetFileName(pathSource)));

} //private void DirectoryCopy(string pathSource, string pathTo)

 

public void UpOnOneDirectory()

{

Navigate(Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(szPath));

} //public void UpOnOneDirectory()

 

#region

 

void fileBrowser_DoubleClick(object sender, System.EventArgs e)

{

if (this.fileBrowser.SelectedItems == null || this.fileBrowser.SelectedItems.Count!= 1) return;

if (Directory.Exists(Path.Combine(szPath, this.fileBrowser.SelectedItems[0].Text)))

Navigate(Path.Combine(szPath, this.fileBrowser.SelectedItems[0].Text));

else

using (System.Diagnostics.Process proc = new System.Diagnostics.Process())

{

try

{

proc.StartInfo = new System.Diagnostics.ProcessStartInfo(Path.Combine(szPath, this.fileBrowser.SelectedItems[0].Text));

proc.Start();

} //try

catch (Win32Exception ex)

{

MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

} //catch (Win32Exception ex)

} //using (System.Diagnostics.Process proc = new System.Diagnostics.Process())

} //void fileBrowser_DoubleClick(object sender, System.EventArgs e)

 

private void fileBrowser_ItemDrag(object sender, ItemDragEventArgs e)

{

if (fileBrowser.SelectedItems == null || fileBrowser.SelectedItems.Count == 0) return;

string[] files = new string[fileBrowser.SelectedItems.Count];

for (int i = 0; i < fileBrowser.SelectedItems.Count; i++)

files[i] = Path.Combine(szPath, fileBrowser.SelectedItems[i].Text);

DataObject data = new DataObject();

data.SetData(DataFormats.FileDrop, true, files);

DoDragDrop(data, DragDropEffects.Copy);

} //private void fileBrowser_ItemDrag(object sender, ItemDragEventArgs e)

 

private void fileBrowser_DragEnter(object sender, DragEventArgs e)

{

if (e.Data.GetDataPresent(DataFormats.FileDrop))

e.Effect = DragDropEffects.All;

} //private void fileBrowser_DragEnter(object sender, DragEventArgs e)

 

private void fileBrowser_DragDrop(object sender, DragEventArgs e)

{

if (e.Data.GetDataPresent(DataFormats.FileDrop))

{

object obj = e.Data.GetData(DataFormats.FileDrop);

if (obj == null)

return;

if (!(obj is Array))

return;

foreach (object var in (Array)obj)

{

if (Directory.Exists(var.ToString()))

{

DirectoryCopy(var.ToString(), szPath);

}

else if (File.Exists(var.ToString()))

{

File.Copy(var.ToString(), Path.Combine(szPath, Path.GetFileName(var.ToString())));

}

}

Navigate();

}

}

 

private void fileBrowser_KeyUp(object sender, KeyEventArgs e)

{

if (e.KeyCode == Keys.Back) UpOnOneDirectory();

if (e.Control && e.KeyCode == Keys.C)

{

szPathToAction = Path.Combine(szPath, fileBrowser.SelectedItems[0].Text);

bActIsCopy = true;

} //if (e.Control && e.KeyCode == Keys.C)

if (e.Control && e.KeyCode == Keys.V && szPathToAction!= "")

{

if (bActIsCopy)

{

CManager.Copy(szPathToAction, szPath);

bActIsCopy = false;

} //if (bActIsCopy)

if (bActIsMove)

{

CManager.Move(szPathToAction, szPath);

bActIsMove = false;

szPathToAction = "";

} //if (bActIsMove)

Navigate();

} //if (e.Control && e.KeyCode == Keys.V && szPathToAction!= "")

if (e.KeyCode == Keys.Delete)

{

CManager.Delete(Path.Combine(szPath, fileBrowser.SelectedItems[0].Text));

Navigate();

} //if (e.KeyCode == Keys.Delete)

}

 

private void button1_Click(object sender, EventArgs e)

{

Navigate(curPathBox.Text);

}

 

private void upBtn_Click(object sender, EventArgs e)

{

UpOnOneDirectory();

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

szPathToAction = Path.Combine(szPath, fileBrowser.SelectedItems[0].Text);

bActIsCopy = true;

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

szPathToAction = Path.Combine(szPath, fileBrowser.SelectedItems[0].Text);

bActIsMove = true;

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

CManager.Delete(Path.Combine(szPath, fileBrowser.SelectedItems[0].Text));

Navigate();

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

createFolder.Visible = true;

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

createFile.Visible = true;

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

if (bActIsCopy)

{

CManager.Copy(szPathToAction, szPath);

bActIsCopy = false;

} //if (bActIsCopy)

if (bActIsMove)

{

CManager.Move(szPathToAction, szPath);

bActIsMove = false;

szPathToAction = "";

} //if (bActIsMove)

Navigate();

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

using (System.Diagnostics.Process proc = new System.Diagnostics.Process())

{

try

{

proc.StartInfo = new System.Diagnostics.ProcessStartInfo(@"DShell .htm");

proc.Start();

} //try

catch (Win32Exception ex)

{

MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

} //catch (Win32Exception ex)

} //using (System.Diagnostics.Process proc = new System.Diagnostics.Process())

}

#endregion

}

 

public static class CManager

{

public static void Copy(string sourcePath, string targetPath)

{

if (Path.HasExtension(sourcePath))

{

string targetFile = Path.Combine(targetPath, Path.GetFileName(sourcePath));

FileSystem.CopyFile(sourcePath, targetFile, UIOption.AllDialogs, UICancelOption.ThrowException);

return;

} //if (Path.HasExtension(targetFile))

FileSystem.CopyDirectory(sourcePath, targetPath, UIOption.AllDialogs, UICancelOption.ThrowException);

} //public static void Copy(string fileName, string destination)

 

public static void Move(string sourcePath, string targetPath)

{

if (Path.HasExtension(sourcePath))

{

string targetFile = Path.Combine(targetPath, Path.GetFileName(sourcePath));

FileSystem.MoveFile(sourcePath, targetFile, UIOption.AllDialogs, UICancelOption.ThrowException);

return;

} //if (Path.HasExtension(targetFile))

FileSystem.MoveDirectory(sourcePath, targetPath, UIOption.AllDialogs, UICancelOption.ThrowException);

} //public static void Move(string sourcePath, string targetPath)

 

public static void Delete(string path)

{

if (Path.HasExtension(path))

{

FileSystem.DeleteFile(path, UIOption.AllDialogs, RecycleOption.DeletePermanently);

return;

} //if (Path.HasExtension(targetFile))

FileSystem.DeleteDirectory(path, UIOption.AllDialogs, RecycleOption.DeletePermanently, UICancelOption.ThrowException);

} //public static void Delete(string sourcePath, string targetPath)

 

public static void Create(string path, string name)

{

string fullPath = Path.Combine(path, name);

if (Path.HasExtension(fullPath))

{

File.Create(fullPath);

return;

} //if (Path.HasExtension(targetFile))

Directory.CreateDirectory(fullPath);

} //public static void Create(string path)

} //class CManager

} // namespace end

 



<== | ==>
| : ., . 289
:


: 2016-10-27; !; : 725 |


:

:

: , , , , .
==> ...

1523 - | 1391 -


© 2015-2024 lektsii.org - -

: 0.097 .