//UIからクラスに代入する Core.ApplicationSetting.SettingClass PutSettingToClass() { Core.ApplicationSetting.SettingClass set = new Core.ApplicationSetting.SettingClass(); set.TweetText = TextBoxTweetText.Text; set.EnableAutoPost = CheckBoxEnableAutoPost.Checked; set.EnablePostWait = CheckBoxEnablePostWait.Checked; set.EnableCheckAlbum = CheckBoxEnableCheckAlbum.Checked; set.EnableCheckTime = CheckBoxCheckTime.Checked; set.PostAlbumArtWork = checkBoxPostAlbumArtWork.Checked; set.CheckUpdate = CheckUpdate.Checked; set.NotifyUpdate = NotifyUpdate.Checked; set.WaitSecond = (int)numericUpDownWaitSecond.Value; set.WaitSecond2 = (int)numericUpDownWaitSecond2.Value; set.DeleteText140 = CheckBoxDeleteText140.Checked; set.ExitWithiTunes = CheckBoxExitWithiTunes.Checked; set.NoAlbumArtworkOnSameAlbum = checkBoxSameAlbumNoArtwork.Checked; foreach (ListViewItem item in AccountList.Items) { Core.ApplicationSetting.AccountClass account = new Core.ApplicationSetting.AccountClass(); account.AccountName = item.Text; account.Token = item.SubItems[1].Text; account.TokenSecret = item.SubItems[2].Text; account.Enabled = item.Checked; set.AccountList.Add(account); } return(set); }
//クラスからUIに設定を復元する void PutSettingToUI(Core.ApplicationSetting.SettingClass set) { TextBoxTweetText.Text = set.TweetText; CheckBoxEnableAutoPost.Checked = set.EnableAutoPost; CheckBoxEnablePostWait.Checked = set.EnablePostWait; CheckBoxEnableCheckAlbum.Checked = set.EnableCheckAlbum; CheckBoxCheckTime.Checked = set.EnableCheckTime; checkBoxPostAlbumArtWork.Checked = set.PostAlbumArtWork; CheckUpdate.Checked = set.CheckUpdate; CheckBoxDeleteText140.Checked = set.DeleteText140; CheckBoxExitWithiTunes.Checked = set.ExitWithiTunes; NotifyUpdate.Checked = set.NotifyUpdate; numericUpDownWaitSecond.Value = set.WaitSecond; numericUpDownWaitSecond2.Value = set.WaitSecond2; checkBoxSameAlbumNoArtwork.Checked = set.NoAlbumArtworkOnSameAlbum; foreach (Core.ApplicationSetting.AccountClass account in set.AccountList) { ListViewItem item = AccountList.Items.Add(account.AccountName); item.SubItems.Add(account.Token); item.SubItems.Add(account.TokenSecret); item.Checked = account.Enabled; } if (CheckBoxEnableAutoPost.Checked == true) { AutoPostONOFFToolStripMenuItem.Text = "自動投稿を無効にする"; } else { AutoPostONOFFToolStripMenuItem.Text = "自動投稿を有効にする"; } }
void CloseAndSave() { //フォームが閉じるときに設定を保存する try { //設定を取得 Core.ApplicationSetting.SettingClass set = PutSettingToClass(); //設定を代入 initiTunes(set); //クラスをシリアライズ String XmlPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\setting.xml"; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Core.ApplicationSetting.SettingClass)); System.IO.FileStream fs = new System.IO.FileStream(XmlPath, System.IO.FileMode.Create); serializer.Serialize(fs, set); fs.Close(); } catch (Exception ex) { Debug.Write(ex.ToString()); } }
void initiTunes(Core.ApplicationSetting.SettingClass set) { //iTunesと連携する if (itunes == null && songmanage == null) { itunes = new iTunes.LinkToiTunes(); songmanage = new Core.SongManagement(itunes); } //イベントハンドラを登録 songmanage.OnSongChangedEvent -= songmanage_OnSongChangedEvent; songmanage.OnSongChangedEvent += songmanage_OnSongChangedEvent; itunes.OniTunesStartExit -= itunes_OniTunesStartExit; itunes.OniTunesStartExit += itunes_OniTunesStartExit; //イベント発生条件を登録 songmanage.EventSetting.EnableAutoPost = set.EnableAutoPost; songmanage.EventSetting.CheckIsAlbumChanged = set.EnableCheckAlbum; songmanage.EventSetting.CheckIsTimeElapsedFromLastTweet = set.EnableCheckTime; songmanage.EventSetting.EnableLateTweet = set.EnablePostWait; songmanage.EventSetting.LateTweetSeconds = set.WaitSecond; songmanage.EventSetting.TimeElapsedFromLastTweetSec = set.WaitSecond2; songmanage.EventSetting.NoAlbumArtSameAlbum = set.NoAlbumArtworkOnSameAlbum; }
private void MainWindow_Load(object sender, EventArgs e) { //デバッガの準備 Core.Debugger.TextBoxTraceListener tbtl = new Core.Debugger.TextBoxTraceListener(DebugTextBox); //Debug.Listeners.Add(tbtl); Trace.Listeners.Add(tbtl); String TMPDIR = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\tmp\"; //tmpフォルダの作成 if (System.IO.Directory.Exists(TMPDIR) == false) { System.IO.Directory.CreateDirectory(TMPDIR); } else { //tmpをクリアする foreach (String path in System.IO.Directory.GetFiles(TMPDIR)) { System.IO.File.Delete(path); } } //設定を読み出す Core.ApplicationSetting.SettingClass set; if (System.IO.File.Exists(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\setting.xml")) { //XmlSerializerオブジェクトを作成 System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Core.ApplicationSetting.SettingClass)); //読み込むファイルを開く System.IO.FileStream fs = new System.IO.FileStream(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\setting.xml", System.IO.FileMode.Open); //XMLファイルから読み込み、逆シリアル化する set = (Core.ApplicationSetting.SettingClass)serializer.Deserialize(fs); //ファイルを閉じる fs.Close(); //初回起動ではないのでフォーム非表示 this.WindowState = FormWindowState.Minimized; } else { set = new Core.ApplicationSetting.SettingClass(); } //初期化処理 PutSettingToUI(set); initiTunes(set); //プラグインシステムの初期化 plugin = new Plugin.PluginSystem(songmanage); plugin.StartThread(); externalplayer = new Plugin.ExternalPlayerPipe(); externalplayer.StartThread(); externalplayer.onSongChangedEvent += externalplayer_onSongChangedEvent; this.FormClosing += MainWindow_Closing; this.Shown += MainWindow_Shown; CheckForIllegalCrossThreadCalls = false; //更新の確認をする if (set.CheckUpdate == true) { updater = new UpdateChecker.Updater(); updater.CheckUpdateFinished += updater_CheckUpdateFinished; Thread UpdaterThread = new Thread(updater.CheckUpdate); UpdaterThread.IsBackground = true; UpdaterThread.Start(); } }
//UIからクラスに代入する Core.ApplicationSetting.SettingClass PutSettingToClass() { Core.ApplicationSetting.SettingClass set = new Core.ApplicationSetting.SettingClass(); set.TweetText = TextBoxTweetText.Text; set.EnableAutoPost = CheckBoxEnableAutoPost.Checked; set.EnablePostWait = CheckBoxEnablePostWait.Checked; set.EnableCheckAlbum = CheckBoxEnableCheckAlbum.Checked; set.EnableCheckTime = CheckBoxCheckTime.Checked; set.PostAlbumArtWork = checkBoxPostAlbumArtWork.Checked; set.CheckUpdate = CheckUpdate.Checked; set.NotifyUpdate = NotifyUpdate.Checked; set.WaitSecond = (int)numericUpDownWaitSecond.Value; set.WaitSecond2 = (int)numericUpDownWaitSecond2.Value; set.DeleteText140 = CheckBoxDeleteText140.Checked; set.ExitWithiTunes = CheckBoxExitWithiTunes.Checked; set.NoAlbumArtworkOnSameAlbum = checkBoxSameAlbumNoArtwork.Checked; foreach (ListViewItem item in AccountList.Items) { Core.ApplicationSetting.AccountClass account = new Core.ApplicationSetting.AccountClass(); account.AccountName = item.Text; account.Token = item.SubItems[1].Text; account.TokenSecret = item.SubItems[2].Text; account.Enabled = item.Checked; set.AccountList.Add(account); } return set; }
private void MainWindow_Load(object sender, EventArgs e) { //デバッガの準備 Core.Debugger.TextBoxTraceListener tbtl = new Core.Debugger.TextBoxTraceListener(DebugTextBox); //Debug.Listeners.Add(tbtl); Trace.Listeners.Add(tbtl); String TMPDIR = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\tmp\"; //tmpフォルダの作成 if (System.IO.Directory.Exists(TMPDIR) == false) { System.IO.Directory.CreateDirectory(TMPDIR); } else { //tmpをクリアする foreach(String path in System.IO.Directory.GetFiles(TMPDIR)){ System.IO.File.Delete(path); } } //設定を読み出す Core.ApplicationSetting.SettingClass set; if(System.IO.File.Exists(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\setting.xml")) { //XmlSerializerオブジェクトを作成 System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Core.ApplicationSetting.SettingClass)); //読み込むファイルを開く System.IO.FileStream fs = new System.IO.FileStream(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\setting.xml", System.IO.FileMode.Open); //XMLファイルから読み込み、逆シリアル化する set = (Core.ApplicationSetting.SettingClass) serializer.Deserialize(fs); //ファイルを閉じる fs.Close(); //初回起動ではないのでフォーム非表示 this.WindowState = FormWindowState.Minimized; } else { set = new Core.ApplicationSetting.SettingClass(); } //初期化処理 PutSettingToUI(set); initiTunes(set); //プラグインシステムの初期化 plugin = new Plugin.PluginSystem(songmanage); plugin.StartThread(); externalplayer = new Plugin.ExternalPlayerPipe(); externalplayer.StartThread(); externalplayer.onSongChangedEvent += externalplayer_onSongChangedEvent; this.FormClosing += MainWindow_Closing; this.Shown += MainWindow_Shown; CheckForIllegalCrossThreadCalls = false; //更新の確認をする if (set.CheckUpdate == true) { updater = new UpdateChecker.Updater(); updater.CheckUpdateFinished += updater_CheckUpdateFinished; Thread UpdaterThread = new Thread(updater.CheckUpdate); UpdaterThread.IsBackground = true; UpdaterThread.Start(); } }