mIRC Home    About    Download    Register    News    Help

Topic Options
#261673 - 09/11/17 03:10 AM $sfile returns a folder
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3166
Loc: France
Calling $sfile and going to the Windows's fonts's folder, it's not allowing me to enter that folder, instead $sfile will return with the value "C:\Windows\Fonts" for example.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261686 - 13/11/17 01:04 PM Re: $sfile returns a folder [Re: Wims]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 3928
Loc: London, UK
Thanks for your bug report. This is because the fonts folder is a special folder that redirects any attempt to open it to the Font control pannel. That said, there should be a way to make mIRC return an error in this case. This change should be in the next version.

Top
#261687 - 13/11/17 06:32 PM Re: $sfile returns a folder [Re: Khaled]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3166
Loc: France
I see, we more or less figured it was a special folder but there was some differences with others functions, like $findfile is able to report the fonts in the folder, $isdir works etc, so I was thinking maybe it could be made to work.

On a side note, $sfile and $sdir are already hidding some folders, (try them on the Windows folder and compare with what you see in the explorer), I think it would be better for mIRC to hide that font folder; I believe returning an error and halting the script is going to cause some issues in some scripts, because I don't think it could have been anticipated that $sfile/$sdir could halt with an error once the dialog is displayed, what do you think?
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261689 - 14/11/17 09:26 AM Re: $sfile returns a folder [Re: Wims]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 3928
Loc: London, UK
The $sfile and $sdir dialogs are Windows managed dialogs, so mIRC cannot selectively hide files/folders in that folder. If displaying an error is not useful, I can leave it as it is currently.

Top
#261690 - 14/11/17 09:40 AM Re: $sfile returns a folder [Re: Khaled]
Protopia Offline
Babel fish

Registered: 30/08/03
Posts: 99
Loc: UK
Originally Posted By: Khaled
The $sfile and $sdir dialogs are Windows managed dialogs, so mIRC cannot selectively hide files/folders in that folder. If displaying an error is not useful, I can leave it as it is currently.


IMO it would be better to return $null than raise an error or return something incorrect - as scripts can then check this easily rather than have to deal with it using :error etc.

Top
#261692 - 14/11/17 10:19 AM Re: $sfile returns a folder [Re: Khaled]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3166
Loc: France
I see. Then what about making them returns the plain text $error value which is used in some cases in mIRC, because scripts already check for $null value and they all (from my own experience) assume the user canceled the dialog, which is a fair assumption imo, not sure if $sfile/$sdir could return $null to mean anything different in the past.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261693 - 14/11/17 10:26 AM Re: $sfile returns a folder [Re: Wims]
Protopia Offline
Babel fish

Registered: 30/08/03
Posts: 99
Loc: UK
Originally Posted By: Wims
What about making them returns the plain text $error value which is used in some cases in mIRC, because scripts already check for $null value and they all (from my own experience) assume the user canceled the dialog, which is a fair assumption imo, not sure if $sfile/$sdir could return $null to mean anything different in the past.


$error documentation suggests it is only filled when a formal error is raised and you go to :error and is reset by /reseterror. That does not mean that we should not use $error, just that we have to be careful that this won't break scripts that check whether $error is $null later on. IMO if we are going to use $error, then we should do it properly and raise the error and look for :error. So long as this is documented, then the script writer can handle it in the alias they use for $sdir $sfile or move their code into a separate alias in order to achieve this - and we can document this in WikiChip.

But this is still more complex than returning a special value. If $null is already used (when cancelling the dialog) how about returning $false instead?


Edited by Protopia (14/11/17 10:30 AM)

Top
#261694 - 14/11/17 10:33 AM Re: $sfile returns a folder [Re: Protopia]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 3928
Loc: London, UK
It turns out that the Windows file dialog does not treat this as an error. It returns a successful result with no errors set. One way around this would be to make the dialog itself display an error, however this would require unsetting the OFN_NOTESTFILECREATE flag, which mIRC has used for a long time because there were side-effects without it. So the only remaining option is for mIRC to check if the result of $sfile() is an existing folder. If it is, it will make $sfile() return no value. This will be in the next version.

Top
#261695 - 14/11/17 10:49 AM Re: $sfile returns a folder [Re: Protopia]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3166
Loc: France
I specifically mentioned the plain text $error value.
$error is an identifier filled when you use the goto :error but it is also a plain text value returned by some identifiers, $dde for example (I think there are some others but can't find them right now).
Using $false is the same idea as using plain text $error, but plain text $error makes more sense, nothing is false here.


Edited by Wims (14/11/17 10:51 AM)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261696 - 14/11/17 11:08 AM Re: $sfile returns a folder [Re: Khaled]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3166
Loc: France
Quote:
If it is, it will make $sfile() return no value. This will be in the next version.
But that makes it impossible for a script to tell the difference between the user canceling the dialog and the folder being a special folder, what do you think of using plain text $error instead, to allow scripts to tell the difference?
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261697 - 14/11/17 12:16 PM Re: $sfile returns a folder [Re: Wims]
Protopia Offline
Babel fish

Registered: 30/08/03
Posts: 99
Loc: UK
Originally Posted By: Wims
I specifically mentioned the plain text $error value.
$error is an identifier filled when you use the goto :error but it is also a plain text value returned by some identifiers, $dde for example (I think there are some others but can't find them right now).
Using $false is the same idea as using plain text $error, but plain text $error makes more sense, nothing is false here.

Using plain text which looks like an identifier is (IMO) a bad idea for several reasons.

1. If you code this as you might naturally do, then it won't work:
Code:
if ($sfile(C:\) == $error) return

To make it work you have to code:
Code:
if ($sfile(C:\) == $ $+ error) return


2. "$error" is a valid file name. So if I select such a file in $sfile dialog how do you distinguish between the two?

For $sfile (or any identifier returning a file name) you would have to use text which is impossible to be a valid filename. According to Microsoft, the following characters are not valid in a filename: *?"<>|

How about using ? followed by an explanatory error message (either generated by Windows or mIRC)?


Edited by Protopia (14/11/17 12:21 PM)

Top
#261698 - 14/11/17 12:32 PM Re: $sfile returns a folder [Re: Protopia]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3166
Loc: France
Quote:
Using plain text which looks like an identifier is (IMO) a bad idea for several reasons.
I agree that there isn't much difference between returning a static "$error" vs "error"; and since the former might be confused as an identifier it shouldn't have been used, but $!error can be used instead of $+, it's simple enough and working, which is what matters to me.
Quote:

2. "$error" is a valid file name. So if I select such a file in $sfile dialog how do you distinguish between the two?
If you select such a file the complete filename will be returned, I don't think $sfile can possibly returns "$error" for a valid filename, it would be 'C:\$error' or something.

Reading versions.txt about $inwho it looks like Khaled wants to move away from using such returned values, but there is a need for script to tell if the $sfile call returns because of a special folder or if it's because the user pressed the escape key, for example. edit: well that note about $inwho was for mIRC 6.0 and $chan().ial still return $inwho although it says that future version would stop doing so.


Edited by Wims (14/11/17 12:38 PM)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261699 - 14/11/17 01:15 PM Re: $sfile returns a folder [Re: Wims]
Protopia Offline
Babel fish

Registered: 30/08/03
Posts: 99
Loc: UK
Originally Posted By: Wims
$!error can be used instead of $+, it's simple enough and working, which is what matters to me.
Still not intuitive.

Originally Posted By: Wims
If you select a file $error, the complete filename will be returned (e.g. C:\$error). I don't think $sfile can possibly returns "$error" for a valid filename.
True. I have tried to think of a counter example, but cannot create one.

If $sfile returns "$error" then, since this is the only way it can start with $, I would personally test for this with:
Code:
var %f $sfile(C:\)
if ($left(%f,1) == $) return

Top