Exemplo n.º 1
0
        protected override bool ProcessInternal()
        {
            try
            {
                DateTime fileTimeStamp = DateTime.MinValue;
                string filePath = string.Empty;
                string fileName = "~" + _descName + ".frtmp";
                _pendingDownloadFile = Path.Combine(_repositoryPath, fileName);

                using (WebFileRetriever downloader =
                    new WebFileRetriever(_ns, _downloadUrl, _pendingDownloadFile, false))
                {
                }

                string ext = PathUtils.GetExtension(_downloadUrl);

                if (!AreFilesIdentical(GetLatestFileInRepository(), _pendingDownloadFile))
                {
                    DateTime dt = DateTime.MinValue;
                    string newFileName = StringUtils.GetUniqueFileName(ref dt);
                    string newFilePath = Path.Combine(_repositoryPath, newFileName + ext);
                    File.Move(_pendingDownloadFile, newFilePath);

                    if (NewFileRetrieved != null)
                    {
                        NewFileRetrieved(newFilePath, true, string.Empty);
                    }
                }

                DeleteFile(_pendingDownloadFile);
                _pendingDownloadFile = string.Empty;
            }
            catch (ThreadAbortException)
            {
                if (!string.IsNullOrEmpty(_pendingDownloadFile) && File.Exists(_pendingDownloadFile))
                {
                    EventDispatch.DispatchEvent(EventNames.ShowMessageBox, "Download cancelled.", _descName, MessageBoxIcon.Warning);

                    _retriever.Dispose();
                    _retriever = null;

                    DeleteFile(_pendingDownloadFile);
                    _pendingDownloadFile = string.Empty;
                }

                return false;
            }
            catch (Exception ex)
            {
                ErrorDispatcher.DispatchError(ex);
            }

            // DownloadInterval is in seconds
            Thread.Sleep(_downloadInterval * 1000);

            return true;
        }
Exemplo n.º 2
0
        private void StartDownload()
        {
            string file = string.Format("{0} {1}.exe", Constants.SuiteName, _version);
            string fileUri = AppConfig.DownloadUriBase + "/" + file;
            string tempFile = Path.Combine(Path.GetTempPath(), file);

            Logger.LogInfo("Downloading update file from {0} ...", fileUri);

            _wfr = new WebFileRetriever(AppConfig.ProxySettings, fileUri, tempFile, true);
            _wfr.FileRetrieveComplete += new FileRetrieveCompleteEventHandler(OnDownloadComplete);
        }
        void OnBackgroundDetect(object sender, DoWorkEventArgs e)
        {
            string versionFile = "/Versions.txt";
            string versionFileUri = AppConfig.DownloadUriBase + versionFile;
            string tempVersionFile = Path.GetTempFileName();
            bool detectOnDemand = (bool)e.Argument;

            WebFileRetriever retriever = null;

            try
            {
                retriever = new WebFileRetriever(AppConfig.ProxySettings, versionFileUri, tempVersionFile, false);
                StringBuilder sb = new StringBuilder();

                if (Kernel32.GetPrivateProfileString(Constants.SuiteName, "Version", "1.0.0.0", sb, 255, tempVersionFile) > 0)
                {
                    Version current = new Version(SuiteVersion.Version);
                    Version available = new Version(sb.ToString());

                    if (available.CompareTo(current) > 0)
                    {
                        Logger.LogInfo("Current version: {0}, available on server: {1}. Update is required.",
                            current, available);

                        EventDispatch.DispatchEvent(EventNames.NewVersionAvailable, sb.ToString());
                    }
                    else
                    {
                        Logger.LogInfo("Current version: {0}, available on server: {1}. Update is NOT required.",
                           current, available);

                        if (detectOnDemand)
                        {
                            MainThread.Post(delegate(object x)
                            {
                                MessageDisplay.Show("TXT_NOUPDATEREQUIRED", "TXT_APP_NAME", MessageBoxIcon.Information);
                            });
                        }
                    }
                }

            }
            finally
            {
                if (retriever != null)
                    retriever.Dispose();
            }
        }
Exemplo n.º 4
0
        protected override string DoDownloadSubtitle(string fileName, SubtitleInfo subtitle)
        {
            string destPath = Path.ChangeExtension(fileName, subtitle.SubFormat);
            string downloadPath = Path.ChangeExtension(fileName, "gz");

            bool downloaded = false;
            using (WebFileRetriever wfr = new WebFileRetriever(AppConfig.ProxySettings,
                subtitle.SubDownloadLink, downloadPath, false))
            {
                downloaded = true;
            }

            if (downloaded)
            {
                using (FileStream compressedSubtitle = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read))
                {
                    using (GZipStream str = new GZipStream(compressedSubtitle, CompressionMode.Decompress, false))
                    {
                        using (FileStream outputSubtitle = new FileStream(destPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            byte[] buffer = new byte[65536];
                            int read = 0;
                            do
                            {
                                read = str.Read(buffer, 0, buffer.Length);
                                if (read > 0)
                                {
                                    outputSubtitle.Write(buffer, 0, read);
                                }
                            }
                            while (read > 0);
                        }
                    }
                }

                File.Delete(downloadPath);

                return destPath;
            }

            return string.Empty;
        }
Exemplo n.º 5
0
 private void AbortDownload()
 {
     if (_wfr != null)
     {
         _wfr.Dispose();
         _wfr = null;
     }
 }