Esempio n. 1
0
        private bool DownloadMTA(string downloadLink, string outFilePath)
        {
            BITS.BackgroundCopyManager1_5 mgr;
            try
            {
                mgr = new BITS.BackgroundCopyManager1_5();
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                installationPackage.HandleDownloadError("BackgroundCopyManager is not initialized - " + e.Message);
                return(false);
            }

            if (mgr == null)
            {
                installationPackage.HandleDownloadError("BackgroundCopyManager is not initialized");
                return(false);
            }

            try
            {
                // A single user can create a maximum of 60 jobs at one time...
                mgr.CreateJob("DotSetup Installer", BITS.BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, out _, out _job);
                SetJobProperties(_job);

                _downloadFileName = outFilePath;
                _job.AddFile(downloadLink, outFilePath);

                if (_job is BITS5.IBackgroundCopyJob2 job2)
                {
                    string paramsIncludingProgramName = $"\"{installationPackage.RunFileName}\" {installationPackage.RunParams}";
                    job2.SetNotifyCmdLine(installationPackage.RunFileName, paramsIncludingProgramName);
                }

                //Activating events for job.
                _job.SetNotifyFlags(
                    (uint)BitsNotifyFlags.JOB_TRANSFERRED
                    + (uint)BitsNotifyFlags.JOB_ERROR);
                _job.SetNotifyInterface(this);

                _job.Resume();  //starting the job
            }
            catch (Exception e)
            {
                installationPackage.HandleDownloadError(e.Message);
                CancelJob();
                return(false);
            }

            _aTimer.Start();

            return(true);
        }
Esempio n. 2
0
 //Usage params: url or ip:port, full path
 private void downloadFile(string name, string remoteLoc, string writeLoc)
 {
     mgr.CreateJob(name, BITS.BG_JOB_TYPE.BG_JOB_TYPE_DOWNLOAD, out jobGuid, out job);
     job.AddFile(remoteLoc, writeLoc);
     jo.executeBITSJob(); // normal BITS function
 }