PageRenderTime 66ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Settings Migrator/Migrator.cs

http://yet-another-music-application.googlecode.com/
C# | 1543 lines | 875 code | 258 blank | 410 comment | 258 complexity | 2faef0fe08d404b4c5efcb7ecc9b5cc4 MD5 | raw file
  1. /**
  2. * Migrator.cs
  3. *
  4. * Creates a modified version of a settings file for migration
  5. * between two versions of Stoffi Music Player.
  6. *
  7. * * * * * * * * *
  8. *
  9. * Copyright 2012 Simplare
  10. *
  11. * This code is part of the Stoffi Music Player Project.
  12. * Visit our website at: stoffiplayer.com
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 3 of the License, or (at your option) any later version.
  18. *
  19. * See stoffiplayer.com/license for more information.
  20. **/
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Collections.Specialized;
  24. using System.Collections.ObjectModel;
  25. using System.Globalization;
  26. using System.IO;
  27. using System.Linq;
  28. using System.Text;
  29. using System.Xml;
  30. using System.Xml.Serialization;
  31. namespace Stoffi
  32. {
  33. /// <summary>
  34. /// Migrates settings between two versions of Stoffi.
  35. /// </summary>
  36. public class SettingsMigrator : IMigrator
  37. {
  38. #region Members
  39. private Utility utility;
  40. #endregion
  41. #region Methods
  42. #region Public
  43. /// <summary>
  44. /// Migrates a settings file.
  45. /// </summary>
  46. /// <param name="fromFile">The original file</param>
  47. /// <param name="toFile">The output file</param>
  48. public void Migrate(String fromFile, String toFile)
  49. {
  50. utility = new Utility();
  51. utility.LogFile = "migrator.log";
  52. utility.Mode = LogMode.Debug;
  53. NewSettings settings = new NewSettings();
  54. utility.LogMessageToFile(LogMode.Information, "Reading configuration");
  55. ReadConfig(settings, fromFile);
  56. utility.LogMessageToFile(LogMode.Information, "Modifying configuration");
  57. foreach (SourceData source in settings.Sources)
  58. FixSource(source);
  59. utility.LogMessageToFile(LogMode.Information, "Writing configuration");
  60. WriteConfig(settings, toFile);
  61. }
  62. #endregion
  63. #region Private
  64. private void FixSource(SourceData item)
  65. {
  66. item.Icon = item.Icon.Replace(
  67. "pack://application:,,,/GUI/Images/Icons/",
  68. "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/"
  69. );
  70. }
  71. private KeyboardShortcut GetKeyboardShortcut(KeyboardShortcutProfile profile, String keysAsText)
  72. {
  73. foreach (KeyboardShortcut s in profile.Shortcuts)
  74. if (s.Keys == keysAsText)
  75. return s;
  76. return null;
  77. }
  78. private KeyboardShortcut GetKeyboardShortcut(KeyboardShortcutProfile profile, String category, String name)
  79. {
  80. foreach (KeyboardShortcut s in profile.Shortcuts)
  81. if (s.Name == name && s.Category == category)
  82. return s;
  83. return null;
  84. }
  85. private void SetKeyboardShortcut(KeyboardShortcut sc, String keysAsText, String isGlobal = "false")
  86. {
  87. sc.Keys = keysAsText;
  88. sc.IsGlobal = isGlobal;
  89. }
  90. private void SetKeyboardShortcut(KeyboardShortcutProfile profile, String category, String name, String keysAsText, String isGlobal = "false")
  91. {
  92. KeyboardShortcut sc = GetKeyboardShortcut(profile, category, name);
  93. if (sc == null)
  94. {
  95. sc = new KeyboardShortcut();
  96. sc.Category = category;
  97. sc.Name = name;
  98. profile.Shortcuts.Add(sc);
  99. }
  100. SetKeyboardShortcut(sc, keysAsText, isGlobal);
  101. }
  102. private void InitShortcutProfile(KeyboardShortcutProfile profile, String name, String isprotected)
  103. {
  104. profile.Name = name;
  105. profile.IsProtected = isprotected;
  106. profile.Shortcuts = new List<KeyboardShortcut>();
  107. // set the default shortcuts
  108. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Add track", IsGlobal = "false", Keys = "Ctrl+T" });
  109. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Add folder", IsGlobal = "false", Keys = "Ctrl+F" });
  110. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Open playlist", IsGlobal = "false", Keys = "Ctrl+O" });
  111. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Minimize", IsGlobal = "false", Keys = "Ctrl+M" });
  112. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Restore", IsGlobal = "true", Keys = "Ctrl+Shift+R" });
  113. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Help", IsGlobal = "false", Keys = "F1" });
  114. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Application", Name = "Close", IsGlobal = "false", Keys = "Ctrl+W" });
  115. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Library", IsGlobal = "false", Keys = "Alt+L" });
  116. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Queue", IsGlobal = "false", Keys = "Alt+Q" });
  117. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "History", IsGlobal = "false", Keys = "Alt+H" });
  118. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Playlists", IsGlobal = "false", Keys = "Alt+P" });
  119. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Now playing", IsGlobal = "false", Keys = "Alt+W" });
  120. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Tracklist", IsGlobal = "false", Keys = "Alt+T" });
  121. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Search", IsGlobal = "false", Keys = "Alt+F" });
  122. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "General preferences", IsGlobal = "false", Keys = "Alt+G" });
  123. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Services", IsGlobal = "false", Keys = "Alt+V" });
  124. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Library sources", IsGlobal = "false", Keys = "Alt+S" });
  125. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Keyboard shortcuts", IsGlobal = "false", Keys = "Alt+K" });
  126. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "About", IsGlobal = "false", Keys = "Alt+A" });
  127. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Toggle details pane", IsGlobal = "false", Keys = "Alt+D" });
  128. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Toggle menu bar", IsGlobal = "false", Keys = "Alt+M" });
  129. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MainWindow", Name = "Create playlist", IsGlobal = "false", Keys = "Alt+N" });
  130. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Play or pause", IsGlobal = "false", Keys = "Alt+5 (numpad)" });
  131. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Next", IsGlobal = "false", Keys = "Alt+6 (numpad)" });
  132. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Previous", IsGlobal = "false", Keys = "Alt+4 (numpad)" });
  133. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Toggle shuffle", IsGlobal = "false", Keys = "Alt+7 (numpad)" });
  134. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Toggle repeat", IsGlobal = "false", Keys = "Alt+9 (numpad)" });
  135. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Increase volume", IsGlobal = "false", Keys = "Alt+8 (numpad)" });
  136. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Decrease volume", IsGlobal = "false", Keys = "Alt+2 (numpad)" });
  137. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Seek forward", IsGlobal = "false", Keys = "Alt+3 (numpad)" });
  138. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Seek backward", IsGlobal = "false", Keys = "Alt+1 (numpad)" });
  139. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Add bookmark", IsGlobal = "false", Keys = "Alt+B" });
  140. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to previous bookmark", IsGlobal = "false", Keys = "Alt+Left" });
  141. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to next bookmark", IsGlobal = "false", Keys = "Alt+Right" });
  142. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to first bookmark", IsGlobal = "false", Keys = "Alt+Home" });
  143. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to last bookmark", IsGlobal = "false", Keys = "Alt+End" });
  144. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 1", IsGlobal = "false", Keys = "Alt+1" });
  145. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 2", IsGlobal = "false", Keys = "Alt+2" });
  146. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 3", IsGlobal = "false", Keys = "Alt+3" });
  147. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 4", IsGlobal = "false", Keys = "Alt+4" });
  148. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 5", IsGlobal = "false", Keys = "Alt+5" });
  149. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 6", IsGlobal = "false", Keys = "Alt+6" });
  150. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 7", IsGlobal = "false", Keys = "Alt+7" });
  151. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 8", IsGlobal = "false", Keys = "Alt+8" });
  152. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 9", IsGlobal = "false", Keys = "Alt+9" });
  153. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to bookmark 10", IsGlobal = "false", Keys = "Alt+0" });
  154. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to current track", IsGlobal = "false", Keys = "Alt+C" });
  155. profile.Shortcuts.Add(new KeyboardShortcut { Category = "MediaCommands", Name = "Jump to selected track", IsGlobal = "false", Keys = "Alt+X" });
  156. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "Queue and dequeue", IsGlobal = "false", Keys = "Shift+Q" });
  157. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "Remove track", IsGlobal = "false", Keys = "Delete" });
  158. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "Play track", IsGlobal = "false", Keys = "Enter" });
  159. profile.Shortcuts.Add(new KeyboardShortcut { Category = "Track", Name = "View information", IsGlobal = "false", Keys = "Shift+I" });
  160. }
  161. /// <summary>
  162. /// Creates a ViewDetailsConfig with default values
  163. /// </summary>
  164. /// <returns>The newly created config</returns>
  165. public static ViewDetailsConfig CreateListConfig()
  166. {
  167. Stoffi.ViewDetailsConfig config = new Stoffi.ViewDetailsConfig();
  168. config.HasNumber = true;
  169. config.IsNumberVisible = false;
  170. config.Filter = "";
  171. config.IsClickSortable = true;
  172. config.IsDragSortable = true;
  173. config.LockSortOnNumber = false;
  174. config.SelectedIndices = new List<int>();
  175. config.UseIcons = true;
  176. config.AcceptFileDrops = true;
  177. config.Columns = new ObservableCollection<Stoffi.ViewDetailsColumn>();
  178. config.NumberColumn = CreateListColumn("#", "#", "Number", "Number", 60, "Right", false);
  179. return config;
  180. }
  181. /// <summary>
  182. /// Creates a ViewDetailsColumn
  183. /// </summary>
  184. /// <param name="name">The name of the column</param>
  185. /// <param name="text">The displayed text</param>
  186. /// <param name="binding">The value to bind to</param>
  187. /// <param name="width">The width</param>
  188. /// <param name="isVisible">Whether the column is visible</param>
  189. /// <param name="alignment">The alignment of the text</param>
  190. /// <param name="isAlwaysVisible">Whether the column is always visible</param>
  191. /// <param name="isSortable">Whether the column is sortable</param>
  192. /// <returns>The newly created column</returns>
  193. public static ViewDetailsColumn CreateListColumn(string name, string text, string binding, int width,
  194. string alignment = "Left",
  195. bool isVisible = true,
  196. bool isAlwaysVisible = false,
  197. bool isSortable = true)
  198. {
  199. ViewDetailsColumn column = new ViewDetailsColumn();
  200. column.Name = name;
  201. column.Text = text;
  202. column.Binding = binding;
  203. column.Width = width;
  204. column.Alignment = alignment;
  205. column.IsAlwaysVisible = isAlwaysVisible;
  206. column.IsSortable = isSortable;
  207. column.IsVisible = isVisible;
  208. column.SortField = binding;
  209. return column;
  210. }
  211. /// <summary>
  212. /// Creates a ViewDetailsColumn
  213. /// </summary>
  214. /// <param name="name">The name of the column</param>
  215. /// <param name="text">The displayed text</param>
  216. /// <param name="binding">The value to bind to</param>
  217. /// <param name="sortField">The column to sort on</param>
  218. /// <param name="width">The width</param>
  219. /// <param name="isVisible">Whether the column is visible</param>
  220. /// <param name="alignment">The alignment of the text</param>
  221. /// <param name="isAlwaysVisible">Whether the column is always visible</param>
  222. /// <param name="isSortable">Whether the column is sortable</param>
  223. /// <returns>The newly created column</returns>
  224. public static ViewDetailsColumn CreateListColumn(string name, string text, string binding, string sortField, int width,
  225. string alignment = "Left",
  226. bool isVisible = true,
  227. bool isAlwaysVisible = false,
  228. bool isSortable = true)
  229. {
  230. ViewDetailsColumn column = new ViewDetailsColumn();
  231. column.Name = name;
  232. column.Text = text;
  233. column.Binding = binding;
  234. column.Width = width;
  235. column.Alignment = alignment;
  236. column.IsAlwaysVisible = isAlwaysVisible;
  237. column.IsSortable = isSortable;
  238. column.IsVisible = isVisible;
  239. column.SortField = sortField;
  240. return column;
  241. }
  242. private void ReadConfig(NewSettings settings, String file)
  243. {
  244. utility.LogMessageToFile(LogMode.Debug, "Reading config");
  245. if (File.Exists(file) == false)
  246. {
  247. utility.LogMessageToFile(LogMode.Error, "Could not find data file " + file);
  248. return;
  249. }
  250. XmlTextReader xmlReader = new XmlTextReader(file);
  251. xmlReader.WhitespaceHandling = WhitespaceHandling.None;
  252. xmlReader.Read();
  253. while (xmlReader.Read())
  254. {
  255. if (xmlReader.NodeType == XmlNodeType.Element)
  256. {
  257. if (xmlReader.Name == "setting")
  258. {
  259. String name = "";
  260. for (int i = 0; i < xmlReader.AttributeCount; xmlReader.MoveToAttribute(i), i++)
  261. if (xmlReader.Name == "name") name = xmlReader.Value;
  262. xmlReader.Read();
  263. if (!xmlReader.IsEmptyElement)
  264. xmlReader.Read();
  265. utility.LogMessageToFile(LogMode.Debug, "Parsing attribute '" + name + "'");
  266. if (name == "WinHeight")
  267. settings.WinHeight = xmlReader.Value;
  268. else if (name == "WinWidth")
  269. settings.WinWidth = xmlReader.Value;
  270. else if (name == "WinTop")
  271. settings.WinTop = xmlReader.Value;
  272. else if (name == "WinLeft")
  273. settings.WinLeft = xmlReader.Value;
  274. else if (name == "WinState")
  275. settings.WinState = xmlReader.Value;
  276. else if (name == "EqualizerHeight")
  277. settings.EqualizerHeight = xmlReader.Value;
  278. else if (name == "EqualizerWidth")
  279. settings.EqualizerWidth = xmlReader.Value;
  280. else if (name == "EqualizerTop")
  281. settings.EqualizerTop = xmlReader.Value;
  282. else if (name == "EqualizerLeft")
  283. settings.EqualizerLeft = xmlReader.Value;
  284. else if (name == "MediaState")
  285. settings.MediaState = xmlReader.Value;
  286. else if (name == "Language")
  287. settings.Language = xmlReader.Value;
  288. else if (name == "NavigationPaneWidth")
  289. settings.NavigationPaneWidth = xmlReader.Value;
  290. else if (name == "DetailsPaneHeight")
  291. settings.DetailsPaneHeight = xmlReader.Value;
  292. else if (name == "Repeat")
  293. settings.Repeat = xmlReader.Value;
  294. else if (name == "Shuffle")
  295. settings.Shuffle = xmlReader.Value;
  296. else if (name == "Volume")
  297. settings.Volume = xmlReader.Value;
  298. else if (name == "EqualizerProfiles")
  299. settings.EqualizerProfiles = ReadSetting<List<EqualizerProfile>>(xmlReader);
  300. else if (name == "CurrentEqualizerProfile")
  301. settings.CurrentEqualizerProfile = ReadSetting<EqualizerProfile>(xmlReader);
  302. else if (name == "Seek")
  303. settings.Seek = xmlReader.Value;
  304. else if (name == "CurrentTrack")
  305. settings.CurrentTrack = ReadSetting<TrackData>(xmlReader);
  306. else if (name == "HistoryIndex")
  307. settings.HistoryIndex = xmlReader.Value;
  308. else if (name == "CurrentSelectedNavigation")
  309. settings.CurrentSelectedNavigation = xmlReader.Value;
  310. else if (name == "CurrentActiveNavigation")
  311. settings.CurrentActiveNavigation = xmlReader.Value;
  312. else if (name == "CurrentVisualizer")
  313. settings.CurrentVisualizer = xmlReader.Value;
  314. else if (name == "MenuBarVisibility" || name == "MenuBarVisible")
  315. settings.MenuBarVisible = xmlReader.Value;
  316. else if (name == "DetailsPaneVisibility" || name == "DetailsPaneVisible")
  317. settings.DetailsPaneVisible = xmlReader.Value;
  318. else if (name == "FirstRun")
  319. settings.FirstRun = xmlReader.Value;
  320. else if (name == "PluginSettings")
  321. settings.PluginSettings = ReadSetting<List<PluginSettings>>(xmlReader);
  322. else if (name == "PluginListConfig")
  323. settings.PluginListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  324. else if (name == "Sources")
  325. settings.Sources = ReadSetting<List<SourceData>>(xmlReader);
  326. else if (name == "SourceListConfig")
  327. settings.SourceListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  328. else if (name == "LibraryListConfig")
  329. settings.LibraryListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  330. else if (name == "RadioListConfig")
  331. settings.RadioListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  332. else if (name == "DiscListConfig")
  333. settings.DiscListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  334. else if (name == "HistoryListConfig")
  335. settings.HistoryListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  336. else if (name == "QueueListConfig")
  337. settings.QueueListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  338. else if (name == "YouTubeListConfig")
  339. settings.YouTubeListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  340. else if (name == "SoundCloudListConfig")
  341. settings.SoundCloudListConfig = ReadSetting<ViewDetailsConfig>(xmlReader);
  342. else if (name == "LibraryTracks")
  343. settings.LibraryTracks = ReadSetting<List<TrackData>>(xmlReader);
  344. else if (name == "RadioTracks")
  345. settings.RadioTracks = ReadSetting<List<TrackData>>(xmlReader);
  346. else if (name == "HistoryTracks")
  347. settings.HistoryTracks = ReadSetting<List<TrackData>>(xmlReader);
  348. else if (name == "QueueTracks")
  349. settings.QueueTracks = ReadSetting<List<TrackData>>(xmlReader);
  350. else if (name == "Playlists")
  351. settings.Playlists = ReadSetting<List<PlaylistData>>(xmlReader);
  352. else if (name == "OpenAddPolicy")
  353. settings.OpenAddPolicy = xmlReader.Value;
  354. else if (name == "OpenPlayPolicy")
  355. settings.OpenPlayPolicy = xmlReader.Value;
  356. else if (name == "UpgradePolicy")
  357. settings.UpgradePolicy = xmlReader.Value;
  358. else if (name == "SearchPolicy")
  359. settings.SearchPolicy = xmlReader.Value;
  360. else if (name == "ShowOSD")
  361. settings.ShowOSD = xmlReader.Value;
  362. else if (name == "MinimizeToTray")
  363. settings.MinimizeToTray = xmlReader.Value;
  364. else if (name == "ID")
  365. settings.ID = xmlReader.Value;
  366. else if (name == "UpgradeCheck")
  367. settings.UpgradeCheck = xmlReader.Value;
  368. else if (name == "ShortcutProfiles")
  369. settings.ShortcutProfiles = ReadSetting<List<KeyboardShortcutProfile>>(xmlReader);
  370. else if (name == "OAuthToken")
  371. settings.OAuthToken = xmlReader.Value;
  372. else if (name == "OAuthSecret")
  373. settings.OAuthSecret = xmlReader.Value;
  374. else if (name == "SubmitSongs")
  375. settings.SubmitSongs = xmlReader.Value;
  376. else if (name == "SubmitPlaylists")
  377. settings.SubmitPlaylists = xmlReader.Value;
  378. else if (name == "PauseWhenLocked" || name == "PauseWhileLocked")
  379. settings.PauseWhenLocked = xmlReader.Value;
  380. else if (name == "PauseWhenSongEnds")
  381. settings.PauseWhenSongEnds = xmlReader.Value;
  382. else if (name == "CloudIdentities")
  383. settings.CloudIdentities = ReadSetting<List<CloudIdentity>>(xmlReader);
  384. utility.LogMessageToFile(LogMode.Debug, "Done");
  385. }
  386. }
  387. }
  388. xmlReader.Close();
  389. }
  390. private void WriteConfig(NewSettings settings, String file)
  391. {
  392. utility.LogMessageToFile(LogMode.Debug, "Writing config");
  393. XmlTextWriter xmlWriter = new XmlTextWriter(file, Encoding.UTF8);
  394. xmlWriter.WriteStartDocument();
  395. xmlWriter.WriteWhitespace("\n");
  396. xmlWriter.WriteStartElement("configuration");
  397. xmlWriter.WriteWhitespace("\n ");
  398. xmlWriter.WriteStartElement("configSections");
  399. xmlWriter.WriteWhitespace("\n ");
  400. xmlWriter.WriteStartElement("sectionGroup");
  401. xmlWriter.WriteStartAttribute("name");
  402. xmlWriter.WriteString("userSettings");
  403. xmlWriter.WriteEndAttribute();
  404. xmlWriter.WriteWhitespace("\n ");
  405. xmlWriter.WriteStartElement("section");
  406. xmlWriter.WriteStartAttribute("name");
  407. xmlWriter.WriteString("Stoffi.Properties.Settings");
  408. xmlWriter.WriteEndAttribute();
  409. xmlWriter.WriteStartAttribute("type");
  410. xmlWriter.WriteString("System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
  411. xmlWriter.WriteEndAttribute();
  412. xmlWriter.WriteStartAttribute("allowExeDefinition");
  413. xmlWriter.WriteString("MachineToLocalUser");
  414. xmlWriter.WriteEndAttribute();
  415. xmlWriter.WriteStartAttribute("requirePermission");
  416. xmlWriter.WriteString("false");
  417. xmlWriter.WriteEndAttribute();
  418. xmlWriter.WriteEndElement();
  419. xmlWriter.WriteWhitespace("\n ");
  420. xmlWriter.WriteEndElement();
  421. xmlWriter.WriteWhitespace("\n ");
  422. xmlWriter.WriteEndElement();
  423. xmlWriter.WriteWhitespace("\n ");
  424. xmlWriter.WriteStartElement("userSettings");
  425. xmlWriter.WriteWhitespace("\n ");
  426. xmlWriter.WriteStartElement("Stoffi.Properties.Settings");
  427. WriteSetting(xmlWriter, "WinWidth", 3, settings.WinWidth);
  428. WriteSetting(xmlWriter, "WinHeight", 3, settings.WinHeight);
  429. WriteSetting(xmlWriter, "WinTop", 3, settings.WinTop);
  430. WriteSetting(xmlWriter, "WinLeft", 3, settings.WinLeft);
  431. WriteSetting(xmlWriter, "WinWidth", 3, settings.EqualizerWidth);
  432. WriteSetting(xmlWriter, "WinState", 3, settings.WinState);
  433. WriteSetting(xmlWriter, "EqualizerHeight", 3, settings.EqualizerHeight);
  434. WriteSetting(xmlWriter, "EqualizerTop", 3, settings.EqualizerTop);
  435. WriteSetting(xmlWriter, "EqualizerLeft", 3, settings.EqualizerLeft);
  436. WriteSetting(xmlWriter, "MediaState", 3, settings.MediaState);
  437. WriteSetting(xmlWriter, "Language", 3, settings.Language);
  438. WriteSetting(xmlWriter, "NavigationPaneWidth", 3, settings.NavigationPaneWidth);
  439. WriteSetting(xmlWriter, "DetailsPaneHeight", 3, settings.DetailsPaneHeight);
  440. WriteSetting(xmlWriter, "Repeat", 3, settings.Repeat);
  441. WriteSetting(xmlWriter, "Shuffle", 3, settings.Shuffle);
  442. WriteSetting(xmlWriter, "Volume", 3, settings.Volume);
  443. WriteSetting<List<EqualizerProfile>>(xmlWriter, "EqualizerProfiles", "Xml", 3, settings.EqualizerProfiles);
  444. WriteSetting<EqualizerProfile>(xmlWriter, "CurrentEqualizerProfile", "Xml", 3, settings.CurrentEqualizerProfile);
  445. WriteSetting(xmlWriter, "Seek", 3, settings.Seek);
  446. WriteSetting<TrackData>(xmlWriter, "CurrentTrack", "Xml", 3, settings.CurrentTrack);
  447. WriteSetting(xmlWriter, "HistoryIndex", 3, settings.HistoryIndex);
  448. WriteSetting(xmlWriter, "CurrentSelectedNavigation", 3, settings.CurrentSelectedNavigation);
  449. WriteSetting(xmlWriter, "CurrentActiveNavigation", 3, settings.CurrentActiveNavigation);
  450. WriteSetting(xmlWriter, "CurrentVisualizer", 3, settings.CurrentVisualizer);
  451. WriteSetting(xmlWriter, "MenuBarVisible", 3, settings.MenuBarVisible);
  452. WriteSetting(xmlWriter, "DetailsPaneVisibile", 3, settings.DetailsPaneVisible);
  453. WriteSetting(xmlWriter, "FirstRun", 3, settings.FirstRun);
  454. WriteSetting<List<PluginSettings>>(xmlWriter, "PluginSettings", "Xml", 3, settings.PluginSettings);
  455. WriteSetting<ViewDetailsConfig>(xmlWriter, "PluginListConfig", "Xml", 3, settings.PluginListConfig);
  456. WriteSetting<List<SourceData>>(xmlWriter, "Sources", "Xml", 3, settings.Sources);
  457. WriteSetting<ViewDetailsConfig>(xmlWriter, "SourceListConfig", "Xml", 3, settings.SourceListConfig);
  458. WriteSetting<ViewDetailsConfig>(xmlWriter, "LibraryListConfig", "Xml", 3, settings.LibraryListConfig);
  459. WriteSetting<ViewDetailsConfig>(xmlWriter, "RadioListConfig", "Xml", 3, settings.RadioListConfig);
  460. WriteSetting<ViewDetailsConfig>(xmlWriter, "DiscListConfig", "Xml", 3, settings.DiscListConfig);
  461. WriteSetting<ViewDetailsConfig>(xmlWriter, "HistoryListConfig", "Xml", 3, settings.HistoryListConfig);
  462. WriteSetting<ViewDetailsConfig>(xmlWriter, "QueueListConfig", "Xml", 3, settings.QueueListConfig);
  463. WriteSetting<ViewDetailsConfig>(xmlWriter, "YouTubeListConfig", "Xml", 3, settings.YouTubeListConfig);
  464. WriteSetting<ViewDetailsConfig>(xmlWriter, "SoundCloudListConfig", "Xml", 3, settings.SoundCloudListConfig);
  465. WriteSetting<List<TrackData>>(xmlWriter, "LibraryTracks", "Xml", 3, settings.LibraryTracks);
  466. WriteSetting<List<TrackData>>(xmlWriter, "RadioTracks", "Xml", 3, settings.RadioTracks);
  467. WriteSetting<List<TrackData>>(xmlWriter, "HistoryTracks", "Xml", 3, settings.HistoryTracks);
  468. WriteSetting<List<TrackData>>(xmlWriter, "QueueTracks", "Xml", 3, settings.QueueTracks);
  469. WriteSetting<List<PlaylistData>>(xmlWriter, "Playlists", "Xml", 3, settings.Playlists);
  470. WriteSetting(xmlWriter, "OpenAddPolicy", 3, settings.OpenAddPolicy);
  471. WriteSetting(xmlWriter, "OpenPlayPolicy", 3, settings.OpenPlayPolicy);
  472. WriteSetting(xmlWriter, "UpgradePolicy", 3, settings.UpgradePolicy);
  473. WriteSetting(xmlWriter, "SearchPolicy", 3, settings.SearchPolicy);
  474. WriteSetting(xmlWriter, "ShowOSD", 3, settings.ShowOSD);
  475. WriteSetting(xmlWriter, "MinimizeToTray", 3, settings.MinimizeToTray);
  476. WriteSetting(xmlWriter, "ID", 3, settings.ID);
  477. WriteSetting(xmlWriter, "UpgradeCheck", 3, settings.UpgradeCheck);
  478. WriteSetting<List<KeyboardShortcutProfile>>(xmlWriter, "ShortcutProfiles", "Xml", 3, settings.ShortcutProfiles);
  479. WriteSetting(xmlWriter, "CurrentShortcutProfile", 3, settings.CurrentShortcutProfile);
  480. WriteSetting(xmlWriter, "OAuthToken", 3, settings.OAuthToken);
  481. WriteSetting(xmlWriter, "OAuthSecret", 3, settings.OAuthSecret);
  482. WriteSetting(xmlWriter, "SubmitSongs", 3, settings.SubmitSongs);
  483. WriteSetting(xmlWriter, "SubmitPlaylists", 3, settings.SubmitPlaylists);
  484. WriteSetting(xmlWriter, "PauseWhenLocked", 3, settings.PauseWhenLocked);
  485. WriteSetting(xmlWriter, "PauseWhenSongEnds", 3, settings.PauseWhenSongEnds);
  486. WriteSetting<List<CloudIdentity>>(xmlWriter, "CloudIdentities", "Xml", 3, settings.CloudIdentities);
  487. xmlWriter.WriteWhitespace("\n ");
  488. xmlWriter.WriteEndElement();
  489. xmlWriter.WriteWhitespace("\n ");
  490. xmlWriter.WriteEndElement();
  491. xmlWriter.WriteWhitespace("\n");
  492. xmlWriter.WriteEndElement();
  493. xmlWriter.WriteEndDocument();
  494. utility.LogMessageToFile(LogMode.Debug, "Write done");
  495. xmlWriter.Close();
  496. }
  497. /// <summary>
  498. /// Writes a settings to the XML settings file
  499. /// </summary>
  500. /// <typeparam name="T">The type of the settings</typeparam>
  501. /// <param name="xmlWriter">The XmlWriter</param>
  502. /// <param name="setting">The name of the setting</param>
  503. /// <param name="serializeAs">A string describing how the setting is serialized</param>
  504. /// <param name="indent">The number of spaces used for indentation</param>
  505. /// <param name="value">The value</param>
  506. private void WriteSetting<T>(XmlWriter xmlWriter, String setting, String serializeAs, int indent, T value)
  507. {
  508. String indentString = "";
  509. for (int i = 0; i < indent; i++)
  510. indentString += " ";
  511. xmlWriter.WriteWhitespace("\n" + indentString);
  512. xmlWriter.WriteStartElement("setting");
  513. xmlWriter.WriteStartAttribute("name");
  514. xmlWriter.WriteString(setting);
  515. xmlWriter.WriteEndAttribute();
  516. xmlWriter.WriteStartAttribute("serializeAs");
  517. xmlWriter.WriteString(serializeAs);
  518. xmlWriter.WriteEndAttribute();
  519. xmlWriter.WriteWhitespace("\n" + indentString + " ");
  520. xmlWriter.WriteStartElement("value");
  521. if (value != null)
  522. {
  523. XmlSerializer ser = new XmlSerializer(typeof(T));
  524. ser.Serialize(xmlWriter, value);
  525. }
  526. xmlWriter.WriteEndElement();
  527. xmlWriter.WriteWhitespace("\n" + indentString);
  528. xmlWriter.WriteEndElement();
  529. }
  530. /// <summary>
  531. /// Reads a setting from the XML settings file
  532. /// </summary>
  533. /// <typeparam name="T">The type of the setting</typeparam>
  534. /// <param name="xmlReader">The xml reader</param>
  535. /// <returns>The deserialized setting</returns>
  536. private T ReadSetting<T>(XmlTextReader xmlReader)
  537. {
  538. try
  539. {
  540. XmlSerializer ser = new XmlSerializer(typeof(T));
  541. return (T)ser.Deserialize(xmlReader);
  542. }
  543. catch (Exception e)
  544. {
  545. utility.LogMessageToFile(LogMode.Error, e.Message);
  546. return (T)(null as object);
  547. }
  548. }
  549. /// <summary>
  550. /// Reads an old list data structure and uses it to populate
  551. /// a list of tracks and a config structure.
  552. /// </summary>
  553. /// <param name="data">The old list data structure</param>
  554. /// <param name="tracks">The track list to populate</param>
  555. /// <param name="config">The config to populate</param>
  556. private void ListDataToListAndConfig(TrackListData data, List<TrackData> tracks, ViewDetailsConfig config)
  557. {
  558. tracks.AddRange(data.Tracks);
  559. config.SelectedIndices = new List<int>();
  560. foreach (string index in data.SelectedIndices)
  561. config.SelectedIndices.Add(Convert.ToInt32(index));
  562. config.Filter = data.SearchText;
  563. Dictionary<string, string> columnIndices = StringToDictionary(data.ColumnIndices);
  564. Dictionary<string, string> columnWidths = StringToDictionary(data.ColumnWidths);
  565. Dictionary<string, string> columnVisibilities = StringToDictionary(data.ColumnVisibilities);
  566. int artistWidth = columnWidths.ContainsKey("Artist") ? Convert.ToInt32(columnWidths["Artist"]) : 150;
  567. int albumWidth = columnWidths.ContainsKey("Album") ? Convert.ToInt32(columnWidths["Album"]) : 150;
  568. int titleWidth = columnWidths.ContainsKey("Title") ? Convert.ToInt32(columnWidths["Title"]) : 150;
  569. int genreWidth = columnWidths.ContainsKey("Genre") ? Convert.ToInt32(columnWidths["Genre"]) : 100;
  570. int lengthWidth = columnWidths.ContainsKey("Length") ? Convert.ToInt32(columnWidths["Length"]) : 100;
  571. int lpWidth = columnWidths.ContainsKey("LastPlayed") ? Convert.ToInt32(columnWidths["LastPlayed"]) : 150;
  572. int pcWidth = columnWidths.ContainsKey("PlayCount") ? Convert.ToInt32(columnWidths["PlayCount"]) : 100;
  573. int pathWidth = columnWidths.ContainsKey("Path") ? Convert.ToInt32(columnWidths["Path"]) : 300;
  574. bool artistVis = columnVisibilities.ContainsKey("Artist") && columnVisibilities["Artist"] == "visible";
  575. bool albumVis = columnVisibilities.ContainsKey("Album") && columnVisibilities["Album"] == "visible";
  576. bool titleVis = columnVisibilities.ContainsKey("Title") && columnVisibilities["Title"] == "visible";
  577. bool genreVis = columnVisibilities.ContainsKey("Genre") && columnVisibilities["Genre"] == "visible";
  578. bool lengthVis = columnVisibilities.ContainsKey("Length") && columnVisibilities["Length"] == "visible";
  579. bool lpVis = columnVisibilities.ContainsKey("LastPlayed") && columnVisibilities["LastPlayed"] == "visible";
  580. bool pcVis = columnVisibilities.ContainsKey("PlayCount") && columnVisibilities["PlayCount"] == "visible";
  581. bool pathVis = columnVisibilities.ContainsKey("Path") && columnVisibilities["Path"] == "visible";
  582. config.Columns = new ObservableCollection<ViewDetailsColumn>();
  583. Dictionary<string, ViewDetailsColumn> columns = new Dictionary<string, ViewDetailsColumn>();
  584. columns.Add("Artist", CreateListColumn("Artist", "Artist", "Artist", artistWidth, "Left", artistVis));
  585. columns.Add("Album", CreateListColumn("Album", "Album", "Album", albumWidth, "Left", albumVis));
  586. columns.Add("Title", CreateListColumn("Title", "Title", "Title", titleWidth, "Left", titleVis));
  587. columns.Add("Genre", CreateListColumn("Genre", "Genre", "Genre", genreWidth, "Left", genreVis));
  588. columns.Add("Length", CreateListColumn("Length", "Length", "Length", "RawLength", lengthWidth, "Right", lengthVis));
  589. columns.Add("Year", CreateListColumn("Year", "Year", "Year", "Year", 100, "Right", false));
  590. columns.Add("Last Played", CreateListColumn("LastPlayed", "Last played", "LastPlayed", lpWidth, "Left", lpVis));
  591. columns.Add("Play Count", CreateListColumn("PlayCount", "Play count", "PlayCount", pcWidth, "Right", pcVis));
  592. columns.Add("Track", CreateListColumn("Track", "Track", "Track", 100, "Right", false));
  593. columns.Add("Path", CreateListColumn("Path", "Path", "Path", pathWidth, "Left", pathVis));
  594. foreach (string column in columnIndices.Keys)
  595. {
  596. config.Columns.Add(columns[column]);
  597. columns.Remove(column);
  598. }
  599. foreach (ViewDetailsColumn column in columns.Values)
  600. config.Columns.Add(column);
  601. config.AcceptFileDrops = true;
  602. config.HasNumber = true;
  603. config.UseIcons = true;
  604. config.IsClickSortable = true;
  605. config.IsDragSortable = true;
  606. config.IsNumberVisible = false;
  607. config.LockSortOnNumber = false;
  608. config.Sorts = new List<string>();
  609. foreach (string sortPair in data.ColumnSorts)
  610. {
  611. string[] s = sortPair.Split(':');
  612. string dir = s[1] == "Ascending" ? "asc" : "dsc";
  613. string name = s[0];
  614. if (name == "Last Played") name = "LastPlayed";
  615. if (name == "Play Count") name = "PlayCount";
  616. config.Sorts.Add(dir + ":" + name);
  617. }
  618. }
  619. private Dictionary<string,string> StringToDictionary(string str)
  620. {
  621. Dictionary<string, string> ret = new Dictionary<string, string>();
  622. foreach (string pair in str.Split(';'))
  623. {
  624. string[] s = pair.Split(':');
  625. if (ret.ContainsKey(s[0]))
  626. ret.Remove(s[0]);
  627. ret.Add(s[0], s[1]);
  628. }
  629. return ret;
  630. }
  631. private void WriteSetting(XmlWriter xmlWriter, String setting, int indent, String value)
  632. {
  633. if (value == "" || value == null) return;
  634. String indentString = "";
  635. for (int i = 0; i < indent; i++)
  636. indentString += " ";
  637. xmlWriter.WriteWhitespace("\n" + indentString);
  638. xmlWriter.WriteStartElement("setting");
  639. xmlWriter.WriteStartAttribute("name");
  640. xmlWriter.WriteString(setting);
  641. xmlWriter.WriteEndAttribute();
  642. xmlWriter.WriteStartAttribute("serializeAs");
  643. xmlWriter.WriteString("String");
  644. xmlWriter.WriteEndAttribute();
  645. xmlWriter.WriteWhitespace("\n" + indentString + " ");
  646. xmlWriter.WriteStartElement("value");
  647. xmlWriter.WriteString(value);
  648. xmlWriter.WriteEndElement();
  649. xmlWriter.WriteWhitespace("\n" + indentString);
  650. xmlWriter.WriteEndElement();
  651. }
  652. #endregion
  653. #endregion
  654. }
  655. /// <summary>
  656. ///
  657. /// </summary>
  658. public class TrackData : ViewDetailsItemData
  659. {
  660. #region Properties
  661. /// <summary>
  662. ///
  663. /// </summary>
  664. public String Artist { get; set; }
  665. /// <summary>
  666. ///
  667. /// </summary>
  668. public String Album { get; set; }
  669. /// <summary>
  670. ///
  671. /// </summary>
  672. public String Title { get; set; }
  673. /// <summary>
  674. ///
  675. /// </summary>
  676. public String Genre { get; set; }
  677. /// <summary>
  678. ///
  679. /// </summary>
  680. public String Length { get; set; }
  681. /// <summary>
  682. ///
  683. /// </summary>
  684. public String RawLength { get; set; }
  685. /// <summary>
  686. /// Gets the amount of views on YouTube in a localized,
  687. /// human readable format.
  688. /// </summary>
  689. public string Views { get; set; }
  690. /// <summary>
  691. /// Gets or sets the amount of views on YouTube.
  692. /// </summary>
  693. public int RawViews { get; set; }
  694. /// <summary>
  695. ///
  696. /// </summary>
  697. public String LastPlayed { get; set; }
  698. /// <summary>
  699. ///
  700. /// </summary>
  701. public String RawLastPlayed { get; set; }
  702. /// <summary>
  703. ///
  704. /// </summary>
  705. public String PlayCount { get; set; }
  706. /// <summary>
  707. ///
  708. /// </summary>
  709. public String LastWrite { get; set; }
  710. /// <summary>
  711. ///
  712. /// </summary>
  713. public String Processed { get; set; }
  714. /// <summary>
  715. ///
  716. /// </summary>
  717. public String Track { get; set; }
  718. /// <summary>
  719. ///
  720. /// </summary>
  721. public String Path { get; set; }
  722. /// <summary>
  723. ///
  724. /// </summary>
  725. public String Year { get; set; }
  726. /// <summary>
  727. /// Gets or sets the bitrate of the track
  728. /// </summary>
  729. public int Bitrate { get; set; }
  730. /// <summary>
  731. /// Gets or sets the number of channels of the track
  732. /// </summary>
  733. public int Channels { get; set; }
  734. /// <summary>
  735. /// Gets or sets the sample rate of the track
  736. /// </summary>
  737. public int SampleRate { get; set; }
  738. /// <summary>
  739. /// Gets or sets the codecs of the track
  740. /// </summary>
  741. public string Codecs { get; set; }
  742. /// <summary>
  743. ///
  744. /// </summary>
  745. public String Source { get; set; }
  746. /// <summary>
  747. ///
  748. /// </summary>
  749. public List<String> Bookmarks { get; set; }
  750. #endregion
  751. }
  752. /// <summary>
  753. /// Describes an equalizer profile
  754. /// </summary>
  755. public class EqualizerProfile
  756. {
  757. /// <summary>
  758. /// Get or sets the name of the profile
  759. /// </summary>
  760. public String Name { get; set; }
  761. /// <summary>
  762. /// Get or sets whether the user can modify the profile
  763. /// </summary>
  764. public Boolean IsProtected { get; set; }
  765. /// <summary>
  766. /// Get or sets the levels.
  767. /// </summary>
  768. /// <remarks>
  769. /// Is a list with 10 floats between 0 and 10,
  770. /// where each float represents the maximum level
  771. /// on a frequency band going from lower to higher.
  772. /// </remarks>
  773. public float[] Levels;
  774. /// <summary>
  775. /// Get or sets the echo level.
  776. /// A float ranging from 0 to 10 going from
  777. /// dry to wet.
  778. /// </summary>
  779. public string EchoLevel;
  780. }
  781. /// <summary>
  782. ///
  783. /// </summary>
  784. public class TrackListData
  785. {
  786. #region Properties
  787. /// <summary>
  788. ///
  789. /// </summary>
  790. public String ColumnWidths { get; set; }
  791. /// <summary>
  792. ///
  793. /// </summary>
  794. public String ColumnIndices { get; set; }
  795. /// <summary>
  796. ///
  797. /// </summary>
  798. public String ColumnVisibilities { get; set; }
  799. /// <summary>
  800. ///
  801. /// </summary>
  802. public List<String> SelectedIndices { get; set; }
  803. /// <summary>
  804. ///
  805. /// </summary>
  806. public List<String> ColumnSorts { get; set; }
  807. /// <summary>
  808. ///
  809. /// </summary>
  810. public String SearchText { get; set; }
  811. /// <summary>
  812. ///
  813. /// </summary>
  814. public List<TrackData> Tracks { get; set; }
  815. #endregion
  816. }
  817. /// <summary>
  818. ///
  819. /// </summary>
  820. public class PlaylistData
  821. {
  822. #region Properites
  823. /// <summary>
  824. ///
  825. /// </summary>
  826. public String Name { get; set; }
  827. /// <summary>
  828. ///
  829. /// </summary>
  830. public String Time { get; set; }
  831. /// <summary>
  832. ///
  833. /// </summary>
  834. public List<TrackData> Tracks { get; set; }
  835. /// <summary>
  836. /// Get or sets the configuration of the list view
  837. /// </summary>
  838. public ViewDetailsConfig ListConfig { get; set; }
  839. /// <summary>
  840. /// Deprecated!
  841. /// </summary>
  842. public TrackListData ListData { get; set; }
  843. #endregion
  844. }
  845. /// <summary>
  846. ///
  847. /// </summary>
  848. public class SourceData : ViewDetailsItemData
  849. {
  850. #region Properties
  851. /// <summary>
  852. ///
  853. /// </summary>
  854. public String Include { get; set; }
  855. /// <summary>
  856. ///
  857. /// </summary>
  858. public String Ignore { get; set; }
  859. /// <summary>
  860. ///
  861. /// </summary>
  862. public String Type { get; set; }
  863. /// <summary>
  864. ///
  865. /// </summary>
  866. public String HumanType { get; set; }
  867. /// <summary>
  868. ///
  869. /// </summary>
  870. public String Data { get; set; }
  871. #endregion
  872. }
  873. /// <summary>
  874. ///
  875. /// </summary>
  876. public class KeyboardShortcut
  877. {
  878. #region Properties
  879. /// <summary>
  880. ///
  881. /// </summary>
  882. public String Name { get; set; }
  883. /// <summary>
  884. ///
  885. /// </summary>
  886. public String Category { get; set; }
  887. /// <summary>
  888. ///
  889. /// </summary>
  890. public String Keys { get; set; }
  891. /// <summary>
  892. ///
  893. /// </summary>
  894. public String IsGlobal { get; set; }
  895. #endregion
  896. }
  897. /// <summary>
  898. ///
  899. /// </summary>
  900. public class KeyboardShortcutProfile
  901. {
  902. #region Members
  903. public List<KeyboardShortcut> Shortcuts; // TODO: rename to shortcuts
  904. #endregion
  905. #region Properties
  906. /// <summary>
  907. ///
  908. /// </summary>
  909. public String Name { get; set; }
  910. /// <summary>
  911. ///
  912. /// </summary>
  913. public String IsProtected { get; set; }
  914. #endregion
  915. }
  916. public class PluginSettings
  917. {
  918. public String PluginID { get; set; }
  919. public List<Setting> Settings { get; set; }
  920. public String Enabled { get; set; }
  921. public String Installed { get; set; }
  922. }
  923. public class Setting
  924. {
  925. public String ID { get; set; }
  926. public String Type { get; set; }
  927. public String Value { get; set; }
  928. public String Maximum { get; set; }
  929. public String Minimum { get; set; }
  930. public List<String> PossibleValues { get; set; }
  931. public String IsVisible { get; set; }
  932. }
  933. public class CloudIdentity
  934. {
  935. public String UserID { get; set; }
  936. public String ConfigurationID { get; set; }
  937. public String Synchronize { get; set; }
  938. public String SynchronizePlaylists { get; set; }
  939. public String SynchronizeConfig { get; set; }
  940. public String SynchronizeQueue { get; set; }
  941. public String SynchronizeFiles { get; set; }
  942. public String DeviceID { get; set; }
  943. }
  944. /// <summary>
  945. /// The settings after the migration
  946. /// </summary>
  947. public class NewSettings
  948. {
  949. #region Properties
  950. public String WinHeight { get; set; }
  951. public String WinWidth { get; set; }
  952. public String WinTop { get; set; }
  953. public String WinLeft { get; set; }
  954. public String WinState { get; set; }
  955. public String EqualizerHeight { get; set; }
  956. public String EqualizerWidth { get; set; }
  957. public String EqualizerTop { get; set; }
  958. public String EqualizerLeft { get; set; }
  959. public String MediaState { get; set; }
  960. public String Language { get; set; }
  961. public String NavigationPaneWidth { get; set; }
  962. public String DetailsPaneHeight { get; set; }
  963. public String Shuffle { get; set; }
  964. public String Repeat { get; set; }
  965. public String Volume { get; set; }
  966. public List<EqualizerProfile> EqualizerProfiles { get; set; }
  967. public EqualizerProfile CurrentEqualizerProfile { get; set; }
  968. public String Seek { get; set; }
  969. public TrackData CurrentTrack { get; set; }
  970. public String HistoryIndex { get; set; }
  971. public String CurrentSelectedNavigation { get; set; }
  972. public String CurrentActiveNavigation { get; set; }
  973. public String CurrentVisualizer { get; set; }
  974. public String MenuBarVisible { get; set; }
  975. public String DetailsPaneVisible { get; set; }
  976. public String FirstRun { get; set; }
  977. public List<PluginSettings> PluginSettings { get; set; }
  978. public ViewDetailsConfig PluginListConfig { get; set; }
  979. public List<SourceData> Sources { get; set; }
  980. public ViewDetailsConfig SourceListConfig { get; set; }
  981. public ViewDetailsConfig LibraryListConfig { get; set; }
  982. public ViewDetailsConfig RadioListConfig { get; set; }
  983. public ViewDetailsConfig DiscListConfig { get; set; }
  984. public ViewDetailsConfig HistoryListConfig { get; set; }
  985. public ViewDetailsConfig QueueListConfig { get; set; }
  986. public ViewDetailsConfig YouTubeListConfig { get; set; }
  987. public ViewDetailsConfig SoundCloudListConfig { get; set; }
  988. public List<TrackData> LibraryTracks { get; set; }
  989. public List<TrackData> RadioTracks { get; set; }
  990. public List<TrackData> HistoryTracks { get; set; }
  991. public List<TrackData> QueueTracks { get; set; }
  992. public List<PlaylistData> Playlists { get; set; }
  993. public String OpenAddPolicy { get; set; }
  994. public String OpenPlayPolicy { get; set; }
  995. public String UpgradePolicy { get; set; }
  996. public String SearchPolicy { get; set; }
  997. public String ShowOSD { get; set; }
  998. public String MinimizeToTray { get; set; }
  999. public String ID { get; set; }
  1000. public String UpgradeCheck { get; set; }
  1001. public List<KeyboardShortcutProfile> ShortcutProfiles { get; set; }
  1002. public String CurrentShortcutProfile { get; set; }
  1003. public String OAuthToken { get; set; }
  1004. public String OAuthSecret { get; set; }
  1005. public String SubmitSongs { get; set; }
  1006. public String SubmitPlaylists { get; set; }
  1007. public String PauseWhenLocked { get; set; }
  1008. public String PauseWhenSongEnds { get; set; }
  1009. public List<CloudIdentity> CloudIdentities { get; set; }
  1010. #endregion
  1011. }
  1012. /// <summary>
  1013. /// Describes the data source of an item inside the ViewDetails list
  1014. /// </summary>
  1015. public class ViewDetailsItemData
  1016. {
  1017. #region Properties
  1018. /// <summary>
  1019. /// Gets or sets the index number of the item
  1020. /// </summary>
  1021. public int Number { get; set; }
  1022. /// <summary>
  1023. /// Gets or sets whether the item is marked as active or not
  1024. /// </summary>
  1025. public bool IsActive { get; set; }
  1026. /// <summary>
  1027. /// Gets or sets the icon of the item
  1028. /// </summary>
  1029. public string Icon { get; set; }
  1030. /// <summary>
  1031. /// Gets or sets whether the items should feature a strikethrough
  1032. /// </summary>
  1033. public bool Strike { get; set; }
  1034. #endregion
  1035. }
  1036. /// <summary>
  1037. /// Describes a configuration for the ViewDetails class
  1038. /// </summary>
  1039. public class ViewDetailsConfig
  1040. {
  1041. #region Properties
  1042. /// <summary>
  1043. /// Gets or sets the columns
  1044. /// </summary>
  1045. public ObservableCollection<ViewDetailsColumn> Columns { get; set; }
  1046. /// <summary>
  1047. /// Gets or sets the number column configuration
  1048. /// </summary>
  1049. public ViewDetailsColumn NumberColumn { get; set; }
  1050. /// <summary>
  1051. /// Gets or sets the indices of the selected items
  1052. /// </summary>
  1053. public List<int> SelectedIndices { get; set; }
  1054. /// <summary>
  1055. /// Gets or sets the the sort orders
  1056. /// Each sort is represented as a string on the format
  1057. /// "asc/dsc:ColumnName"
  1058. /// </summary>
  1059. public List<string> Sorts { get; set; }
  1060. /// <summary>
  1061. /// Gets or sets text used to filter the list
  1062. /// </summary>
  1063. public string Filter { get; set; }
  1064. /// <summary>
  1065. /// Gets or sets whether the number column should be enabled
  1066. /// </summary>
  1067. public bool HasNumber { get; set; }
  1068. /// <summary>
  1069. /// Gets or sets whether the number column should be visible
  1070. /// </summary>
  1071. public bool IsNumberVisible { get; set; }
  1072. /// <summary>
  1073. /// Gets or sets the position of the number column
  1074. /// </summary>
  1075. public int NumberIndex { get; set; }
  1076. /// <summary>
  1077. /// Gets or sets whether to display icons or not
  1078. /// </summary>
  1079. public bool UseIcons { get; set; }
  1080. /// <summary>
  1081. /// Gets or sets whether files can be dropped onto the list
  1082. /// </summary>
  1083. public bool AcceptFileDrops { get; set; }
  1084. /// <summary>
  1085. /// Gets or sets whether the list can be resorted via drag and drop
  1086. /// </summary>
  1087. public bool IsDragSortable { get; set; }
  1088. /// <summary>
  1089. /// Gets or sets whether the list can be resorted by clicking on a column
  1090. /// </summary>
  1091. public bool IsClickSortable { get; set; }
  1092. /// <summary>
  1093. /// Gets or sets whether only the number column can be used to sort the list
  1094. /// </summary>
  1095. public bool LockSortOnNumber { get; set; }
  1096. #endregion
  1097. }
  1098. /// <summary>
  1099. /// Represents a column of a details list
  1100. /// </summary>
  1101. public class ViewDetailsColumn
  1102. {
  1103. #region Properties
  1104. /// <summary>
  1105. /// Gets or sets the name of the column
  1106. /// </summary>
  1107. public string Name { get; set; }
  1108. /// <summary>
  1109. /// Gets or sets the displayed text
  1110. /// </summary>
  1111. public string Text { get; set; }
  1112. /// <summary>
  1113. /// Gets or sets the value to bind to
  1114. /// </summary>
  1115. public string Binding { get; set; }
  1116. /// <summary>
  1117. /// Gets or sets the value to sort on
  1118. /// </summary>
  1119. public string SortField { get; set; }
  1120. /// <summary>
  1121. /// Gets or sets whether the column is always visible
  1122. /// </summary>
  1123. public bool IsAlwaysVisible { get; set; }
  1124. /// <summary>
  1125. /// Gets or sets whether the column is sortable
  1126. /// </summary>
  1127. public bool IsSortable { get; set; }
  1128. /// <summary>
  1129. /// Gets or sets the width of the column
  1130. /// </summary>
  1131. public double Width { get; set; }
  1132. /// <summary>
  1133. /// Gets or sets whether the column is visible (only effective if IsAlwaysVisible is false)
  1134. /// </summary>
  1135. public bool IsVisible { get; set; }
  1136. /// <summary>
  1137. /// Gets or sets the text alignment of the displayed text
  1138. /// </summary>
  1139. public String Alignment { get; set; }
  1140. #endregion
  1141. }
  1142. /// <summary>
  1143. ///
  1144. /// </summary>
  1145. interface IMigrator
  1146. {
  1147. #region Constructor
  1148. /// <summary>
  1149. ///
  1150. /// </summary>
  1151. /// <param name="fromFile"></param>
  1152. /// <param name="toFile"></param>
  1153. void Migrate(String fromFile, String toFile);
  1154. #endregion
  1155. }
  1156. /// <summary>
  1157. ///
  1158. /// </summary>
  1159. public class Utility
  1160. {
  1161. #region Properties
  1162. /// <summary>
  1163. ///
  1164. /// </summary>
  1165. public string LogFile { get; set; }
  1166. /// <summary>
  1167. ///
  1168. /// </summary>
  1169. public LogMode Mode { get; set; }
  1170. /// <summary>
  1171. ///
  1172. /// </summary>
  1173. private DateTime InitTime { get; set; }
  1174. #endregion
  1175. #region Constructor
  1176. /// <summary>
  1177. ///
  1178. /// </summary>
  1179. public Utility()
  1180. {
  1181. LogFile = "Stoffi.log";
  1182. Mode = LogMode.Warning;
  1183. InitTime = DateTime.Now;
  1184. }
  1185. #endregion
  1186. #region Methods
  1187. #region Public
  1188. /// <summary>
  1189. ///
  1190. /// </summary>
  1191. /// <param name="mode"></param>
  1192. /// <param name="message"></param>
  1193. public void LogMessageToFile(LogMode mode, string message)
  1194. {
  1195. if (ModeToInt(mode) < ModeToInt(Mode)) return;
  1196. TimeSpan ts = (DateTime.Now - InitTime);
  1197. #if (!DEBUG)
  1198. System.IO.StreamWriter sw = System.IO.File.AppendText(LogFile);
  1199. #endif
  1200. try
  1201. {
  1202. string logLine = String.Format("{0} {1}:{2:00}:{3:00}.{4:000} ({5:G}) [{6}] {7}",
  1203. ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds, DateTime.Now, ModeToString(mode), message);
  1204. #if (!DEBUG)
  1205. sw.WriteLine(logLine);
  1206. #endif
  1207. if (Mode == LogMode.Debug)
  1208. Console.WriteLine(logLine);
  1209. }
  1210. finally
  1211. {
  1212. #if (!DEBUG)
  1213. sw.Close();
  1214. #endif
  1215. }
  1216. }
  1217. #endregion
  1218. #region Private
  1219. /// <summary>
  1220. ///
  1221. /// </summary>
  1222. /// <param name="mode"></param>
  1223. /// <returns></returns>
  1224. private int ModeToInt(LogMode mode)
  1225. {
  1226. if (mode == LogMode.Debug) return 1;
  1227. else if (mode == LogMode.Information) return 2;
  1228. else if (mode == LogMode.Warning) return 3;
  1229. else if (mode == LogMode.Error) return 4;
  1230. else return 0;
  1231. }
  1232. /// <summary>
  1233. ///
  1234. /// </summary>
  1235. /// <param name="mode"></param>
  1236. /// <returns></returns>
  1237. private string ModeToString(LogMode mode)
  1238. {
  1239. if (mode == LogMode.Debug) return "DEBUG";
  1240. else if (mode == LogMode.Information) return "INFO";
  1241. else if (mode == LogMode.Warning) return "OOPS";
  1242. else if (mode == LogMode.Error) return "SHIT";
  1243. else return "HUH?";
  1244. }
  1245. #endregion
  1246. #endregion
  1247. }
  1248. public enum LogMode
  1249. {
  1250. /// <summary>
  1251. ///
  1252. /// </summary>
  1253. Debug,
  1254. /// <summary>
  1255. ///
  1256. /// </summary>
  1257. Information,
  1258. /// <summary>
  1259. ///
  1260. /// </summary>
  1261. Warning,
  1262. /// <summary>
  1263. ///
  1264. /// </summary>
  1265. Error
  1266. }
  1267. /// <summary>
  1268. /// The type of a source
  1269. /// </summary>
  1270. public enum SourceType
  1271. {
  1272. /// <summary>
  1273. /// A single file
  1274. /// </summary>
  1275. File,
  1276. /// <summary>
  1277. /// A folder
  1278. /// </summary>
  1279. Folder,
  1280. /// <summary>
  1281. /// A Windows 7 Library
  1282. /// </summary>
  1283. Library
  1284. }
  1285. }