PDA

View Full Version : How to Get the full path of an avs script in my own filter?


milkyjing
20th November 2009, 03:28
Hi there,

I'm trying hard to write my very first Avisynth plugin recently.
There's no doubt that I've met a lot of questions, but luckily, many of them could be solved after Looking up the very large amout of already-existed Examples (ie. source code).
Obviously, there are questions that I couldn't solve using my own power.

Here is a simple one:

#####test.avs#####

LoadPlugin("testPlugin.dll") # Load the plugin
AVISource("test.avi")
testFunc("test.txt") # this function is from testPlugin

#####end########

here comes my question: How to get the full path of "test.txt" in my own plugin?

I've looked through the avisynth.h all I found is only
virtual int __stdcall SetWorkingDir(const char * newdir) = 0;
not GetWorkingDir or something like that.

regards,
milkyjing

neuron2
20th November 2009, 05:10
There's a dirty hack involving forcing an error, catching it, and parsing the error string. It's on the forum somewhere but I can't find it. :(

Probably Gavino will be along shortly with the link.

milkyjing
20th November 2009, 06:58
Thank you very much neuron2! You're always so kind to answer my questions.

Why I want to get the full path is that when I use MeGUI to run my avs script, the CreateFile(lpFileName,....) // (lpFileName is from the param of testFunc)
function in my testPlugin always fails if I didn't use a full name (e.g. testFunc("C:\test.txt") succeeds while testFunc("test.txt") fails).
However VirtualDubMod is OK (i.e. both testFunc("C:\test.txt") and testFunc("test.txt") will succeed) as well as MPC-HC.
Sigh~, so I decided to convert the relative path to the full path in my plugin to avoid the annoying error.

milkyjing

Baxich
20th November 2009, 10:14
For C++: http://bytes.com/topic/c/answers/860067-relative-path-absolute
For C#: http://bytes.com/topic/c-sharp/answers/606021-relative-path

milkyjing
20th November 2009, 10:42
Thanks Baxich!

After using GetFullPathName function I finally found the cause of this strange error!

When I use MeGUI to run the following avs script:

#####test.avs#####

LoadPlugin("testPlugin.dll") # Load the plugin
AVISource("test.avi")
testFunc("op_2.tcs") # this function is from testPlugin, Simply show the full path of op_2.tcs file

#####end########


then I got:

(before encoding)
http://www.tcsub.com/attachments/month_0911/0911201737e742824d90123b12.jpg
(↑ the correct path)

and (when encoding starts)
http://www.tcsub.com/attachments/month_0911/091120173717d486657d956f2c.jpg
(↑ the wrong path)

The path has been changed!

Now I think I can fix the bug (of my own plugin) :P


milkyjing

Gavino
20th November 2009, 10:48
There's a dirty hack involving forcing an error, catching it, and parsing the error string. It's on the forum somewhere but I can't find it. :(

Probably Gavino will be along shortly with the link.
http://forum.doom9.org/showthread.php?t=147689

However, the OP wants to do this from code, not from within a script, so GetFullPathName is the answer.

Gavino
20th November 2009, 10:53
The path has been changed!
During script loading, the current folder is temporarily set to the folder containing the script. However, during frame serving it will be whatever the client application has set.

Therefore, you need to extract the full path in your constructor and store it somewhere if you want to use it in GetFrame.

milkyjing
20th November 2009, 11:14
Therefore, you need to extract the full path in your constructor and store it somewhere if you want to use it in GetFrame.

:thanks:

That's exactly what I've just done, and certainly it works! :)


milkyjing