Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

ZipTrack

4.86/5 (28 votes)
2 Dec 2009CPOL5 min read 61.6K   783  
A comprehensive way to manage all of your downloaded zip files.

ZipTrack - Main Screen

Introduction

Over the years, I've collected quite a few code and program examples. The problem is that sometimes I may remember I have an example of how to do something, but I can not find it. This program is designed to scan my downloaded zip files and parse the documents inside, then insert the content information into a database that can further be used to provide RegEx search on.

To that end, it provides me with a sort of Zip library. As such, I can add bookmarks concerning each zip file that take me back to the original article for the zip archive.

Version 1.0

Technologies and design approaches demonstrated

  • SQL Express 2008 Datasource
  • Custom framework Datalayer
  • Strongly typed Dataset
  • ICSharpCode.SharpZipLib
  • ICSharpCode.TextEditor
  • Creational / Factory / Proxy / Singleton - Design Patterns
  • Customized User Controls
  • Custom GUI designers
  • Owner drawn controls

Requirements

Here is a step-by-step process for what you're going to need to do:

  1. Make sure you have SQL Server 2008 [^] installed on your machine.
  2. Ensure that you have the following DLL: ICSharpCode.SharpZipLib and ICSharpCode.TextEditor, from SharpDevelop [^] (included with the article download).
  3. Create the database on your own instance of SQL Server. The script can be found in the "...\Data\Create.dbArchive.sql" directory included with the solution.
  4. Change the ConnectionString property in the InitializeClass method of the Host class.
  5. Run the program. The sample website is included in the new database you created in the previous step.
  6. If you want to add one zip file at a time, click the "New archive" button.
  7. If you want to add several zip archives all at once, then click on the "Open" button located in the toolbar.
  8. Choose the website you want to associate with the file(s) that will be imported, and click the "Accept" button.
  9. Once this action is complete, click "Cancel" to close the form.
  10. By choosing the appropriate website from the [Website View], you should see the zip files that were found.
  11. You may choose to add one or more bookmarks after you have at least one zip file in [Zip File View].
  12. Once you select a Zip file on the left, its contents will be displayed in [Zip File Contents View] on the right.
  13. Select an ASCII text based file in [Zip File Contents View] and the file's contents will display in [File Content View].

ZipTrack - Main Screen

Definitions

Let's begin by defining the domain specific language used by this utility program:

  1. Archive - An Archive represents a Zip file (e.g., HelloWorld.zip).
  2. Bookmark - A Bookmark is an Internet shortcut stored in the database that links back to the original, or supporting web page article(s), and can be retrieved.
  3. Document - A Document is *any* content that is found inside a zip archive file (i.e., *.cs, *.txt, *.doc, *.dll, *.exe, *.vb, etc...).
  4. Website - Websites are used extensively by this program to associate each downloaded archive to an origination source.

Usage

uml

Typically, the scenario is that most users will already have multiple files that have been previously downloaded on to the desktop PC. What we want to do is create a library of those files for easy lookup at a future date. Thus, the need for ZipTrack to organize and manage those files.

Categories

Often times, I am led to several places across the internet that offer various tips / tricks / solutions. I needed a way to categorize what I found and where. The best way that I have found to accomplish this was to put all files into separate directories named for the website I download from (e.g., CodeProject, etc...).

Website Categories

Grouping

If you are like me, you have files that date back for more than just a couple of days, maybe even years. Using code found on the internet for listbox grouping, we can group our archives by date, much similar to the way that Microsoft Outlook groups email.

Archive Grouping

Searching

Probably the most beneficial part of this program is the ability to search within the zip archive(s) without having to unzip each file to examine its contents.

Archive Grouping

Datalayer architecture

The script file is included for you to re-create the database for your own SQL Server instance. The data layer consists of common inheritable objects that facilitate data retrieval and storage. The data layer consists of the following objects in no particular order:

  • Models - These objects provide a base class for any derived business class. The Business Object class inherits from the base class to share common functionality and properties.
  • Business Object - A business object that encapsulates all of the data and business behavior associated with the data table that it represents.
  • Manager Class - This Manager class is useful for easy access to the data store. All data is captured and supplied in this centralized repository. It serves as a creational design pattern to create and retrieve concrete business objects.
  • DataHandler - The DataHandler class provides a consistent interface to data available in many different sources and formats. It manages simple data requests, conversions, and related operations using DataRequestEventHandlers. It provides access to commands that can operate on the data.

Base model example

VB
Namespace Common
    Public MustInherit Class Model

        Public MustOverride Property Name() As String

        Public MustOverride ReadOnly Property PrimaryID() As Integer

    End Class
End Namespace

Points of interest

One of the things that I found quite interesting during this project was when I needed a way to drag-n-drop shortcuts onto my form to help produce bookmarks. However, I needed a way to implement the GetData function for an Internet shortcut:

Drag-n-drop

VB
Private Sub BookmarksGrid1_DragDrop(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
    If e.Data.GetDataPresent("UniformResourceLocator", False) Then

        Dim data As Object = e.Data.GetData("UniformResourceLocator")

        Dim ms As MemoryStream = TryCast(data, MemoryStream)
        Dim bytes() As Byte = ms.ToArray()
        Dim encod As Encoding = Encoding.ASCII
        Dim LnkText As String = encod.GetString(bytes)

        Me.CreateNew(LnkText)

    ElseIf e.Data.GetDataPresent("FileNameW", False) Then

        '------------------------------------------------
        'You can drag and drop items from the desktop or Explorer onto the DataGridView
        '------------------------------------------------

        'Dim names As System.Array = _
        '     CType(e.Data.GetData("FileNameW", False), System.Array)
        'Dim LnkText As String = ResolveShellLink(CStr(names.GetValue(0)))

        'Me.CreateNew(LnkText)

    End If
End Sub

ResolveShellLink

During my search, I also ran across a way to retrieve link information for desktop shortcuts to files. You can now drag and drop items from the desktop or Explorer onto the DataGridView. Note that you'll get an array of file names since you can select multiple files and drop them; I just utilize the first item. To use this functionality, 'Add Reference' to c:\windows\system32\shell32.dll.

VB
Private Function ResolveShellLink(ByVal name As String) As String
    ' --- Find the target for a short-cut
    If String.Compare(Path.GetExtension(name), ".lnk", True) <> 0 Then Return name
    Dim shl As New Shell32.Shell
    Dim dir As Shell32.Folder = shl.NameSpace(Path.GetDirectoryName(name))
    Dim itm As Shell32.FolderItem = dir.Items().Item(Path.GetFileName(name))
    Dim lnk As Shell32.ShellLinkObject = CType(itm.GetLink, Shell32.ShellLinkObject)
    Return lnk.Path
End Function

Todo

Although not implemented here, I think that I might implement the file shortcut method in the future. Also perhaps implement a way to add new websites to the database. Happy coding!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)