Author Topic: How can I know the path of the addin?  (Read 3832 times)

Marcos Calleja

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
How can I know the path of the addin?
« on: August 10, 2015, 07:39:58 pm »
Hi! I'm developing an addin for EA and using an installer to share it. The thing is that i want to create/save some files of config and log in the same path that the addin is installed. But because the user can change the path in the installation, i need to acquire it in execution time.

I thought that maybe there's a way to obtain it but i couldn't find anything in the SDK or in this forum.

Anyone knows if this is even possible?

Greetings and thanks for your time.  :)
« Last Edit: August 10, 2015, 07:41:14 pm by mcalleja »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13304
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How can I know the path of the addin?
« Reply #1 on: August 10, 2015, 08:09:24 pm »
You'll have to get the path of the currently executing assembly. (Google will show the way)
Check the different options to make sure you get the path of the dll and not of ea.exe

Geert

Marcos Calleja

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: How can I know the path of the addin?
« Reply #2 on: August 10, 2015, 09:42:00 pm »
Thanks a lot Geert, I was totally blind. Instead of trying to get it from EA I should just get it from c# like you said.

If someone finish here searching this, i'm using:

Code: [Select]
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
« Last Edit: August 10, 2015, 09:42:41 pm by mcalleja »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How can I know the path of the addin?
« Reply #3 on: August 10, 2015, 11:11:11 pm »
The above code does what you say it does, but storing logs and configuration files (unless they are created during the installation process and then never modified) in the installation directory, where the user running the program may not have write access, is bad design.

That sort of stuff should go in the program data directory (default C:\ProgramData) or, if it's user-specific, the respective user's directory (default C:\Users\[UserName]). Have a look at this Stack Overflow question for some tips.

If you need the installation directory in runtime for some other reason, it's better to store it in the registry during installation (like EA does) than to retrieve it from the DLL file.

Finally, in the long run you're far better off using Windows' built-in logging facility instead of rolling your own.


/Uffe
My theories are always correct, just apply them to the right reality.

Marcos Calleja

  • EA Novice
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile
Re: How can I know the path of the addin?
« Reply #4 on: August 11, 2015, 05:08:40 pm »
You are completly right. I'm kind of new doing this type of software and I actually I don't know sometimes how to do thing correctly.

Like you said, trying to store log/config files in the plugin installation folder I have errors about access permissions and I can not write (or even create) in them.

So I will do like you say.

Thanks a lot for all this help :)