Log in

View Full Version : GetSystemEnv v0.3.1 - by Stickboy


StainlessS
25th July 2019, 18:15
As there is no thread for this I created this one.

GetSystemEnv dll, original v0.3.0 recompile for avs+ x86 and x64.
(2 x dll, + source + VS2008 Project files. Required VS 2008 runtimes, also original v2.5 dll in original zip)


Overview

GetSystemEnv retrieves the value of an environment variable.

GetWorkingDir retrieves the current working directory.

SetWorkingDir sets the current working directory.

GetFileInfo retrieves information about a specified file.
Syntax

GetSystemEnv(string varName)
GetWorkingDir()
SetWorkingDir(string path)
GetFileInfo(string filename, string propertyName)

GetSystemEnv
Syntax

GetSystemEnv(string varName)

Parameters
varName The environment variable to retrieve.
Usage

Returns the string associated with the specified environment variable.

Examples:

val = GetSystemEnv("name")

try
{
x = Int(GetSystemEnv("someNumber"))
}
catch (err_msg)
{
x = 0
}

GetWorkingDir
Syntax

GetWorkingDir()

Usage

Returns the full path of the current working directory. The path is guaranteed to have a trailing slash ('\').
SetWorkingDir
Syntax

SetWorkingDir(string path)

Usage

Sets the path to the current working directory.
GetFileInfo
Syntax

GetFileInfo(string filename, string propertyName)

Parameters
filename The name of the file.
propertyName The name of the property to retrieve. Can be one of:
"creationTime" The date and time the file was created.
"modificationTime" The date and time the file was last modified.
"accessTime" The date and time the file was last accessed.
Usage

Returns the property value for the specified file.

Examples:

filename = "D:\someFile.avi"
AVISource(filename)
Subtitle(GetFileInfo(filename, "creationTime"))



See HOSTED folder @ Mediafire in my sig below this post.

Groucho2004
25th July 2019, 18:22
Thanks Stainless.

Only yesterday I was thinking about adding environment variable readout to the SysInfo plugin. I guess I'll put that on hold now.

StainlessS
25th July 2019, 18:30
Nope, by all means add to your lovely sysinfo dll. (one less dll required, + some of Stickboy functions were later implemented in avs)

EDIT: Actually, I think I did a throwaway info dll on request several years ago, dont think I kept a copy.

EDIT: And the file time stuff is also available via one of th RT_ routines.

Groucho2004
25th July 2019, 18:36
Are these "GetWorkingDir()", "SetWorkingDir()" and "GetFileInfo()" functions really useful? Anything I can discard?

StainlessS
25th July 2019, 18:40
"GetWorkingDir()", "SetWorkingDir()" were (I think) implemented in avs, Stickboy did em first.

RT_Stats already implements file time extraction, so of no use to me.

Nope, by all means add to your lovely sysinfo dll. (one less dll required, + some of Stickboy functions were later implemented in avs)

EDIT: Actually, I think I did a throwaway info dll on request several years ago, dont think I kept a copy.

EDIT: And the file time stuff is also available via one of th RT_ routines.


EDIT: from Docs (not GetWorkingDir, use the script builtin dir/file stuff instead.)
SetWorkingDir | v2 | SetWorkingDir(path)
Sets the default directory for AviSynth to the path argument.
This is primarily for easy loading of source clips, importing scripts, etc. It does not affect plugins' autoloading.
Return value is 0 if successful, -1 otherwise.
Examples:
SetWorkingDir("c:\my_presets")
AviSource("border_mask.avi") # this loads c:\my_presets\border_mask.avi


EDIT: Actually, I implemented RT_GetSystemEnv() already [forgot].


RT_GetSystemEnv(String envname)
Returns a string from the System Environment with the env name of the string arg.
Returns "", if cannot find environment variable of given name.
eg, TEMP=RT_GetSystemEnv("TEMP") # to get TEMP folder path.
and eg
ComSpec=RT_GetSystemEnv("ComSpec") # might return "C:\WINDOWS\system32\cmd.exe"
To see the environment variables from command console, type 'set'.
http://en.wikipedia.org/wiki/Environment_variable

Groucho2004
25th July 2019, 18:42
OK, so just the environment variables for now.

StainlessS
25th July 2019, 18:47
Well, see last edit too, maybe.

I did not really need to do the x64 GetSystemEnv() plug at all :(
[I could have been in the pub an hour ago, if I had remembered]

real.finder
25th July 2019, 18:51
Well, see last edit too, maybe.

I did not really need to do the x64 GetSystemEnv() plug at all :(
[I could have been in the pub an hour ago, if I had remembered]

aside from that I already build one years ago https://forum.doom9.org/showthread.php?p=1777483#post1777483

StainlessS
25th July 2019, 19:03
Well in that case we defo dont need any more versions of it. :)
RF, JFYI, the x64 compile that you did, probably produced 4 Warnings [about conversion of size_t to int, and possible data loss due to being differing bit size].
Those particular warnings are nothing really to worry about, but I added casts to avoid the warnings [warnings never look nice, and require inspection after every compile
to see if important, so best avoid them (and many inspections) altogether when non important].

EDIT: Think I will not bother with the pub, maybe make an early start tomorrow though :) [plenty beer in the fridge for now]

real.finder
25th July 2019, 19:10
Well in that case we defo dont need any more versions of it. :)
RF, JFYI, the x64 compile that you did, probably produced 4 Warnings [about conversion of size_t to int, and possible data loss due to being differing bit size].
Those particular warnings are nothing really to worry about, but I added casts to avoid the warnings [warnings never look nice, and require inspection after every compile
to see if important, so best avoid them (and many inspections) altogether when non important].

don't remember if it did, but it work since years for me, I am using it mainly for load 2.6 plugins from sub folder in plugins main folder if avs26 is used since I love to make the plugins folder work with any avs/avs+ :)

StainlessS
25th July 2019, 19:35
Yes, you would not have seen any problems.
One of the warnings was where GetSystemEnv() returns a string.
Before return, we must use Avisynth Env->SaveString(s,strlen(s)) to make a copy of the string and give it and all control over it to Avisynth.
Where strlen(s) is the length of the string text that we will ask avisynth to provide a buffer for. [dll malloc is different to avs malloc, they both have their own memory heap],
and so we must make a copy of the string {using avisynth alloc, not our mem alloc stuff} and pass control of the string back to Avisynth so that it is responsible for freeing the memory buffer when Avs closes down.
The strlen() function returns type size_t (64 bit on x64) but avisynth Env->SaveStr() requires a 32 bit int for string length when requesting a string buffer.
Truncating the (64 bit) size_t to (32 bit) int just throws away the most significant 32 bits which mean nothing to Avisynth Env->SaveStr() anyway.
[EDIT: Also, the path to any environment variable is unlikely to excede 32 bit int in length, even on a 65536 bit system, so is pretty safe on a 64 bit sys]

The other 3 warnings were not so different to the above one.

EDIT: Avisynth string lengths are 32 bit, whether x86 or x64, ints are still 32 bit etc.