Author Topic: Can a plugin read an XML file in its Apps folder?  (Read 9098 times)

netkingcol

  • Newbie
  • *
  • Posts: 28
Can a plugin read an XML file in its Apps folder?
« on: May 20, 2016, 06:21:45 AM »
I'm just starting to write my first plugin (the C# sample is very useful), so this may be a naive question.

I want to store some data for the plugin in XML format; can I put this in a local file or must I retrieve it, for security reasons, from some remote resource? The obvious place would be in the folder where the plugin .dll sits, i.e. within the Apps folder hierarchy.

netkingcol

  • Newbie
  • *
  • Posts: 28
Re: Can a plugin read an XML file in its Apps folder?
« Reply #1 on: May 20, 2016, 08:05:49 AM »
As an alternative to a local XML file, I'm considering using a String Resource to hold the XML data.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: Can a plugin read an XML file in its Apps folder?
« Reply #2 on: May 20, 2016, 08:27:34 AM »
Regardless of what you're storing, keep in mind that Microsoft doesn't want people to write to "Program Files" any more:
Quote
Applications should be installed to the Program Files folder by default. User data or application data must never be stored in this location because of the security permissions configured for this folder
Source
Quote
    10.3 Your app data, which must be shared among users on the computer, should be stored within ProgramData
    10.4 Your app’s data that is exclusive to a specific user and that is not to be shared with other users of the computer, must be stored in Users\<username>\AppData
Source


If it's a plugin for personal use, and you don't have VoiceAttack installed to "Program Files", you can get away with it; If you're looking to have other people use it, store your data in the correct location.

TheGrayFox

  • Newbie
  • *
  • Posts: 16
Re: Can a plugin read an XML file in its Apps folder?
« Reply #3 on: May 20, 2016, 11:12:01 AM »
In C#, I would suggest you use:

Code: [Select]
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
This will give you the user's AppData directory, where application data is meant to be stored.

netkingcol

  • Newbie
  • *
  • Posts: 28
Re: Can a plugin read an XML file in its Apps folder?
« Reply #4 on: May 20, 2016, 01:53:07 PM »
@TheGrayFox, thanks, I'll use AppData as you suggest; the XML will be easier to edit outside a String Resource anyway.

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Can a plugin read an XML file in its Apps folder?
« Reply #5 on: May 20, 2016, 01:54:06 PM »
So far, I've coded my plugins to store their settings in the same folder the DLL is stored... since adding/removing a plugin is a simple manual process, I didn't like the idea of leaving data around outside of the VA main folder.

Even if it's not the best practice, like Pfeil pointed out, I haven't had problem wint Win7 and Win10, and also never had any bug report from users so far... i think it might be due to the fact that many people run VA with admin priviledge to begin with, for other reasons.

Anyway, if you want to use the proper data folder, one option could be to use the one where VoiceAttack stores his main profile database... this way people that backup that folder will backup the plugin settings too, and you are not creating any extra directory: you can obtain that dinamically with

Code: [Select]
Io.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"VoiceAttack")
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin