コード例 #1
0
ファイル: WebDownloader.cs プロジェクト: toowind/BBMessenger
        private void DownloadAsync(DownloadInfo newInfo)
        {
            _Client = null;

            DownloadInfo downloadInfo = newInfo;

            //string exePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string exePath   = System.Windows.Forms.Application.StartupPath;
            string localPath = exePath + "\\" + downloadInfo._filePath.Replace('/', '\\');

            if (File.Exists(localPath) == true)
            {
                if (downloadInfo._completeHandler != null)
                {
                    downloadInfo._completeHandler(localPath);
                }

                return;
            }

            string[] folderNames = localPath.Split('\\');
            string   folderPath  = string.Empty;

            fileName = folderNames[folderNames.Length - 1];
            for (int i = 0; i < folderNames.Length - 1; i++)
            {
                folderPath += folderNames[i];

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

                folderPath += '\\';
            }

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

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

            var url = Login._ServerPath + downloadInfo._filePath;

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

            //_ProgressBarWindow.Show();
            //_ProgressBarWindow.Left = downloadInfo._window.Left + downloadInfo._window.Width / 2;
            //_ProgressBarWindow.Top = downloadInfo._window.Top + downloadInfo._window.Height / 2;

            return;

            //_ProgressBarWindow.Hide();
        }
コード例 #2
0
ファイル: WebDownloader.cs プロジェクト: toowind/BBMessenger
        public bool DownloadFile(string filePath, DownloadCompleteHandler completeHandler, Control control)
        {
            DownloadInfo newInfo = new DownloadInfo();

            newInfo._filePath        = filePath;
            newInfo._completeHandler = completeHandler;
            newInfo._window          = Window.GetWindow(control);

            //newInfo._window.Closed += new EventHandler(_window_Closed);
            DownloadAsync(newInfo);

            return(true);
        }
コード例 #3
0
ファイル: WebDownloader.cs プロジェクト: toowind/BBMessenger
        private AsyncCompletedEventHandler DownloadFileCompleted(string strFileName, DownloadInfo downloadInfo)
        {
            Action <object, AsyncCompletedEventArgs> action = (sender, e) =>
            {
                var _filename = strFileName;

                if (e.Error != null)
                {
                    //throw e.Error;
                }

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

            return(new AsyncCompletedEventHandler(action));
        }