Exemplo n.º 1
0
        private void DownloadAsync(DownloadInfo newInfo)
        {
            _Client = null;

            DownloadInfo downloadInfo = newInfo;

            string exePath = System.Windows.Forms.Application.StartupPath + "\\";

            if (localRoot != null)
            {
                exePath = localRoot;
            }

            string localPath = exePath + downloadInfo._filePath.Replace('/', '\\');

            if (File.Exists(localPath) == true)
            {
                try
                {
                    File.Delete(localPath);
                }
                catch (Exception)
                { }
            }

            string[] folders  = downloadInfo._filePath.Split('\\');
            string   fullPath = exePath;

            for (int i = 0; i < folders.Length - 1; i++)
            {
                if (folders[i] == "Update")
                {
                    folders[i] = "NewUpdate";
                }

                fullPath = string.Format("{0}\\{1}", fullPath, folders[i]);

                if (Directory.Exists(fullPath) == false)
                {
                    Directory.CreateDirectory(fullPath);
                }
            }

            _Client       = new WebClient();
            _Client.Proxy = null;

            _Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
            _Client.DownloadFileCompleted   += DownloadFileCompleted(localPath, downloadInfo);

            var url = "http://" + downloadInfo._strServerPath + downloadInfo._filePath.Replace("\\", "/");

            _Client.DownloadFileAsync(new Uri(url), localPath);

            return;
        }
Exemplo n.º 2
0
        public bool DownloadFile(string filePath, DownloadCompleteHandler completeHandler, string strServerPath)
        {
            DownloadInfo newInfo = new DownloadInfo();

            newInfo._filePath        = filePath;
            newInfo._completeHandler = completeHandler;
            newInfo._strServerPath   = strServerPath;

            DownloadAsync(newInfo);

            return(true);
        }
Exemplo n.º 3
0
        private AsyncCompletedEventHandler DownloadFileCompleted(string strFileName, DownloadInfo downloadInfo)
        {
            Action <object, AsyncCompletedEventArgs> action = (sender, e) =>
            {
                var _filename = strFileName;

                if (e.Error != null)
                {
                }

                if (downloadInfo._completeHandler != null)
                {
                    downloadInfo._completeHandler(strFileName);
                }
            };

            return(new AsyncCompletedEventHandler(action));
        }