public static List<XObject> Load() { string key = @"Software\Sony Corporation\Sony MediaPlayerX\Database"; string dbpath = ""; RegistryKey registryKey; if (Environment.Is64BitOperatingSystem) { registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(key); } else { registryKey = Registry.LocalMachine.OpenSubKey(key); } if (registryKey == null) { //旧式 registryKey = Registry.LocalMachine.OpenSubKey(key); } dbpath = (string)registryKey.GetValue("MetallicData", ""); registryKey.Close(); if (String.IsNullOrEmpty(dbpath)) { MessageBox.Show("X-APPLICATIONが正常にインストールされていません。"); return null; } string accessConnection = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", dbpath); string sql = "select * from t_object where ObjectSpecId=2;"; DataSet ds = new DataSet(); OleDbConnection connection = null; try { connection = new OleDbConnection(accessConnection); } catch (Exception) { try { accessConnection = String.Format("Driver={Microsoft Access Driver (*.mdb)};DBQ={0};", dbpath); connection = new OleDbConnection(accessConnection); } catch (Exception) { MessageBox.Show("Microsoft Data Access ComponentsもしくはMicrosoft Access Driverがインストールされていません。"); return null; } } try { OleDbCommand command = new OleDbCommand(sql, connection); OleDbDataAdapter adapter = new OleDbDataAdapter(command); connection.Open(); adapter.Fill(ds, "t_object"); } catch (Exception) { MessageBox.Show("X-APPLICATIONの楽曲データベースへのアクセスに失敗しました。"); return null; } finally { connection.Close(); } List<XObject> xobjects = new List<XObject>(); DataRowCollection collection = ds.Tables["t_object"].Rows; foreach (DataRow row in collection) { var xobj = new XObject(row[2].ToString(), row[69].ToString(), row[70].ToString(), row[74].ToString(), row[111].ToString()); xobj.Object100 = row[3].ToString(); xobjects.Add(xobj); } return xobjects; }
public void Update(object _) { bool found = false; foreach (List<XObject> list in this._parallel) { var list1 = list; Task.Run(() => { List<string> buf = list1.Select(obj => obj.Object500).ToList(); if (GetUsingFiles(buf.ToArray<string>())) { foreach (XObject o in list1) { if (GetUsingFiles(new[] { o.Object500 })) { var o1 = o; DispatcherHelper.UIDispatcher.Invoke(() => { found = true; if (this._currentObject == o1) { //曲が切り替わってから最低10秒経過した(曲の早送りでのツイートを拒否するため) if (_curCount >= 0 && _curCount++ >= 2) { //自動投稿 if (Settings.Settings.AutoTweet) { if (this.CanTweet()) { this.Tweet(); } if (this.CanWhisper()) { this.Whisper(); } _curCount = -1; } } return; } _curCount = 0; this.Title = "X-NowPlaying - " + o1.ObjectName; this.Music = o1.ObjectName; this.Album = o1.Object206; this.Artist = o1.Object201; if (!String.IsNullOrEmpty(o1.Object202)) { this.JacketImage = new BitmapImage(new Uri(o1.Object202)); this.JacketImageStr = o1.Object202; } else { this.JacketImage = new BitmapImage(new Uri("/Resources/insert2.png", UriKind.Relative)); this.JacketImageStr = ""; } this._currentObject = o1; }); } } } }); if (found) { break; } } }