It is currently July 18th, 2019, 8:26 pm

WebParser on local files

Help with creating, editing & fixing problems with skins
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

WebParser on local files

kyriakos876 » October 7th, 2018, 10:11 am

Hello, I have this context in a .txt file at #@#

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3]
"Settings"=hex:30,00,00,00,fe,ff,ff,ff,02,00,00,00,03,00,00,00,4e,00,00,00,28,\
00,00,00,00,00,00,00,10,04,00,00,80,07,00,00,38,04,00,00,60,00,00,00,01,00,\
00,00
How can I use webparser to extract for example the large red "03" from all of this?

I tried

Code: Select all

[MeasureParser]
Measure=Plugin
Plugin=WebParser
URL=file://#@#ExportedRegistry.txt
RegExp=(.*)
DynamicVariables=1
Just to first try and read everything, but that returns some weird symbols like it's encrypted.
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser on local files

balala » October 7th, 2018, 10:18 am

Is that a registry key or a text file you want to read? Not clear. It looks like a registry key, but if it is, why do you need a WebParser measure?
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: WebParser on local files

kyriakos876 » October 7th, 2018, 10:20 am

balala wrote:Is that a registry key or a text file you want to read? Not clear. It looks like a registry key, but if it is, why do you need a WebParser measure?
https://docs.rainmeter.net/manual/measures/registry/#RegValue

The value is a REG_BINARY and rainmeter doesn't read that kind of registry values so I extracted it using CMD into a file, and now I want to read that.
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser on local files

balala » October 7th, 2018, 10:30 am

OK, understand. Please post the whole code. I probably would use a substitution, but would want to see the code first.
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: WebParser on local files

kyriakos876 » October 7th, 2018, 10:38 am

balala wrote:OK, understand. Please post the whole code. I probably would use a substitution, but would want to see the code first.
Here's what I've got so far. (Keep in mind that I want to extract the "03" mentioned above from the ExportedRegistry.txt file)

NOTE: This KEY could be different in your pc and you might get 00, 01, 02 instead of 03... don't stick to that, just try and extracted some of these values. For example the one after the 5th comma.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser on local files

balala » October 7th, 2018, 12:37 pm

A first and most important problem is that the ExportedRegistry.txt file should have to be encoded as ANSI, but it's a Unicode. Rainmeter doesn't handle fine this encoding.
But there is a solution: add a CodePage=1200 option to the [MeasureParser] measure.
Beside this I also rewrote and removed a few options. Below you can see the rewritten code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
Solidcolor=40,40,40
MouseScrollDownAction=[!Refresh]
OnRefreshAction=[!CommandMeasure DeletionOfTXT "Run"]

[MeasureWindowsVersion]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3
RegValue=Settings
;UpdateDivider=-1

;[MeasureLua]
;Measure=Script
;ScriptFile=#@#ReadExport.lua

[DeletionOfTXT]
Measure=Plugin
Plugin=RunCommand
Parameter=REG EXPORT HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 "#@#ExportedRegistry.txt"
;FinishAction=[!CommandMeasure "MeasureParser" "Update"]

;[MeasureReg]
;Measure=Calc
;IfCondition=1
;IfTrueAction=[!CommandMeasure DeletionOfTXT "Run"][!Delay 24][REG EXPORT HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 "#@#ExportedRegistry.txt"]
;UpdateDivider=-1

;[StringMeasure]
;Measure=String
;String=([&MeasureLua:ReadFile('#@#ExportedRegistry.txt')]
;DynamicVariables=1

[MeasureParser]
Measure=Plugin
Plugin=WebParser
URL=file://#@#ExportedRegistry.txt
CodePage=1200
RegExp=(?siU)^(.*)$
StringIndex=1
RegExpSubstitute=1
Substitute=".*\n.*\n.*\n.*:..,..,..,..,(..),.*\n.*\n.*":"\1"
UpdateRate=10
DynamicVariables=1

[MeterText]
Meter=String
MeasureName=MeasureParser
FontColor=255,255,255,255
Text=The value is: %1
Padding=15,5,15,5
See that:
  • I modified the [DeletionOfTXT] measure (I'm not sure if you1re using this for any specific task). Now it exports the value of the appropriate registry key, to the file.
  • This measure is ran now by the OnRefreshAction option of the [Rainmeter] section.
  • I completely commented out the [MeasureReg] measure.
  • The Substitute option of the [MeasureParser] measure removes the not needed parts of the parsed string.
Please test the above code and let me know how does it work.
User avatar
kyriakos876
Posts: 914
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: WebParser on local files

kyriakos876 » October 7th, 2018, 1:28 pm

balala wrote:A first and most important problem is that the ExportedRegistry.txt file should have to be encoded as ANSI, but it's a Unicode. Rainmeter doesn't handle fine this encoding.
But there is a solution: add a CodePage=1200 option to the [MeasureParser] measure.
Beside this I also rewrote and removed a few options. Below you can see the rewritten code:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
Solidcolor=40,40,40
MouseScrollDownAction=[!Refresh]
OnRefreshAction=[!CommandMeasure DeletionOfTXT "Run"]

[MeasureWindowsVersion]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3
RegValue=Settings
;UpdateDivider=-1

;[MeasureLua]
;Measure=Script
;ScriptFile=#@#ReadExport.lua

[DeletionOfTXT]
Measure=Plugin
Plugin=RunCommand
Parameter=REG EXPORT HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 "#@#ExportedRegistry.txt"
;FinishAction=[!CommandMeasure "MeasureParser" "Update"]

;[MeasureReg]
;Measure=Calc
;IfCondition=1
;IfTrueAction=[!CommandMeasure DeletionOfTXT "Run"][!Delay 24][REG EXPORT HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 "#@#ExportedRegistry.txt"]
;UpdateDivider=-1

;[StringMeasure]
;Measure=String
;String=([&MeasureLua:ReadFile('#@#ExportedRegistry.txt')]
;DynamicVariables=1

[MeasureParser]
Measure=Plugin
Plugin=WebParser
URL=file://#@#ExportedRegistry.txt
CodePage=1200
RegExp=(?siU)^(.*)$
StringIndex=1
RegExpSubstitute=1
Substitute=".*\n.*\n.*\n.*:..,..,..,..,(..),.*\n.*\n.*":"\1"
UpdateRate=10
DynamicVariables=1

[MeterText]
Meter=String
MeasureName=MeasureParser
FontColor=255,255,255,255
Text=The value is: %1
Padding=15,5,15,5
See that:
  • I modified the [DeletionOfTXT] measure (I'm not sure if you1re using this for any specific task). Now it exports the value of the appropriate registry key, to the file.
  • This measure is ran now by the OnRefreshAction option of the [Rainmeter] section.
  • I completely commented out the [MeasureReg] measure.
  • The Substitute option of the [MeasureParser] measure removes the not needed parts of the parsed string.
Please test the above code and let me know how does it work.
I actually wanted the [DeletionOfTXT] because if you don't delete the file and execute the EXPORT command in the CMD you will get a CMD prompt to either overwrite the already existing txt file or not, and I don't want to bother the user with that, so I delete it before I pull the registry key.

The [MeasureReg] is also used for the above reason.

All in all, combining your code and my code, I ended up with this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
Solidcolor=40,40,40
MouseScrollDownAction=[!Refresh]

[DeletionOfTXT]
Measure=Plugin
Plugin=RunCommand
Parameter=DEL #@#\ExportedRegistry.txt

[MeasureReg]
Measure=Calc
IfCondition=1
IfTrueAction=[!CommandMeasure DeletionOfTXT "Run"][!Delay 500][REG EXPORT HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 "#@#ExportedRegistry.txt"]

[MeasureParser]
Measure=Plugin
Plugin=WebParser
URL=file://#@#ExportedRegistry.txt
CodePage=1200
RegExp=(?siU)^(.*)$
StringIndex=1
RegExpSubstitute=1
Substitute=".*\n.*\n.*\n.*:..,..,..,..,..,..,..,..,..,..,..,..,(..),.*\n.*\n.*":"\1"
UpdateRate=1
DynamicVariables=1

[Translator]
Measure=String
String=[MeasureParser]
IfMatch=00
IfMatchAction=[!SetOption MeterText Text "Your taskbar is located on the left of your screen."][!UpdateMeter MeterText][!Redraw]
IfMatch2=01
IfMatchAction2=[!SetOption MeterText Text "Your taskbar is located at the top of your screen."][!UpdateMeter MeterText][!Redraw]
IfMatch3=02
IfMatchAction3=[!SetOption MeterText Text "Your taskbar is located on the right of your screen."][!UpdateMeter MeterText][!Redraw]
IfMatch4=03
IfMatchAction4=[!SetOption MeterText Text "Your taskbar is located at the bottom of your screen."][!UpdateMeter MeterText][!Redraw]
DynamicVariables=1

[MeterText]
Meter=String
MeasureName=MeasureParser
FontColor=255,255,255,255
Text=The value is: %1
Padding=15,5,15,5
which works great.
User avatar
balala
Rainmeter Sage
Posts: 8376
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: WebParser on local files

balala » October 7th, 2018, 3:02 pm

kyriakos876 wrote:All in all, combining your code and my code, I ended up with this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
Solidcolor=40,40,40
MouseScrollDownAction=[!Refresh]

[DeletionOfTXT]
Measure=Plugin
Plugin=RunCommand
Parameter=DEL #@#\ExportedRegistry.txt

[MeasureReg]
Measure=Calc
IfCondition=1
IfTrueAction=[!CommandMeasure DeletionOfTXT "Run"][!Delay 500][REG EXPORT HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3 "#@#ExportedRegistry.txt"]

[MeasureParser]
Measure=Plugin
Plugin=WebParser
URL=file://#@#ExportedRegistry.txt
CodePage=1200
RegExp=(?siU)^(.*)$
StringIndex=1
RegExpSubstitute=1
Substitute=".*\n.*\n.*\n.*:..,..,..,..,..,..,..,..,..,..,..,..,(..),.*\n.*\n.*":"\1"
UpdateRate=1
DynamicVariables=1

[Translator]
Measure=String
String=[MeasureParser]
IfMatch=00
IfMatchAction=[!SetOption MeterText Text "Your taskbar is located on the left of your screen."][!UpdateMeter MeterText][!Redraw]
IfMatch2=01
IfMatchAction2=[!SetOption MeterText Text "Your taskbar is located at the top of your screen."][!UpdateMeter MeterText][!Redraw]
IfMatch3=02
IfMatchAction3=[!SetOption MeterText Text "Your taskbar is located on the right of your screen."][!UpdateMeter MeterText][!Redraw]
IfMatch4=03
IfMatchAction4=[!SetOption MeterText Text "Your taskbar is located at the bottom of your screen."][!UpdateMeter MeterText][!Redraw]
DynamicVariables=1

[MeterText]
Meter=String
MeasureName=MeasureParser
FontColor=255,255,255,255
Text=The value is: %1
Padding=15,5,15,5
which works great.
:thumbup: I'm glad. :thumbup: