It is currently April 26th, 2024, 5:52 am

Convert lowercase to uppercase

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Convert lowercase to uppercase

Post by balala »

jsmorley wrote:So how are the initial values received?
Dynamically. They will be set by a !SetVariable bang.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert lowercase to uppercase

Post by jsmorley »

balala wrote:Dynamically. They will be set by a !SetVariable bang.
I need to understand what is going to trigger updating the String measure, which will then do the !WriteKeyValue when it is updated.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Convert lowercase to uppercase

Post by balala »

jsmorley wrote:I need to understand what is going to trigger updating the String measure, which will then do the !WriteKeyValue when it is updated.
When the Path variable is set (through a !SetVariable bang), the String measure should have to be updated and this one should have to make the appropriate substitution, if it's possible (so, if the set variable is a a path of a file contained into the @Resources folder of the current config).
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert lowercase to uppercase

Post by jsmorley »

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
@Include=#CURRENTPATH#MyVars.inc

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[MeasurePath]
Measure=String
Disabled=1
UpdateDivider=-1
DynamicVariables=1
OnUpdateAction=[!WriteKeyValue Variables Path1 "[Lua:ReplaceResources('[#Path1]')]" "[#CURRENTPATH]MyVars.inc"]

[MeterChange]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=Update
LeftMouseUpAction=[!SetVariable Path1 "c:\Users\jeffrey\Documents\Rainmeter\Skins\@Working\@Resources\SomeImage.png"][!EnableMeasure MeasurePath][!UpdateMeasure MeasurePath]
Lua:

Code: Select all

function ReplaceResources(inArg)

	MyResources = SKIN:GetVariable('@')
	
	startResources, endResources = string.find(string.upper(inArg), string.upper(MyResources))

	if startResources then
		return '#@#'..string.sub(inArg, endResources + 1)
	else
		return inArg
	end

end
Does that make some sense?

I caution that this will likely not work well with multi-byte Unicode characters in the @Resources path, as that can and will throw off things that are dependent on "string length". The only solution for that is to convert the path to upper case in the Lua, and then use string.gsub() which is not dependent on the position of anything in the string. That will mean that the result that is written will have to be upper case though.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert lowercase to uppercase

Post by jsmorley »

That would look like:

Code: Select all

function ReplaceResources(inArg)

	myResources = SKIN:GetVariable('@')
	
	outArg = string.gsub(string.upper(inArg), string.upper(myResources), '#@#')
	
	return outArg

end
But you would end up with:

Code: Select all

[Variables]
Path1=#@#SOMEIMAGE.PNG
To be honest, string "case" is just a matter of cosmetics in any path you use with Windows. It doesn't care. Paths and file names are never case sensitive.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Convert lowercase to uppercase

Post by balala »

jsmorley wrote:Does that make some sense?
Yep, it does and works for now. Will have to study the code of the .lua file, to better understand how does it work. But it seems that definitely works.
Many thanks for your help.
jsmorley wrote:I caution that this will likely not work well with multi-byte Unicode characters in the @Resources path, as that can and will throw off things that are dependent on "string length". The only solution for that is to convert the path to upper case in the Lua, and then use string.gsub() which is not dependent on the position of anything in the string. That will mean that the result that is written will have to be upper case though.
At least for now this isn't a problem, I used just simple letters, without diacritics, I hope will be no problems with this.
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert lowercase to uppercase

Post by jsmorley »

The problem would come if the users name or any other part of the path has multi-bye Unicode like 某些文件夹
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Convert lowercase to uppercase

Post by balala »

jsmorley wrote:But you would end up with:

Code: Select all

[Variables]
Path1=#@#SOMEIMAGE.PNG
No problem!
jsmorley wrote:To be honest, string "case" is just a matter of cosmetics in any path you use with Windows. It doesn't care. Paths and file names are never case sensitive.
Yes, I know. The initial question came when I wanted to make the Substitute="#@#":"#*@*#" substitution (didn't think yet to the reserved character issue then), but due to the lowercase drive letter in the Path variable, the substitution wasn't made.
User avatar
balala
Rainmeter Sage
Posts: 16172
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Convert lowercase to uppercase

Post by balala »

jsmorley wrote:The problem would come if the users name or any other part of the path has multi-bye Unicode like 某些文件夹
:thumbup: I think there is no (good) solution for this?
User avatar
jsmorley
Developer
Posts: 22630
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Convert lowercase to uppercase

Post by jsmorley »

balala wrote:No problem!

Yes, I know. The initial question came when I wanted to make the Substitute="#@#":"#*@*#" substitution (didn't think yet to the reserved character issue then), but due to the lowercase drive letter in the Path variable, the substitution wasn't made.
Right, I'm just saying that case isn't important to Windows, so if you store the path variables in the .inc file in upper case, it will work fine, unless you are "displaying" the path in the skin, in which case converting to upper case might not look great. So my first approach maintains the case as is, but will have trouble with Unicode, and the second is more certain, but will have the cosmetic issue.