示例#1
0
//----------------------------------------------------------------------------------------------------------------------
        DCCPluginDownloadInfo FindNextPluginToDownload(DCCPluginMeta meta, string version)
        {
            DCCPluginDownloadInfo ret = null;

            while (m_dccPlatformNames.Count > 0 && null == ret)
            {
                DCCPluginDownloadInfo downloadInfo = new DCCPluginDownloadInfo(version,
                                                                               m_dccPlatformNames.Peek(), m_destFolder);
                if (null != meta && File.Exists(downloadInfo.LocalFilePath))
                {
                    //Check MD5
                    string             md5       = FileUtility.ComputeFileMD5(downloadInfo.LocalFilePath);
                    DCCPluginSignature signature = meta.GetSignature(Path.GetFileName(downloadInfo.LocalFilePath));
                    if (signature.MD5 != md5)
                    {
                        ret = downloadInfo;
                    }
                    else
                    {
                        //The same file has been downloaded. Skip.
                        m_dccPlatformNames.Dequeue();
                        m_finishedDCCPluginLocalPaths.Add(downloadInfo.LocalFilePath);
                    }
                }
                else
                {
                    ret = downloadInfo;
                }
            }

            return(ret);
        }
示例#2
0
//-------------------------------------------------1---------------------------------------------------------------------

        void DownloadDCCPlugins(string version, Action onComplete, Action onFail)
        {
            Directory.CreateDirectory(m_destFolder);
            WebClient client            = new WebClient();
            int       initialQueueCount = m_dccPlatformNames.Count;

            //meta can be null when we failed to download it
            DCCPluginMeta meta = GetOrDownloadDCCPluginMeta(version);

            //Prepare WebClient
            client.DownloadFileCompleted += (object sender, AsyncCompletedEventArgs e) => {
                DCCPluginDownloadInfo lastInfo = new DCCPluginDownloadInfo(version, m_dccPlatformNames.Peek(), m_destFolder);
                if (e.Error != null)
                {
                    if (File.Exists(lastInfo.LocalFilePath))
                    {
                        File.Delete(lastInfo.LocalFilePath);
                    }

                    //Try downloading using the latest known version to work.
                    if (version != LATEST_KNOWN_VERSION)
                    {
                        DownloadDCCPlugins(LATEST_KNOWN_VERSION, onComplete, onFail);
                    }
                    else
                    {
                        onFail();
                    }
                    return;
                }

                //Remove the finished one from queue
                m_dccPlatformNames.Dequeue();
                m_finishedDCCPluginLocalPaths.Add(lastInfo.LocalFilePath);


                DCCPluginDownloadInfo nextInfo = FindNextPluginToDownload(meta, version);
                if (null == nextInfo)
                {
                    onComplete();
                }
                else
                {
                    //Download the next one
                    client.DownloadFileAsync(new Uri(nextInfo.URL), nextInfo.LocalFilePath);
                }
            };

            client.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
            {
                float inverseNumPlugins = 1.0f / initialQueueCount;
                int   curIndex          = initialQueueCount - m_dccPlatformNames.Count;
                float curFileProgress   = (curIndex) * inverseNumPlugins;
                float nextFileProgress  = (curIndex + 1) * inverseNumPlugins;

                float progress = curFileProgress + (e.ProgressPercentage * 0.01f * (nextFileProgress - curFileProgress));
                if (DisplayCancelableProgressBar("Downloading MeshSync DCC Plugins", m_dccPlatformNames.Peek(), progress))
                {
                    client.CancelAsync();
                }
            };


            DCCPluginDownloadInfo downloadInfo = FindNextPluginToDownload(meta, version);

            if (null == downloadInfo)
            {
                onComplete();
                return;
            }

            //Execute downloading
            DisplayProgressBar("Downloading MeshSync DCC Plugins", m_dccPlatformNames.Peek(), 0);
            client.DownloadFileAsync(new Uri(downloadInfo.URL), downloadInfo.LocalFilePath);
        }