/********************************************************************************************* * Copyright 2004 - Volian Enterprises, Inc. All rights reserved. * Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE * ------------------------------------------------------------------------------ * $Workfile: Archive.cs $ $Revision: 3 $ * $Author: Kathy $ $Date: 1/31/05 11:05a $ * * $History: Archive.cs $ * * ***************** Version 3 ***************** * User: Kathy Date: 1/31/05 Time: 11:05a * Updated in $/LibSource/VEObject * Fix B2005-005 - this just fixed empty icon usage * * ***************** Version 2 ***************** * User: Kathy Date: 1/24/05 Time: 2:45p * Updated in $/LibSource/VEObject * B2005-004 fixes - icon clean-up * * ***************** Version 1 ***************** * User: Kathy Date: 7/27/04 Time: 8:52a * Created in $/LibSource/VEObject *********************************************************************************************/ using System; using System.Windows.Forms; using System.Windows.Forms.Design; using System.ComponentModel; using System.IO; using System.Text; using Utils; using System.Collections.Specialized; namespace VEObject { /// /// Archive Object. /// public class VEO_Archive: VEO_Base { public bool isnew; // These three strings are stored in the Zip file's // comment field private String tmpArchiveTitle; private String _Comment; public ArchiveTypeOptions _ArchiveType; private String tmpComment; private bool _ReadOnly; private bool oldReadOnly; private bool NeedToGetReadOnly; private bool changeReadOnly; private bool changeComment; private bool changeArchiveTitle; public VEO_Archive(string ipath, VEO_DummyZip dz) { iconStates = new int[5] {0,0,0,0,0}; _Location = ipath; // full path to the Zip file VEObjectType = (int)VEObjectTypesDefs.Archive; changeReadOnly = false; changeComment = false; changeArchiveTitle = false; NeedToGetReadOnly = true; isnew = IsThisANewArchive(ipath); if (isnew) { _Title = "New Archive"; _Comment = "Created: " + System.DateTime.Now.ToString(); } else // get the title and comment from the Zip file { GetInfoFromZipComment(); } LoadLockInfo(); icon = iconStates[(int)Lock.LockStatus]; parentObj = dz; usrRunTime = dz.usrRunTime; } // Read in the Title, Archive Type, and Comment from the Zip file's // comment field. private void GetInfoFromZipComment() { string tmpstr; ZipFuncs ZipInfo = new ZipFuncs(_Location); // just opening the zip file like this will read the zip's comment field if (ZipInfo.strArcTitle != null) tmpstr = ZipInfo.strArcTitle.Trim(); else tmpstr = ""; // if the title is blank, then use the zip file name as the title if (tmpstr.Length == 0) this._Title = _Location.Substring(_Location.LastIndexOf("\\")+1); else this._Title = tmpstr; _Comment = ZipInfo.strComment; if (ZipInfo.ArchiveType == (int)VEO_Base.ArchiveTypeOptions.Full) _ArchiveType = VEO_Base.ArchiveTypeOptions.Full; else _ArchiveType = VEO_Base.ArchiveTypeOptions.Partial; } private bool IsThisANewArchive(string arcPath) { string tmpstr = arcPath.ToUpper(); return (!tmpstr.EndsWith(".ZIP") || !File.Exists(tmpstr)); } private string ParseOutZipPath() { string zpath = _Location.Substring(0,_Location.LastIndexOf("\\")); return zpath; } // Gets and Sets for the Property Page [Description("Location"),Category("Archive"),ReadOnly(true)] public string Location { get{return _Location;} //note: we don't allow them to change the zip file name or path. } [Description("Archive Title"),Category("Archive")]public string Description { get { if (!changeArchiveTitle) return _Title; else return tmpArchiveTitle; } set { changeArchiveTitle = true; tmpArchiveTitle = value; } } [Description("Archive Type"),Category("Archive"),ReadOnly(true)]public ArchiveTypeOptions ArchiveType { get { return _ArchiveType; } set { _ArchiveType=value; } } [Description("Comment"),Category("Archive")]public string Comment { get { if (!changeComment) return _Comment; else return tmpComment; } set { changeComment = true; tmpComment = value; } } [Description("ReadOnly"),Category("Archive")]public bool ReadOnlyArchiveFile { get { if (!changeReadOnly && NeedToGetReadOnly) { FileAttributes attrib = File.GetAttributes(_Location); _ReadOnly = (attrib & FileAttributes.ReadOnly) == FileAttributes.ReadOnly; NeedToGetReadOnly = false; } return _ReadOnly; } set { if (!changeReadOnly) // only save previous value once oldReadOnly = _ReadOnly; changeReadOnly = true; _ReadOnly = value; } } // When the Save Button is pressed on the Property page, this function // is called. public override bool Write() { if (changeReadOnly) { changeReadOnly = false; NeedToGetReadOnly = true; FileAttributes attrib = File.GetAttributes(_Location); if (_ReadOnly != ((attrib & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)) attrib ^= FileAttributes.ReadOnly; //toggle File.SetAttributes(_Location,attrib); } if (changeComment) { changeComment = false; _Comment = tmpComment; } if (changeArchiveTitle) { changeArchiveTitle = false; _Title = tmpArchiveTitle; } return true; } // When the Cancel Button on the Property Page is pressed, // this function is called. public override void CancelWrite() { if (changeReadOnly) { _ReadOnly = oldReadOnly; } changeArchiveTitle = false; changeComment = false; changeReadOnly = false; NeedToGetReadOnly = true; } public override bool Read(bool dummy) { //load archive file list return true; } public override void AddToTree(TreeNode parentnd) { } public override bool Expand(TreeNode parentnd) { return true; } public override bool PropertiesDlg(Object parent) { ARProperties propdlg = new ARProperties(parent, this); if (propdlg.ShowDialog() == DialogResult.OK) return true; return false; } public bool Exists(string dname) { if(dname==null||dname=="") return false; string archname=null; // see if this is a pathname, it needs to be for the Exists check. if (dname.IndexOf("\\") < 0) // it's not a path, prepend the path archname = _Location + "\\" + dname; else archname = dname; return File.Exists(archname); } public override bool mnuAllowNew() { return false; } public override bool mnuAllowDelete() { // VEO_DummyArchive ds = (VEO_DummyArchive) this.parentObj; // VEO_ProcSet ps = (VEO_ProcSet) ds.parentObj; // if (ps.isApproved == true) return false; // if (amILockedByMe()==false) return false; // if ((ps.accessFlags&Security.DOCMAINT)==Security.DOCMAINT) return true; return true; } public override bool mnuAllowUpdateArch() { if (amILockedByMe()==false) return false; return true; } public override bool mnuAllowExtractArch() { if (amILockedByMe()==false) return false; return true; } public override bool mnuAllowTestArchive() { return true; } public override void DoListView(ListView veoListView) { ZipFuncs ZipInfo = new ZipFuncs(_Location); ListViewItem item=null; veoListView.Columns.Add("Date/Time", 150, HorizontalAlignment.Left); veoListView.Columns.Add("File", 450, HorizontalAlignment.Left); StringCollection ZipFileList; // veoListView.Sorting = SortOrder.Ascending; ZipFileList = ZipInfo.ZipFileContents(); for (int i=0; i< ZipFileList.Count; i++) { string tmpstr = ZipFileList[i].ToString(); int subIdx = tmpstr.IndexOf('!'); item = new ListViewItem(tmpstr.Substring(0,subIdx)); item.SubItems.Add(tmpstr.Substring(subIdx+1)); item.Tag = this; veoListView.Items.Add(item); } AllowListViewSort = true; } public override bool Delete() { if ((File.GetAttributes(_Location) & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly) File.SetAttributes(_Location,System.IO.FileAttributes.Normal); File.Delete(_Location); // if this is the last zip, then change parent's icon to empty VEO_DummyZip zip = (VEO_DummyZip) this.parentObj; if (zip.Children.Count==1) zip.IsEmpty=true; // just this one. return true; } } // This class is used when creating a new archive public class VEO_ArchiveN: VEO_Archive { public VEO_ArchiveN(string ipath, VEO_DummyZip dz) : base(ipath, dz) { } [Description("Location"),Category("Archive"),ReadOnly(false),EditorAttribute(typeof(PropSaveFileAsDlg), typeof(System.Drawing.Design.UITypeEditor))] public new string Location { get{return _Location;} set { _Location=value.ToString(); } } [Description("Archive Type"),Category("Archive"),ReadOnly(false)]public new ArchiveTypeOptions ArchiveType { get { return _ArchiveType; } set { _ArchiveType=value; } } } /* * Setup a class that will display the SaveFileAs dialog from the property dialog * when the "..." is pressed. */ public class PropSaveFileAsDlg : System.Drawing.Design.UITypeEditor { public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) { return System.Drawing.Design.UITypeEditorEditStyle.Modal; } public override object EditValue( System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.AddExtension = true; saveFileDialog1.CheckPathExists = true; saveFileDialog1.DefaultExt = ".zip"; saveFileDialog1.Filter = "ZIP Files|*.zip|All Files|*.*||"; saveFileDialog1.DereferenceLinks = true; saveFileDialog1.OverwritePrompt = true; saveFileDialog1.Title = "Archive Location and Name"; saveFileDialog1.FileName = value.ToString(); saveFileDialog1.ShowDialog(); return saveFileDialog1.FileName; } public override bool GetPaintValueSupported( System.ComponentModel.ITypeDescriptorContext context) { return false; } } }