RunCommand is using Measure values from the last update cycle
Posted: April 23rd, 2018, 10:31 pm
Hello, I was working on a music skin and at one point my skin looks for a random album cover image and then has to look for a music file that belongs to that cover. For that I need to have the option to get the content of a folder so I can iterate through each file. Unfortunately the io.popen function in Lua which gets a list of files from a folder doesn't work with Rainmeter. I looked for a workaround and wrote a powershell script that writes the content of a folder into a text file. I can then use that text file to find the music file I need.
Here's the problem: I run the powershell script using the RunCommand plugin. RunCommand has to be called with a bang so every time a new album cover is extracted the RunCommand measure is called and runs the powershell script that writes the list of files. For some reason RunCommand seems to lag behind and uses the Measure Values from the last update cycle. So in the end the skin shows the music file that matches the previous album cover which isn't right. What's also weird is that if you call RunCommand with "OnRefreshAction" it will work right for the first cycle. Using "OnUpdateAction" is no alternative though since this is too taxing on the CPU.
It would be nice if someone could help me with this problem.
Here are all parts of my skin needed to reproduce the problem:
The .ini file:
The powershell script:
An image of the test skin. You can see that the found music file (just renamed text files in this skin, no actual music files) doesn't match the found cover image.
Here's the problem: I run the powershell script using the RunCommand plugin. RunCommand has to be called with a bang so every time a new album cover is extracted the RunCommand measure is called and runs the powershell script that writes the list of files. For some reason RunCommand seems to lag behind and uses the Measure Values from the last update cycle. So in the end the skin shows the music file that matches the previous album cover which isn't right. What's also weird is that if you call RunCommand with "OnRefreshAction" it will work right for the first cycle. Using "OnUpdateAction" is no alternative though since this is too taxing on the CPU.
It would be nice if someone could help me with this problem.
Here are all parts of my skin needed to reproduce the problem:
The .ini file:
Code: Select all
[Rainmeter]
Update=1000
;OnUpdateAction=[!CommandMeasure "MeasureRunFolderContent" "Run"]
;OnRefreshAction=[!CommandMeasure MeasureRunFolderContent "Run"]
[Variables]
MusicPath=#@#Albums
[StringStyle]
FontFace=Courier New
FontSize=8
FontColor=255,255,255,255
StringAlign=LEFT
StringEffect=Border
Antialias=1
###Measures###
[MeasureRandomCover]
Measure=Plugin
Plugin=QuotePlugin
PathName=#MusicPath#
Subfolders=1
FileFilter=*.jpg;*.png;*.gif
UpdateDivider=5
OnChangeAction=[!UpdateMeasureGroup "Image"]
;This lua script will get the file path to the image [MeasureRandomCover] extracted.
[MeasureLuaGetImagePath]
Measure=Script
ScriptFile=#@#GetImagePath.lua
TableName=NoPath
Group=Image
UpdateDivider=-1
OnChangeAction=[!CommandMeasure MeasureRunFolderContent "Run"]
;DynamicVariables=1
[MeasureStringCoverFolder]
Measure=String
String=[MeasureLuaGetImagePath]
RegExpSubstitute=1
Substitute="\\[^\\]*$":""
Group=Image
UpdateDivider=-1
DynamicVariables=1
[MeasureStringCoverFolderParent]
Measure=String
String=[MeasureLuaGetImagePath]
RegExpSubstitute=1
Substitute="\\[^\\]*\\[^\\]*$":""
Group=Image
UpdateDivider=-1
DynamicVariables=1
;This measure calls a powershell script that gets the filepaths of all files inside [MeasureStringCoverFolder] and [MeasureStringCoverFolderParent]
;and writes them into the output file #@#\TempFileList.txt.
[MeasureRunFolderContent]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell.exe
Parameter=-NoProfile -ExecutionPolicy Bypass -Command "& '#@#\FolderContent.ps1' '[MeasureStringCoverFolder]' '[MeasureStringCoverFolderParent]' '#@#\TempFileList.txt'"
State=Hide
FinishAction=[!UpdateMeasure MeasureLuaFindMusicFile]
DynamicVariables=1
;This lua script will determine if the image from [MeasureStringImagePath] is possibly
;an album cover. It will then find the album folder with all music files that belongs to the
;cover. It will return false if no album folder can be found or it returns the path to a music
;file from the album folder. This music file can then be used to extract more metadata about
;the album.
[MeasureLuaFindMusicFile]
Measure=Script
ScriptFile=#@#FindMusicFile.lua
TableName=NoPath
UpdateDivider=-1
;DynamicVariables=1
[MeasureStringFindMusicFile]
Measure=String
String=[MeasureLuaFindMusicFile]
DynamicVariables=1
###Meters###
[MeterImage]
Meter=Image
MeasureName=MeasureRandomCover
X=10
Y=10
H=100
W=100
AntiAlias=1
[MeterImagePath]
Meter=STRING
MeasureName=MeasureLuaGetImagePath
MeterStyle=StringStyle
ClipString=2
Text=Found Cover Path: %1
X=120
Y=10
W=200
[MeterFoundFile]
Meter=STRING
MeasureName=MeasureStringFindMusicFile
MeterStyle=StringStyle
ClipString=2
Text=Found Music File: %1
X=120
Y=70
W=200
H=300
Code: Select all
$inputFolderOne = $args[0]
$inputFolderTwo = $args[1]
$outputPath = $args[2]
try
{
$stream = [System.IO.StreamWriter]::new( $outputPath )
Get-ChildItem -LiteralPath "$inputFolderOne","$inputFolderTwo" | ForEach-Object { $stream.WriteLine($_.FullName) }
}
finally
{
$stream.close()
#See which values the PowerShell script used:
#start cmd "/c echo $inputFolderOne && timeout 5"
}