public Settings() { InitializeComponent(); textBoxVLCPath.Text = SSettings.GetVlcFile(); textBoxDownload.Text = SSettings.getDownloadFolder(); textBoxChacheLocation.Text = SSettings.getCacheFolder(); }
public void DownloadVideo(YouTubeVideo video, string VideoURL) { // TODO if a file like this already exists warn the user of the duplicated download // don't waste his localFileLocation = SSettings.getDownloadFolder() + @"\" + $"[{video.Resolution}]" + video.FullName; bool download = true; if (File.Exists(localFileLocation)) { const string message = "This video has been already downloaded \n Do you want to re-Download it again ? "; const string caption = "Redownload ?"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { download = false; } } if (download) { try { tempDownloadFile = SSettings.getCacheFolder() + $"[{video.Resolution}]" + video.FullName; if (File.Exists(tempDownloadFile)) { try { File.Delete(tempDownloadFile); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR "); Dispose(); } } webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFinished); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); webClient.DownloadFileAsync(new Uri(video.Uri), tempDownloadFile); startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); labRemoteLink.Text = VideoURL; labLocalFile.Text = $"[{video.Resolution}]" + video.FullName; Text = "Downloading " + $"[{video.Resolution}]" + video.FullName; } catch (Exception ex) { MessageBox.Show(ex.Message, "Network Error"); } } else { webClient.Dispose(); Dispose(); } }
static void Main() { SSettings.getCurrentLocation(); SSettings.loadSettings(); Directory.CreateDirectory(SSettings.getDownloadFolder()); Directory.CreateDirectory(SSettings.getCacheFolder()); foreach (var str in Directory.GetFiles(SSettings.getCacheFolder())) { try { File.Delete(str); } catch (Exception e) { Console.WriteLine(e.Message); } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); }