It is currently May 3rd, 2024, 3:23 am

Need help getting various values from a C# Plugin

Share and get help with Plugins and Addons
AMoo-Miki
Posts: 12
Joined: January 30th, 2012, 1:17 pm

Need help getting various values from a C# Plugin

Post by AMoo-Miki »

I tend to automate the tasks I frequently do, and the majority of that I do with PHP, via command line. That is until I stumbled upon Rainmeter which is giving me the ability to have a wonderful minimalistic interface for doing what I want.

I ported my PHP script for downloading Youtube videos to a C# plugin (can't stand C++). It works beautifully but I was thinking of adding some return parameters to it such as Status, Progress, File Size and Downloaded Size, and that is where I hit a road block and it has been over 10hrs and I have found nothing helpful.

C# Portion

Code: Select all

        public UInt32 Update(Rainmeter.Settings.InstanceSettings instance) {
            switch (instance.INI_Value("FieldType").ToUpper()) {
                case "PROGRESS":
                    return Convert.ToUInt32(instance.GetTempValue("LastProgress", 0));
                case "FILESIZE":
                    return Convert.ToUInt32(instance.GetTempValue("LastFileSize", 0));

                case "DOWNLOADSIZE":
                    return Convert.ToUInt32(instance.GetTempValue("LastDownloadSize", 0));

                case "BUSY":
                    return Convert.ToUInt32(instance.GetTempValue("LastBusy", 0));
            } 
            return 0;
        }

        public double Update2(Rainmeter.Settings.InstanceSettings instance) {
            return 0.0;
        }

        public string GetString(Rainmeter.Settings.InstanceSettings instance) {
            switch (instance.INI_Value("FieldType").ToUpper()) {
                case "PROGRESS":
                    return instance.GetTempValue("LastProgress", 0).ToString();
                case "FILESIZE":
                    return instance.GetTempValue("LastFileSize", 0).ToString();

                case "DOWNLOADSIZE":
                    return instance.GetTempValue("LastDownloadSize", 0).ToString();

                case "BUSY":
                    return instance.GetTempValue("LastBusy", 0).ToString();
            } 
            return instance.GetTempValue("LastStatus", "Ready").ToString();
        }
Test Config.ini

Code: Select all

[YTDownloader]
Measure=Plugin
Plugin=Plugins\YoutubeDownloader.dll
SaveTo=#SaveTo#

[YT.Status.Text]
Meter=STRING
MeasureName=YTDownloader
X=385
Y=40
FontColor=255, 255, 255, 60
FontSize=9
FontFace=Segoe UI Semibold
AntiAlias=1
AutoScale=1
StringAlign=Right
StringEffect=Shadow
FontEffectColor=0,0,0,40

[YT.Progress]
Measure=Plugin
Plugin=Plugins\YoutubeDownloader.dll
FieldType="Progress"

[YT.Progress.Text]
Meter=STRING
MeasureName=YT.Progress
X=385
Y=80
FontColor=255, 255, 255, 60
FontSize=9
FontFace=Segoe UI Semibold
AntiAlias=1
AutoScale=1
StringAlign=Right
StringEffect=Shadow
FontEffectColor=0,0,0,40
Prefix="Progress: "
The "YT.Status.Text" part works perfectly fine, and I believe that is because it points "YTDownloader". If I put in any of the valid values for "FieldType" under "YTDownloader", it still works fine.
The problem is that I can't get YT.Progress.Text to show anything but "0".

I would be grateful if anyone with any hints could pitch in.
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Need help getting various values from a C# Plugin

Post by poiru »

We've been working on a new plugin API for Rainmeter 2.3 beta, which is scheduled for release next Sunday. The current C# plugin template is far from ideal and has a number of issues including potential deadlocks and crashes. I would encourage you to wait a week for the new C# plugin SDK.

If you want to take a shot it at now, the issue is that the instance parameter is specific to a single measure (i.e. [YTDownloader] and [YT.Progress] are completely unrelated). In order to have a parent/child measure structure, you'd have to do implement something like this:

Code: Select all

[ParentMeasure]
...

[ChildMeasure]
Parent=ParentMeasure
C++ plugins such as NowPlaying, FolderInfo, and WebParser use a similar implementation, but that isn't of much delight for your C# needs. To implement this with the current C# template will be tough -- you'll have to remove all of the unneeded abstractions and start from the bare essentials.

Your best shot it to just wait a week. As mentioned, the new C# plugin SDK will be vastly simplified and will also be quite a bit more flexible to work with. I'll be sure to include an example implementation of a parent/child measure structure.

Regards,
C++ lover ;)
AMoo-Miki
Posts: 12
Joined: January 30th, 2012, 1:17 pm

Re: Need help getting various values from a C# Plugin

Post by AMoo-Miki »

Thanks a ton for explaining the complications. I had actually gone through the NowPlaying to understand how that the job, and now I'm happy you gave me an excuse to stay away from it.

I will be eagerly waiting for Sunday, for the v2.3 and your parent->child example.
BTW, did I mention I love Rainmeter? Kudos to you guys.

I still have a wide grin seeing how you signed ur response :)
User avatar
psouza4
Developer
Posts: 30
Joined: December 2nd, 2010, 1:56 pm
Location: Meridian, ID, USA

Re: Need help getting various values from a C# Plugin

Post by psouza4 »

poiru wrote:The current C# plugin template is far from ideal and has a number of issues including potential deadlocks and crashes. I would encourage you to wait a week for the new C# plugin SDK.
That's basically my fault as I wrote the original template/implementation as a proof of concept. I threw together some quick documentation to get your average .NET developer up and running and then got too busy to ever really expand on that. It's good to see the template evolve under the capable Rainmeter team!
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Need help getting various values from a C# Plugin

Post by poiru »

psouza4 wrote:That's basically my fault as I wrote the original template/implementation as a proof of concept. I threw together some quick documentation to get your average .NET developer up and running and then got too busy to ever really expand on that. It's good to see the template evolve under the capable Rainmeter team!
We've put a lot of work and thought into the new API for both C/C++ and C# in an attempt to unify and simplify the code. We wouldn't have a C# template at all without you, so I just wanted to apologize if you felt my tone was judgemental. Much thanks for laying the seeds -- we really appreciate it :) Hopefully we'll see you around more in the future!
User avatar
psouza4
Developer
Posts: 30
Joined: December 2nd, 2010, 1:56 pm
Location: Meridian, ID, USA

Re: Need help getting various values from a C# Plugin

Post by psouza4 »

poiru wrote:We've put a lot of work and thought into the new API for both C/C++ and C# in an attempt to unify and simplify the code. We wouldn't have a C# template at all without you, so I just wanted to apologize if you felt my tone was judgemental. Much thanks for laying the seeds -- we really appreciate it :) Hopefully we'll see you around more in the future!
Oh not at all, and I didn't mean to thread hijack -- just chiming in! It's great to see work pushed to new and emerging technologies to leverage today's developers who aren't as familiar with pure C/C++. Just wish I had more time to be part o everything -- I'll look forward to seeing the improvements to the C# template too! Are you still using my utility to convert the DLL's (IL DASM/ASM) or using something more native now?
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Need help getting various values from a C# Plugin

Post by poiru »

psouza4 wrote:Are you still using my utility to convert the DLL's (IL DASM/ASM) or using something more native now?
With your utility, the issue, if I recall correctly, was crashes due to calling convention mismatch. The tool exported functions as __stdcall (rather than __cdecl as Rainmeter expected), but that became a problem only after the new API parameters were added.

Tried other exporters, but they all had their share of issues. Had a major headache figuring things out (given my non-existent experience with C# or .NET in general), but ended up writing my own exporter tool. Not perfect, but does the job well enough :)
AMoo-Miki
Posts: 12
Joined: January 30th, 2012, 1:17 pm

Re: Need help getting various values from a C# Plugin

Post by AMoo-Miki »

I just paid a visit to the SVN. Thanks a ton for the examples. All I have to wait for is the 2.3 installer :)
poiru
Developer
Posts: 2872
Joined: April 17th, 2009, 12:18 pm

Re: Need help getting various values from a C# Plugin

Post by poiru »

AMoo-Miki wrote:I just paid a visit to the SVN. Thanks a ton for the examples. All I have to wait for is the 2.3 installer :)
No problem. One day to go.. :)
AMoo-Miki
Posts: 12
Joined: January 30th, 2012, 1:17 pm

Re: Need help getting various values from a C# Plugin

Post by AMoo-Miki »

@poiru

Looking at the documentation, at http://rainmeter.net/cms/Developers-PluginAPI-CS specifically under "Plugin methods", I didn't see a mention of "ExecuteBang". How can I send commands to the plugin?

Update: (just saw this)
Note: The ExecuteBang function present in the old API is not (yet) implemented in the new API. If your plugin must react to the !CommandMeasure (or !PluginBang) bang, wait until the SDK update next week.