It is currently April 19th, 2024, 3:56 am

Help can't find way to detect a certain file name

Get help with creating, editing & fixing problems with skins
Leeroi
Posts: 11
Joined: August 8th, 2018, 12:43 pm

Help can't find way to detect a certain file name

Post by Leeroi »

I'm modding this skin and what I want is if (filename).dll exist [meterRightSide] Text=On if the file exist otherwise Text=Off if the file does not exist. I used the Illustro script and grab the design of it so it can fit to the other skin I have

Code: Select all

[Variables]
OnText=On
OffText=Off
fontName=Trebuchet MS
textSize=8
colorBar=235,170,0,255
colorText=255,255,255,205

[Rainmeter]
Update=1000
Background=#@#Background.png
BackgroundMode=3
BackgroundMargins=0,34,0,14

[MeasureFile]
Measure=Plugin
Plugin=FileView
PathName="D:\Program Files\Steam\"
Type=FileType
Index=crashhandlerhack.dll

; ----------------------------------
; File Check and Change.
; ----------------------------------

[meterTitle]
Meter=String
MeterStyle=styleTitle
X=100
Y=12
W=190
H=18
Text=Check
LeftMouseUpAction=[!CommandMeasure measureBinItems "OpenBin"]
RightMouseUpAction=[!CommandMeasure measureBinItems "EmptyBin"]
ToolTipText=Left-click to On Right-click to Off

[meterLeftSide]
Meter=String
MeterStyle=styleLeftText
MeasureName=measureBinItems
X=10
Y=40
W=190
H=14
Text=Check Availability

[meterRightSide]
Meter=String
MeterStyle=styleRightText
MeasureName=measureBinSize
X=200
Y=0r
W=190
H=14
Text=

[meterSeperator]
Meter=Image
MeterStyle=styleSeperator
X=10
Y=52
W=190
H=1
[styleTitle]
StringAlign=Center
StringCase=Upper
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,50
FontColor=#colorText#
FontFace=#fontName#
FontSize=10
AntiAlias=1
ClipString=1

[styleLeftText]
StringAlign=Left
; Meters using styleLeftText will be left-aligned.
StringCase=None
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=Right
StringCase=None
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleSeperator]
SolidColor=255,255,255,15
User avatar
ikarus1969
Posts: 571
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Help can't find way to detect a certain file name

Post by ikarus1969 »

In the following thread jsmorley posted a way to detect if a picture exists. You can use it for your purpose as well:

https://forum.rainmeter.net/viewtopic.php?f=14&t=36296&p=185584&hilit=file+exists#p185584

Does this help you?
Leeroi
Posts: 11
Joined: August 8th, 2018, 12:43 pm

Re: Help can't find way to detect a certain file name

Post by Leeroi »

ikarus1969 wrote: December 3rd, 2020, 6:30 am In the following thread jsmorley posted a way to detect if a picture exists. You can use it for your purpose as well:

https://forum.rainmeter.net/viewtopic.php?f=14&t=36296&p=185584&hilit=file+exists#p185584

Does this help you?
I don't know how to use this I'm just new at this thing
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help can't find way to detect a certain file name

Post by balala »

Leeroi wrote: December 3rd, 2020, 7:22 am I don't know how to use this I'm just new at this thing
Do the followings:
  • Create the MyLua.lua file in the @Resources folder. Take care about its encoding. Set it to UTF-16 LE (a few details about encoding here).
  • Open the previously added MyLua.lua file and paste the following code into it:

    Code: Select all

    function file_exists(name)
    	local f=io.open(name,"r")
    	if f~=nil then
    		io.close(f)
    		return 1
    	else
    		return 0
    	end
    end
    Save and close the file.
  • Add the following variable to the [Variables] section of the skin: FileToCheck=D:\Program Files\Steam\crashhandlerhack.dll (obviously here you have to add the file which has to be checked if does exist).
  • Add the following measure to the code which you posted above, in your initial post:

    Code: Select all

    [MeasureLuaScript]
    Measure=Script
    ScriptFile=#@#MyLua.lua
    Disabled=1
  • You can find out if the file exists or not through the [&MeasureLuaScript:file_exists('#FileToCheck#')] section variable. See that here I used the previously added FileToCheck variable.
  • Finally to modify what the [meterRightSide] meter does show, you need to add a Calc measure. Add the following one:

    Code: Select all

    [MeasureCheck]
    Measure=Calc
    Formula=[&MeasureLuaScript:file_exists('#FileToCheck#')]
    IfCondition=(#CURRENTSECTION#>=1)
    IfTrueAction=[!SetOption meterRightSide Text "Text=On"][!UpdateMeter "meterRightSide"][!Redraw]
    IfFalseAction=[!SetOption meterRightSide Text "Text=Off"][!UpdateMeter "meterRightSide"][!Redraw]
    DynamicVariables=1
    The !SetOption bangs of the above IfTrueAction and IfFalseAction options set the appropriate Text option to the [meterRightSide] meter.
Please try the above described procedure. If any question arrises and you are not entirely sure what to do, please come back with a question.
Leeroi
Posts: 11
Joined: August 8th, 2018, 12:43 pm

Re: Help can't find way to detect a certain file name

Post by Leeroi »

Thank you both of you for helping me finish my skin :)
Leeroi wrote: December 3rd, 2020, 7:22 am I don't know how to use this I'm just new at this thing
balala wrote: December 3rd, 2020, 8:55 am Do the followings:
  • Create the MyLua.lua file in the @Resources folder. Take care about its encoding. Set it to UTF-16 LE (a few details about encoding here).
  • Open the previously added MyLua.lua file and paste the following code into it:

    Code: Select all

    function file_exists(name)
    	local f=io.open(name,"r")
    	if f~=nil then
    		io.close(f)
    		return 1
    	else
    		return 0
    	end
    end
    Save and close the file.
  • Add the following variable to the [Variables] section of the skin: (obviously here you have to add the file which has to be checked if does exist).
  • Add the following measure to the code which you posted above, in your initial post:

    Code: Select all

    [MeasureLuaScript]
    Measure=Script
    ScriptFile=#@#MyLua.lua
    Disabled=1
  • You can find out if the file exists or not through the [&MeasureLuaScript:file_exists('#FileToCheck#')] section variable. See that here I used the previously added FileToCheck variable.
  • Finally to modify what the [meterRightSide] meter does show, you need to add a Calc measure. Add the following one:

    Code: Select all

    [MeasureCheck]
    Measure=Calc
    Formula=[&MeasureLuaScript:file_exists('#FileToCheck#')]
    IfCondition=(#CURRENTSECTION#>=1)
    IfTrueAction=[!SetOption meterRightSide Text "Text=On"][!UpdateMeter "meterRightSide"][!Redraw]
    IfFalseAction=[!SetOption meterRightSide Text "Text=Off"][!UpdateMeter "meterRightSide"][!Redraw]
    DynamicVariables=1
    The !SetOption bangs of the above IfTrueAction and IfFalseAction options set the appropriate Text option to the [meterRightSide] meter.
Please try the above described procedure. If any question arrises and you are not entirely sure what to do, please come back with a question.
User avatar
balala
Rainmeter Sage
Posts: 16144
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Help can't find way to detect a certain file name

Post by balala »

Leeroi wrote: December 3rd, 2020, 9:41 am Thank you both of you for helping me finish my skin :)
Does it work?