Page 1 of 1

environment vars

Posted: 04 Oct 2009 05:38
by Muroph
the new environment variables handling inside paths has broken a handful of my scripts.
even something as simple as this stopped working:

Code: Select all

writefile("%temp%\test.tmp","this is a test")

Re: environment vars

Posted: 04 Oct 2009 08:48
by admin
Argh, yes. I forgot that a full path at the beginning is ok. :roll:

Re: environment vars

Posted: 05 Oct 2009 19:55
by TheQwerty
So now how do we use an environment variable in OpenWith and pass additional arguments?

Code: Select all

OpenWith("""%programfiles%\winrar\winrar.exe"" x -ad -- <items>", "m");
All this work to help the morons who create folders named the same as their environment variables has rendered a lot of my scripts and catalog useless in v8.50. :roll:

Re: environment vars

Posted: 05 Oct 2009 21:15
by admin
TheQwerty wrote:So now how do we use an environment variable in OpenWith and pass additional arguments?

Code: Select all

OpenWith("""%programfiles%\winrar\winrar.exe"" x -ad -- <items>", "m");
All this work to help the morons who create folders named the same as their environment variables has rendered a lot of my scripts and catalog useless in v8.50. :roll:
Indeed, I start to regret it.

I give it one more try. But I fear ultimately the ambiguities are not solvable without a telepathic module, so it's likely that I will finally give up.

Re: environment vars

Posted: 06 Oct 2009 01:39
by TheQwerty
Clearly I have no idea how you're currently checking the paths and I'm a bit of a noob to win32 programming with no VB experience but with a bit of playing in C++ would something like this work:

Code: Select all

TCHAR path[MAX_PATH+1];
_tcscpy_s(path, _T("\"D:\\Downloads\\%username%\\test.exe\" -n"));

TCHAR pathCopy[MAX_PATH+1];
_tcscpy_s(pathCopy, path); //Copy just in case.

PathRemoveArgs(path);
TCHAR *args = _tcsninc(pathCopy, _tcslen(path)); //Store args.

PathUnquoteSpaces(path);
if (! PathFileExists(path)) {  //Try as is.
	if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try as resolved relative or unqualified.
		DoEnvironmentSubst(path, MAX_PATH);
		if (! PathFileExists(path)) {	//Try with expanded env. vars.
			if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try with expanded env. vars and resolved relative or unqualified.
				_tprintf(pathCopy); //File not found use starting value.
				return 0;
			}
		}
	}
}

PathQuoteSpaces(path);
_tcscat_s(path, MAX_PATH+1, args); //Restore the args.
_tprintf(path);
return 1;
It's not a pretty solution and probably not that efficient, but I'm sure you come up with something better. :P

Re: environment vars

Posted: 06 Oct 2009 09:09
by admin
TheQwerty wrote:Clearly I have no idea how you're currently checking the paths and I'm a bit of a noob to win32 programming with no VB experience but with a bit of playing in C++ would something like this work:

Code: Select all

TCHAR path[MAX_PATH+1];
_tcscpy_s(path, _T("\"D:\\Downloads\\%username%\\test.exe\" -n"));

TCHAR pathCopy[MAX_PATH+1];
_tcscpy_s(pathCopy, path); //Copy just in case.

PathRemoveArgs(path);
TCHAR *args = _tcsninc(pathCopy, _tcslen(path)); //Store args.

PathUnquoteSpaces(path);
if (! PathFileExists(path)) {  //Try as is.
	if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try as resolved relative or unqualified.
		DoEnvironmentSubst(path, MAX_PATH);
		if (! PathFileExists(path)) {	//Try with expanded env. vars.
			if (! PathResolve(path, NULL, PRF_VERIFYEXISTS)) { //Try with expanded env. vars and resolved relative or unqualified.
				_tprintf(pathCopy); //File not found use starting value.
				return 0;
			}
		}
	}
}

PathQuoteSpaces(path);
_tcscat_s(path, MAX_PATH+1, args); //Restore the args.
_tprintf(path);
return 1;
It's not a pretty solution and probably not that efficient, but I'm sure you come up with something better. :P
Extracting the path and checking for existence is a possibility but it would indeed slow down the whole thing too much. I will rather try to solve it on a purely syntactical level.

Re: environment vars

Posted: 06 Oct 2009 15:49
by admin
admin wrote:Extracting the path and checking for existence is a possibility but it would indeed slow down the whole thing too much. I will rather try to solve it on a purely syntactical level.
PS: The checking for existence method would also fail when new files are to be created: they do not exist, yet there path is perfectly alright.

Re: environment vars

Posted: 06 Oct 2009 15:54
by TheQwerty
admin wrote:
admin wrote:Extracting the path and checking for existence is a possibility but it would indeed slow down the whole thing too much. I will rather try to solve it on a purely syntactical level.
PS: The checking for existence method would also fail when new files are to be created: they do not exist, yet there path is perfectly alright.
Indeed, but I wasn't aiming to provide a way to further this idiocy of creating items with "%...%" names, I just want my catalog and scripts to work correctly! :P

Re: environment vars

Posted: 06 Oct 2009 21:05
by TheQwerty
Not sure if there's any remaining/new problems now, but my catalog/scripts work again! :D