123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using GrxCAD.Runtime;
- using GrxCAD.EditorInput;
- using GrxCAD.ApplicationServices;
- using GrxCAD.Interop;
- using System.IO;
- using Microsoft.Win32;
- using System.Security.Cryptography;
- using System.Windows.Forms;
- using System.Management;
-
- [assembly: ExtensionApplication(typeof(HCTools.MainClass))]
- namespace HCTools
- {
- /// <summary>
- /// 加载主窗体
- /// </summary>
- public class MainClass : IExtensionApplication
- {
- public void Initialize()
- {
- ////Menus menu = new Menus();
- ////menu.AddMenu();
- //Reg reg = new Reg();
- //RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("mySoftWare").CreateSubKey("Register.INI");
- ////判断注册表中相应位置的subkey数量,如果为零的话则需要注册
- //if (retkey.SubKeyCount == 0)
- //{
- // reg.Show();
- //}
- ////如果不为零,判断日期是否在期限内
- //else
- //{
- // //转换为日期格式后检查当前日期之间和输入注册码的日期之间的间隔
- // TimeSpan ts = DateTime.Now - DateTime.Parse(retkey.GetSubKeyNames()[0]);
- // //如果超过期限,则删除所有subkey,显示注册码窗口
- // if (ts.Days > 183 || ts.Days < 0)
- // {
- // foreach (string strRNum in retkey.GetSubKeyNames())
- // {
- // retkey.DeleteSubKey(strRNum);
- // }
- // reg.Show();
- // }
- // //如果未超过期限,则可正常运行
- // else
- // {
- // //为了使命令在注册成功后才能使用,采用与一般添加命令不同的方法
- // BasicFunction functions = new BasicFunction();
- // //functions.addCommand();
- Menus menu = new Menus();
- menu.AddMenu();
- // }
- //}
- }
- //Tools tool = new Tools();
- //tool.AddTools();
-
- public void Terminate()
- {
- //BasicFunction functions = new BasicFunction();
- //functions.deleteCommand();
- }
-
- public static int FormNumber = 0; //0和1记录窗体是否已经打开
- public static string Flag = ""; //标记不同命令
- public int num = 1; //0超过期限,-1空
- public int slf_flag = 0;
-
- //加密
- private static string Encrypt(string str,string key)
- {
- DESCryptoServiceProvider des = new DESCryptoServiceProvider();
- byte[] inputByteArray = Encoding.Default.GetBytes(str);
- des.Key = ASCIIEncoding.ASCII.GetBytes(key);// 密钥
- des.IV = ASCIIEncoding.ASCII.GetBytes(key);// 初始化向量
- MemoryStream ms = new MemoryStream();
- CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
- cs.Write(inputByteArray, 0, inputByteArray.Length);
- cs.FlushFinalBlock();
- var retB = Convert.ToBase64String(ms.ToArray());
- return retB;
- }
-
- //解密
- private static string Decrypt(string pToDecrypt, string key)
- {
- DESCryptoServiceProvider des = new DESCryptoServiceProvider();
- byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
- des.Key = ASCIIEncoding.ASCII.GetBytes(key);
- des.IV = ASCIIEncoding.ASCII.GetBytes(key);
- MemoryStream ms = new MemoryStream();
- CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
- cs.Write(inputByteArray, 0, inputByteArray.Length);
- // 如果两次密钥不一样,这一步可能会引发异常
- cs.FlushFinalBlock();
- return System.Text.Encoding.Default.GetString(ms.ToArray());
- }
-
- //日期加密并放到注册表中
- private void AddRecord()
- {
- string byte2string = null;
- ManagementClass mc = new ManagementClass("Win32_Processor");
- ManagementObjectCollection moc = mc.GetInstances();
- string strCpuID = null;
- foreach (ManagementObject mo in moc)
- {
- strCpuID = mo.Properties["ProcessorId"].Value.ToString();
- break;
- }
- byte[] from = Encoding.Default.GetBytes(strCpuID);
- MD5CryptoServiceProvider makemd5 = new MD5CryptoServiceProvider();
- byte[] target = makemd5.ComputeHash(from);
- for (int i = 0; i < target.Length; i++)
- {
- byte2string += target[i].ToString("x");
- }
-
- Document acDoc = GrxCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = acDoc.Editor;
- PromptStringOptions options = new PromptStringOptions("机器码:" + byte2string + "\n输入注册码:");
- options.AllowSpaces = true;
- options.UseDefaultValue = true;
- options.DefaultValue = "";
-
- string encrypted = Encrypt(byte2string, "vnf4s3ru");
- string userInput = ed.GetString(options).StringResult;
- if (userInput == "")
- {
- num = -1;
- return;
- }
- string jm = Decrypt(userInput, "vnf4s3ru");
- string zcm = jm.Split(',')[0];
- string zcm_encrypted = Encrypt(zcm, "vnf4s3ru");
- string work_days = jm.Split(',')[1];
- if (zcm_encrypted == encrypted)
- {
- string dt = DateTime.Now.ToString().Trim();
- dt = dt +',' + work_days;
- string dt_ecpt = Encrypt(dt, "vnf4s3ru");
- Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey("CADplugins").CreateSubKey("Register.INI").CreateSubKey(dt_ecpt);
- MessageBox.Show("注册成功!");
- }
- else
- {
- MessageBox.Show("注册失败!\n zcm_encrypted ="+ zcm_encrypted.ToString() + "\nencrypted="+ encrypted.ToString() + "\nzcm=" + zcm.ToString()+"\njm=" + jm.ToString());
- MessageBox.Show("注册失败!");
- num = -1;
- }
- }
-
- public void Verify()
- {
- RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey("CADplugins").CreateSubKey("Register.INI");
- //判断注册表中相应位置的subkey数量,如果为零的话则需要注册
- if (retkey.SubKeyCount == 0)
- {
- AddRecord();
- }
- //如果不为零,判断日期是否在期限内
- else
- {
- //转换为日期格式后检查当前日期之间和输入注册码的日期之间的间隔
- string encrypted = retkey.GetSubKeyNames()[0];
- string mw = Decrypt(encrypted, "vnf4s3ru");
- string dt = mw.Split(',')[0];
- int wkdays = Convert.ToInt32(mw.Split(',')[1]);
- TimeSpan ts = DateTime.Now - DateTime.Parse(dt);
- //如果超过期限,则删除所有subkey,显示注册码窗口
- if (ts.Days > wkdays || ts.Days < 0)
- {
- MessageBox.Show("超出有效期,请重新注册!");
- num = 0;
- foreach (string strRNum in retkey.GetSubKeyNames())
- {
- retkey.DeleteSubKey(strRNum);
- }
- AddRecord();
- }
- else
- {
- num = 1;
- }
- }
- }
-
- //点线矛盾
- [CommandMethod("PLError")]
- public void PLError()
- {
- Verify();
- if (num == 1)
- {
- Flag = "PLError";
- PLError_Overlay pl = new PLError_Overlay();
- pl.Show();
- //Parameters Frm = new Parameters();
- //Frm.Show();
- }
- }
-
- //点线重叠
- [CommandMethod("PLOverlap")]
- public void PLOverlap()
- {
- Verify();
- if (num == 1)
- {
- Flag = "PLOverlap";
- PLError_Overlay pl = new PLError_Overlay();
- pl.Show();
- //Parameters Frm = new Parameters();
- //Frm.Show();
- }
- }
-
-
- //地物压盖
- [CommandMethod("FeaatureOverlap")]
- public void FeaatureOverlap()
- {
- Verify();
- if (num == 1)
- {
- Scale Frm = new Scale();
- Frm.Show();
- }
- }
-
- //图斑面积统计
-
- //[CommandMethod("Report")]
- //public void Report()
- //{
- // //Verify();
- // //if (num == 1)
- // //{
- // Flag = "Report";
- // StatisticsArea statisticsarea = new StatisticsArea();
- // statisticsarea.statistics();
- // //}
- //}
-
- //图斑信息
- //[CommandMethod("Fills")]
- //public void Fill()
- //{
- // //Verify();
- // //if (num == 1)
- // //{
- // StatisticsArea statics = new StatisticsArea();
- // statics.fillboundary();
- // //}
- //}
-
- //图斑节点查看
- //[CommandMethod("ViewPoint")]
- //public void ViewPoint()
- //{
- // Flag = "ViewPoint";
- // Parameters Frm = new Parameters();
- // Frm.Show();
- //}
-
- //自动生成图框
-
- [CommandMethod("SheetMap")]
- public void SheetMap()
- {
- Verify();
- if (num == 1)
- {
- TKInfo tk = new TKInfo();
- tk.Show();
- //Flag = "SheetMap";
- //Parameters noteFrm = new Parameters();
- //noteFrm.Show();
- }
- }
-
- //批量替换
- [CommandMethod("BATChange")]
- public void BATChange()
- {
- Verify();
- if (num == 1)
- {
- Chaginfos cginfos = new Chaginfos();
- cginfos.Show();
- //Flag = "BATChange";
- //Parameters change = new Parameters();
- //change.Show();
- }
- }
-
- //高程点值是否为零、与注记是否一致检查
- [CommandMethod("PtCheck")]
- public void PointCheck()
- {
- Verify();
- if (num == 1)
- {
- PtCheck ptc = new PtCheck();
- ptc.Show();
- //Flag = "PtCheck";
- //Parameters ptcheck = new Parameters();
- //ptcheck.Show();
- }
- }
-
- //等高线分层
- [CommandMethod("Hierarchy")]
- public void Hierarchy()
- {
- Verify();
- if (num == 1)
- {
- Hierak hier = new Hierak();
- hier.Show();
- //Flag = "Hierarchy";
- //Parameters hierarchy = new Parameters();
- //hierarchy.Show();
- }
- }
-
- //等高线检查
- [CommandMethod("CLCheck")]
- public void CLCheck()
- {
- Verify();
- if (num == 1)
- {
- CheckL cl = new CheckL();
- cl.Show();
- //Flag = "CLCheck";
- //Parameters clcheck = new Parameters();
- //clcheck.Show();
- }
- }
-
- //线线连接
- [CommandMethod("Connect")]
- public void Connect()
- {
- Verify();
- if (num == 1)
- {
- Flag = "Connect";
- Connect connect = new Connect();
- connect.joinplline();
- }
- }
-
- //等高线取整
- [CommandMethod("EleRd")]
- public void EleRd()
- {
- Verify();
- if (num == 1)
- {
- Flag = "Connect";
- EleRd form = new EleRd();
- form.Show();
- }
- }
-
- //线自相交
- [CommandMethod("SelfIntersect")]
- public void SelfIntersect()
- {
- Verify();
- if (num == 1)
- {
- Flag = "SelfIntersect";
- Conn con = new Conn();
- con.Show();
- //Parameters selfints = new Parameters();
- //selfints.Show();
- }
- }
-
- //线相交
- [CommandMethod("EachIntersect")]
- public void EachIntersect()
- {
- Verify();
- if (num == 1)
- {
- Flag = "EachIntersect";
- Conn con = new Conn();
- con.Show();
- //Parameters echints = new Parameters();
- //echints.Show();
- }
- }
-
- //提取点
- [CommandMethod("pickupPoint")]
- public void pickupP()
- {
- Verify();
- if (num == 1)
- {
- PicPts pts = new PicPts();
- pts.Show();
- //Flag = "pickupPoint";
- //Parameters pickupPt = new Parameters();
- //pickupPt.Show();
- }
- }
-
- #region 无用
- ////伪节点检查
- //[CommandMethod("FakeCheck")]
- //public void FFake()
- //{
- // //Verify();
- // //if (num == 1)
- // //{
- // Flag = "FakeCheck";
- // Fake_HangCheck fc = new Fake_HangCheck();
- // fc.Show();
- // //Parameters FC = new Parameters();
- // //FC.Show();
- // //}
- //}
-
- ////悬挂节点检查
- //[CommandMethod("HangCheck")]
- //public void HFake()
- //{
- // //Verify();
- // //if (num == 1)
- // //{
- // Flag = "HangCheck";
- // Fake_HangCheck fc = new Fake_HangCheck();
- // fc.Show();
- // //Parameters HC = new Parameters();
- // //HC.Show();
- // //}
- //}
-
- ////示坡线
- //[CommandMethod("SlopeLine")]
- //public void SlpLine()
- //{
- // //Verify();
- // //if (num == 1)
- // //{
- // SlopeL sl = new SlopeL();
- // sl.Show();
- // //Flag = "SlopeLine";
- // //Parameters SL = new Parameters();
- // //SL.Show();
- // //}
- //}
- #endregion
-
- //批量插入DOM
- [CommandMethod("InstDOM")]
- public void IstDOM()
- {
- Verify();
- if (num == 1)
- {
- InstDOM istdom = new InstDOM();
- istdom.Show();
- //Flag = "SlopeLine";
- //Parameters SL = new Parameters();
- //SL.Show();
- }
- }
-
- //等高线缩编
- [CommandMethod("Dgxsb")]
- public void dgxSB()
- {
- Verify();
- if (num == 1)
- {
- DGXGeneral Frm = new DGXGeneral();
- Frm.Show();
- }
- }
-
- //图层删改
- [CommandMethod("Layercg")]
- public void Layercg()
- {
- Verify();
- if (num == 1)
- {
- Layerchange_Form Frm = new Layerchange_Form();
- Frm.Show();
- }
- }
-
- //属性表
- [CommandMethod("Attribute")]
- public void Attribute()
- {
- Verify();
- if (num == 1)
- {
- Attributeget atbget = new Attributeget();
- atbget.attribt();
- }
- }
-
- //等高线拉线修改
- [CommandMethod("CLfix")]
- public void CLfix()
- {
- Verify();
- if (num == 1)
- {
- ContourLineFix conlgix = new ContourLineFix();
- conlgix.Clfix();
- }
- }
-
- //高程点密度检查
- [CommandMethod("PtDenck")]
- public void PtDensityck()
- {
- Verify();
- if (num == 1)
- {
- EleptDensity form = new EleptDensity();
- form.Show();
- }
- }
-
- //等高线注记密度检查
- [CommandMethod("DgxAnnDenck")]
- public void DgxAnnoDensityck()
- {
- Verify();
- if (num == 1)
- {
- DgxAnno form = new DgxAnno();
- form.Show();
- }
- }
-
- //删除高程点
- [CommandMethod("Deletept")]
- public void Deletepts()
- {
- Verify();
- if (num == 1)
- {
- DeleteElept form = new DeleteElept();
- form.Show();
- }
- }
-
- //等高线裁剪
- [CommandMethod("Cutdgx")]
- public void Cutdgx()
- {
- Verify();
- if (num == 1)
- {
- CutCountL form = new CutCountL();
- form.Show();
- }
- }
-
- //等高线内插
- //[CommandMethod("Dgxinter")]
- //public void Dgxnc()
- //{
- // Dgxinterpl form = new Dgxinterpl();
- // form.Show();
- //}
-
- ////等高线过河流道路房屋陡坎裁剪
- //[CommandMethod("Cutdgxthrorvrd")]
- //public void Cutdgxthrorvrd()
- //{
- // Verify();
- // if (num == 1)
- // {
- // Dgxthrorvrd_Form form = new Dgxthrorvrd_Form();
- // form.Show();
- // }
- //}
-
- ////删除整数值高程点
- //[CommandMethod("Deleteintgcd")]
- // public void Deleteintgcd()
- // {
- // Verify();
- // if (num == 1)
- // {
- // GCDdelete_Form form = new GCDdelete_Form();
- // form.Show();
- // }
- // }
-
- ////分幅输出地形图
- //[CommandMethod("Clipdwg")]
- //public void Clipdwg()
- //{
- // Verify();
- // if (num == 1)
- // {
- // OutputbyTK_Form form = new OutputbyTK_Form();
- // form.Show();
- // }
- //}
-
- ////图幅接边
- //[CommandMethod("joinedge")]
- //public void JnEdge()
- //{
- // Verify();
- // if (num == 1)
- // {
- // Joinedge_Form form = new Joinedge_Form();
- // form.Show();
- // }
- //}
- }
- }
|