load and save the 2548:1002 config for XBMC too. try to create the profile directory...
authorLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 12:12:45 +0000 (14:12 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Sat, 6 Oct 2012 12:12:45 +0000 (14:12 +0200)
src/LibCecTray/Properties/Resources.Designer.cs
src/LibCecTray/Properties/Resources.resx
src/LibCecTray/controller/CECController.cs
src/LibCecTray/controller/applications/internal/XBMCController.cs
src/LibCecTray/ui/CECTray.cs

index 817b21e928d75c0fa37f77b11725a516a215b1e8..ecf2b61c24458a6772202998df77a982629857d9 100644 (file)
@@ -465,6 +465,15 @@ namespace LibCECTray.Properties {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Couldn&apos;t create directory &apos;{0}&apos;.
+        /// </summary>
+        internal static string could_not_create_directory {
+            get {
+                return ResourceManager.GetString("could_not_create_directory", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to AVR.
         /// </summary>
@@ -546,6 +555,15 @@ namespace LibCECTray.Properties {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Error.
+        /// </summary>
+        internal static string error {
+            get {
+                return ResourceManager.GetString("error", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Executables (*.exe)|*.exe|All files (*.*)|*.*.
         /// </summary>
index 8ff31f655b5ff8e7b388f37c480844df62a15fd1..31cab95f6c7e4f068e31126d224feeb437bea2d2 100644 (file)
   <data name="app_standby_screensaver" xml:space="preserve">
     <value>Put devices in standby mode when activating screensaver</value>
   </data>
+  <data name="could_not_create_directory" xml:space="preserve">
+    <value>Couldn't create directory '{0}'</value>
+  </data>
+  <data name="error" xml:space="preserve">
+    <value>Error</value>
+  </data>
 </root>
\ No newline at end of file
index f7a3a04fb37dec7777e6c2ce78cbc6d58247817c..13d75201cbdd644a7e63c9834ff87f7488da40fc 100644 (file)
@@ -490,6 +490,20 @@ namespace LibCECTray.controller
       get { return Lib.ToString(Config.ClientVersion); }
     }
 
+    /// <summary>
+    /// Get the usb vid:prod descriptor
+    /// </summary>
+    public string USBDescriptor
+    {
+      get
+      {
+        DateTime checkDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
+        checkDate = checkDate.AddSeconds(0x5045dbf5);
+
+        return string.Format("2548:100{0}", ((DateTime)Config.FirmwareBuildDate >= checkDate ? "2" : "1"));
+      }
+    }
+
     /// <summary>
     /// libCEC
     /// </summary>
index 9e4fb3a1973d717351d04993bb8cc145a4d4b212..5ffe8f9ec88c15d3968d48bec1354d471dd4115b 100644 (file)
@@ -70,16 +70,16 @@ 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 + @"\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 +203,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}.xml", Program.Instance.Controller.USBDescriptor.Replace(':', '_')),
         Filter = Resources.xml_file_filter,
         FilterIndex = 1
       };
index a44cd8ac155e936ea2ea0d1b46b60ab79b49b364..e8dd66b584b8817ad6e5b505d455b17269c81602 100644 (file)
@@ -491,6 +491,10 @@ namespace LibCECTray.ui
     private ConfigTab _selectedTab = ConfigTab.Configuration;
     private string _log = string.Empty;
     private readonly CECController _controller;
+    public CECController Controller
+    {
+      get { return _controller; }
+    }
     public Control.ControlCollection TabControls
     {
       get { return tabPanel.Controls; }