Author Topic: Environment variable token  (Read 2430 times)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Environment variable token
« on: May 23, 2018, 01:23:32 PM »
With the implementation of {STATE_SYSDIR} and {STATE_WINDIR}, and the mentioning of performance overhead related to automatically parsing environment variables, I'm wondering if it would make sense to have a token to explicitly parse environment variables instead(or additionally).

E.G.
Code: [Select]
{ENVVAR:%windir%}
This would allow the use of any given environment variable, without having to check for them in every given string(assuming the overhead of parsing a token is lesser).
« Last Edit: May 28, 2018, 07:38:07 PM by Pfeil »

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: Environment variable token
« Reply #1 on: May 23, 2018, 01:52:33 PM »
Actually, I think if you try, '{STATE_ENV:textValueOrTokenNotAVariable}', it will resolve to the process environment variable (not documented).
I started adding it, but there are actually environment variables that apply to proccess/user/machine.  I may split it up into 3 tokens:  {STATE_ENVPROCESS:textValueOrTokenNotAVariable}, {STATE_ENVUSER:textValueOrTokenNotAVariable}, {STATE_ENVMACHINE:textValueOrTokenNotAVariable}
if needed.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Environment variable token
« Reply #2 on: May 23, 2018, 02:23:11 PM »
I can't seem to get that token to work, it always returns blank(I'm assuming it's a passthrough to "Environment.GetEnvironmentVariable()", so I tried "{STATE_ENV:WINDIR}" among others).

It does seem the most relevant context is Process, as more commonly used variables like "%USERPROFILE%" don't return a value for Machine or User(the latter of which I found odd, but then I'm not that familiar with the subject matter).

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: Environment variable token
« Reply #3 on: May 23, 2018, 02:36:34 PM »
I started to add it with the new tokens but I was thinking it might have been a little confusing given that it can have three states.  It seemed like it would be good to add at first, but if it was just going to cause confusion it would be better to just leave it out for now.  I'll look into it more now that I know there is at least some interest in it.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2826
Re: Environment variable token
« Reply #4 on: May 26, 2018, 06:07:06 PM »
Where I left it when testing different things out was, 'User'.  I'm going to leave it at the default of, 'Process' and if anybody has a need for the other two contexts, I'll revisit ;)

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4761
  • RTFM
Re: Environment variable token
« Reply #5 on: May 28, 2018, 07:37:46 PM »
"{STATE_ENV:}" does exactly what I wanted; Thanks, Gary ;D