Author Topic: Autoloader does not load my dll  (Read 313 times)

0 Members and 1 Guest are viewing this topic.

AngelKostadinov

  • Newt
  • Posts: 30
Autoloader does not load my dll
« on: January 10, 2017, 11:05:31 am »
Hello,

I use Autodesk Autoloader http://adndevblog.typepad.com/autocad/2013/01/autodesk-autoloader-white-paper.html in order to deploy my extention application.
I put myApp.dll and PackageContents.xml files into ProgramFiles/Autodesk/ApplicationPlugins/MyApp.bundle folder. The structure of the xml file is carefully taken from Autoloader White Paper and ModuleName attribute points directly to my dll file:
Code: [Select]
ModuleName="myApp.dll"When AutoCAD starts, it loads my dll automatically, cool!

Now I have to introduce "autoupdater" functionality and that what I'm doing is on AutoCAD startup, to check, if new version of dll is available and download it to a subfolder:
ApplicationPlugins/MyApp.bundle/NewVersion/myApp.dll. I inform the user, that a newer version is available and it has to restart Autocad. Meanwhile, I change ModuleName attribute value to point to the newer dll version
Code: [Select]
ModuleName="./NewVersion/myApp.dll"The problem is that, when Autocad is restarted, neither one of two (old and new) files are loaded.
If somebody has already faced the same issue, please suggest something :)

« Last Edit: January 12, 2017, 07:28:46 am by AngelKostadinov »

Bryco

  • Water Moccasin
  • Posts: 1780
Re: Autoloader does not load my dll
« Reply #1 on: January 14, 2017, 08:38:28 pm »
This function sounds very cool. What I do is first autoload a dll that checks for a newer version and if true copies the new one to the appropriate spot then the next autoload loads the dll. I put it in acad support (probably  a non kosher move) but it is available to all users on that box using acad

BlackBox

  • King Gator
  • Posts: 3735
"Potential has a shelf life." - Margaret Atwood

AngelKostadinov

  • Newt
  • Posts: 30
Re: Autoloader does not load my dll
« Reply #3 on: January 20, 2017, 05:25:37 am »
Thank you for the replays!

Very tricky problem, indeed. Sometimes works, sometimes does not. I found some related threads on Autodesk's forum, like this one: http://forums.autodesk.com/t5/net/autocad-2015-autoloader-changes/td-p/4910140. It seems that people have a problem with XML structure of the PackageContents file, so I will compare everything again with the white paper and if spot something will update the post.
With regard to AutoCAD version, I could say that my extension will be used on Acad 2012 <-> 2016 and I don't think it wil be used with 2017 soon.

As a side note, BricsCAD doesn't support Autoloader mechanism in a such way as AutoCAD. I have to edit registry keys in that case.


Atook

  • Swamp Rat
  • Posts: 778
Re: Autoloader does not load my dll
« Reply #4 on: January 21, 2017, 12:39:34 pm »
..What I do is first autoload a dll that checks for a newer version and if true copies the new one to the appropriate spot then the next autoload loads the dll...

This seems like a workable approach as well, what function  do you use to load the working/updated dll?

AngelKostadinov

  • Newt
  • Posts: 30
Re: Autoloader does not load my dll
« Reply #5 on: January 24, 2017, 04:57:11 am »
This is what I have so far:

Code: [Select]
            var oldContext = SynchronizationContext.Current;
            SynchronizationContext context = oldContext;
            if (oldContext == null)
            {
                context = new WindowsFormsSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(context);
            }

            var currentVersion = _versionService.GetInstalledProductVersion();
           
            // last available revisions
            var lastVersionTask = _versionService.GetLastReleasedVersionAsync(currentVersion);
            await lastVersionTask;

            var lastVersion = lastVersionTask.Result;
            if (lastVersion == null || lastVersion <= currentVersion)
            {
                SynchronizationContext.SetSynchronizationContext(oldContext);
                return;
            }

            // changes Sync context from AutoCadSyncContext/WindowsFormsSyncContext to new SyncronizationContext()
            if (_utilityClass.ShowDialog(new UpdateDialog()) != DialogResult.OK)
            {
                SynchronizationContext.SetSynchronizationContext(oldContext);
                return;
            }

            if (!IsAdministrator())
            {
                MessageBox.Show("Run as Administrator", "E R R O R !", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
                SynchronizationContext.SetSynchronizationContext(oldContext);
                return;
            }

            SynchronizationContext.SetSynchronizationContext(context);

            var progressDialog = new UpdateProgressDialog();
            progressDialog.Show();

            var cancellationToken = progressDialog.CancellationTokenSource.Token;

            string newVersionDir = null;
            try
            {
                // remove old versions
                var bundleDir = _appConfigurationProvider.GetKojtoCadPluginDir();
                var previousVersions = _versionService.GetPreviousInstalledVersions(bundleDir, currentVersion);
                foreach (var previousVersion in previousVersions)
                {
                    await _fileService.DeleteDirectoryAsync(previousVersion.Item2, true, cancellationToken);
                }

                // download files
                var tempCopy = Path.Combine(_fileService.GetUsersTempDir(), lastVersion.ToString());
                await _packageRepository.DownloadPackageAsync(lastVersion, tempCopy, progressDialog.Progress,
                    cancellationToken);

                // copy new version
                newVersionDir = Path.Combine(bundleDir, lastVersion.ToString());
                await _fileService.CopyDirectoryAsync(tempCopy, newVersionDir, cancellationToken);
                progressDialog.Progress.Report(new UpdateProgressData {CopyCompleted = true});

                // remove temp files
                await _fileService.DeleteDirectoryAsync(tempCopy, true, cancellationToken);
                progressDialog.Progress.Report(new UpdateProgressData {RemoveTemp = true});

                cancellationToken.ThrowIfCancellationRequested();

                // edit PackageContents.xml file and Registry value
                foreach (var autoloaderSettingsService in _autoloaderSettingsServices)
                {
                    await autoloaderSettingsService.EditSettingsSoTheNewVersionWillBeLoadedOnNextStartupAsync(
                        newVersionDir);
                }

                progressDialog.Progress.Report(new UpdateProgressData { EditAutoloaderSettingsCompleted = true });
            }
            catch (Exception e)
            {
                if (!(e is OperationCanceledException))
                {
                    MessageBox.Show(e.Message, "E R R O R !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (Directory.Exists(newVersionDir))
                {
                    try
                    {
                        await _fileService.DeleteDirectoryAsync(newVersionDir, true, CancellationToken.None);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "E R R O R !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                foreach (var autoloaderSettingsService in _autoloaderSettingsServices)
                {
                    autoloaderSettingsService.RevertOldValues();
                }

                // in case of exception there will be no background threads working
                // and we can safely dispose cancellation token source
                progressDialog.Close();

                SynchronizationContext.SetSynchronizationContext(oldContext);
                return;
            }

            // revert synchronization context
            SynchronizationContext.SetSynchronizationContext(oldContext);

Bryco

  • Water Moccasin
  • Posts: 1780
Re: Autoloader does not load my dll
« Reply #6 on: January 24, 2017, 03:46:06 pm »
LexStartup2017 IS THE FIRST ONE.
This is all through the registry

Code: [Select]
using System;
using System.IO;
using System.Collections.Generic;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using acadApp=Autodesk.AutoCAD.ApplicationServices.Application;
using Microsoft.Win32;
using IP = Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop;
using rkey = Autodesk.AutoCAD.Runtime.RegistryKey;
using Regy = Autodesk.AutoCAD.Runtime.Registry;
[assembly: ExtensionApplication(typeof(Autodesk.AutoCAD.AutoCAD_2017_plug_in1.MyPlugin))]

namespace Autodesk.AutoCAD.AutoCAD_2017_plug_in1
{

    public class MyPlugin : IExtensionApplication
    {
        //HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.2\ACAD-A005:409\Applications
        private static string startup = @"C:\Program Files\Autodesk\AutoCAD 2017\Support\LexStartup2017.dll"; 
        private static string GetThangs = @"C:\Program Files\Autodesk\AutoCAD 2017\Support\GetThangs15.dll";
        private static Editor ed;
        void IExtensionApplication.Initialize()
        {
            string Keypath = @"Software\Autodesk\AutoCAD\R21.0\ACAD-0001:409\Applications\LexStartup";   
//HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R20.0\ACAD-E005:409\Applications

              Document doc = acadApp.DocumentManager.MdiActiveDocument;
            ed = doc.Editor;
            rkey key = Regy.CurrentUser;  // Registry.CurrentUser;
            key = key.OpenSubKey(Keypath,true);
            //ed.WriteMessage
            if (key == null)
            {
                key = Regy.CurrentUser;
                key = key.CreateSubKey(Keypath);
                key.SetValue("DESCRIPTION", (string)"LexStartup2017.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\R21.0\ACAD-0001:409\Applications\LexStartup2";
            key =Regy.CurrentUser;
            key = key.OpenSubKey(Keypath, true);
         
                if (key == null)
                {
                    key = Regy.CurrentUser;
                    key = key.CreateSubKey(Keypath);
                    key.SetValue("DESCRIPTION", (string)"GetThangs15.dll autoload", RegistryValueKind.String);
                    key.SetValue("LOADCTRLS", 2, RegistryValueKind.DWord);
                    key.SetValue("MANAGED", 1, RegistryValueKind.DWord);
                    key.SetValue("LOADER", GetThangs, RegistryValueKind.String);
                }
                key.Close();
           





            //HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R21.0\ACAD - 0005:409
            Keypath = @"Software\Autodesk\AutoCAD\R21.0\ACAD-0005:409\Applications\";   
//HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R20.0\ACAD-E005:409\Applications
            key = Regy.CurrentUser;  // Registry.CurrentUser;
            key = key.OpenSubKey(Keypath, true);
            if (key != null)
            {
                key.Close();
                key = Regy.CurrentUser;
                key = key.OpenSubKey(Keypath, true);
                Keypath = @"Software\Autodesk\AutoCAD\R21.0\ACAD-0005:409\Applications\LexStartup";
                key = key.OpenSubKey(Keypath, true);
                if (key == null)
                {
                    key = Regy.CurrentUser;
                    key = key.CreateSubKey(Keypath);
                    key.SetValue("DESCRIPTION", (string)"LexStartup2017.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\R21.0\ACAD-0005:409\Applications\LexStartup2";
                key = Regy.CurrentUser;
                key = key.OpenSubKey(Keypath, true);
                if ((string)acadApp.GetSystemVariable("Loginname") != "bwalmsley")
                {
                    if (key == null)
                    {
                        key = Regy.CurrentUser;
                        key = key.CreateSubKey(Keypath);
                        key.SetValue("DESCRIPTION", (string)"GetThangs15.dll autoload", RegistryValueKind.String);
                        key.SetValue("LOADCTRLS", 2, RegistryValueKind.DWord);
                        key.SetValue("MANAGED", 1, RegistryValueKind.DWord);
                        key.SetValue("LOADER", GetThangs, RegistryValueKind.String);
                    }
                    key.Close();
                }

            }

Jeff H

  • Needs a day job
  • Posts: 5705
Re: Autoloader does not load my dll
« Reply #7 on: January 24, 2017, 05:54:53 pm »
This is what I use.


I publish files to the server and every time autocad starts it checks to see what files and file types to update and if any files are newer or never been copied then it copies locally and then loads in the assembly defined in file
http://forums.autodesk.com/t5/net/updating-plugin/td-p/4834421