示例#1
0
 protected virtual void OnAfterNewFile(PatchFile file)
 {
     if (afterNewFile != null)
     {
         AfterFileDownloadedEventArgs e = new AfterFileDownloadedEventArgs();
         e.file = file;
         afterNewFile(this, e);
     }
 }
示例#2
0
        public void startDownload()
        {
            if (Progress != null)
            {
                client.DownloadProgressChanged += Progress;
            }
            if (Completed != null)
            {
                client.DownloadFileCompleted += Completed;
            }

            if (client.BaseAddress.Length == 0)
            {
                throw new Exception("BaseAddress missing in the WebClient Object");
            }

            int       index = 0;
            PatchFile f     = files[index];

            setCurrentIndex(index + 1);
            OnNewFile(f);
            setCurrentFile(f);
            string path         = Path.Combine(f.BasePath, f.Name);
            string downloadPath = basePath + path;

            if (f.BasePath != String.Empty)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            client.DownloadFileAsync(new Uri(new Uri(client.BaseAddress), downloadPath), path);
            void onFileDownloaded(object se, AsyncCompletedEventArgs es)
            {
                if (files.Count > index + 1)
                {
                    index = index + 1;
                    f     = files[index];
                    OnAfterNewFile(f);
                    setCurrentIndex(index + 1);
                    OnNewFile(f);
                    path         = Path.Combine(f.BasePath, f.Name);
                    downloadPath = basePath + path;
                    if (f.BasePath != String.Empty)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(path));
                    }
                    client.DownloadFileAsync(new Uri(new Uri(client.BaseAddress), downloadPath), path);
                }
                else
                {
                    client.DownloadFileCompleted -= onFileDownloaded;
                    OnAllFileDownloaded();
                }
            }

            client.DownloadFileCompleted += onFileDownloaded;
        }
示例#3
0
 protected virtual void OnNewFile(PatchFile file)
 {
     if (newFile != null)
     {
         NewFileDownloadingEventArgs args = new NewFileDownloadingEventArgs();
         args.file           = file;
         args.remainingFiles = getCurrentIndex();
         newFile(this, args);
     }
 }
        public bool IsFileUpToDate(PatchFile file)
        {
            var path = Path.Combine(file.BasePath, file.Name);

            if (!File.Exists(path))
            {
                return(false);
            }

            using (var stream = File.OpenRead(path))
            {
                var md5 = BitConverter.ToString(MD5.Create().ComputeHash(stream)).Replace("-", "");
                return(md5 == file.MD5);
            }
        }
        public List <PatchFile> extract()
        {
            List <PatchFile> files = new List <PatchFile>();

            string[] lines = source.Split('\n');
            foreach (string l in lines)
            {
                if (l.Length > 0)
                {
                    PatchFile file = new PatchFile(Path.GetFileName(l).Trim(), Path.GetDirectoryName(l).Trim(), null, 0);
                    file.Name     = Path.GetFileName(l).Trim();
                    file.BasePath = Path.GetDirectoryName(l).Trim();
                    files.Add(file);
                }
            }

            return(files);
        }
示例#6
0
 protected void setCurrentFile(PatchFile file)
 {
     currentFile = file;
 }