So far I have a bit of every bodies version that seems to be working.
Mick's idea seemed the easiest for me, but then I realized quite a few people start their acad from windows explorer.
So I have 2 dlls autoloading via the registry. The first one just checks for the most up to date version, and updates the file main dll if reqd. The second one is the main dll.
The keys are called startup and startup2. Startup2 fires after startup so the file replacement isn't a problem.
Not a lot of code really, below makes the Startup.dll. You need to netload it once to set the registry keys.
It's definately not as good as the other solutions offered. Thanks again for the help
using System.IO;
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using acadApp=Autodesk.AutoCAD.ApplicationServices.Application;
using Microsoft.Win32;
[assembly: ExtensionApplication(typeof(Autodesk.AutoCAD.AutoCAD_2010_plug_in1.MyPlugin))]
namespace Autodesk.AutoCAD.AutoCAD_2010_plug_in1
{
public class MyPlugin : IExtensionApplication
{
private static string startup = @"C:\Program Files\Autodesk\ACADM 2010\Support\LexStartup.dll";
private static string GetThangs = @"C:\Program Files\Autodesk\ACADM 2010\Support\GetThangs10.dll";
void IExtensionApplication.Initialize()
{
string Keypath = @"Software\Autodesk\AutoCAD\R18.0\ACAD-8005:409\Applications\LexStartup";
Document doc = acadApp.DocumentManager.MdiActiveDocument;
RegistryKey key = Registry.CurrentUser;
key = key.OpenSubKey(Keypath,true);
if (key == null)
{
key = Registry.CurrentUser;
key = key.CreateSubKey(Keypath);
key.SetValue("DESCRIPTION", (string)"LexStartup.dll autoload", RegistryValueKind.String);
key.SetValue("LOADCTRLS",2,RegistryValueKind.DWord);
key.SetValue("MANAGED", 1, RegistryValueKind.DWord);
key.SetValue("LOADER", startup, RegistryValueKind.String);
}
key.Close();
Keypath = @"Software\Autodesk\AutoCAD\R18.0\ACAD-8005:409\Applications\LexStartup2";
key = Registry.CurrentUser;
key = key.OpenSubKey(Keypath, true);
if (key == null)
{
key = Registry.CurrentUser;
key = key.CreateSubKey(Keypath);
key.SetValue("DESCRIPTION", (string)"GetThangs10.dll autoload", RegistryValueKind.String);
key.SetValue("LOADCTRLS", 2, RegistryValueKind.DWord);
key.SetValue("MANAGED", 1, RegistryValueKind.DWord);
key.SetValue("LOADER", GetThangs, RegistryValueKind.String);
}
key.Close();
CopyFile();
doc.Editor.WriteMessage("\nC# loading");
} //End Initialize
void IExtensionApplication.Terminate()
{
// Do plug-in application clean up here
}
public static void CopyFile()
{
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
string sMainfile=@"I:\0001 DesignPro\Menu\lexVba\C#\GetThangs10.dll";
if (!File.Exists(GetThangs))
{
File.Copy(sMainfile, GetThangs);
ed.WriteMessage("\nCopying file.");
return;
}
FileInfo fileInfo = new FileInfo(sMainfile);
DateTime date = fileInfo.LastWriteTime;
DateTime dateCopy = File.GetLastWriteTime(GetThangs);
if (fileInfo.Exists)
{
if (((double)(date - dateCopy).Seconds) > 15.0)
{
ed.WriteMessage("\nUpdating file.");
File.Copy(sMainfile, GetThangs, true);
}
}
} //End CopyFile
}//End MyPlugin
}