Exemple #1
0
 protected virtual void OnBeginDownloadSourceFile(object sender, DownloadFileEventArgs args)
 {
 }
Exemple #2
0
 protected virtual void OnDownloadSourceFileAfterEulaAccepted(
     object sender, DownloadFileEventArgs args)
 {
 }
Exemple #3
0
        public bool DownloadWholeFiles(string targetPath)
        {
            List <SrcSrvDownloadAbleFile> pdbResults =
                RetrieveFileRelationsExtended(targetPath);

            List <SrcSrvDownloadAbleFile> .Enumerator tempEnum =
                pdbResults.GetEnumerator();

            int i = 1;

            while (tempEnum.MoveNext())
            {
                PDBWebClient tempClient = GetWebClientWithCookie();


                string directoryName = String.Empty;
                try
                {
                    if (UseSourceFilePath)
                    {
                        directoryName =
                            System.IO.Path.GetDirectoryName(tempEnum.Current.LocalFileTargetAlternative);
                    }
                    else
                    {
                        directoryName =
                            System.IO.Path.GetDirectoryName(tempEnum.Current.LocalFileTarget);
                    }
                    DirectoryInfo createdDirectory = null;
                    if (!System.IO.Directory.Exists(directoryName))
                    {
                        createdDirectory =
                            Directory.CreateDirectory(directoryName);
                    }
                    else
                    {
                        createdDirectory = new DirectoryInfo(directoryName);
                    }
                    //{{HDN==================================================
                    DownloadFileEventArgs args = new DownloadFileEventArgs();
                    args.TargetFilePath = UseSourceFilePath
                        ? tempEnum.Current.LocalFileTargetAlternative : tempEnum.Current.LocalFileTarget;
                    if (_skipExistingSourceFiles)
                    {
                        if (File.Exists(args.TargetFilePath) || Path.GetExtension(args.TargetFilePath) == ".h")
                        {
                            continue;
                        }
                    }

                    OnBeginDownloadSourceFile(this, args);

                    byte[] downloadedData = new byte[] {};
                    bool   downloadOk     = tempClient.DownloadDataWithProgress(
                        tempEnum.Current.UrlToBeRequested, out downloadedData);
                    if (!downloadOk)
                    {
                        createdDirectory.Delete(true);
                        continue;
                    }
                    //}}HDN==================================================

                    EulaRequestEvent eulaEventArg = null;

                    if (tempClient.IsEulaResponse)
                    {
                        eulaEventArg =
                            new EulaRequestEvent(new EulaContents(tempClient.EulaBody));

                        OnEulaAcceptRequested(eulaEventArg);

                        if (!eulaEventArg.EulaAccepted)
                        {
                            throw new EulaNotAcceptedException();
                        }
                        else
                        {
                            //{{HDN==================================================
                            OnDownloadSourceFileAfterEulaAccepted(this, args);

                            downloadOk = tempClient.DownloadDataWithProgress(
                                tempEnum.Current.UrlToBeRequested + "?" + eulaEventArg.EulaContent.AcceptCmdKey, out downloadedData);
                            if (!downloadOk)
                            {
                                continue;
                            }
                            //}}HDN==================================================
                        }
                    }

                    if (UseSourceFilePath)
                    {
                        System.IO.File.WriteAllBytes(tempEnum.Current.LocalFileTargetAlternative,
                                                     downloadedData);
                        if (tempClient.HasLastFileWriteTimeOnServer)
                        {
                            File.SetLastAccessTimeUtc(tempEnum.Current.LocalFileTargetAlternative, tempClient.LastFileWriteTimeOnServer);
                        }
                    }
                    else
                    {
                        System.IO.File.WriteAllBytes(tempEnum.Current.LocalFileTarget,
                                                     downloadedData);
                        if (tempClient.HasLastFileWriteTimeOnServer)
                        {
                            File.SetLastAccessTimeUtc(tempEnum.Current.LocalFileTarget, tempClient.LastFileWriteTimeOnServer);
                        }
                    }
                    OnSourceFileDownloaded(new SourceFileLoadEventArg((UseSourceFilePath?tempEnum.Current.LocalFileTargetAlternative:tempEnum.Current.LocalFileTarget), tempEnum.Current.UrlToBeRequested, i.ToString() + "/" + pdbResults.Count));
                }
                catch (Exception ex)
                {
                    if (ex is EulaNotAcceptedException)
                    {
                        throw;
                    }
                    OnSourceFileDownloaded(new SourceFileLoadEventArg((UseSourceFilePath ? tempEnum.Current.LocalFileTargetAlternative : tempEnum.Current.LocalFileTarget), tempEnum.Current.LocalFileTarget, i.ToString() + "/" + pdbResults.Count, ex));
                }
                i++;
            }
            return(true);
        }