public MainProgram() { tm = new TransmissionManager(); transmission = tm.DefaultTransmission; exeDirectory = Path.GetDirectoryName(Application.ExecutablePath); dataDirectory = Path.Combine(exeDirectory, "data"); canExit = false; isExiting = false; web = transmission.Crawler; if(!web.Internet()) { MessageBox.Show("Per usare questo programma devi essere connesso ad Internet.", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); return; } sw = new ExternalSoftware(transmission.MplayerEndsWithError); var appData = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData); configDirectory = Path.Combine(appData, "la_storia_in_giallo"); if (!Directory.Exists(configDirectory)) Directory.CreateDirectory(configDirectory); Text = "La storia in giallo"; Font = new Font("Tahoma", 8); StartPosition = FormStartPosition.CenterScreen; ClientSize = new Size(400, 600); Icon = new Icon(Path.Combine(dataDirectory, "icon.ico")); FormClosing += CheckClosing; // Top lbTrasmission = new Label(); lbTrasmission.Text = "Trasmissione"; Controls.Add(lbTrasmission); cbTrasmission = new ComboBox(); foreach (string t in tm.TransmissionNames) cbTrasmission.Items.Add(t); cbTrasmission.DropDownStyle = ComboBoxStyle.DropDownList; cbTrasmission.SelectedValueChanged += delegate { ChangeTransmission(); }; Controls.Add(cbTrasmission); lbSearch = new Label(); lbSearch.Text = "Cerca titolo"; Controls.Add(lbSearch); txSearch = new TextBox(); txSearch.TextChanged += delegate { SearchEpisode(); }; txSearchBackground = txSearch.BackColor; Controls.Add(txSearch); // Middle lsEpisodes = new ListBox(); Controls.Add(lsEpisodes); Resize += delegate { ResizeControls(); }; // Bottom btDownload = new Button(); btDownload.Text = "Scarica in formato MP3"; btDownload.Font = new Font("Times New Roman", 12, FontStyle.Bold | FontStyle.Italic); btDownload.Click += delegate { new Thread(new ThreadStart(DownloadEpisode)).Start(); }; Controls.Add(btDownload); // Bottom (continues...) lbDownload = new Label(); lbDownload.Text = "Scaricamento"; Controls.Add(lbDownload); pgDownload = new ProgressBar(); pgDownload.Style = ProgressBarStyle.Continuous; pgDownload.Minimum = 0; pgDownload.Maximum = 100; Controls.Add(pgDownload); lbConvert = new Label(); lbConvert.Text = "Conversione in MP3"; Controls.Add(lbConvert); pgConvert = new ProgressBar(); pgConvert.Style = ProgressBarStyle.Continuous; pgConvert.Minimum = 0; pgConvert.Maximum = 100; Controls.Add(pgConvert); ResizeControls(); EnableControls(true); // Initializes with the default radio program cbTrasmission.SelectedItem = "La Storia in Giallo"; }
private void ChangeTransmission() { var code = tm.TransmissionCode((string)cbTrasmission.SelectedItem); transmission = tm.Transmission(code); sw = new ExternalSoftware(transmission.MplayerEndsWithError); // Check if the episode list file is in place episodesFile = Path.Combine(configDirectory, "episodes-" + code + ".txt"); var exeDirectory = Path.GetDirectoryName(Application.ExecutablePath); var dataDirectory = Path.Combine(exeDirectory, "data"); if (!File.Exists(episodesFile)) { var originalEpisodesFile = Path.Combine(dataDirectory, "episodes-" + code + ".txt"); File.Copy(originalEpisodesFile, episodesFile); } db = new EpisodeDB(episodesFile); lsEpisodes.Items.Clear(); lsEpisodes.Items.AddRange(db.GetRange()); if (!updatedTrasmission.ContainsKey(code)) { updatedTrasmission[code] = transmission.IsOver; } if (!updatedTrasmission[code]) { new Thread(new ThreadStart(UpdateEpisodes)).Start(); } }