Click here to Skip to main content
12,297,215 members (64,501 online)
Click here to Skip to main content

Stats

1.3M views
94.8K downloads
1.2K bookmarked
Posted

MyDownloader: A Multi-thread C# Segmented Download Manager

, 12 Feb 2008 CPOL
Sample application that manages multiple segmented downloads and supports HTTP, FTP and YouTube video downloads
ffmpeg.exe
ICSharpCode.SharpZipLib.dll
MyDownloader.App.exe
MyDownloader.Core.dll
MyDownloader.Extension.dll
MyDownloader.Spider.dll
pthreadGC2.dll
TabStrip.dll
TabStrip.dll
ICSharpCode.SharpZipLib.dll
Interop.SHDocVw.dll
MyDownloader.App
Controls
BlockedProgressBar.bmp
MyDownloader.App.csproj.user
Properties
SingleInstancing
UI
About.rtf
MyDownloader.Core
Common
Concurrency
Extensions
Instrumentation
MyDownloader.Core.csproj.user
Properties
UI
MyDownloader.Extension
AntiVirus
UI
AutoDownloads
UI
MyDownloader.Extension.csproj.user
Notifications
Helpers
UI
PersistedList
Properties
Protocols
UI
SpeedLimit
UI
Video
Impl
Logos
BreakVideoDownloader.png
GoogleVideoDownloader.png
MetaCafeVideoDownloader.png
PutfileVideoDownloader.PNG
YouTubeDownloader.png
UI
WindowsIntegration
ClipboardMonitor
Zip
MyDownloader.IEPlugin
BandObjectLib
MyDownloader.IEPlugin.csproj.user
MyDownloader.IEPlugin.snk
Properties
MyDownloader.Spider
Parsers
Html
Properties
UI
Web
Rules
MyDownloader.Tests
Extension
Video
MyDownloader.Tests.csproj.user
Properties
using System;
using System.Collections.Generic;
using System.Text;
using MyDownloader.Core;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;

namespace MyDownloader.Extension.Zip
{
    public class ZipProtocolProvider: IProtocolProvider
    {
        private const string ZipEntryNameProperty = "ZipEntryNameProperty";

        #region Helper Methods

        public static void SetZipEntryNameProperty(Downloader downloader, string entryName)
        {
            downloader.ExtendedProperties[ZipEntryNameProperty] = entryName;
        }

        public static string GetZipEntryNameProperty(Downloader downloader)
        {
            return downloader.ExtendedProperties[ZipEntryNameProperty] as string;
        } 

        #endregion

        private Downloader downloader;
        private ZipRemoteFile remoteZipFile;
        private ZipEntry entry;

        #region IProtocolProvider Members

        public void Initialize(Downloader downloader)
        {
            this.downloader = downloader;
        }

        public Stream CreateStream(ResourceLocation rl, long initialPosition, long endPosition)
        {
            /*
             * a chamada desse metodo nao sera apos o GetFileInfo se o download for resumeable 
             * sendo assim, preciso ter algum repositorio comum para guardas os "remoteZipFile"
             * assim evita-se de ficar carregando as entries a cada segmento/arquivo.
             * 
             * outro, pronto, apos o uso do segmento, deve-se liberar o remoteZipFile se n�o houver
             * nenhum outro download vinculado a este "remoteZipFile"
             */
            return remoteZipFile.GetInputStream(entry);
        }

        public RemoteFileInfo GetFileInfo(ResourceLocation rl, out System.IO.Stream stream)
        {
            stream = null;

            remoteZipFile = new ZipRemoteFile(rl);
            remoteZipFile.Load();

            string entryName = GetZipEntryNameProperty(this.downloader);

            entry = remoteZipFile[entryName];

            RemoteFileInfo result = new RemoteFileInfo();
            result.AcceptRanges = false;  // TODO make resumeable
            result.FileSize = entry.Size;
            result.LastModified = entry.DateTime;
            result.MimeType = "application/zip";

            return result;
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Guilherme Labigalini
Web Developer
Brazil Brazil
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160525.2 | Last Updated 13 Feb 2008
Article Copyright 2007 by Guilherme Labigalini
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid