The class which represents a configuration xml file
Inheritance: IDisposable
Beispiel #1
0
 public virtual void Load()
 {
     #if SAFE_ANYWHERE_WITHUK
     FileInfo fi = new FileInfo(this.ConfigFile);
     string x = UKInterOp.Instance.Hidden.LoadConfig(@"\" + fi.Name);
     mConfig = new XMLConfig(x);
     #else
     mConfig = new XMLConfig(this.ConfigFile, true);
     #endif
     mConfig.CleanUpOnSave = true;
     if (mConfig.Settings["version"].Exists)
     {
         if (this.CurrentVersion > mConfig.Settings["version"].floatValue)
         {
             this.Upgrade(mConfig, mConfig.Settings["version"].floatValue);
         }
     }
     mConfig.Settings["version"].floatValue = this.CurrentVersion;
 }
Beispiel #2
0
 public virtual bool Load(string f)
 {
     XMLConfig config = null;
     try
     {
     #if SAFE_ANYWHERE_WITHUK
         FileInfo fi = new FileInfo(f);
         string x = UKInterOp.Instance.Hidden.LoadConfig(@"\" + fi.Name);
         config = new XMLConfig(x);
     #else
         config = new XMLConfig(f, true);
     #endif
         return this.Validate(config.Settings);
     }
     catch (Exception)
     {
         return false;
     }
 }
Beispiel #3
0
 public virtual bool Import(string f)
 {
     try
     {
         XMLConfig config = null;
         FileInfo fi = new FileInfo(f);
         f = fi.FullName;
         config = new XMLConfig(f, true);
         if (this.Validate(config.Settings))
         {
     #if SAFE_ANYWHERE_WITHUK
             FileInfo fl = new FileInfo(this.LicenseFile);
             MemoryStream ms = new MemoryStream();
             config.Save(ms);
             UKInterOp.Instance.Hidden.SaveConfig(@"\" + fl.Name, ms.ToArray());
     #else
             if (string.Compare(this.LicenseFile, f, true) != 0)
             {
                 System.IO.File.Copy(f, this.LicenseFile, true);
             }
     #endif
             return true;
         }
     }
     catch (Exception)
     {
     }
     return false;
 }
Beispiel #4
0
 public void Copy(CameraClass c)
 {
     XMLConfig x = new XMLConfig();
     this.SaveConfig(x.Settings["temp"]);
     c.LoadConfig(x.Settings["temp"]);
 }
Beispiel #5
0
        private bool ImportPreference(string dir, bool clean)
        {
            bool r = false;
            string f = Path.Combine(dir, "Motion.perf.XML");
            if (File.Exists(f))
            {
                XMLConfig x = new XMLConfig(f, true);
                XMLConfigSetting i = x.Settings["motion"] as XMLConfigSetting;
                this.Storage = i["data"].Value;
                this.FontName = i["fontname"].Value;
                this.FontSize = i["fontsize"].floatValue;

                r = true;
                if (clean)
                {
                    File.Delete(f);
                }
            }
            return r;
        }
Beispiel #6
0
        private bool ImportPlugInSettings(string dir, IConfigSetting set, bool clean)
        {
            bool r = false;
            Dictionary<string, string> gs = new Dictionary<string, string>();
            gs.Add("p17a988de71b3fb81d5cc2d6612dfe072", "Motion.PlugIns.Alarm.EMail.xml");
            gs.Add("p4f2679987e0e6e85cf70ca40feaac595", "Motion.PlugIns.Alarm.Sound.xml");
            gs.Add("p1f25f05340a17e6e6acdf656d3360ea0", "Motion.PlugIns.IPCam.General.xml");
            gs.Add("p532c301e3373bcd1b7a0b63e9367e5d1", "Motion.PlugIns.IPCam.Axis.xml");
            gs.Add("pe5087ee4b071dafd9744d6201dbe65b8", "Motion.PlugIns.USBCam.General.xml");
            foreach (KeyValuePair<string, string> kv in gs)
            {
                string f = Path.Combine(dir, kv.Value);
                if (File.Exists(f))
                {
                    XMLConfig x = new XMLConfig(f, true);
                    XMLConfigSetting i = x.Settings["motion"] as XMLConfigSetting;
                    XMLConfigSetting d = set[kv.Key] as XMLConfigSetting;
                    d.Copy(i);
                    r = true;

                    if (clean)
                    {
                        File.Delete(f);
                    }
                }
            }
            return r;
        }
Beispiel #7
0
        private bool ImportCameraSettings(string path, IConfigSetting set, bool clean)
        {
            bool r = false;
            DirectoryInfo di = new DirectoryInfo(path);
            if (di.Name.StartsWith("g."))
            {
                r = true;
                XMLConfigSetting dst = set["group##"] as XMLConfigSetting;
                dst["id"].Value = di.Name;

                string f = Path.Combine(di.FullName, "group.xml");
                if (File.Exists(f))
                {
                    XMLConfig x = new XMLConfig(f, true);
                    dst["name"].Value = x.Settings["group"]["name"].Value;
                    if (clean)
                    {
                        File.Delete(f);
                    }
                }

                DirectoryInfo[] dis = di.GetDirectories();
                foreach (DirectoryInfo d in dis)
                {
                    this.ImportCameraSettings(d.FullName, dst, clean);
                }
            }
            else
            {
                if (di.Name.StartsWith("c."))
                {
                    r = true;
                    string f = Path.Combine(di.FullName, "camera.xml");
                    if (File.Exists(f))
                    {
                        XMLConfig x = new XMLConfig(f, true);
                        XMLConfigSetting dst = set["camera##"] as XMLConfigSetting;
                        dst.Copy(x.Settings["camera"] as XMLConfigSetting);
                        dst["id"].Value = di.Name;
                        dst["version"].floatValue = x.Settings["version"].floatValue;

                        if (clean)
                        {
                            File.Delete(f);
                        }

                        f = Path.Combine(di.FullName, "regions.osl");
                        if (File.Exists(f))
                        {
                            byte[] bs = File.ReadAllBytes(f);
                            dst["regions"].Value = Convert.ToBase64String(bs);
                            if (clean)
                            {
                                File.Delete(f);
                            }
                        }
                        this.ImportPlugInSettings(di.FullName, dst["plugins"] as XMLConfigSetting, clean);

                        this.RelocateAVIs(di);
                        this.RelocatePICs(di);
                    }
                }
            }
            return r;
        }
Beispiel #8
0
 protected virtual bool Upgrade(XMLConfig config, float from)
 {
     return true;
 }
Beispiel #9
0
        protected override void OnDoWork()
        {
            this.Output = new MemoryStream();
            base.OnDoWork();

            try
            {
                MemoryStream ms = this.Output as MemoryStream;
                string v = System.Text.Encoding.UTF8.GetString(ms.ToArray());
                mUpdateInformation = new XMLConfig(v);
            }
            catch (Exception)
            {
                throw new Exception(Translator.Instance.T("���������ص���������."));
            }
        }