- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2009-8-25 13:35:00
|
显示全部楼层
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Xml.Serialization;
- using System.IO;
- using System.Collections;
- using Microsoft.Win32;
- using Autodesk.AutoCAD.DatabaseServices;
- namespace TlsCad.NetAutoLoad
- {
-     [Serializable]
-     public class Module
-     {
-         public string Name;
-         public string Location;
-         public bool Load;
-         public long Loadctrls;
-         public string Description;
-         private static List<string> _regApps;
-         public Module() { }
-         public Module(string name, string location, bool load,int loadctrls, string description)
-         {
-             Name = name;
-             Location = location;
-             Load = load;
-             Loadctrls = loadctrls;
-             Description = description;
-         }
-         public bool SearchForReg()
-         {
-             if (_regApps == null)
-             {
-                 RegistryKey appkey = GetAcAppKey(false);
-                 _regApps = new List<string>(appkey.GetSubKeyNames());
-                 appkey.Close();
-             }
-             return _regApps.Contains(Name);
-         }
-         public void RegApp()
-         {
-             RegistryKey appkey = GetAcAppKey(true);
-             RegistryKey rk = appkey.CreateSubKey(Name);
-             rk.SetValue("DESCRIPTION", Name, RegistryValueKind.String);
-             rk.SetValue("LOADCTRLS", Loadctrls, RegistryValueKind.DWord);
-             rk.SetValue("LOADER", Location, RegistryValueKind.String);
-             rk.SetValue("MANAGED", 1, RegistryValueKind.DWord);
-             appkey.Close();
-         }
-         private RegistryKey GetAcAppKey(bool writable)
-         {
-             RegistryKey ackey =
-                 Registry.CurrentUser.OpenSubKey(
-                     HostApplicationServices.Current.RegistryProductRootKey);
-             return ackey.OpenSubKey("Applications", writable);
-         }
-     }
-     public class ModuleCollection : ICollection
-     {
-         private List<Module> lst = new List<Module>();
-         public Module this[int id]
-         {
-             get { return (Module)lst[id]; }
-         }
-         public void Add(Module mod)
-         {
-             lst.Add(mod);
-         }
-         public void Remove(Module mod)
-         {
-             lst.Remove(mod);
-         }
-         public void WriteXml(string path)
-         {
-             try
-             {
-                 XmlSerializer xs = new XmlSerializer(typeof(ModuleCollection));
-                 StreamWriter sw = new StreamWriter(path);
-                 xs.Serialize(sw, this);
-                 sw.Close();
-             }
-             catch
-             { }
-         }
-         public void ReadXml(string path)
-         {
-             try
-             {
-                 XmlSerializer xs = new XmlSerializer(typeof(Module[]));
-                 StreamReader sr = new StreamReader(path);
-                 Module[] ps = ((Module[])xs.Deserialize(sr));
-                 sr.Close();
-                 for (int i = 0; i < ps.Length; Add(ps[i++])) ;
-             }
-             catch
-             { }
-         }
-         #region ICollection 成员
-         public void CopyTo(Array array, int index)
-         {
-             lst.CopyTo((Module[])array, index);
-         }
-         public int Count
-         {
-             get { return lst.Count; }
-         }
-         public bool IsSynchronized
-         {
-             get { return false; }
-         }
-         public object SyncRoot
-         {
-             get { return this; }
-         }
-         #endregion
-         #region IEnumerable 成员
-         public IEnumerator GetEnumerator()
-         {
-             return lst.GetEnumerator();
-         }
-         #endregion
-     }
- }
|
|