It is currently March 28th, 2024, 7:05 pm

Validate if a file exist otherwise set a default file

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

jsmorley wrote: November 2nd, 2020, 11:17 pm Parsing is complicated indeed. I think Brian will have to weigh in on that one.
Ok then. Sorry for giving you folks something to work on - again. :confused:
Regarding the non-existent image dimensions being set to 0 (the lil' bug), this might be a somewhat logical (not sure if the expected though) behavior, since the general action when encountering an error (like a file missing) is to "do nothing" - thus don't modify the W and H either. Don't know, just saying - that's why I mentioned backward compatibilty there, because I remember some skins being based on the fact that Rainmeter will just silently ignore somewhat similar "errors". Probably something to think about.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

django933 wrote: November 2nd, 2020, 10:06 pmYes, i tried the first variant and didn't work.
I sort of suspected that, actually - but I promised you that I'll try to post a version of that approach today. Too bad I discovered the "inconsistency" in the process...
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Validate if a file exist otherwise set a default file

Post by balala »

Yincognito wrote: November 2nd, 2020, 9:46 pm Thanks for the suggestion, but does one need to use a plugin for every little bit of functionality out there, especially when that functionality exists already?
Without reading all the following discussion, it's obvious you can use what you want. I'd prefer the ImageSize plugin instead of adding an Image meter just to get the size of the image. But if you dislike it, you're free to create the code as you want.
Yincognito wrote: November 2nd, 2020, 9:46 pm why not including them in the standard Rainmeter distribution instead of having to hunt them through the many pages of the forum?
Because all plugins can't be uincluded and doesn't even worth.
PS:
Yincognito wrote: November 2nd, 2020, 9:46 pm it really feels awkward to have to use an image size plugin when there is an image plugin already.
Sorry, that's not a plugin, it's a meter, in fact (sorry, hope you don't mind I had to tell this)...
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

balala wrote: November 3rd, 2020, 11:50 am Without reading all the following discussion, it's obvious you can use what you want. I'd prefer the ImageSize plugin instead of adding an Image meter just to get the size of the image. But if you dislike it, you're free to create the code as you want.
While I think the difference is negligible in a practical sense, I would argue that using the ImageSize plugin is a tad more efficient than creating a transparent or "outside the skin" Image meter to get the size. The ImageSize plugin is as resource friendly as I could make it, as while it does load the image into memory, once it has the width and height it immediately after throws the new bitmap away entirely. An Image meter in Rainmeter is going to cache the image and carry it around in memory as long as the skin is active.

The plugin also only ever reads the image one time. It will only re-read the image if you specifically "tell" it to, when you use !SetOption to change the image you want to evaluate. While an Image meter in Rainmeter will cache the image, so it isn't re-reading the entire thing on each update, it does have to touch the image each time to ensure it hasn't changed.

The downside to the plugin is that you need two measures, one for width and one for height, for each image you want to evaluate. I really need to change this to allow section variable calls to it so you only need one measure.

So I don't have a strong opinion on this. There is no reason to be particularly skeptical of an approach where you just create an Image meter with ImageAlpaha=0 on it, and use the :W and :H section variable parameters to get the image size.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Validate if a file exist otherwise set a default file

Post by balala »

jsmorley wrote: November 3rd, 2020, 12:33 pm While I think the difference is negligible in a practical sense, I would argue that using the ImageSize plugin is a tad more efficient than creating a transparent or "outside the skin" Image meter to get the size. The ImageSize plugin is as resource friendly as I could make it, as while it does load the image into memory, once it has the width and height it immediately after throws the new bitmap away entirely. An Image meter in Rainmeter is going to cache the image and carry it around in memory as long as the skin is active.
Yes, but I think on modern computers and OSs this doesn't worth too much. Any of these operations are easily handled (at least as far as I can tell) by a decent processor, running a Win 10 for instance. Am I right?
jsmorley wrote: November 3rd, 2020, 12:33 pm The downside to the plugin is that you need two measures, one for width and one for height, for each image you want to evaluate. I really need to change this to allow section variable calls to it so you only need one measure.
Again, my opinion is that doesn't worth. Having two measure is not a big problem, me personally don't see this as a great disadvantage.
jsmorley wrote: November 3rd, 2020, 12:33 pm So I don't have a strong opinion on this. There is no reason to be particularly skeptical of an approach where you just create an Image meter with ImageAlpaha=0 on it, and use the :W and :H section variable parameters to get the image size.
I'm not skeptical at all. As said, this question, as most (all?) in Rainmeter, has more solutions. Using the Image meter is one of them, the plugin is another. I'd prefer the plugin solution, but definitely not everyone agrees me.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Validate if a file exist otherwise set a default file

Post by jsmorley »

balala wrote: November 3rd, 2020, 12:55 pm Yes, but I think on modern computers and OSs this doesn't worth too much. Any of these operations are easily handled (at least as far as I can tell) by a decent processor, running a Win 10 for instance. Am I right?
Right. When I say "negligible" above, I really mean "rounds to zero" on any decent computer.
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

balala wrote: November 3rd, 2020, 11:50 am Without reading all the following discussion, it's obvious you can use what you want. I'd prefer the ImageSize plugin instead of adding an Image meter just to get the size of the image. But if you dislike it, you're free to create the code as you want.

Because all plugins can't be uincluded and doesn't even worth.
PS:

Sorry, that's not a plugin, it's a meter, in fact (sorry, hope you don't mind I had to tell this)...
Yeah, I understand the plugins matter and I'm all for it, really. The long and short of the discussion is that a little bug prevents my solution to work as it should, and I couldn't comprehend why it would take a plugin to do what should have been possible without it in the first place. That's all there is to it. My personal approach on this (like using plugins only for inter-application stuff or things that are just not possible otherwise) has no relevance here, since it's not about one of my own skins, but about an (alternative) solution for the OP.

And yes, I wrongly typed "image plugin" when I should have typed "image meter" - guess I was still thinking about it when typing. :D

Regarding plugins, one that comes to mind is a PowerShell one. Not a "classic" one, but one that can help PowerShell execute faster (like CMD, for example) than it is by running through RunCommand. If that's even possible, that is, through some sort of an already loaded PowerShell "module".
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Yincognito
Rainmeter Sage
Posts: 7025
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Validate if a file exist otherwise set a default file

Post by Yincognito »

jsmorley wrote: November 3rd, 2020, 12:33 pmWhile I think the difference is negligible in a practical sense, I would argue that using the ImageSize plugin is a tad more efficient than creating a transparent or "outside the skin" Image meter to get the size.
I agree with you on this one. I don't know if it applies to images as well besides shapes (my guess is that it won't, but I could be very well mistaken), but for very large shapes the difference is huge, even if only a "small" portion of them are actually visible in the skin. Proof: my Solar System skin. Sure, it's about a fast update rate and some relatively complex math there as well, but still, even out of view very large shapes take a bit too much CPU for my liking. I have no idea if it applies to images as well, or if it's that bad for images too, that's a question for another time.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth