/// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> static void Main() { try { Application.Run(new MainForm()); // 終了時処理 try { PodcasCoSpecificProcess.ExitDisable(); } catch (IOException) { MessageBox.Show("設定ファイルが書き込めませんでした", "設定ファイル書き込みエラー"); } } catch (Exception ex) { // ログに例外情報を書き込む Log exceptionLog = new Log(AssemblyUtility.GetExecutablePath() + @"\" + PodcasCoInfo.ExceptionLogFile); StringBuilder error = new StringBuilder(); error.Append("Application: " + PodcasCoInfo.ApplicationName + " " + PodcasCoInfo.VersionNumber + "\r\n"); error.Append("Date: " + System.DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\r\n"); error.Append("OS: " + Environment.OSVersion.ToString() + "\r\n"); error.Append("Culture: " + System.Globalization.CultureInfo.CurrentCulture.Name + "\r\n"); error.Append("Exception class: " + ex.GetType().ToString() + "\r\n"); error.Append("ToString: " + ex.ToString() + "\r\n"); error.Append("Exception message: " + "\r\n"); error.Append(ex.Message); Exception innnerEx = ex.InnerException; while (innnerEx != null) { error.Append(innnerEx.Message); error.Append("\r\n"); innnerEx = innnerEx.InnerException; } error.Append("\r\n"); error.Append("\r\n"); exceptionLog.LogThis(error.ToString(), Log.LogPrefix.date); #if DEBUG // デバッガで例外内容を確認するため、例外をアプリケーションの外に出す throw ex; #else Trace.Assert(false, "予期しないエラーが発生したため、終了します"); #endif } }
private void MainForm_Load(object sender, EventArgs e) { try { // 起動時のチェック PodcasCoSpecificProcess.StartUpCheck(); } catch (DllNotFoundException ex) { MessageBox.Show(ex.Message); Application.Exit(); return; } try { // 起動時の初期化 PodcasCoSpecificProcess.StartUpInitialize(); StationList.StationListChanged += new EventHandler(StationList_StationListChanged); AddStationFilterComboBoxItem(); // 起動直後には放送局切り替えボックスで"All"を選択する stationFilterComboBox.SelectedIndex = 0; // 放送局リストがある場合 if (StationList.GetStationList().Length > 0) { // ローカルヘッドラインのみの番組表をチェックする CheckHeadlines(CheckHeadlinesOption.LocalOnly); } } catch (XmlException) { MessageBox.Show("設定ファイルが読み込めませんでした", "設定ファイルの解析エラー"); } catch (IOException) { MessageBox.Show("設定ファイルが読み込めませんでした", "設定ファイルの読み込みエラー"); } catch (ArgumentNullException) { MessageBox.Show("設定ファイルが読み込めませんでした", "設定ファイルの読み込みエラー"); } StationList.HeadlineFetching += new FetchEventHandler(StationList_HeadlineFetching); StationList.HeadlineAnalyzing += new HeadlineAnalyzeEventHandler(StationList_HeadlineAnalyzing); #region 起動時自動ダウンロード // クリップする番組の数をカウントする int clipCount = 0; foreach (Station station in StationList.GetStationList()) { // 現在の放送局を設定する StationList.ChangeCurrentStation(station); // 指定の個数の番組を自動ダウンロードし、指定の日数より古い番組を自動削除する if (station.StartupDownload == true && station.StartupDelete == true) { // 指定の個数の番組を自動ダウンロードする if (station.StartupDownloadNum > 0) { // グローバルヘッドラインを取得する station.GlobalHeadline.FetchHeadline(); // グローバル・ローカルの両方の番組 IChannel[] channels = StationList.GetChannelsOfCurrentStationFromAllHeadline(); // 日付で降順ソートする Array.Sort(channels, 0, channels.Length, (IComparer) new ChannelDateComparer()); Array.Reverse(channels, 0, channels.Length); // これより古い日付のものはダウンロードしない DateTime undownloadDate = DateTime.Today.Subtract(new TimeSpan(station.StartupDeleteRemainDay - 1, 0, 0, 0)); for (int i = 0; i < station.StartupDownloadNum && i < channels.Length; ++i) { if (station.ContainLocalHeadline(channels[i]) == false && channels[i].GetDate() > undownloadDate) { // チェックを立てる channels[i].Check = true; ++clipCount; } } } } else if (station.StartupDownload == true && station.StartupDelete == false) { // 指定の個数の番組を自動ダウンロードする if (station.StartupDownloadNum > 0) { // グローバルヘッドラインを取得する station.GlobalHeadline.FetchHeadline(); // グローバル・ローカルの両方の番組 IChannel[] channels = StationList.GetChannelsOfCurrentStationFromAllHeadline(); // 日付で降順ソートする Array.Sort(channels, 0, channels.Length, (IComparer) new ChannelDateComparer()); Array.Reverse(channels, 0, channels.Length); for (int i = 0; i < station.StartupDownloadNum && i < channels.Length; ++i) { if (station.ContainLocalHeadline(channels[i]) == false) { // チェックを立てる channels[i].Check = true; ++clipCount; } } } } } // 現在の放送局を全放送局に戻す StationList.ChangeCurrentStationAt(-1); // ダウンロードする番組が存在する場合 if (clipCount > 0) { // チェックのある番組をダウンロードする ClipPodcast(); } #endregion // 起動時自動ダウンロード #region 起動時自動削除 // クリップする番組の数をカウントする int deleteCount = 0; foreach (Station station in StationList.GetStationList()) { // 指定の日数より古い番組を自動削除する if (station.StartupDelete == true) { // これより古い日付のものは削除する DateTime deleteDate = DateTime.Today.Subtract(new TimeSpan(station.StartupDeleteRemainDay - 1, 0, 0, 0)); foreach (IChannel channel in station.LocalHeadline.GetChannels()) { if (channel.GetDate() <= deleteDate) { channel.Check = true; ++deleteCount; } } } } // 削除する番組が存在する場合 if (deleteCount > 0) { // チェックのある番組を削除する DeletePodcast(); } #endregion // 起動時自動削除 // 番組リストを更新する UpdateChannelList(); SetAnchorControl(); FixWindowSize(); }