It is currently March 28th, 2024, 1:11 pm

FileChoose [Ver.1.2.0.1]

Share and get help with Plugins and Addons
Post Reply
User avatar
Setsukka
Posts: 19
Joined: March 20th, 2018, 9:53 am
Location: China

FileChoose [Ver.1.2.0.1]

Post by Setsukka »

------------------------------------
Ver.1.2.0.1 Jan. 31 2021
_Fixed a bug where ChooseFolder and ChooseImage dont work when GetIcon=0.
_Added a new option "FileInitialDirectory" to set the initial folder when choosing files and folders.
_Added a new option "ImageInitialDirectory" to set the initial folder when choosing images.

Ver.1.1.0.4 Jan. 23 2021
_Fixed a bug where closing the skin while the choosing dialog opened can cause rainmeter to crash.

Ver.1.1.0.2 Dec. 08 2019
_Changed the code for saving icon image to solve some bugs.

Ver.1.1.0.1 Oct. 31 2019
_Added $Icon$ for use.
_Added a new bang "Resolve N Path" for use.

============================================

The idea comes up when I am working on my skin suite. I find I need a method to open a dialog to choose a file/folder/image without refreshing the skin. So I work for about a week on this plugin.
The plugin works like "RainFile.exe". FileChoose.dll enable users to open a windows dialog to choose a file/folder/image, and then get the name, extension, path.

I develop the plugin on win10, VS2017. In theory the plugin can be used on WinXP and greater, but I have tested it only on win10.

Download
FileChoose Sample_1.2.0.1.rmskin
(438.68 KiB) Downloaded 581 times
SouceCode :
FileChoose_SourceCode_1.2.0.1.rar
(413.73 KiB) Downloaded 302 times
Usage

Code: Select all

[MeasureChoose]
Measure=Plugin
Plugin=FileChoose
UseNewStyle=0
GetTarget=1
AllowNonstorageFolder=1
CopyLink=1
LinkCache=#CurrentPath#
GetIcon=1
IconCache=#CurrentPath#
IconSize=3
ReturnValue=Path
FileInitialDirectory=
ImageInitialDirectory=

Command1=[!Log "$Name$"][!Log "$Path$"][!Log """$[Path]$"""][!Log "$Ext$"][!Log "$NameAndExt$"][!Log "$Icon$"]
Command2=......

[MeterChooseButton]
xxxxxxxxxx
LeftMouseUpAction=[!CommandMeasure MeasureChoose "ChooseFile 1"]
Option
  • UseNewStyle ( Default : 0 )
If set to 1, will use the Common Item Dialog instead of old methods.
DO NOT TURN IT TO "1" UNLESS YOUR SKIN IS DESIGNED FOR ONLY WIN10
  • GetTarget ( Default : 1 )
If set to 1, the ".lnk" file and ".url" file will be dereferanced to get the path of the target.
If failed to get the target, return the path of the shortcut file, or copy the shortcut if "CopyLink = 1".
Only be valid when choosing a file.
NOTE : Whether GetTarget = 1 or not, the name will be that of the shortcut file rather than the target.
  • AllowNonstorageFolder ( Default : 0 )
If set to 1, a nonstorage folder is allowed for choose.
Only be valid when choosing a folder and "UseNewStyle = 1".
NOTE : Nonstorage folder:
like "My Computer", whose path is "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
like some folder packed in the rar (DONT CHOOSE IT, PLEASE)

  • CopyLink ( Default : 0 )
If set to 1, when fail to get the target, the original shortcut file will be copied to a cache folder.
In this case, the path we get will be the path of the copy.
The cache folder must exist, which can be set with the option "LinkCache".
If failed to copy it, return the path of the original one.
NOTE : The name of the copy will be the same as the original one.
If there exist a file of the same name in the cache folder, REPLACE IT.

  • LinkCache ( Default : #CurrentPath# )
Set the cache folder of the shortcut file.
The path must exist. And the folder path should contain a "\" in the end of the string.
  • GetIcon ( Default : 0 )
If set to 1, will copy the icon into the cache folder.
The cache folder must exist, which can be set with the option "LinkCache".
If failed to get the icon, return a empty string.
NOTE : (VERY IMPORTANT!)
Folders, images (*.png, *.jpg, *.jpeg, *.bmp, *.ico), these files' icon will not be copied.
As for images, we return the file path to use as the icon path.
As for folders, just return a string "(IconCache\)folder.png", WHETHER THE FILE "folder.png" EXIST OR NOT!
THEREFORE, REMEMBER TO ADD A IMAGE "folder.png" INTO THE ICON CACHE!
If there exist a file of the same name in the cache folder, REPLACE IT.

  • IconCache ( Default : #CurrentPath# )
Set the cache folder of the shortcut file.
The path must exist. And the folder path should contain a "\" in the end of the string.
Remember to add a image "folder.png" in the folder for use.
  • IconSize ( Default : 3 )
Set the size of the icon.
Valid Value :
0 : Small, 16x16
1 : Medium, 32x32
2 : Large, 48x48
3 : ExtraLarge, 256x256
NOTE : For some files who dont have a extralarge icon, get the large icon(48x48) instead.
  • ReturnValue ( Default : Path )
This option define the type of the string value of the measure.
Valid value: Path / WholePath / Name / Extensions / NameAndExt / Icon
The meaning of the value will be introduced later.
NOTE : In most time, I suggest to use the bang command instead of the string value,
but when using lua script, it can be surprisingly useful.

  • FileInitialDirectory
This option define the initial directory of the choosing dialog.
If defined, every time choosing a file or a folder, the intial directory is forced to be set as this.
if "UseNewStyle = 1" is not set, this is ineffective when choosing folders.
  • ImageInitialDirectory
This option define the initial directory of the choosing dialog.
If defined, every time choosing a image, the intial directory is forced to be set as this.
  • Command N
Like the inputtext.dll, when finished choosing file/folder/image, the bangs in the corresponding command is executed.
Some $Variable$ you may use:
$Path$ / $[Path]$ / $Name$ / $Ext$ / $NameAndExt$ / $Icon$
The meaning of the value will be introduced later.

Bangs
  • "ChooseFile N"
  • "ChooseFolder N"
  • "ChooseImage N"
N is a number, which should correspond with the Option "Command N".
  • "Resolve N PATH"
N is a number, which should correspond with the Option "Command N".
PATH is a string of file path. (DONT CONTAIN ANY "")
This bang enable user to first get a filepath in other method, and then use this plugin to get the information of the file. In the end, execute the "Command N".

Meaning of the value
Lets see the example to show the meaning of the ReturnValue and the $Variables$ :
We assume to choose "AIMP_SHORTCUT.lnk", whose target is "D:\Program\AIMP\AIMP.exe".
========================================
ReturnValue | $Variables$ | Sample Value

Path | $Path$ | D:\Program\AIMP\AIMP.exe
WholePath | $[Path]$ | ["D:\Program\AIMP\AIMP.exe"]
Name | $Name$ | AIMP_SHORTCUT
Extensions | $Ext$ | exe (empty if folder)
NameAndExt | $NameAndExt$ | AIMP.exe
Icon | $Icon$ | (IconCache\)AIMP_SHORTCUT_lnk.png
========================================

Tips
  • Use $[Path]$
The Event Variable $[Path]$ contains "" and [], so when using it in bangs, please write like this : """$[Path]$"""
  • Cache folders
Be sure the path of the cache folder contains a "\" in the end of the string.
The default value #CurrentPath# contains "\" in the end itself.
For example :
LinkCache = #CurrentPath# (OK)
LinkCache = #CurrentPath#LinkCache\ (OK)
LinkCache = #CurrentPath#LinkCache (Not OK)
We dont check if the folder really exist now, so you should take care.
If unfortunately you forgot, and write LinkCache = #CurrentPath#LinkCache, but the parent folder #CurrentPath# does exist, the string "LinkCache" will be seen as the prefix of the file. This means, you will get a file "LinkCacheAIMP.lnk" instead of "AIMP.lnk" in the parent folder.
Similarly, if IconCache = #@#Images\IconCache, a file "IconCachefolder.png" should exist in the folder "#@#Images\".
  • Use various bangs with the same "N"
The "N" is no need bounded with "ChooseFile" or other type of bangs.
You can surely use part or all of the bangs with the same "N". Just as below:

Code: Select all

[MeasureChoose]
Measure=Plugin
Plugin=FileChoose
Command1=[!SetVariable Path "$Path$"][!Update]

[MeterChooseFileButton]
Meter=String
Text=Choose File
LeftMouseUpAction=[!CommandMeasure MeasureChoose "ChooseFile 1"]

[MeterChooseFolderButton]
Meter=String
Text=Choose Folder
LeftMouseUpAction=[!CommandMeasure MeasureChoose "ChooseFolder 1"]
  • Use it in lua script
It is not a good idea to simply write CommandN=[!CommandMeasure MeasureScript "MyFunction('$Name$','$Path$','$Icon$')"]
because $Path$, $Icon$ often contain "\".
Therefore, I prefer to use the return value of the measure.
Codes are below. This little trick is also suitable for other plugins, like InputText.dll
If you just need one string of them, you dont need to update the measure.

Code: Select all

Codes in Rainmeter files (.ini)
[MeasureChoose]
XXXXXXXX
Command1=[!CommandMeasure MeasureScript "ChooseOver()"]

Codes in lua files (.lua)
function ChooseOver()
    -- Get the Measure
    local Measure=SKIN:GetMeasure('MeasureChoose')
    -- Get Path
    SKIN:Bang('!SetOption','MeasureChoose','ReturnValue','WholePath')
    SKIN:Bang('!UpdateMeasure','MeasureChoose')
    local Path=Measure:GetStringValue()
    -- Get Icon
    SKIN:Bang('!SetOption','MeasureChoose','ReturnValue','Icon')
    SKIN:Bang('!UpdateMeasure','MeasureChoose')
    local Icon=Measure:GetStringValue()
    -- Get Name
    SKIN:Bang('!SetOption','MeasureChoose','ReturnValue','Name')
    SKIN:Bang('!UpdateMeasure','MeasureChoose')
    local Name=Measure:GetStringValue()
end
Last edited by Setsukka on January 31st, 2021, 9:14 am, edited 7 times in total.
dujianaliuli
Posts: 1
Joined: October 23rd, 2019, 3:36 pm

Re: FileChoose [Ver.1.0.0.2]

Post by dujianaliuli »

Great job. It's amazing. I'm using it. :thumbup: :thumbup:
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: FileChoose [Ver.1.0.0.2]

Post by gkmaz9 »

Thank you. This is very useful. :D
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FileChoose [Ver.1.1.0]

Post by balala »

An extremely useful and interesting plugin for me. Didn't know about it, but now I'm playing with it and I like it very much.
A question however: is there any way to get open certain folder when I run the plugin? I mean that when I use a [!CommandMeasure "MeasureChoose" "ChooseFile 1"] bang, in the opening window the last path is retained. I'd like to can open certain folder, instead of the last one. Is this possible?
Same for the case when I open the plugin to choose a folder (with the [!CommandMeasure "MeasureChoose" "ChooseFolder 1"] bang).

Congratulations to the author, great work.
User avatar
Setsukka
Posts: 19
Joined: March 20th, 2018, 9:53 am
Location: China

Re: FileChoose [Ver.1.1.0]

Post by Setsukka »

balala wrote: September 24th, 2020, 7:28 pm An extremely useful and interesting plugin for me. Didn't know about it, but now I'm playing with it and I like it very much.
A question however: is there any way to get open certain folder when I run the plugin? I mean that when I use a [!CommandMeasure "MeasureChoose" "ChooseFile 1"] bang, in the opening window the last path is retained. I'd like to can open certain folder, instead of the last one. Is this possible?
Same for the case when I open the plugin to choose a folder (with the [!CommandMeasure "MeasureChoose" "ChooseFolder 1"] bang).

Congratulations to the author, great work.
Thanks you like it. For some reason I didn't touch rainmeter for some months, so I feel so sorry to not reply till now.
I think I have got what you mean, and my friend has suggested me for the same thing.
In fact, it is certainly possible and I'm considering to add a new option to solve it.
  Maybe in some days (or months)  
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FileChoose [Ver.1.1.0]

Post by balala »

Setsukka wrote: January 22nd, 2021, 6:56 pm Thanks you like it. For some reason I didn't touch rainmeter for some months, so I feel so sorry to not reply till now.
I think I have got what you mean, and my friend has suggested me for the same thing.
In fact, it is certainly possible and I'm considering to add a new option to solve it.
  Maybe in some days (or months)  
Ok, thanks. Would be extremely useful for me. Better later then never.
And thank you again for this plugin.
User avatar
Setsukka
Posts: 19
Joined: March 20th, 2018, 9:53 am
Location: China

Re: FileChoose [Ver.1.1.0]

Post by Setsukka »

balala wrote: January 22nd, 2021, 7:50 pm Ok, thanks. Would be extremely useful for me. Better later then never.
And thank you again for this plugin.
I have updated this plugin now, and added 2 options "FileInitialDirectory" and "ImageInitialDirectory". Hopefully those can help you.
But I sadly failed on folders. Maybe the only way now is "UseNewStyle=1".
I do not suggest anyone less than win 10 to use "UseNewStyle=1" is because I met some problems when I test ver.1.1.0.1 on win 7.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FileChoose [Ver.1.1.0]

Post by balala »

Setsukka wrote: January 31st, 2021, 9:25 am I have updated this plugin now, and added 2 options "FileInitialDirectory" and "ImageInitialDirectory". Hopefully those can help you.
Definitely they are helping me. Great addition, thank you very much for it. I'm playing with these new options. A way to get the same for folder selection would be great, however even these options are extremely useful for me.
Thank you very much for your great and extremely usefull work.
:rosegift: :great: :thumbup: :rosegift:
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: FileChoose [Ver.1.1.0]

Post by balala »

Setsukka wrote: January 31st, 2021, 9:25 am But I sadly failed on folders. Maybe the only way now is "UseNewStyle=1".
Now that I played a little bit with the plugin, my question is if I set the UseNewStyle=1 option, how do I set the starting folder?
User avatar
Setsukka
Posts: 19
Joined: March 20th, 2018, 9:53 am
Location: China

Re: FileChoose [Ver.1.1.0]

Post by Setsukka »

balala wrote: January 31st, 2021, 9:29 pm Now that I played a little bit with the plugin, my question is if I set the UseNewStyle=1 option, how do I set the starting folder?
With the option FileInitialDirectory.
This option is designed for file and folder. The only problem is that when UseNewStyle=0, it dont work on folder.
Post Reply