Exemplo n.º 1
0
        public override bool Download( UpdaterFileProgress progress, UpdaterFileSave save, UpdaterFileComplete complete )
        {
            this.progress = progress;
            this.save = save;
            this.complete = complete;

            WebClient download = new WebClient();

            download.DownloadProgressChanged += new DownloadProgressChangedEventHandler( download_Progress );
            download.DownloadDataCompleted += new DownloadDataCompletedEventHandler( download_Complete );

            download.Headers[HttpRequestHeader.UserAgent] = "FOUpdater/" + FOUpdaterClient.VersionString;

            try
            {
                download.BaseAddress = this.URL;
                download.DownloadDataAsync( new Uri( ((UpdateInfoHTTP)this.Parent).RootAddress + this.FileName ), this.FileName );
            }
            catch
            {
                return (false);
            }

            while( download.IsBusy )
            {
                if( this.Parent.Parent.Cancelled )
                {
                    download.CancelAsync();
                }
                Thread.Sleep( 100 );
            }

            // should be enough to make sure that UpdaterFileComplete callback finished
            Thread.Sleep( 500 );

            return (true);
        }
Exemplo n.º 2
0
        public override bool Download( UpdaterFileProgress progress, UpdaterFileSave save, UpdaterFileComplete complete )
        {
            UpdateInfoStream parent = (UpdateInfoStream)this.Parent;

            parent.Send( "Get\n" );
            parent.Send( this.FileName.Replace( '/', '\\' ) + "\n" );
            string catch_ = parent.ReadLine(); // Catch/Catchpack

            uint size = parent.ReadUint();

            if( this.Parent.InfoVersion == 1 || this.Size == 0 )
                this.Parent.Parent.SendProgress( FOUpdaterProgress.FileMaximum, size );

            byte[] data = new byte[size];

            long lastPercent = 0;
            long readed = 0;
            while( readed != size )
            {
                if( this.Parent.Parent.Cancelled )
                    return (false);

                if( parent.Client == null || !parent.Client.Connected )
                    return (false);

                int input = parent.Client.GetStream().ReadByte();
                if( input == -1 )
                    continue;

                data[readed++] = (byte)input;
                long percent = (readed * 100) / size;
                if( percent > lastPercent )
                {
                    progress( this, readed, (long)size, (uint)percent );
                    lastPercent = percent;
                    Thread.Sleep( 50 );
                }
            }

            if( catch_ == "Catchpack" || this.Packed )
            {
                byte[] saveData = ZlibStream.UncompressBuffer( data );
                data = saveData;
            }

            save( this );
            File.WriteAllBytes( this.FileName, data );

            complete( this );
            return (true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Downloads file from update source.
 /// <para>NOTE: Must be overriden by subclass.</para>
 /// </summary>
 /// <param name="progress">function called when progress percentage changes</param>
 /// <param name="save">function called before file is saved</param>
 /// <param name="complete">function called when download is finished</param>
 public virtual bool Download( UpdaterFileProgress progress, UpdaterFileSave save, UpdaterFileComplete complete )
 {
     throw new NotImplementedException( "FOUpdateFile(" + Enum.GetName( typeof( FOUpdateType ), this.Type ) + ")::Download" );
 }