mIRC Home    About    Download    Register    News    Help

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

Registered: 31/07/06
Posts: 3376
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: 4158
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 panel. 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: 3376
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: 4158
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
Vogon poet

Registered: 30/08/03
Posts: 160
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: 3376
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
Vogon poet

Registered: 30/08/03
Posts: 160
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: 4158
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: 3376
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: 3376
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
Vogon poet

Registered: 30/08/03
Posts: 160
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: 3376
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
Vogon poet

Registered: 30/08/03
Posts: 160
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
#261866 - 03/12/17 04:54 PM Re: $sfile returns a folder [Re: Khaled]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3376
Loc: France
I'm afraid I have to ask again, are you not concerned with the fact that scripts already use $null value from $sfile to indicate that the user canceled the selection dialog?
Right now a $null value returned from $sfile because of 'reserved' folder is going to be taken as a cancel, and rightfully so.
In others words, there is no way to tell the difference between the user canceling with the mouse/keyboard and the folder being a reserved folder.
Not only it's breaking backward compatibilities but the behavior itself doesn't help us because we can't even tell either that a reserved folder was reached (regardless of users's canceling).
Please consider returning plain text $error or any other similar value that would indicate a reserved folder was reached, or at least please explain the reasoning of this choice.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#261867 - 03/12/17 05:04 PM Re: $sfile returns a folder [Re: Wims]
Protopia Offline
Vogon poet

Registered: 30/08/03
Posts: 160
Loc: UK
What about returning $false - this is not the same as $null so you can test it explicitly and will be returned by any other situation.

Top
#261868 - 03/12/17 05:51 PM Re: $sfile returns a folder [Re: Protopia]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3376
Loc: France
We already discussed the value that could be returned, I said that it is meaningless as long as functionality is there.
It could return the value "468737", "sup?", "-1", "reserved" "$error" or "$false", as long as it's not a valid value currently returned by $sfile.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#262207 - 09/01/18 02:57 PM Re: $sfile returns a folder [Re: Khaled]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3376
Loc: France
I'm posting a reply because you didn't answer me but, this change of $sfile returning $null on reserved folder will break my scripts (and it should break all scripts which handle $null as a 'cancel' which is common since we have no way of knowing when the user canceled the dialog), it doesn't look like there is a need for this break of backward compatibility at all, where returning a different value such as -1 would be a much better idea.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#262209 - 09/01/18 03:49 PM Re: $sfile returns a folder [Re: Wims]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 4158
Loc: London, UK
As far as I can tell, returning anything other than a filename or $null would break backwards compatibility because these are the only values that $sfile() has ever returned. Every script that uses $sfile() and checks if it returns $null would be broken if it returned -1.

Top
#262210 - 09/01/18 04:15 PM Re: $sfile returns a folder [Re: Khaled]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3376
Loc: France
Ahah, yes, that's how backward compatibility works sorry, my own scripts would break on -1 if not modified but since I'd be modifying them, I forgot.

Then a solution would be to improve $sfile to allow it to return a different value when the dialog is canceled.

Something like $sfile().cancel, which would return -1 if the old $sfile were to return $null (which as far as I know, is only possible when the user cancel the dialog), and would still return $null for reserved folder
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#262215 - 09/01/18 09:30 PM Re: $sfile returns a folder [Re: Wims]
Khaled Offline


Planetary brain

Registered: 04/12/02
Posts: 4158
Loc: London, UK
I have added a $sfstate identifier that is usable immediately after $sfile() and returns "cancel", "error", or $null. This will be in the next version.

Top
Page 1 of 2 1 2 >