It is currently December 15th, 2019, 6:33 am

FileChoose [Ver.1.1.0]

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

FileChoose [Ver.1.1.0]

Setsukka » October 23rd, 2019, 2:38 pm

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

Ver.1.1.0.1 Oct. 31 2019
_Add $Icon$ for use.
_Add 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 and win7.

Download
FileChoose Sample_1.1.0.2.rmskin
SouceCode :
FileChoose_SourceCode_1.1.0.2.rar
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

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, a new method will be used.
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.

  • 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 way 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
You do not have the required permissions to view the files attached to this post.
Last edited by Setsukka on December 8th, 2019, 3:02 pm, edited 5 times in total.
dujianaliuli
Posts: 1
Joined: October 23rd, 2019, 3:36 pm

Re: FileChoose [Ver.1.0.0.2]

dujianaliuli » October 23rd, 2019, 3:44 pm

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

Re: FileChoose [Ver.1.0.0.2]

gkmaz9 » October 28th, 2019, 11:19 am

Thank you. This is very useful. :D