private void btnInstall_Click(object sender, EventArgs e) { if (cbAgree.Checked) { //try //{ if (AcadProductManager.GetProduct() == null) { MessageBox.Show("未检测到 AutoCAD 2010。无法安装本程序。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { SetupManager.Start(SetupManager.BuildSetupConfig(txtPath.Text)); MessageBox.Show("安装成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } //} //catch //{ // MessageBox.Show("安装程序遇到问题。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //} btnInstall.Enabled = false; btnExit.Focus(); btnExit.Click -= btnExit_Click; btnExit.Click += (s, args) => Application.Exit(); } else { MessageBox.Show("必须同意安装协议才能安装本软件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static SetupConfig BuildSetupConfig(string path) { SetupConfig config = new SetupConfig(); AcadProduct product = AcadProductManager.GetProduct(); _xmlConfig.Element("Folders").Elements().ToList().ForEach(x => { config.SourceAndTargetFolders.Add(x.AttValue("Source"), string.Format(x.AttValue("Target"), path, product.Path)); }); _xmlConfig.Element("Desktop").Elements().ToList().ForEach(x => { Shortcut sc = new Shortcut(x.AttValue("Name"), GetDesktop(), string.Format(x.AttValue("Target"), path)) { Description = x.AttValue("Description"), Args = x.AttValue("Args"), Icon = x.AttValue("Icon") }; config.DesktopShortcuts.Add(sc); }); _xmlConfig.Element("StartMenu").Elements().ToList().ForEach(x => { string programStartMenu = GetStartMenu() + "\\" + x.AttValue("Folder"); if (!System.IO.Directory.Exists(programStartMenu)) { System.IO.Directory.CreateDirectory(programStartMenu); } Shortcut sc = new Shortcut(x.AttValue("Name"), programStartMenu, string.Format(x.AttValue("Target"), path)) { Description = x.AttValue("Description"), Args = x.AttValue("Args"), Icon = x.AttValue("Icon") }; config.StartMenuShortcuts.Add(sc); }); return(config); }