home *** CD-ROM | disk | FTP | other *** search
- /*
- * Xceed Zip for .NET - UsingExtendingDemo Sample Application
- * Copyright (c) 2000-2002 - Xceed Software Inc.
- *
- * [Main.cs]
- *
- * This application demonstrates how to use the IsolatedFile and IsolatedFolder
- * class of the EntendingDemo sample application. Both of these classes
- * demonstrate how to derive from the AbstractFolder and AbstractFile classes.
- * *
- * This file is part of Xceed Zip for .NET. The source code in this file
- * is only intended as a supplement to the documentation, and is provided
- * "as is", without warranty of any kind, either expressed or implied.
- */
-
- using System;
- using System.IO;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using Xceed.FileSystem;
- using Xceed.FileSystem.Samples.ExtendingDemo;
-
- namespace UsingExtendingDemo
- {
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Button btCopy;
- private System.Windows.Forms.Button btMove;
- private System.Windows.Forms.Button btDelete;
- private System.Windows.Forms.ImageList images;
- private System.Windows.Forms.ListView listIsolated;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox txtInput;
- private System.Windows.Forms.Button btCreate;
- private System.Windows.Forms.TextBox txtCreate;
- private System.Windows.Forms.Label label2;
- private System.ComponentModel.IContainer components;
-
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
-
- }
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
- this.btCopy = new System.Windows.Forms.Button();
- this.btMove = new System.Windows.Forms.Button();
- this.btDelete = new System.Windows.Forms.Button();
- this.images = new System.Windows.Forms.ImageList(this.components);
- this.listIsolated = new System.Windows.Forms.ListView();
- this.label1 = new System.Windows.Forms.Label();
- this.txtInput = new System.Windows.Forms.TextBox();
- this.btCreate = new System.Windows.Forms.Button();
- this.txtCreate = new System.Windows.Forms.TextBox();
- this.label2 = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // btCopy
- //
- this.btCopy.Location = new System.Drawing.Point(8, 8);
- this.btCopy.Name = "btCopy";
- this.btCopy.TabIndex = 5;
- this.btCopy.Text = "Copy";
- this.btCopy.Click += new System.EventHandler(this.btCopy_Click);
- //
- // btMove
- //
- this.btMove.Location = new System.Drawing.Point(88, 8);
- this.btMove.Name = "btMove";
- this.btMove.TabIndex = 6;
- this.btMove.Text = "Move";
- this.btMove.Click += new System.EventHandler(this.btMove_Click);
- //
- // btDelete
- //
- this.btDelete.Location = new System.Drawing.Point(168, 8);
- this.btDelete.Name = "btDelete";
- this.btDelete.TabIndex = 8;
- this.btDelete.Text = "Delete";
- this.btDelete.Click += new System.EventHandler(this.btDelete_Click);
- //
- // images
- //
- this.images.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- this.images.ImageSize = new System.Drawing.Size(16, 16);
- this.images.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("images.ImageStream")));
- this.images.TransparentColor = System.Drawing.Color.White;
- //
- // listIsolated
- //
- this.listIsolated.FullRowSelect = true;
- this.listIsolated.Location = new System.Drawing.Point(8, 80);
- this.listIsolated.MultiSelect = false;
- this.listIsolated.Name = "listIsolated";
- this.listIsolated.Size = new System.Drawing.Size(312, 152);
- this.listIsolated.SmallImageList = this.images;
- this.listIsolated.TabIndex = 14;
- this.listIsolated.View = System.Windows.Forms.View.List;
- this.listIsolated.DoubleClick += new System.EventHandler(this.listIsolated_DoubleClick);
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(8, 40);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(100, 16);
- this.label1.TabIndex = 16;
- this.label1.Text = "Destination folder :";
- //
- // txtInput
- //
- this.txtInput.Location = new System.Drawing.Point(8, 56);
- this.txtInput.Name = "txtInput";
- this.txtInput.Size = new System.Drawing.Size(312, 20);
- this.txtInput.TabIndex = 17;
- this.txtInput.Text = "D:\\dump";
- //
- // btCreate
- //
- this.btCreate.Location = new System.Drawing.Point(248, 256);
- this.btCreate.Name = "btCreate";
- this.btCreate.TabIndex = 18;
- this.btCreate.Text = "Create";
- this.btCreate.Click += new System.EventHandler(this.btCreate_Click);
- //
- // txtCreate
- //
- this.txtCreate.Location = new System.Drawing.Point(8, 256);
- this.txtCreate.Name = "txtCreate";
- this.txtCreate.Size = new System.Drawing.Size(232, 20);
- this.txtCreate.TabIndex = 19;
- this.txtCreate.Text = "test.txt";
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(8, 240);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(160, 16);
- this.label2.TabIndex = 20;
- this.label2.Text = "File or folder name to create:";
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(328, 285);
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.label2,
- this.txtCreate,
- this.btCreate,
- this.txtInput,
- this.label1,
- this.listIsolated,
- this.btDelete,
- this.btMove,
- this.btCopy});
- this.Name = "Form1";
- this.Text = "UsingExtendingDemo sample application";
- this.Load += new System.EventHandler(this.Form1_Load);
- this.ResumeLayout(false);
-
- }
- #endregion
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
-
- /// <summary>
- /// Load the form and call the <see cref="FillList"/> method to
- /// initialize the contents of the listview.
- /// </summary>
- private void Form1_Load(object sender, System.EventArgs e)
- {
- FillList( @"\" );
- }
-
- /// <summary>
- /// Fill the listview control with the items of the folder.
- /// </summary>
- /// <param name="folderName">The fullname and path of the folder whose contents will
- /// be listed.</param>
- private void FillList( string folderName )
- {
- listIsolated.Items.Clear();
- IsolatedFolder folder = new IsolatedFolder( folderName );
-
- listIsolated.Items.Add( @".", 1 );
-
- foreach( FileSystemItem item in folder.GetItems( false ) )
- {
- if( item is IsolatedFolder )
- {
- listIsolated.Items.Add( item.Name, 1 ); // Folder
- }
- else
- {
- listIsolated.Items.Add( item.Name, 0 ); //File
- }
- }
-
- m_currentFolder = folder.FullName;
- }
-
- /// <summary>
- /// Copy the file or folder (and it's content) to the destination disk folder.
- /// </summary>
- private void btCopy_Click(object sender, System.EventArgs e)
- {
- DiskFolder destFolder = new DiskFolder( txtInput.Text );
-
- // Check the ImageIndex of the list item to see if we are dealing with a
- // file or a folder.
- if( listIsolated.FocusedItem.ImageIndex == 0 ) // File
- {
- IsolatedFile file = new IsolatedFile( m_currentFolder + listIsolated.FocusedItem.Text );
- file.CopyTo( destFolder, true );
- }
- else // Folder
- {
- IsolatedFolder folder = new IsolatedFolder( m_currentFolder + listIsolated.FocusedItem.Text );
- folder.CopyTo( destFolder, true );
- }
- }
-
- /// <summary>
- /// Move the file or folder (and it's content) to the destination disk folder.
- /// </summary>
- private void btMove_Click(object sender, System.EventArgs e)
- {
- DiskFolder destFolder = new DiskFolder( txtInput.Text );
-
- // Check the ImageIndex of the list item to see if we are dealing with a
- // file or a folder.
- if( listIsolated.FocusedItem.ImageIndex == 0 ) // File
- {
- IsolatedFile file = new IsolatedFile( m_currentFolder + listIsolated.FocusedItem.Text );
- file.MoveTo( destFolder, true );
- }
- else // Folder
- {
- IsolatedFolder folder = new IsolatedFolder( m_currentFolder + listIsolated.FocusedItem.Text );
- folder.MoveTo( destFolder, true );
- }
-
- // Refresh our list view control.
- FillList( m_currentFolder );
- }
-
- /// <summary>
- /// Delete the selected item in the list view control
- /// </summary>
- private void btDelete_Click(object sender, System.EventArgs e)
- {
- // Check the ImageIndex of the list item to see if we are dealing with a
- // file or a folder.
- if( listIsolated.FocusedItem.ImageIndex == 0 ) // File
- {
- IsolatedFile file = new IsolatedFile( m_currentFolder + listIsolated.FocusedItem.Text );
- file.Delete();
- }
- else // Folder
- {
- if( listIsolated.FocusedItem.Text != @"." )
- {
- IsolatedFolder folder = new IsolatedFolder( m_currentFolder + listIsolated.FocusedItem.Text );
-
- if( !folder.IsRoot )
- {
- folder.Delete();
- }
- }
- }
- // Refresh our list view control.
- FillList( m_currentFolder );
- }
-
- /// <summary>
- /// Create the new item.
- /// </summary>
- private void btCreate_Click(object sender, System.EventArgs e)
- {
- // If the filename includes ans extension, we will create a file.
- if( Path.HasExtension( txtCreate.Text ) )
- {
- IsolatedFile file = new IsolatedFile( m_currentFolder + txtCreate.Text );
-
- if( !file.Exists )
- {
- file.Create();
- }
- }
- else // If the filename does not have an extension, we will create a folder.
- {
- IsolatedFolder folder = new IsolatedFolder( m_currentFolder + txtCreate.Text );
-
- if( !folder.Exists )
- {
- folder.Create();
- }
- }
-
- // Refresh our list view control.
- FillList( m_currentFolder );
- }
-
- /// <summary>
- /// Change the current location when clicking on an item in the list.
- /// </summary>
- private void listIsolated_DoubleClick(object sender, System.EventArgs e)
- {
- // We will only change folders if the ImageIndex indicates that the
- // selected items is a folder.
- if( listIsolated.FocusedItem.ImageIndex == 1 )
- {
- // If we are at the root level, we cannot go up a level. Therefore
- // we verify to make sure that the folder is not a root folder
- // before attempting to fill the list.
- IsolatedFolder folder = new IsolatedFolder( m_currentFolder );
-
- // If the selected item is "." and is not a root folder, we
- // go to the parent folder and list the contents.
- if( listIsolated.FocusedItem.Text == @"." && !folder.IsRoot )
- {
- FillList( Path.GetDirectoryName( m_currentFolder.Remove( m_currentFolder.Length -1, 1 ) ) );
- }
- else // Go to the selected subfolder and list the contents.
- {
- FillList( m_currentFolder + listIsolated.FocusedItem.Text );
- }
- }
- }
-
- // Contains the path and name of the current folder.
- private string m_currentFolder;
- }
- }
-
-