Example #1
0
        private bool ExecuteLine(Rainmeter.Settings.InstanceSettings Instance, string sLine)
        {
            // If this line contains a $UserInput$ token, then we need to do some extra
            // parsing
            if (sLine.ToUpper().Contains("$USERINPUT$"))
            {
                try
                {
                    #region Handle in-line overrides
                    // Create a blank list of overrides
                    Dictionary <string, string> Overrides = new Dictionary <string, string>();

                    // Start looking for overridable settings and adjust the list accordingly,
                    // stripping out settings from the line if they are discovered.
                    //
                    // The supporting TagData() function allows for whitespace if quotes are
                    // used.  For example:
                    //
                    // DefaultValue="hello there, how are you"
                    sLine = ScanAndReplace(sLine, "DefaultValue", ref Overrides);
                    sLine = ScanAndReplace(sLine, "X", ref Overrides);
                    sLine = ScanAndReplace(sLine, "Y", ref Overrides);
                    sLine = ScanAndReplace(sLine, "W", ref Overrides);
                    sLine = ScanAndReplace(sLine, "H", ref Overrides);
                    sLine = ScanAndReplace(sLine, "StringStyle", ref Overrides);
                    sLine = ScanAndReplace(sLine, "StringAlign", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FocusDismiss", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FontColor", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FontFace", ref Overrides);
                    sLine = ScanAndReplace(sLine, "SolidColor", ref Overrides);
                    sLine = ScanAndReplace(sLine, "Password", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FontSize", ref Overrides);
                    sLine = ScanAndReplace(sLine, "TopMost", ref Overrides);
                    #endregion

                    // Get user input
                    string sInput = GetUserInput(Instance, Overrides);
                    if (sInput == null)
                    {
                        // Rainmeter.Log(Rainmeter.LogLevel.Debug, "InputText: Aborted, user cancelled text box");
                        return(false);
                    }

                    // Swap out the $UserInput$ token with what the user typed
                    sLine = Replace(sLine, "$USERINPUT$", sInput);
                }
                catch (Exception ex)
                {
                    // If there was an error doing any of the above, log it for debugging purposes.
                    Rainmeter.Log(Rainmeter.LogLevel.Warning, "InputText: Exception " + ex.GetType().ToString() + ": " + ex.Message);
                    return(false);
                }
            }

            // Execute the bang.  This will either be the original line from CommandX= (sLine variable) or
            // an adjusted line based on special parsing above.
            // Rainmeter.Log(Rainmeter.LogLevel.Debug, "InputText: Executing bang: " + sLine);
            Rainmeter.Bang(sLine);
            return(true);
        }
Example #2
0
        // Call this function to determine if the parent skin is topmost
        public static bool ParentIsTopmost(Rainmeter.Settings.InstanceSettings Instance)
        {
            IntPtr     hwnd = (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File))));
            WINDOWINFO info = new WINDOWINFO(true);

            GetWindowInfo(hwnd, ref info);
            return((info.dwExStyle & 0x00000008L) > 0);
        }
Example #3
0
                public unsafe void Initialize(Settings _PluginSettings, char *iniFile, char *section, UInt32 id)
                {
                    this.PluginSettings = _PluginSettings;
                    this._ID            = id;
                    this._INI_File      = new string(iniFile);
                    this._Section       = new string(section);

                    this.ConfigName = Rainmeter.PluginBridge("GetConfig", this.INI_File);
                }
Example #4
0
        private unsafe static string PluginBridge(string sCommand, string sData)
        {
            try
            {
                return(new string(PluginBridge(Rainmeter.String(sCommand), Rainmeter.String(sData))));
            }
            catch { }

            return(string.Empty);
        }
Example #5
0
        public static int ConfigY(Rainmeter.Settings.InstanceSettings Instance)
        {
            IntPtr hwnd = (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File))));
            RECT   rct;

            if (!GetWindowRect(hwnd, out rct))
            {
                Rainmeter.Log(LogLevel.Error, "Rainmeter told us the HWND for window '" + Rainmeter.PluginBridge("GetConfig", Instance.INI_File) + "' is " + hwnd.ToInt32().ToString() + "L, but couldn't receive a proper RECT from it");
                return(0);
            }
            return(rct.Top);
        }
Example #6
0
        public static int ConfigWidth(string sSkin)
        {
            IntPtr hwnd = (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", sSkin)));
            RECT   rct;

            if (!GetWindowRect(hwnd, out rct))
            {
                Rainmeter.Log(LogLevel.Error, "Rainmeter told us the HWND for window '" + sSkin + "' is " + hwnd.ToInt32().ToString() + "L, but couldn't receive a proper RECT from it");
                return(0);
            }
            return(rct.Right - rct.Left);
        }
Example #7
0
            public void Go()
            {
                this.Instance.SetTempValue("__RMT_EB_AlreadyRunning", true);

                try
                {
                    new PluginCode().ExecuteBang(this.Instance, this.Command);
                }
                catch (Exception ex)
                {
                    Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
                }

                this.Instance.SetTempValue("__RMT_EB_AlreadyRunning", false);
            }
Example #8
0
        // If an INI is missing, a blank string will be returned to avoid raising exceptions
        private unsafe static string ReadConfigString(string sSection, string sKey)
        {
            try
            {
                char *szString = ReadConfigString(Rainmeter.String(sSection), Rainmeter.String(sKey), Rainmeter.String(string.Empty));

                if (szString != null)
                {
                    return(new string(szString));
                }
            }
            catch { }

            return(string.Empty);
        }
Example #9
0
            public void Go()
            {
                this.Instance.SetTempValue("__RMT_GS_AlreadyRunning", true);

                try
                {
                    this.Instance.SetTempValue("__RMT_GS_LastValue", new PluginCode().GetString(this.Instance));
                }
                catch (Exception ex)
                {
                    Rainmeter.Log(Rainmeter.LogLevel.Error, "C# plugin in GetString(), " + ex.GetType().ToString() + ": " + ex.Message);
                }

                this.Instance.SetTempValue("__RMT_GS_AlreadyRunning", false);
            }
Example #10
0
 public unsafe static char *GetPluginAuthor()
 {
     if (!string.IsNullOrEmpty(Plugin.Email) && !string.IsNullOrEmpty(Plugin.Comments))
     {
         return(Rainmeter.String(Plugin.Author + " (" + Plugin.Email + "): " + Plugin.Comments));
     }
     if (!string.IsNullOrEmpty(Plugin.Email))
     {
         return(Rainmeter.String(Plugin.Author + " (" + Plugin.Email + ")"));
     }
     if (!string.IsNullOrEmpty(Plugin.Comments))
     {
         return(Rainmeter.String(Plugin.Author + ": " + Plugin.Comments));
     }
     return(Rainmeter.String(Plugin.Author));
 }
Example #11
0
        public void ChangeY(Rainmeter.Settings.InstanceSettings Instance, string sY)
        {
            try
            {
                // If the position is changed, make sure the form's auto-location is disabled.
                if (this.StartPosition != FormStartPosition.Manual)
                {
                    this.StartPosition = FormStartPosition.Manual;
                }

                // Notice that we need the position of the parent window for offset location.
                //
                // The Rainmeter class does this for us
                this.Location = new System.Drawing.Point(this.Location.X, Rainmeter.ConfigY(Rainmeter.SkinName(Instance)) + int.Parse(sY));
            }
            catch { }
        }
Example #12
0
        public void UpdateStatus(Rainmeter.API rm = null)
        {
            if (rm != null)
            {
                this._SkinName = rm.GetSkinName();
                this._Handle = rm.GetSkinWindow();
            }

            RECT rct;
            if (GetWindowRect(this._Handle, out rct))
            {
                this._X = rct.Left;
                this._Y = rct.Top;
                this._W = rct.Right - rct.Left;
                this._H = rct.Bottom - rct.Top;
            }
            else
            {
                API.Log(API.LogType.Error,
                    "Rainmeter told us the HWND for window '" + this._SkinName + "' is " + this._Handle.ToInt32().ToString() + "L, but couldn't receive a proper RECT from it");
            }

            this._IsTopmost = ((GetWindowLong(this._Handle, GWL_EXSTYLE) & WS_EX_TOPMOST) > 0);
        }
Example #13
0
 private string GetUserInput(Rainmeter.Settings.InstanceSettings Instance)
 {
     // No INI overrides provided, so create an empty list
     return GetUserInput(Instance, new Dictionary<string,string>());
 }
Example #14
0
        // 'ExecuteBang' is a way of Rainmeter telling your plugin to do something *right now*.
        // What it wants to do can be defined by the 'Command' parameter.
        public void ExecuteBang(Rainmeter.Settings.InstanceSettings Instance, string Command)
        {
            #region Handle a single parameter

            // If our parameter list only contains a single word, then open a textbox immediately
            // and set a value.  This mode does not do any batching.
            if (!Command.Trim().Contains(" "))
            {
                // Assume that the parameter is the name of the variable
                string sVariableName = Command.Trim();

                // Ask for input
                string sInput = GetUserInput(Instance);

                // If the user cancelled out of the inputbox (ESC key, etc.), then abort
                if (sInput == null)
                {
                    return;
                }

                // Ask Rainmeter to set the variable using a bang (http://rainmeter.net/RainCMS/?q=Bangs)
                Rainmeter.Bang("!RainmeterSetVariable " + sVariableName + " \"" + sInput.Replace("\"", "\\\"") + "\"");

                // Note that the skin needs DynamicVariables=1 in the measure's settings or the above
                // code will have no effect.
                return;
            }

            #endregion
            #region Handle multiple parameters

            // Our parameter list contains at least two words, so split them up
            string[] sParts = Command.Trim().Split(new string[] { " " }, StringSplitOptions.None);

            // If the first parameter is 'ExecuteBatch' (not case sensitive)...
            if (sParts[0].Trim().ToUpper() == "EXECUTEBATCH")
            {
                // ExecuteBatch tells this plugin to go through the measure's settings to look
                // for lines beginning with "Command" and executing Rainmeter bangs for each one.
                // If a line contains $UserInput$, then an input textbox is opened and command
                // execution pauses until the user enters text or dismisses the textbox.  If the
                // textbox is dismissed (Escape key, for example), all processing ends, otherwise
                // it continues depending on the range of commands selected.
                //
                // Each "Command" line allows overriding all settings that the input textbox
                // supports, therefor some checking and substitution is performed, thus a
                // more complex parser has been implemented.
                //
                // ExecuteBatch expects this syntax:
                //       ExecuteBatch [All|#|#-#]
                //
                // This allows Rainmeter to call the plugin to execute a range including:
                //       All      All commands in the measure
                //       #        Only a single command in the measure
                //       #-#      A specific range of commands in the measure

                #region Determine range
                // Determine range.  Default is 1 to 1,000,000,000, although if processing finds
                // that a requested line is blank, it will stop all processing (so 'All' will
                // only parse 14 lines if "Command15" does not exist or is blank).
                int iMin = 1;
                int iMax = 1000000000;
                try
                {
                    if (sParts[1].Trim().ToUpper() != "ALL")
                    {
                        if (sParts[1].Contains("-"))
                        {
                            string[] sSubParts = sParts[1].Split(new string[] { "-" }, StringSplitOptions.None);
                            iMin = int.Parse(sSubParts[0]);
                            iMax = int.Parse(sSubParts[1]);
                        }
                        else
                        {
                            iMin = iMax = int.Parse(sParts[1]);
                        }
                    }
                }
                catch // handle all errors above
                {
                    // Any error above will be ignored and the default range used instead.
                    // This can occur if the measure asks to ExecuteBatch an invalid range
                    // or the range could not be translated to an acceptable format.
                    //
                    // For example:  ExecuteBatch asdf
                    iMin = 1;
                    iMax = 1000000000;
                }
                #endregion
                #region Parse commands in range
                // Parse each command in the range, aborting if any line returns 'false' or
                // the requested command line does not exist in the config for that measure.
                for (int i = iMin; i <= iMax; i++)
                {
                    // Read this command's line
                    string sCurrentLine = Instance.INI_Value("Command" + i.ToString());

                    // If empty/non-existent, abort
                    if (string.IsNullOrEmpty(sCurrentLine))
                    {
                        break;
                    }

                    // Execute the line, but if there's a problem (error or they cancel the
                    // input textbox), then abort
                    if (!ExecuteLine(Instance, sCurrentLine))
                    {
                        break;
                    }

                    // Continue to the next line, if there is any
                }
                #endregion
                return;
            }

            // Unhandled command, log the message but otherwise do nothing
            Rainmeter.Log(Rainmeter.LogLevel.Debug, "InputText: Received command \"" + sParts[0].Trim() + "\", left unhandled");

            #endregion

            return;
        }
Example #15
0
 public static IntPtr GetConfigWindow(Rainmeter.Settings.InstanceSettings Instance)
 {
     return((IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File)))));
 }
Example #16
0
        private bool ExecuteLine(Rainmeter.Settings.InstanceSettings Instance, string sLine)
        {
            // If this line contains a $UserInput$ token, then we need to do some extra
            // parsing
            if (sLine.ToUpper().Contains("$USERINPUT$"))
            {
                try
                {
                    #region Handle in-line overrides
                    // Create a blank list of overrides
                    Dictionary<string, string> Overrides = new Dictionary<string, string>();

                    // Start looking for overridable settings and adjust the list accordingly,
                    // stripping out settings from the line if they are discovered.
                    //
                    // The supporting TagData() function allows for whitespace if quotes are
                    // used.  For example:
                    //
                    // DefaultValue="hello there, how are you"
                    sLine = ScanAndReplace(sLine, "DefaultValue", ref Overrides);
                    sLine = ScanAndReplace(sLine, "X", ref Overrides);
                    sLine = ScanAndReplace(sLine, "Y", ref Overrides);
                    sLine = ScanAndReplace(sLine, "W", ref Overrides);
                    sLine = ScanAndReplace(sLine, "H", ref Overrides);
                    sLine = ScanAndReplace(sLine, "StringStyle", ref Overrides);
                    sLine = ScanAndReplace(sLine, "StringAlign", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FocusDismiss", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FontColor", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FontFace", ref Overrides);
                    sLine = ScanAndReplace(sLine, "SolidColor", ref Overrides);
                    sLine = ScanAndReplace(sLine, "Password", ref Overrides);
                    sLine = ScanAndReplace(sLine, "FontSize", ref Overrides);
                    sLine = ScanAndReplace(sLine, "TopMost", ref Overrides);
                    #endregion

                    // Get user input
                    string sInput = GetUserInput(Instance, Overrides);
                    if (sInput == null)
                    {
                        // Rainmeter.Log(Rainmeter.LogLevel.Debug, "InputText: Aborted, user cancelled text box");
                        return false;
                    }

                    // Swap out the $UserInput$ token with what the user typed
                    sLine = Replace(sLine, "$USERINPUT$", sInput);
                }
                catch (Exception ex)
                {
                    // If there was an error doing any of the above, log it for debugging purposes.
                    Rainmeter.Log(Rainmeter.LogLevel.Warning, "InputText: Exception " + ex.GetType().ToString() + ": " + ex.Message);
                    return false;
                }
            }

            // Execute the bang.  This will either be the original line from CommandX= (sLine variable) or
            // an adjusted line based on special parsing above.
            // Rainmeter.Log(Rainmeter.LogLevel.Debug, "InputText: Executing bang: " + sLine);
            Rainmeter.Bang(sLine);
            return true;
        }
Example #17
0
 public UpdateThread(Rainmeter.Settings.InstanceSettings _Instance)
 {
     this.Instance = _Instance;
 }
Example #18
0
 public ExecuteBangThread(Rainmeter.Settings.InstanceSettings _Instance, string _Command)
 {
     this.Instance = _Instance;
     this.Command = _Command;
 }
Example #19
0
 public static UInt32 GetPluginVersion()
 {
     return(Rainmeter.Version(Plugin.Version));
 }
Example #20
0
 public unsafe static char *GetString(UInt32 id, UInt32 flags)
 {
     // Do not modify this member.  Instead, update your code in 'PluginCode.cs'.
     return(Rainmeter.String(new YourPlugin().GetString(Plugin, id)));
 }
Example #21
0
 public SkinWindow(Rainmeter.API rm)
 {
     UpdateStatus(rm);
 }
Example #22
0
        public string GetString(Rainmeter.Settings Plugin, UInt32 id)
        {
            bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_GS_AlreadyRunning", false);
            if (!bAlreadyRunning)
            {
                GetStringThread thread_details = new GetStringThread(Plugin.Instances[id]);
                Thread thread = new Thread(new ThreadStart(thread_details.Go));
                thread.Start();
            }

            try
            {
                return (string)Plugin.Instances[id].GetTempValue("__RMT_GS_LastValue", string.Empty);
            }
            catch
            {
                return string.Empty;
            }
        }
Example #23
0
        public void ChangeY(Rainmeter.Settings.InstanceSettings Instance, string sY)
        {
            try
            {
                // If the position is changed, make sure the form's auto-location is disabled.
                if (this.StartPosition != FormStartPosition.Manual)
                    this.StartPosition = FormStartPosition.Manual;

                // Notice that we need the position of the parent window for offset location.
                //
                // The Rainmeter class does this for us
                this.Location = new System.Drawing.Point(this.Location.X, Rainmeter.ConfigY(Rainmeter.SkinName(Instance)) + int.Parse(sY));
            }
            catch { }
        }
Example #24
0
        public double Update2(Rainmeter.Settings Plugin, UInt32 id)
        {
            bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_U2_AlreadyRunning", false);
            if (!bAlreadyRunning)
            {
                Update2Thread thread_details = new Update2Thread(Plugin.Instances[id]);
                Thread thread = new Thread(new ThreadStart(thread_details.Go));
                thread.Start();
            }

            try
            {
                return (double)Plugin.Instances[id].GetTempValue("__RMT_U2_LastValue", 0.0);
            }
            catch
            {
                return 0.0;
            }
        }
Example #25
0
 internal Measure(Rainmeter.API rm)
 {
     this.rm = rm;
 }
Example #26
0
 public GetStringThread(Rainmeter.Settings.InstanceSettings _Instance)
 {
     this.Instance = _Instance;
 }
Example #27
0
 internal void Reload(Rainmeter.API rm, ref double maxValue)
 {
     // Do nothing here.
 }
Example #28
0
 public static int ConfigHeight(Rainmeter.Settings.InstanceSettings Instance)
 {
     IntPtr hwnd = (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File))));
     RECT rct;
     if (!GetWindowRect(hwnd, out rct))
     {
         Rainmeter.Log(LogLevel.Error, "Rainmeter told us the HWND for window '" + Rainmeter.PluginBridge("GetConfig", Instance.INI_File) + "' is " + hwnd.ToInt32().ToString() + "L, but couldn't receive a proper RECT from it");
         return 0;
     }
     return rct.Bottom - rct.Top;
 }
Example #29
0
        // You can call this function directly to log to Rainmeter.log
        //
        // Rainmeter needs to be configured to allow debug logging, of course.

        public static unsafe bool Log(LogLevel level, string sText)
        {
            return(Rainmeter.LSLog((int)level, Rainmeter.String("C# plugin"), Rainmeter.String(sText)) != 0);
        }
Example #30
0
 public double Update2(Rainmeter.Settings.InstanceSettings Instance)
 {
     return 0.0;
 }
Example #31
0
 public string GetVariable(string sVariable)
 {
     return(Rainmeter.PluginBridge("GetVariable", "\"" + this.ConfigName + "\" " + sVariable.Trim() + ""));
 }
Example #32
0
 public string GetString(Rainmeter.Settings.InstanceSettings Instance)
 {
     // This plugin is unique as it is one of the first to not be used to display data
     // back in Rainmeter, but to request user input and use that input during batch
     // operations (and other purposes).
     //
     // However, Rainmeter requires that data be sent back, so we'll return temporary data
     // In this case, the data is whatever the user last entered into an input textbox.
     return Instance.GetTempValue("LastInput", string.Empty).ToString();
 }
Example #33
0
        private string GetUserInput(Rainmeter.Settings.InstanceSettings Instance, Dictionary <string, string> sOverrides)
        {
            // Create the form.  'InputBox' is a .NET form with a textbox and two button controls on it.
            InputBox input = new InputBox();

            input.Instance = Instance;
            input.ChangeX(Instance, "0");
            input.ChangeY(Instance, "0");

            // Change the styles of the InputBox form based on overrides or INI values
            #region Style and preference tweaks (INI and override settings)

            if (sOverrides.ContainsKey("FontFace"))
            {
                input.ChangeFontFace(sOverrides["FontFace"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("FontFace")))
            {
                input.ChangeFontFace(Instance.INI_Value("FontFace"));
            }

            if (sOverrides.ContainsKey("FontSize"))
            {
                input.ChangeFontSize(sOverrides["FontSize"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("FontSize")))
            {
                input.ChangeFontSize(Instance.INI_Value("FontSize"));
            }

            if (sOverrides.ContainsKey("W"))
            {
                input.ChangeW(sOverrides["W"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("W")))
            {
                input.ChangeW(Instance.INI_Value("W"));
            }

            if (sOverrides.ContainsKey("H"))
            {
                input.ChangeH(sOverrides["H"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("H")))
            {
                input.ChangeH(Instance.INI_Value("H"));
            }

            if (sOverrides.ContainsKey("X"))
            {
                input.ChangeX(Instance, sOverrides["X"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("X")))
            {
                input.ChangeX(Instance, Instance.INI_Value("X"));
            }

            if (sOverrides.ContainsKey("Y"))
            {
                input.ChangeY(Instance, sOverrides["Y"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("Y")))
            {
                input.ChangeY(Instance, Instance.INI_Value("Y"));
            }

            if (sOverrides.ContainsKey("StringStyle"))
            {
                input.ChangeFontStringStyle(sOverrides["StringStyle"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("StringStyle")))
            {
                input.ChangeFontStringStyle(Instance.INI_Value("StringStyle"));
            }

            if (sOverrides.ContainsKey("StringAlign"))
            {
                input.ChangeStringAlign(sOverrides["StringAlign"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("StringAlign")))
            {
                input.ChangeStringAlign(Instance.INI_Value("StringAlign"));
            }

            bool bFocusDismiss = true;
            if (sOverrides.ContainsKey("FocusDismiss"))
            {
                input.MakeFocusDismiss(sOverrides["FocusDismiss"] == "1");
                bFocusDismiss = sOverrides["FocusDismiss"] == "1";
            }
            else
            {
                input.MakeFocusDismiss(!(Instance.INI_Value("FocusDismiss").Trim().ToUpper() != "1"));
                bFocusDismiss = !(Instance.INI_Value("FocusDismiss").Trim().ToUpper() != "1");
            }

            if (sOverrides.ContainsKey("FontColor"))
            {
                input.ChangeFontColor(sOverrides["FontColor"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("FontColor")))
            {
                input.ChangeFontColor(Instance.INI_Value("FontColor"));
            }

            if (sOverrides.ContainsKey("SolidColor"))
            {
                input.ChangeBackColor(sOverrides["SolidColor"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("SolidColor")))
            {
                input.ChangeBackColor(Instance.INI_Value("SolidColor"));
            }

            if (sOverrides.ContainsKey("Passwords"))
            {
                if (sOverrides["DefaultValue"] == "1")
                {
                    input.MakePassword();
                }
            }
            else if (Instance.INI_Value("Password").Trim().ToUpper() == "1")
            {
                input.MakePassword();
            }

            bool bAutoTopMost = true;
            if (sOverrides.ContainsKey("TopMost"))
            {
                if (sOverrides["TopMost"] == "1")
                {
                    input.MakeTopmost();
                    bAutoTopMost = false;
                }
                else if (sOverrides["TopMost"] == "0")
                {
                    bAutoTopMost = false;
                }
            }
            else if (Instance.INI_Value("TopMost").Trim().ToUpper() == "1")
            {
                input.MakeTopmost();
                bAutoTopMost = false;
            }
            else if (Instance.INI_Value("TopMost").Trim().ToUpper() != "AUTO")
            {
                if (!string.IsNullOrEmpty(Instance.INI_Value("TopMost").Trim()))
                {
                    bAutoTopMost = false;
                }
            }
            if (bAutoTopMost)
            {
                if (Rainmeter.ParentIsTopmost(Instance))
                {
                    input.MakeTopmost();
                }
            }

            if (sOverrides.ContainsKey("DefaultValue"))
            {
                input.DefaultValue(sOverrides["DefaultValue"]);
            }
            else if (!string.IsNullOrEmpty(Instance.INI_Value("DefaultValue")))
            {
                input.DefaultValue(Instance.INI_Value("DefaultValue").Trim());
            }

            #endregion

            if (bFocusDismiss)
            {
                input.Show(new WindowWrapper(Rainmeter.GetConfigWindow(Instance)));

                for (; ;)
                {
                    if (input.DialogResult != System.Windows.Forms.DialogResult.None || input.drBackup != System.Windows.Forms.DialogResult.None)
                    {
                        break;
                    }
                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(44);
                }
            }
            else
            {
                input.ShowDialog(new WindowWrapper(Rainmeter.GetConfigWindow(Instance)));
            }


            if (input.drBackup != System.Windows.Forms.DialogResult.None)
            {
                if (input.drBackup != System.Windows.Forms.DialogResult.OK)
                {
                    return(null);
                }
            }
            else if (input.DialogResult != System.Windows.Forms.DialogResult.None)
            {
                if (input.DialogResult != System.Windows.Forms.DialogResult.OK)
                {
                    return(null);
                }
            }

            Instance.SetTempValue("LastInput", input.sTextValue);
            return(input.sTextValue);
        }
Example #34
0
 // 'Update', 'Update2', and 'GetString' all return data back to Rainmeter, depending on
 // if the Rainmeter measure wants a numeric value or a string/text data.
 //
 // The 'Instance' member contains all of the data necessary to read the INI file
 // passed to your plugin when this instance was first initialized.  Remember: your plugin
 // may be initialized multiple times.  For example, a plugin that reads the free space
 // of a hard drive may be called multiple times -- once for each installed hard drive.
 public UInt32 Update(Rainmeter.Settings.InstanceSettings Instance)
 {
     return 0;
 }
Example #35
0
        public static string SkinName(Rainmeter.Settings.InstanceSettings Instance)
        {
            try
            {
                return Instance.ConfigName;
                /*
                if (Instance.GetTempValue("_internal_SkinPath", string.Empty).ToString() == string.Empty)
                {
                    string sAppDataPath = System.Environment.GetEnvironmentVariable("AppData").Trim();
                    string sRainmeterINIText = System.IO.File.ReadAllText(sAppDataPath + "\\Rainmeter\\Rainmeter.ini");
                    string sSkinPath = Chopper(sRainmeterINIText.Replace('\n', '\r'), "SkinPath=", "\r").Trim().TrimEnd(new char[] { '\\' });
                    Instance.SetTempValue("_internal_SkinPath", sSkinPath);
                }

                System.IO.FileInfo fi = new System.IO.FileInfo(Instance.INI_File);
                return fi.DirectoryName.Replace(Instance.GetTempValue("_internal_SkinPath", string.Empty).ToString(), string.Empty).TrimEnd(new char[] { '\\' }).TrimStart(new char[] { '\\' });
                */
            }
            catch { }

            return string.Empty;
        }
Example #36
0
 public string SetVariable(string sVariable, object oData)
 {
     return(Rainmeter.PluginBridge("SetVariable", "\"" + this.ConfigName + "\" " + sVariable.Trim() + " \"" + oData.ToString().Trim() + "\""));
 }
Example #37
0
 public void ExecuteBang(Rainmeter.Settings Plugin, UInt32 id, string sArguments)
 {
     bool bAlreadyRunning = (bool)Plugin.Instances[id].GetTempValue("__RMT_EB_AlreadyRunning", false);
     if (!bAlreadyRunning)
     {
         ExecuteBangThread thread_details = new ExecuteBangThread(Plugin.Instances[id], sArguments);
         Thread thread = new Thread(new ThreadStart(thread_details.Go));
         thread.Start();
     }
     return;
 }
Example #38
0
 public static IntPtr GetConfigWindow(Rainmeter.Settings.InstanceSettings Instance)
 {
     return (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File))));
 }
Example #39
0
        private string GetUserInput(Rainmeter.Settings.InstanceSettings Instance, Dictionary<string,string> sOverrides)
        {
            // Create the form.  'InputBox' is a .NET form with a textbox and two button controls on it.
            InputBox input = new InputBox();
            input.Instance = Instance;
            input.ChangeX(Instance, "0");
            input.ChangeY(Instance, "0");

            // Change the styles of the InputBox form based on overrides or INI values
            #region Style and preference tweaks (INI and override settings)

            if (sOverrides.ContainsKey("FontFace"))
                input.ChangeFontFace(sOverrides["FontFace"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("FontFace")))
                input.ChangeFontFace(Instance.INI_Value("FontFace"));

            if (sOverrides.ContainsKey("FontSize"))
                input.ChangeFontSize(sOverrides["FontSize"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("FontSize")))
                input.ChangeFontSize(Instance.INI_Value("FontSize"));

            if (sOverrides.ContainsKey("W"))
                input.ChangeW(sOverrides["W"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("W")))
                input.ChangeW(Instance.INI_Value("W"));

            if (sOverrides.ContainsKey("H"))
                input.ChangeH(sOverrides["H"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("H")))
                input.ChangeH(Instance.INI_Value("H"));

            if (sOverrides.ContainsKey("X"))
                input.ChangeX(Instance, sOverrides["X"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("X")))
                input.ChangeX(Instance, Instance.INI_Value("X"));

            if (sOverrides.ContainsKey("Y"))
                input.ChangeY(Instance, sOverrides["Y"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("Y")))
                input.ChangeY(Instance, Instance.INI_Value("Y"));

            if (sOverrides.ContainsKey("StringStyle"))
                input.ChangeFontStringStyle(sOverrides["StringStyle"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("StringStyle")))
                input.ChangeFontStringStyle(Instance.INI_Value("StringStyle"));

            if (sOverrides.ContainsKey("StringAlign"))
                input.ChangeStringAlign(sOverrides["StringAlign"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("StringAlign")))
                input.ChangeStringAlign(Instance.INI_Value("StringAlign"));

            bool bFocusDismiss = true;
            if (sOverrides.ContainsKey("FocusDismiss"))
            {
                input.MakeFocusDismiss(sOverrides["FocusDismiss"] == "1");
                bFocusDismiss = sOverrides["FocusDismiss"] == "1";
            }
            else
            {
                input.MakeFocusDismiss(!(Instance.INI_Value("FocusDismiss").Trim().ToUpper() != "1"));
                bFocusDismiss = !(Instance.INI_Value("FocusDismiss").Trim().ToUpper() != "1");
            }

            if (sOverrides.ContainsKey("FontColor"))
                input.ChangeFontColor(sOverrides["FontColor"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("FontColor")))
                input.ChangeFontColor(Instance.INI_Value("FontColor"));

            if (sOverrides.ContainsKey("SolidColor"))
                input.ChangeBackColor(sOverrides["SolidColor"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("SolidColor")))
                input.ChangeBackColor(Instance.INI_Value("SolidColor"));

            if (sOverrides.ContainsKey("Passwords"))
            {
                if (sOverrides["DefaultValue"] == "1")
                    input.MakePassword();
            }
            else if (Instance.INI_Value("Password").Trim().ToUpper() == "1")
                input.MakePassword();

            bool bAutoTopMost = true;
            if (sOverrides.ContainsKey("TopMost"))
            {
                if (sOverrides["TopMost"] == "1")
                {
                    input.MakeTopmost();
                    bAutoTopMost = false;
                }
                else if (sOverrides["TopMost"] == "0")
                    bAutoTopMost = false;
            }
            else if (Instance.INI_Value("TopMost").Trim().ToUpper() == "1")
            {
                input.MakeTopmost();
                bAutoTopMost = false;
            }
            else if (Instance.INI_Value("TopMost").Trim().ToUpper() != "AUTO")
                if (!string.IsNullOrEmpty(Instance.INI_Value("TopMost").Trim()))
                    bAutoTopMost = false;
            if (bAutoTopMost)
                if (Rainmeter.ParentIsTopmost(Instance))
                    input.MakeTopmost();

            if (sOverrides.ContainsKey("DefaultValue"))
                input.DefaultValue(sOverrides["DefaultValue"]);
            else if (!string.IsNullOrEmpty(Instance.INI_Value("DefaultValue")))
                input.DefaultValue(Instance.INI_Value("DefaultValue").Trim());

            #endregion

            if (bFocusDismiss)
            {
                input.Show(new WindowWrapper(Rainmeter.GetConfigWindow(Instance)));

                for (; ; )
                {
                    if (input.DialogResult != System.Windows.Forms.DialogResult.None || input.drBackup != System.Windows.Forms.DialogResult.None)
                        break;
                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(44);
                }
            }
            else
            {
                input.ShowDialog(new WindowWrapper(Rainmeter.GetConfigWindow(Instance)));
            }

            if (input.drBackup != System.Windows.Forms.DialogResult.None)
            {
                if (input.drBackup != System.Windows.Forms.DialogResult.OK)
                    return null;
            }
            else if (input.DialogResult != System.Windows.Forms.DialogResult.None)
            {
                if (input.DialogResult != System.Windows.Forms.DialogResult.OK)
                    return null;
            }

            Instance.SetTempValue("LastInput", input.sTextValue);
            return input.sTextValue;
        }
Example #40
0
 // Call this function to determine if the parent skin is topmost
 public static bool ParentIsTopmost(Rainmeter.Settings.InstanceSettings Instance)
 {
     IntPtr hwnd = (IntPtr)(UInt32.Parse(Rainmeter.PluginBridge("GetWindow", Rainmeter.PluginBridge("GetConfig", Instance.INI_File))));
     WINDOWINFO info = new WINDOWINFO(true);
     GetWindowInfo(hwnd, ref info);
     return ((info.dwExStyle & 0x00000008L) > 0);
 }
Example #41
0
        // 'ExecuteBang' is a way of Rainmeter telling your plugin to do something *right now*.
        // What it wants to do can be defined by the 'Command' parameter.
        public void ExecuteBang(Rainmeter.Settings.InstanceSettings Instance, string Command)
        {
            #region Handle a single parameter

            // If our parameter list only contains a single word, then open a textbox immediately
            // and set a value.  This mode does not do any batching.
            if (!Command.Trim().Contains(" "))
            {
                // Assume that the parameter is the name of the variable
                string sVariableName = Command.Trim();

                // Ask for input
                string sInput = GetUserInput(Instance);

                // If the user cancelled out of the inputbox (ESC key, etc.), then abort
                if (sInput == null)
                    return;

                // Ask Rainmeter to set the variable using a bang (http://rainmeter.net/RainCMS/?q=Bangs)
                Rainmeter.Bang("!RainmeterSetVariable " + sVariableName + " \"" + sInput.Replace("\"", "\\\"") + "\"");

                // Note that the skin needs DynamicVariables=1 in the measure's settings or the above
                // code will have no effect.
                return;
            }

            #endregion
            #region Handle multiple parameters

            // Our parameter list contains at least two words, so split them up
            string[] sParts = Command.Trim().Split(new string[] { " " }, StringSplitOptions.None);

            // If the first parameter is 'ExecuteBatch' (not case sensitive)...
            if (sParts[0].Trim().ToUpper() == "EXECUTEBATCH")
            {
                // ExecuteBatch tells this plugin to go through the measure's settings to look
                // for lines beginning with "Command" and executing Rainmeter bangs for each one.
                // If a line contains $UserInput$, then an input textbox is opened and command
                // execution pauses until the user enters text or dismisses the textbox.  If the
                // textbox is dismissed (Escape key, for example), all processing ends, otherwise
                // it continues depending on the range of commands selected.
                //
                // Each "Command" line allows overriding all settings that the input textbox
                // supports, therefor some checking and substitution is performed, thus a
                // more complex parser has been implemented.
                //
                // ExecuteBatch expects this syntax:
                //       ExecuteBatch [All|#|#-#]
                //
                // This allows Rainmeter to call the plugin to execute a range including:
                //       All      All commands in the measure
                //       #        Only a single command in the measure
                //       #-#      A specific range of commands in the measure

                #region Determine range
                // Determine range.  Default is 1 to 1,000,000,000, although if processing finds
                // that a requested line is blank, it will stop all processing (so 'All' will
                // only parse 14 lines if "Command15" does not exist or is blank).
                int iMin = 1;
                int iMax = 1000000000;
                try
                {
                    if (sParts[1].Trim().ToUpper() != "ALL")
                    {
                        if (sParts[1].Contains("-"))
                        {
                            string[] sSubParts = sParts[1].Split(new string[] { "-" }, StringSplitOptions.None);
                            iMin = int.Parse(sSubParts[0]);
                            iMax = int.Parse(sSubParts[1]);
                        }
                        else
                            iMin = iMax = int.Parse(sParts[1]);
                    }
                }
                catch // handle all errors above
                {
                    // Any error above will be ignored and the default range used instead.
                    // This can occur if the measure asks to ExecuteBatch an invalid range
                    // or the range could not be translated to an acceptable format.
                    //
                    // For example:  ExecuteBatch asdf
                    iMin = 1;
                    iMax = 1000000000;
                }
                #endregion
                #region Parse commands in range
                // Parse each command in the range, aborting if any line returns 'false' or
                // the requested command line does not exist in the config for that measure.
                for (int i = iMin; i <= iMax; i++)
                {
                    // Read this command's line
                    string sCurrentLine = Instance.INI_Value("Command" + i.ToString());

                    // If empty/non-existent, abort
                    if (string.IsNullOrEmpty(sCurrentLine))
                        break;

                    // Execute the line, but if there's a problem (error or they cancel the
                    // input textbox), then abort
                    if (!ExecuteLine(Instance, sCurrentLine))
                        break;

                    // Continue to the next line, if there is any
                }
                #endregion
                return;
            }

            // Unhandled command, log the message but otherwise do nothing
            Rainmeter.Log(Rainmeter.LogLevel.Debug, "InputText: Received command \"" + sParts[0].Trim() + "\", left unhandled");

            #endregion

            return;
        }