using System.IO;
using System.Linq;
using System.Windows.Forms;
using Microsoft.Win32;
namespace LayLockSel_Install
{
class Program
{
static void Main()
{
try
{
// Check if 'LayLockSel.dll is in the same folder
string filename = Application.StartupPath + "\\LayLockSel.dll";
if (!File.Exists(filename))
{
MessageBox.Show("Can't find 'LayLockSel.dll' file", "LAYLOCKSEL");
return;
}
// Get AutoCAD product key path
RegistryKey hive = Registry.CurrentUser;
string prodk = @"Software\Autodesk\AutoCAD\";
string ver = (string)hive.OpenSubKey(prodk).GetValue("CurVer");
if (ver.CompareTo("18.1") < 0)
{
MessageBox.Show("AutoCAD current version is prior to 2011", "LAYLOCKSEL");
return;
}
prodk += "\\" + ver;
prodk += "\\" + hive.OpenSubKey(prodk).GetValue("CurVer");
hive = Registry.LocalMachine;
using (RegistryKey ack = hive.OpenSubKey(prodk, true))
{
// Create the sysvar definition key
using (RegistryKey vark = ack.OpenSubKey("Variables", true))
{
if (vark.GetSubKeyNames().Contains("LAYLOCKSEL"))
{
MessageBox.Show("LAYLOCKSEL is already installed", "LAYLOCKSEL");
return;
}
else
{
using (RegistryKey rk = vark.CreateSubKey("LAYLOCKSEL"))
{
rk.SetValue("", 0, RegistryValueKind.String);
rk.SetValue("LowerBound", 0, RegistryValueKind.DWord);
rk.SetValue("PrimaryType", 5003, RegistryValueKind.DWord);
rk.SetValue("StorageType", 1, RegistryValueKind.DWord);
rk.SetValue("UpperBound", 1, RegistryValueKind.DWord);
}
}
}
// Create the autoload key
using (RegistryKey appk = ack.OpenSubKey("Applications", true))
{
if (!appk.GetSubKeyNames().Contains("LAYLOCKSEL"))
using (RegistryKey rk = appk.CreateSubKey("LAYLOCKSEL"))
{
rk.SetValue("DESCRIPTION", " LAYLOCKSEL System Variable", RegistryValueKind.String);
rk.SetValue("LOADCTRLS", 2, RegistryValueKind.DWord);
rk.SetValue("LOADER", filename, RegistryValueKind.String);
rk.SetValue("MANAGED", 1, RegistryValueKind.DWord);
}
}
}
MessageBox.Show("Installation succeded", "LAYLOCKSEL");
}
catch (System.Exception ex)
{
MessageBox.Show("Installation failed\n" + ex.Message, "LAYLOCKSEL");
}
}
}
}