private void Download(object obj) { var file = obj as DownloadFile; file.DownloadStatus = DownloadStatus.Downloading; var webClient = new CustomWebClient(); webClient.Data = file; webClient.Clock = new Stopwatch(); webClient.DownloadProgressChanged += webClient_DownloadProgressChanged; webClient.DownloadFileCompleted += webClient_DownloadFileCompleted; webClient.Clock.Start(); webClient.DownloadFileAsync(new Uri(file.Uri), file.DownloadLocation = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), file.Filename)); }
private void Download(object obj, bool checkfile) { var file = obj as DownloadFile; string Folder = DownloadFolder; string Filename = file.Filename; if (Filename.Contains("?")) { Filename = Filename.Split('?').First(); } if (file.Protocol == "LIVE") { Filename = ""; } if (file.Folder != "") { Folder = DownloadFolder + "\\" + file.Folder; } int max = 50; if (Filename != "") { string name = Util.RemoveExtension(Filename); if (name.Length > max) { string ext = Util.GetExtension(Filename); Filename = name.Substring(0, max) + "." + ext; } } if (file.Title != "") { if(file.Title.Length > max) { Filename = file.Title.Substring(0,max) + "-" + Filename; } else { Filename = file.Title + "-" + Filename; } } //Folder = MakeValidFileName(Folder); if(file.Protocol == "LIVE") { Encoding sjis = Encoding.GetEncoding("shift-jis"); Encoding unicode = Encoding.Unicode; byte[] uniBytes = unicode.GetBytes(Filename); byte[] jisBytes = Encoding.Convert(unicode, sjis, uniBytes); Filename = sjis.GetString(jisBytes); } Filename = Util.MakeValidFileName(Filename); if (!Directory.Exists(Folder)) { try { Directory.CreateDirectory(Folder); } catch { if (checkfile == true) { MessageBox.Show("フォルダの作成に失敗しました。"); } file.DownloadStatus = DownloadStatus.Error; return; } } string location = string.Format("{0}\\{1}", Folder, Filename); if(File.Exists(location)) { if (checkfile == true) { if (MessageBox.Show("同名ファイルが存在します。削除してもよろしいですか?", "確認", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff file.DownloadStatus = DownloadStatus.FileExists; return; } else { try { File.Delete(location); } catch { MessageBox.Show("ファイルの削除に失敗しました。"); file.DownloadStatus = DownloadStatus.FileExists; return; } } } else { file.DownloadStatus = DownloadStatus.FileExists; return; } } if (file.Protocol == "LIVE") { Console.WriteLine(file.Uri); var recorder = new LiveDownloader(); recorder.LiveRecord(location, file); recorder.Show(); file.DownloadStatus = DownloadStatus.LiveDownloading; file.DownloadLocation = location; return; } if (file.Protocol == "ISM") { Console.WriteLine(file.Uri); var recorder = new ISMRecorder(); recorder.Record(location, file); recorder.Show(); file.DownloadStatus = DownloadStatus.SilverlightDownloading; file.DownloadLocation = location; return; } if (file.Protocol == "RTMP") { var data = file.Data; string parameter = String.Format("rtmpdump -r \"{0}{1}\" -t \"{0}\" -y \"{1}\" -o {2}", data.RTMP_T, data.RTMP_Y, location); var recorder = new RTMPRecorder(); recorder.Record(location, file, parameter); recorder.Show(); file.DownloadStatus = DownloadStatus.RTMPDownloading; file.DownloadLocation = location; return; } file.DownloadStatus = DownloadStatus.Downloading; file.CalculateFileSize(); var webClient = new CustomWebClient(); webClient.Data = file; webClient.Clock = new Stopwatch(); webClient.DownloadProgressChanged += webClient_DownloadProgressChanged; webClient.DownloadFileCompleted += webClient_DownloadFileCompleted; webClient.Clock.Start(); webClient.Moving = true; webClient.Timer = new System.Windows.Threading.DispatcherTimer(); webClient.Timer.Tag = webClient; webClient.Timer.Tick += Timer_Tick; webClient.Timer.Interval = new TimeSpan(0, 0, 10); webClient.Timer.Start(); webClient.DownloadFileAsync(new Uri(file.Uri), file.DownloadLocation = location); file.client = webClient; }
private void Download(object obj, bool checkfile) { var file = obj as DownloadFile; string Folder = DownloadFolder; string Filename = file.Filename; if (Filename.Contains("?")) { Filename = Filename.Split('?').First(); } if (file.Protocol == "LIVE") { Filename = ""; } if (file.Folder != "") { Folder = DownloadFolder + "\\" + file.Folder; } int max = 50; if (Filename != "") { string name = Util.RemoveExtension(Filename); if (name.Length > max) { string ext = Util.GetExtension(Filename); Filename = name.Substring(0, max) + "." + ext; } } if (file.Title != "") { if (file.Title.Length > max) { Filename = file.Title.Substring(0, max) + "-" + Filename; } else { Filename = file.Title + "-" + Filename; } } //Folder = MakeValidFileName(Folder); if (file.Protocol == "LIVE") { Encoding sjis = Encoding.GetEncoding("shift-jis"); Encoding unicode = Encoding.Unicode; byte[] uniBytes = unicode.GetBytes(Filename); byte[] jisBytes = Encoding.Convert(unicode, sjis, uniBytes); Filename = sjis.GetString(jisBytes); } Filename = Util.MakeValidFileName(Filename); if (!Directory.Exists(Folder)) { try { Directory.CreateDirectory(Folder); } catch { if (checkfile == true) { MessageBox.Show("フォルダの作成に失敗しました。"); } file.DownloadStatus = DownloadStatus.Error; return; } } string location = string.Format("{0}\\{1}", Folder, Filename); if (File.Exists(location)) { if (checkfile == true) { if (MessageBox.Show("同名ファイルが存在します。削除してもよろしいですか?", "確認", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff file.DownloadStatus = DownloadStatus.FileExists; return; } else { try { File.Delete(location); } catch { MessageBox.Show("ファイルの削除に失敗しました。"); file.DownloadStatus = DownloadStatus.FileExists; return; } } } else { file.DownloadStatus = DownloadStatus.FileExists; return; } } if (file.Protocol == "LIVE") { Console.WriteLine(file.Uri); var recorder = new LiveDownloader(); recorder.LiveRecord(location, file); recorder.Show(); file.DownloadStatus = DownloadStatus.LiveDownloading; file.DownloadLocation = location; return; } if (file.Protocol == "ISM") { Console.WriteLine(file.Uri); var recorder = new ISMRecorder(); recorder.Record(location, file); recorder.Show(); file.DownloadStatus = DownloadStatus.SilverlightDownloading; file.DownloadLocation = location; return; } if (file.Protocol == "RTMP") { var data = file.Data; string parameter = String.Format("rtmpdump -r \"{0}{1}\" -t \"{0}\" -y \"{1}\" -o {2}", data.RTMP_T, data.RTMP_Y, location); var recorder = new RTMPRecorder(); recorder.Record(location, file, parameter); recorder.Show(); file.DownloadStatus = DownloadStatus.RTMPDownloading; file.DownloadLocation = location; return; } file.DownloadStatus = DownloadStatus.Downloading; file.CalculateFileSize(); var webClient = new CustomWebClient(); webClient.Data = file; webClient.Clock = new Stopwatch(); webClient.DownloadProgressChanged += webClient_DownloadProgressChanged; webClient.DownloadFileCompleted += webClient_DownloadFileCompleted; webClient.Clock.Start(); webClient.Moving = true; webClient.Timer = new System.Windows.Threading.DispatcherTimer(); webClient.Timer.Tag = webClient; webClient.Timer.Tick += Timer_Tick; webClient.Timer.Interval = new TimeSpan(0, 0, 10); webClient.Timer.Start(); webClient.DownloadFileAsync(new Uri(file.Uri), file.DownloadLocation = location); file.client = webClient; }