예제 #1
0
//----------------------------------------------------------------------------------------------------------------------

        //Download meta file synchronously
        DCCPluginMeta GetOrDownloadDCCPluginMeta(string version)
        {
            DCCPluginMeta ret       = null;
            string        metaURL   = MeshSyncEditorConstants.DCC_PLUGINS_GITHUB_RELEASE_URL + version + "/meta.txt";
            string        localPath = Path.Combine(m_destFolder, "meta_" + version + ".txt");

            if (File.Exists(localPath))
            {
                ret = FileUtility.DeserializeFromJson <DCCPluginMeta>(localPath);
            }

            if (null != ret)
            {
                return(ret);
            }

            WebClient client = new WebClient();

            try {
                client.DownloadFile(new Uri(metaURL), localPath);
                ret = FileUtility.DeserializeFromJson <DCCPluginMeta>(localPath);
            }
            catch {
                Debug.LogWarning("[MeshSync] Meta info can't be downloaded from: " + metaURL);
                if (File.Exists(localPath))
                {
                    File.Delete(localPath);
                }
            }


            return(ret);
        }
예제 #2
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);
        }
예제 #3
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);
        }