So I have simplified my script immensely, here is the new code:
Code: Select all
identifierString = '%^1%^'
cTable = {}
function Initialize() end
function Update() end
function Split(allDisks)
allDisks:gsub(".", function(c)
table.insert(cTable, c)
SKIN:Bang(string.format('!WriteKeyValue Variables "Underliner_Width_%s" "0" "#@#Variables.inc"',c))
end)
-- print(allDisks)
Concat()
SKIN:Bang('!Refresh')
end
function Concat()
local rTable = {}
local lines = {}
for line in io.lines(SELF:GetOption('templateFilePath')) do
table.insert(rTable, line)
end
for k,v in ipairs(cTable) do
for l,line in pairs(rTable) do
line = line:gsub(identifierString, v)
table.insert(lines, line)
end
end
outputFile = io.open(SELF:GetOption('outputFilePath'), 'w')
outputFile:write(table.concat(lines, '\n'))
outputFile:close()
end
Here is the template that the script is using:
Code: Select all
[MeasureTotalDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
Total=1
IgnoreRemovable=0
UpdateDivider=100
[MeasureUsedDisk^1^]
Measure=FreeDiskSpace
Drive=^1^:
InvertMeasure=1
IgnoreRemovable=0
UpdateDivider=100
[DiskAnimation^1^]
Measure=Plugin
Plugin=ActionTimer
ActionList1=UpdateOnce | Wait 16 | Repeat IconAnimationIn, 16, 16
UpdateOnce=[!Update]
IconAnimationIn=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#+25,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure ][!Redraw]
ActionList2=UpdateOnce | Wait 25 | Repeat IconAnimationOut, 16, 13
IconAnimationOut=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,0,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure ][!Redraw]
ActionList3=UpdateOnce | Wait 25 | Repeat MouseUp, 16, 6
MouseUp=[!SetVariable Underliner_Width_^1^ (Clamp(#Underliner_Width_^1^#-20,130,(#MaxWidth#-[MeterDisk^1^_Name:X]*2)))][!UpdateMeter Underliner_^1^][!UpdateMeasure ][!Redraw]
[MeterDisk^1^_Name]
Meter=String
MeterStyle=NormalLeft
X=#XFromTheWall#
Y=20r
DynamicVariables=1
UpdateDivider=-1
[MeterDisk^1^_Value]
Meter=String
MeasureName=MeasureUsedDisk^1^
MeasureName2=MeasureTotalDisk^1^
MeterStyle=NormalRight
X=(#MaxWidth#-#XFromTheWall#)
Y=r
Text=%1B/%2B
NumOfDecimals=1
AutoScale=1
UpdateDivider=100
[Background_Disk_^1^]
Meter=Shape
X=0
Y=([MeterDisk^1^_Name:Y]-[MeterDisk^1^_Name:W]/2)
Shape=Rectangle 0,0,#MaxWidth#,([MeterDisk^1^_Name:H]*1.75) | Fill Color 0,0,0,0 | StrokeWidth 0
LeftMouseUpAction=[^1^:]
DynamicVariables=1
UpdateDivider=-1
[Underliner_^1^]
Meter=Shape
X=(#MaxWidth#/2-0/2)
Y=-5R
Shape=Rectangle 0,0,#Underliner_Width_^1^#,1 | Fill Color 66,133,244 | StrokeWidth 0
DynamicVariables=1
UpdateDivider=-1
And here is the skin INI code I'm using:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
OnUpdateAction=[!CommandMeasure MeasureRun "Run"]
MouseScrollDownAction=[!Refresh]
BackgroundMode=2
Solidcolor=0,0,0
[Metadata]
Name=
Author=
Information=
Version=
License=Creative Commons Attribution - Non - Commercial - Share Alike 3.0
[Variables]
@Include=#@#Variables.inc
@Include2=#@#ScriptOutput.ini
AllDisks=CDE
StringLenght=0
[MeasureLua]
Measure=Script
ScriptFile=#@#Concat.lua
TemplateFilePath=#@#Template.ini
OutputFilePath=#@#ScriptOutput.ini
DynamicVariables=1
[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=wmic logicaldisk get caption
OutputType=ANSI
RegExpSubstitute=1
Substitute="Caption":""," ":"",":":"","Name.*#CRLF#":"","#CRLF#":"
DynamicVariables=1
FinishAction=[!EnableMeasure MeasureComparison][!UpdateMeasure MeasureComparison]
[MeasureComparison]
Measure=String
String=[MeasureRun]
IfMatch=^#AllDisks#$
IfNotMatchAction=[!WriteKeyValue Variables AllDisks "[MeasureRun]"][!DisableMeasure MeasureComparison][!CommandMeasure MeasureLua "Split('[MeasureRun]')"]
DynamicVariables=1
Disabled=1
[MeterDummy]
Meter=Image
SolidColor=10,10,10
W=20
H=20
You will see that I added a new measure,
[MeasureComparison]. When
[MeasureRun] finishes, it enables
[MeasureComparison] which will compare the value of
[MeasureRun] to the value of the
#allDisks# variable. This way, the skin will automatically update when disks are added or removed, and automatically refresh, but avoids the aforementioned refresh loop:
RMAdaptiveDisks2.gif
You can see here that despite needing to write a file and refresh the skin, it is quite fast. Disks Meter is only there to demonstrate which disks are being added and removed.
I have also package an RMSKIN for you so you can check it out in its full glory. With this method, rather than having to worry about escaping variables and getting quotes to work in a !WriteKeyValue bang, all you need to do is edit the template as you would edit a skin, and it'll work. Final note: If you want the script to leave a blank line between iterations of the template, then you need to leave two empty lines at the end of the template.
You do not have the required permissions to view the files attached to this post.