save the correct xml file in LibCecTray, so XBMC picks up the correct config
authorLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 15:55:23 +0000 (17:55 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 15:58:28 +0000 (17:58 +0200)
src/LibCecTray/controller/CECController.cs
src/LibCecTray/controller/applications/internal/XBMCController.cs

index f7a3a04fb37dec7777e6c2ce78cbc6d58247817c..f81cd94181379d9f1dc9e70edb8648220f91ec4b 100644 (file)
@@ -490,6 +490,23 @@ namespace LibCECTray.controller
       get { return Lib.ToString(Config.ClientVersion); }
     }
 
+    /// <summary>
+    /// Get the usb vendor id
+    /// </summary>
+    public ushort AdapterVendorId
+    {
+      get { return Lib.GetAdapterVendorId(); }
+    }
+
+    /// <summary>
+    /// Get the usb product id
+    /// </summary>
+    public ushort AdapterProductId
+    {
+      get { return Lib.GetAdapterProductId(); }
+    }
+
+
     /// <summary>
     /// libCEC
     /// </summary>
index 9e4fb3a1973d717351d04993bb8cc145a4d4b212..5ab82833d8079e17a3d071e803aacba0347f0cce 100644 (file)
@@ -70,16 +70,18 @@ namespace LibCECTray.controller.applications.@internal
 
     public bool LoadXMLConfiguration()
     {
-      bool gotConfig = false;
-      string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
-      string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
-      string file = defaultDir + @"\usb_2548_1001.xml";
-      if (File.Exists(xbmcDir + @"\usb_2548_1001.xml"))
-        file = xbmcDir + @"\usb_2548_1001.xml";
+      var xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
+      return LoadXMLConfiguration(xbmcDir + string.Format(@"\usb_{0:X}_{1:X}.xml", Program.Instance.Controller.AdapterVendorId, Program.Instance.Controller.AdapterProductId)) ||
+             LoadXMLConfiguration(xbmcDir + @"\usb_2548_1001.xml") ||
+             LoadXMLConfiguration(xbmcDir + @"\usb_2548_1002.xml");
+    }
 
-      if (File.Exists(file))
+    public bool LoadXMLConfiguration(string filename)
+    {
+      bool gotConfig = false;
+      if (File.Exists(filename))
       {
-        XmlTextReader reader = new XmlTextReader(file);
+        XmlTextReader reader = new XmlTextReader(filename);
         while (reader.Read())
         {
           gotConfig = true;
@@ -203,14 +205,23 @@ namespace LibCECTray.controller.applications.@internal
     {
       Settings.Persist();
 
-      string xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
-      string defaultDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+      var xbmcDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\XBMC\userdata\peripheral_data";
+      if (!Directory.Exists(xbmcDir))
+        Directory.CreateDirectory(xbmcDir);
+
+      if (!Directory.Exists(xbmcDir))
+      {
+        // couldn't create directory
+        MessageBox.Show(string.Format(Resources.could_not_create_directory, xbmcDir), Resources.error,
+                        MessageBoxButtons.OK, MessageBoxIcon.Error);
+        return;
+      }
 
       SaveFileDialog dialog = new SaveFileDialog
-                                {
+      {
         Title = Resources.store_settings_where,
-        InitialDirectory = Directory.Exists(xbmcDir) ? xbmcDir : defaultDir,
-        FileName = "usb_2548_1001.xml",
+        InitialDirectory = xbmcDir,
+        FileName = string.Format("usb_{0:X}_{1:X}.xml", Program.Instance.Controller.AdapterVendorId, Program.Instance.Controller.AdapterProductId),
         Filter = Resources.xml_file_filter,
         FilterIndex = 1
       };