Exemple #1
0
        private void OnDownloadFailure(object sender, DownloadFailureEventArgs e)
        {
            VersionListProcessorComponent versionListProcessor = e.UserData as VersionListProcessorComponent;

            if (versionListProcessor == null || versionListProcessor != this)
            {
                return;
            }

            if (File.Exists(e.DownloadPath))
            {
                File.Delete(e.DownloadPath);
            }

            if (VersionListUpdateFailure != null)
            {
                VersionListUpdateFailure(e.DownloadUri, e.ErrorMessage);
            }
        }
Exemple #2
0
        private void OnDownloadSuccess(object sender, DownloadSuccessEventArgs e)
        {
            VersionListProcessorComponent versionListProcessor = e.UserData as VersionListProcessorComponent;

            if (versionListProcessor == null || versionListProcessor != this)
            {
                return;
            }

            using (FileStream fileStream = new FileStream(e.DownloadPath, FileMode.Open, FileAccess.ReadWrite))
            {
                int length = (int)fileStream.Length;
                if (length != m_VersionListZipLength)
                {
                    fileStream.Close();
                    string errorMessage = Utility.Text.Format("Latest version list zip length error, need '{0}', downloaded '{1}'.", m_VersionListZipLength.ToString(), length.ToString());
                    DownloadFailureEventArgs downloadFailureEventArgs = DownloadFailureEventArgs.Create(e.SerialId, e.DownloadPath, e.DownloadUri, errorMessage, e.UserData);
                    OnDownloadFailure(this, downloadFailureEventArgs);
                    ReferencePool.Release(downloadFailureEventArgs);
                    return;
                }

                fileStream.Position = 0L;
                int hashCode = Utility.Verifier.GetCrc32(fileStream);
                if (hashCode != m_VersionListZipHashCode)
                {
                    fileStream.Close();
                    string errorMessage = Utility.Text.Format("Latest version list zip hash code error, need '{0}', downloaded '{1}'.", m_VersionListZipHashCode.ToString(), hashCode.ToString());
                    DownloadFailureEventArgs downloadFailureEventArgs = DownloadFailureEventArgs.Create(e.SerialId, e.DownloadPath, e.DownloadUri, errorMessage, e.UserData);
                    OnDownloadFailure(this, downloadFailureEventArgs);
                    ReferencePool.Release(downloadFailureEventArgs);
                    return;
                }

                if (m_ResourceManager.DecompressCachedStream == null)
                {
                    m_ResourceManager.DecompressCachedStream = new MemoryStream();
                }

                try
                {
                    fileStream.Position = 0L;
                    m_ResourceManager.DecompressCachedStream.Position = 0L;
                    m_ResourceManager.DecompressCachedStream.SetLength(0L);
                    if (!Utility.Zip.Decompress(fileStream, m_ResourceManager.DecompressCachedStream))
                    {
                        fileStream.Close();
                        string errorMessage = Utility.Text.Format("Unable to decompress latest version list '{0}'.", e.DownloadPath);
                        DownloadFailureEventArgs downloadFailureEventArgs = DownloadFailureEventArgs.Create(e.SerialId, e.DownloadPath, e.DownloadUri, errorMessage, e.UserData);
                        OnDownloadFailure(this, downloadFailureEventArgs);
                        ReferencePool.Release(downloadFailureEventArgs);
                        return;
                    }

                    if (m_ResourceManager.DecompressCachedStream.Length != m_VersionListLength)
                    {
                        fileStream.Close();
                        string errorMessage = Utility.Text.Format("Latest version list length error, need '{0}', downloaded '{1}'.", m_VersionListLength.ToString(), m_ResourceManager.DecompressCachedStream.Length.ToString());
                        DownloadFailureEventArgs downloadFailureEventArgs = DownloadFailureEventArgs.Create(e.SerialId, e.DownloadPath, e.DownloadUri, errorMessage, e.UserData);
                        OnDownloadFailure(this, downloadFailureEventArgs);
                        ReferencePool.Release(downloadFailureEventArgs);
                        return;
                    }

                    fileStream.Position = 0L;
                    fileStream.SetLength(0L);
                    fileStream.Write(m_ResourceManager.DecompressCachedStream.GetBuffer(), 0, (int)m_ResourceManager.DecompressCachedStream.Length);
                }
                catch (Exception exception)
                {
                    fileStream.Close();
                    string errorMessage = Utility.Text.Format("Unable to decompress latest version list '{0}' with error message '{1}'.", e.DownloadPath, exception.ToString());
                    DownloadFailureEventArgs downloadFailureEventArgs = DownloadFailureEventArgs.Create(e.SerialId, e.DownloadPath, e.DownloadUri, errorMessage, e.UserData);
                    OnDownloadFailure(this, downloadFailureEventArgs);
                    ReferencePool.Release(downloadFailureEventArgs);
                    return;
                }
                finally
                {
                    m_ResourceManager.DecompressCachedStream.Position = 0L;
                    m_ResourceManager.DecompressCachedStream.SetLength(0L);
                }
            }

            if (VersionListUpdateSuccess != null)
            {
                VersionListUpdateSuccess(e.DownloadPath, e.DownloadUri);
            }
        }