Exemplo n.º 1
0
 public Configuration()
 {
     Version             = 1;
     UpdateNotifications = UpdateNotificationsEnum.Undefined;
     DefaultRepository   = UpdateNotificationsEnum.Undefined;
     Root                  = new Folder();
     Root.Name             = I18n.Translate("internal/Configuration/local", "Local triggers");
     RepositoryRoot        = new RepositoryFolder();
     RepositoryRoot.Name   = I18n.Translate("internal/Configuration/remote", "Remote triggers");
     SfxVolumeAdjustment   = 100;
     TtsVolumeAdjustment   = 100;
     DebugLevel            = Plugin.DebugLevelEnum.Info;
     UseACTForTTS          = false;
     UseACTForSound        = false;
     UseOsClipboard        = true;
     LogNormalEvents       = true;
     FfxivLogNetwork       = false;
     TestLiveByDefault     = false;
     UseScarborough        = true;
     WarnAdmin             = true;
     StartupTriggerType    = StartupTriggerTypeEnum.Trigger;
     EventSeparator        = "";
     StartupTriggerId      = Guid.Empty;
     isnew                 = true;
     lastWrite             = DateTime.Now;
     FfxivPartyOrdering    = FfxivPartyOrderingEnum.Legacy;
     FfxivCustomPartyOrder = "19, 1, 21, 3, 32, 37, 24, 6, 28, 33, 20, 2, 22, 4, 30, 29, 34, 23, 5, 31, 38, 25, 7, 27, 26, 35, 36";
     ShowWelcome           = true;
     WindowToMonitor       = "FINAL FANTASY XIV";
 }
Exemplo n.º 2
0
        public override string ToString()
        {
            switch (Grouping)
            {
            case CndGroupingEnum.And:
                return(I18n.Translate("internal/ConditionGroup/and", "All conditions must be true"));

            case CndGroupingEnum.Or:
                return(I18n.Translate("internal/ConditionGroup/or", "At least one condition must be true"));

            case CndGroupingEnum.Xor:
                return(I18n.Translate("internal/ConditionGroup/xor", "Only one condition must be true"));

            case CndGroupingEnum.Not:
                return(I18n.Translate("internal/ConditionGroup/not", "None of the conditions may be true"));
            }
            return(I18n.Translate("internal/ConditionGroup/unknown", "Unknown grouping value '{0}'", Grouping));
        }
Exemplo n.º 3
0
 public Configuration()
 {
     Version = 1;
     corruptRecoveryError = "";
     PersistentVariables  = new Variables.VariableStore();
     UpdateNotifications  = UpdateNotificationsEnum.Undefined;
     DefaultRepository    = UpdateNotificationsEnum.Undefined;
     Root                  = new Folder();
     Root.Name             = I18n.Translate("internal/Configuration/local", "Local triggers");
     RepositoryRoot        = new RepositoryFolder();
     RepositoryRoot.Name   = I18n.Translate("internal/Configuration/remote", "Remote triggers");
     SfxVolumeAdjustment   = 100;
     TtsVolumeAdjustment   = 100;
     DebugLevel            = RealPlugin.DebugLevelEnum.Info;
     UseACTForTTS          = false;
     UseACTForSound        = false;
     UseOsClipboard        = true;
     LogNormalEvents       = true;
     FfxivLogNetwork       = false;
     TestLiveByDefault     = false;
     UseScarborough        = true;
     WarnAdmin             = true;
     DeveloperMode         = false;
     LogVariableExpansions = false;
     StartupTriggerType    = StartupTriggerTypeEnum.Trigger;
     EventSeparator        = "";
     StartupTriggerId      = Guid.Empty;
     isnew                 = true;
     lastWrite             = DateTime.Now;
     FfxivPartyOrdering    = FfxivPartyOrderingEnum.Legacy;
     FfxivCustomPartyOrder = "19, 1, 21, 3, 32, 37, 24, 6, 28, 33, 20, 2, 22, 4, 30, 29, 34, 23, 5, 31, 38, 25, 7, 27, 26, 35, 36";
     ShowWelcome           = true;
     WindowToMonitor       = "FINAL FANTASY XIV";
     CacheImageExpiry      = 518400;
     CacheSoundExpiry      = 518400;
     CacheJsonExpiry       = 10080;
     CacheRepoExpiry       = 518400;
     CacheFileExpiry       = 518400;
     Substitutions         = new List <Substitution>();
 }
Exemplo n.º 4
0
        private double MathParserLogic(List <string> tokens)
        {
            // Variables replacement
            for (var i = 0; i < tokens.Count; i++)
            {
                if (LocalVariables.Keys.Contains(tokens[i]))
                {
                    tokens[i] = LocalVariables[tokens[i]].ToString(CultureInfo);
                }
            }

            while (tokens.IndexOf("(") != -1)
            {
                // getting data between "(" and ")"
                var open  = tokens.LastIndexOf("(");
                var close = tokens.IndexOf(")", open); // in case open is -1, i.e. no "(" // , open == 0 ? 0 : open - 1

                if (open >= close)
                {
                    throw new ArithmeticException(I18n.Translate("internal/MathParser/noclosure", "No closing bracket/parenthesis. Token: {0}", open.ToString(CultureInfo)));
                }

                var roughExpr = new List <string>();

                for (var i = open + 1; i < close; i++)
                {
                    roughExpr.Add(tokens[i]);
                }

                double tmpResult;

                var args         = new List <double>();
                var sargs        = new List <string>();
                var functionName = tokens[open == 0 ? 0 : open - 1];

                if (LocalFunctions.Keys.Contains(functionName))
                {
                    if (roughExpr.Contains(","))
                    {
                        // converting all arguments into a decimal array
                        for (var i = 0; i < roughExpr.Count; i++)
                        {
                            var defaultExpr = new List <string>();
                            var firstCommaOrEndOfExpression = (roughExpr.IndexOf(",", i) != -1)
                                ? roughExpr.IndexOf(",", i)
                                : roughExpr.Count;

                            while (i < firstCommaOrEndOfExpression)
                            {
                                defaultExpr.Add(roughExpr[i++]);
                            }

                            args.Add(defaultExpr.Count == 0 ? 0 : BasicArithmeticalExpression(defaultExpr));
                        }

                        // finally, passing the arguments to the given function
                        tmpResult = double.Parse(LocalFunctions[functionName](args.ToArray()).ToString(CultureInfo), CultureInfo);
                    }
                    else
                    {
                        // but if we only have one argument, then we pass it directly to the function
                        tmpResult =
                            double.Parse(
                                LocalFunctions[functionName](new[] { BasicArithmeticalExpression(roughExpr) })
                                .ToString(CultureInfo), CultureInfo);
                    }
                }
                else if (LocalStringFunctions.Keys.Contains(functionName))
                {
                    if (roughExpr.Contains(","))
                    {
                        // converting all arguments into a decimal array
                        for (var i = 0; i < roughExpr.Count; i++)
                        {
                            var defaultExpr = new List <string>();
                            var firstCommaOrEndOfExpression = (roughExpr.IndexOf(",", i) != -1)
                                ? roughExpr.IndexOf(",", i)
                                : roughExpr.Count;

                            while (i < firstCommaOrEndOfExpression)
                            {
                                defaultExpr.Add(roughExpr[i++]);
                            }

                            sargs.Add(defaultExpr.Count == 0 ? "0" : defaultExpr[0]);
                        }

                        // finally, passing the arguments to the given function
                        tmpResult = double.Parse(LocalStringFunctions[functionName](sargs.ToArray()).ToString(CultureInfo), CultureInfo);
                    }
                    else
                    {
                        // but if we only have one argument, then we pass it directly to the function
                        tmpResult =
                            double.Parse(
                                LocalStringFunctions[functionName](new[] { roughExpr[0] })
                                .ToString(CultureInfo), CultureInfo);
                    }
                }
                else
                {
                    // if no function is need to execute following expression, pass it
                    // to the "BasicArithmeticalExpression" method.
                    tmpResult = BasicArithmeticalExpression(roughExpr);
                }

                // when all the calculations have been done
                // we replace the "opening bracket with the result"
                // and removing the rest.
                tokens[open] = tmpResult.ToString(CultureInfo);
                tokens.RemoveRange(open + 1, close - open);

                if (LocalFunctions.Keys.Contains(functionName))
                {
                    // if we also executed a function, removing
                    // the function name as well.
                    tokens.RemoveAt(open - 1);
                }
                else if (LocalStringFunctions.Keys.Contains(functionName))
                {
                    // if we also executed a function, removing
                    // the function name as well.
                    tokens.RemoveAt(open - 1);
                }
            }

            // at this point, we should have replaced all brackets
            // with the appropriate values, so we can simply
            // calculate the expression. it's not so complex
            // any more!
            return(BasicArithmeticalExpression(tokens));
        }
Exemplo n.º 5
0
 public override string ToString()
 {
     return(Plugin.FormatDateTime(Timestamp) + " - " + I18n.Translate("internal/Plugin/loglevel" + Level.ToString(), "{0}", Level.ToString()) + " - " + Message);
 }
Exemplo n.º 6
0
 internal bool Fire(RealPlugin p, Context ctx, RealPlugin.MutexInformation mtx)
 {
     try
     {
         if (mtx == null && _MutexToCapture != "")
         {
             string mn = ctx.EvaluateStringExpression(TriggerContextLogger, p, _MutexToCapture);
             RealPlugin.MutexInformation mi = ctx.plug.GetMutex(mn);
             RealPlugin.MutexTicket      m  = mi.QueueForAcquisition(ctx);
             Task t = new Task(() => {
                 using (m)
                 {
                     DeferredFire(ctx.plug, ctx, mi, m);
                 }
             });
             t.Start();
             return(true);
         }
         if ((ctx.force & Action.TriggerForceTypeEnum.SkipConditions) == 0)
         {
             if (Condition != null && Condition.Enabled == true)
             {
                 if (Condition.CheckCondition(ctx, TriggerContextLogger, ctx.plug) == false)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/trignotfired", "Trigger '{0}' not fired, condition not met", LogName));
                     return(false);
                 }
             }
         }
         DateTime prevLastFired = LastFired;
         LastFired = DateTime.Now;
         if (_PeriodRefire == RefireEnum.Deny)
         {
             RefireDelayedUntil = LastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/delayingrefire", "Delaying trigger '{0}' refire to {1}", LogName, RefireDelayedUntil));
         }
         else
         {
             RefireDelayedUntil = DateTime.MinValue;
         }
         DateTime curtime = DateTime.Now;
         if (_Scheduling == SchedulingEnum.FromLastAction)
         {
             // get the last queued action as curTime
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           orderby ax.when descending
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     curtime = ixy.ElementAt(0).when;
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/lastactionfound", "Last action for trigger '{0}' found at {1}", LogName, curtime));
                 }
             }
         }
         else if (_Scheduling == SchedulingEnum.FromRefirePeriod)
         {
             curtime = prevLastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             if (curtime < LastFired)
             {
                 curtime = LastFired;
                 AddToLog(p, RealPlugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Trigger/beforelastfired", "Current time is before last fired for trigger '{0}'", LogName));
             }
         }
         if (_PrevActions == PrevActionsEnum.Interrupt)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     List <RealPlugin.QueuedAction> rems = new List <RealPlugin.QueuedAction>();
                     rems.AddRange(ixy);
                     foreach (RealPlugin.QueuedAction qa in rems)
                     {
                         ctx.plug.ActionQueue.Remove(qa);
                         exx++;
                     }
                 }
             }
             if (exx > 0)
             {
                 if (_PrevActionsRefire == RefireEnum.Deny)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueuenorefire", "Removed {0} instance(s) of trigger '{1}' actions from queue, refire denied", exx, LogName));
                     return(false);
                 }
                 else
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueue", "Removed {0} instance(s) of trigger '{1}' actions from queue", exx, LogName));
                 }
             }
         }
         else if (_PrevActionsRefire == RefireEnum.Deny)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 exx = ixy.Count();
             }
             if (exx > 0)
             {
                 AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/refiredenied", "{0} instance(s) of trigger '{1}' actions in queue, refire denied", exx, LogName));
                 return(false);
             }
         }
         QueueActions(ctx, curtime, mtx);
     }
     catch (Exception ex)
     {
         AddToLog(p, RealPlugin.DebugLevelEnum.Error, I18n.Translate("internal/Trigger/firingexception", "Trigger '{0}' didn't fire due to exception: {1}", LogName, ex.Message));
     }
     return(false);
 }
Exemplo n.º 7
0
        internal void Fire(Plugin p, Context ctx)
        {
            if ((ctx.force & Action.TriggerForceTypeEnum.SkipConditions) == 0)
            {
                if (Condition != null && Condition.Enabled == true)
                {
                    if (Condition.CheckCondition(ctx, TriggerContextLogger, ctx.plug) == false)
                    {
                        AddToLog(p, Plugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/trignotfired", "Trigger '{0}' not fired, condition not met", LogName));
                        return;
                    }
                }
            }
            DateTime prevLastFired = LastFired;

            LastFired = DateTime.Now;
            if (PeriodRefire == RefireEnum.Deny)
            {
                RefireDelayedUntil = LastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, RefirePeriodExpression));
                AddToLog(p, Plugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/delayingrefire", "Delaying trigger '{0}' refire to {1}", LogName, RefireDelayedUntil));
            }
            else
            {
                RefireDelayedUntil = DateTime.MinValue;
            }
            DateTime curtime = DateTime.Now;

            if (Scheduling == SchedulingEnum.FromLastAction)
            {
                // get the last queued action as curTime
                lock (ctx.plug.ActionQueue)
                {
                    var ixy = from ax in ctx.plug.ActionQueue
                              where ax.ctx.trig.Id == Id
                              orderby ax.when descending
                              select ax;
                    if (ixy.Count() > 0)
                    {
                        curtime = ixy.ElementAt(0).when;
                        AddToLog(p, Plugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/lastactionfound", "Last action for trigger '{0}' found at {1}", LogName, curtime));
                    }
                }
            }
            else if (Scheduling == SchedulingEnum.FromRefirePeriod)
            {
                curtime = prevLastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, RefirePeriodExpression));
                if (curtime < LastFired)
                {
                    curtime = LastFired;
                    AddToLog(p, Plugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Trigger/beforelastfired", "Current time is before last fired for trigger '{0}'", LogName));
                }
            }
            if (PrevActions == PrevActionsEnum.Interrupt)
            {
                int exx = 0;
                lock (ctx.plug.ActionQueue)
                {
                    var ixy = from ax in ctx.plug.ActionQueue
                              where ax.ctx.trig.Id == Id
                              select ax;
                    if (ixy.Count() > 0)
                    {
                        List <Plugin.QueuedAction> rems = new List <Plugin.QueuedAction>();
                        rems.AddRange(ixy);
                        foreach (Plugin.QueuedAction qa in rems)
                        {
                            ctx.plug.ActionQueue.Remove(qa);
                            exx++;
                        }
                    }
                }
                if (exx > 0)
                {
                    if (PrevActionsRefire == RefireEnum.Deny)
                    {
                        AddToLog(p, Plugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueuenorefire", "Removed {0} instance(s) of trigger '{1}' actions from queue, refire denied", exx, LogName));
                        return;
                    }
                    else
                    {
                        AddToLog(p, Plugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueue", "Removed {0} instance(s) of trigger '{1}' actions from queue", exx, LogName));
                    }
                }
            }
            else if (PrevActionsRefire == RefireEnum.Deny)
            {
                int exx = 0;
                lock (ctx.plug.ActionQueue)
                {
                    var ixy = from ax in ctx.plug.ActionQueue
                              where ax.ctx.trig.Id == Id
                              select ax;
                    exx = ixy.Count();
                }
                if (exx > 0)
                {
                    AddToLog(p, Plugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/refiredenied", "{0} instance(s) of trigger '{1}' actions in queue, refire denied", exx, LogName));
                    return;
                }
            }
            var ix = from tx in Actions
                     orderby tx.OrderNumber ascending
                     select tx;

            foreach (Action a in ix)
            {
                curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a.ExecutionDelayExpression));
                if (a._Enabled == true)
                {
                    p.QueueAction(ctx, this, a, curtime);
                }
            }
        }
Exemplo n.º 8
0
        public string ExpandVariables(LoggerDelegate logger, object o, bool numeric, string expr)
        {
            Match  m, mx;
            string newexpr = expr;
            int    i       = 1;

            while (true)
            {
                m = rex.Match(newexpr);
                if (m.Success == false)
                {
                    m = rexnum.Match(newexpr);
                    if (m.Success == false)
                    {
                        break;
                    }
                }
                string x     = m.Groups["id"].Value;
                string val   = "";
                bool   found = false;
                if (testmode == true)
                {
                    if (x == "_since")
                    {
                        val = ((int)Math.Floor((DateTime.UtcNow - triggered).TotalSeconds)).ToString();
                    }
                    else if (x == "_sincems")
                    {
                        val = ((int)Math.Floor((DateTime.UtcNow - triggered).TotalMilliseconds)).ToString();
                    }
                    else
                    {
                        val = (numeric == true ? "1" : "test");
                    }
                    found = true;
                }
                else
                {
                    int gn;
                    if (Int32.TryParse(x, out gn) == true)
                    {
                        if (gn >= 0 && gn < numgroups.Count)
                        {
                            val   = numgroups[gn];
                            found = true;
                        }
                    }
                    if (found == false)
                    {
                        if (namedgroups.ContainsKey(x) == true)
                        {
                            val   = namedgroups[x];
                            found = true;
                        }
                    }
                    if (found == false)
                    {
                        if (x == "_since")
                        {
                            val   = ((int)Math.Floor((DateTime.UtcNow - triggered).TotalSeconds)).ToString();
                            found = true;
                        }
                        else if (x == "_sincems")
                        {
                            val   = ((int)Math.Floor((DateTime.UtcNow - triggered).TotalMilliseconds)).ToString();
                            found = true;
                        }
                        else if (x == "_systemtime")
                        {
                            val   = ((long)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString();
                            found = true;
                        }
                        else if (x == "_systemtimems")
                        {
                            val   = ((long)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds).ToString();
                            found = true;
                        }
                        else if (x == "_response")
                        {
                            val   = contextResponse;
                            found = true;
                        }
                        else if (x.IndexOf("_jsonresponse") == 0)
                        {
                            mx = rexlidx.Match(x);
                            if (mx.Success == true)
                            {
                                string pathspec = mx.Groups["index"].Value;
                                if (contextJsonParsed == false)
                                {
                                    JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                                    contextJsonResponse = jsonSerializer.Deserialize <dynamic>(contextResponse);
                                    contextJsonParsed   = true;
                                }
                                string[] path   = pathspec.Split("/".ToCharArray());
                                dynamic  curdir = contextJsonResponse;
                                foreach (string px in path)
                                {
                                    curdir = curdir[px];
                                }
                                val   = curdir.ToString();
                                found = true;
                            }
                        }
                        else if (x.IndexOf("evar:") == 0)
                        {
                            string varname = x.Substring(5);
                            lock (plug.simplevariables) // verified
                            {
                                if (plug.simplevariables.ContainsKey(varname) == true)
                                {
                                    val = "1";
                                }
                                else
                                {
                                    val = "0";
                                }
                                found = true;
                            }
                        }
                        else if (x.IndexOf("elvar:") == 0)
                        {
                            string varname = x.Substring(6);
                            lock (plug.listvariables) // verified
                            {
                                if (plug.listvariables.ContainsKey(varname) == true)
                                {
                                    val = "1";
                                }
                                else
                                {
                                    val = "0";
                                }
                                found = true;
                            }
                        }
                        else if (x.IndexOf("var:") == 0)
                        {
                            string varname = x.Substring(4);
                            lock (plug.simplevariables) // verified
                            {
                                if (plug.simplevariables.ContainsKey(varname) == true)
                                {
                                    val   = plug.simplevariables[varname].Value;
                                    found = true;
                                }
                            }
                        }
                        else if (x.IndexOf("lvar:") == 0)
                        {
                            string varname = x.Substring(5);
                            mx = rexlprp.Match(varname);
                            if (mx.Success == true)
                            {
                                string gname = mx.Groups["name"].Value;
                                string gprop = mx.Groups["prop"].Value;
                                switch (gprop)
                                {
                                case "size":
                                {
                                    lock (plug.listvariables)
                                    {
                                        VariableList vl = GetListVariable(plug, gname, false);
                                        val   = vl.Size().ToString();
                                        found = true;
                                    }
                                }
                                break;

                                case "indexof":
                                {
                                    string garg = mx.Groups["arg"].Value;
                                    lock (plug.listvariables)
                                    {
                                        VariableList vl = GetListVariable(plug, gname, false);
                                        val   = vl.IndexOf(garg).ToString();
                                        found = true;
                                    }
                                }
                                break;
                                }
                            }
                            else
                            {
                                mx = rexlidx.Match(varname);
                                if (mx.Success == true)
                                {
                                    string gname  = mx.Groups["name"].Value;
                                    string gindex = mx.Groups["index"].Value;
                                    lock (plug.listvariables)
                                    {
                                        VariableList vl = GetListVariable(plug, gname, false);
                                        if (gindex == "last")
                                        {
                                            gindex = vl.Size().ToString();
                                        }
                                        int iindex;
                                        if (Int32.TryParse(gindex, out iindex) == true)
                                        {
                                            val = vl.Peek(iindex);
                                        }
                                        found = true;
                                    }
                                    found = true;
                                }
                            }
                        }
                        else if (x.IndexOf("numeric:") == 0)
                        {
                            string numexpr = x.Substring(8);
                            val   = I18n.ThingToString(EvaluateNumericExpression(logger, o, numexpr));
                            found = true;
                        }
                        else if (x.IndexOf("string:") == 0)
                        {
                            string numexpr = x.Substring(7);
                            val   = EvaluateStringExpression(logger, o, numexpr);
                            found = true;
                        }
                        else if (x.IndexOf("func:") == 0)
                        {
                            val   = "";
                            found = true;
                            string funcexpr = x.Substring(5);
                            int    splitter = funcexpr.IndexOf(":");
                            if (splitter > 0)
                            {
                                string funcdef = funcexpr.Substring(0, splitter);
                                Match  rxm     = rexfunc.Match(funcdef);
                                if (rxm.Success == true)
                                {
                                    string   funcname = rxm.Groups["name"].Value.ToLower();
                                    string   funcarg  = rxm.Groups["arg"].Value;
                                    string[] args     = SplitArguments(funcarg);
                                    int      argc     = args.Count();
                                    string   funcval  = funcexpr.Substring(splitter + 1);
                                    switch (funcname)
                                    {
                                    case "toupper":     // toupper()
                                        val = funcval.ToUpper();
                                        break;

                                    case "tolower":     // tolower()
                                        val = funcval.ToLower();
                                        break;

                                    case "length":     // length()
                                        val = funcval.Length.ToString();
                                        break;

                                    case "hex2dec":     // hex2dec()
                                        val = "" + int.Parse(funcval, System.Globalization.NumberStyles.HexNumber);
                                        break;

                                    case "padleft":     // padleft(charcode,length)
                                        if (argc != 2)
                                        {
                                            throw new ArgumentException(I18n.Translate("internal/Context/padleftargerror", "Padleft function requires two arguments, {0} were given", argc));
                                        }
                                        else
                                        {
                                            val = funcval.PadLeft(Int32.Parse(args[1]), (char)Int32.Parse(args[0]));
                                        }
                                        break;

                                    case "padright":     // padright(charcode,length)
                                        if (argc != 2)
                                        {
                                            throw new ArgumentException(I18n.Translate("internal/Context/padrightargerror", "Padright function requires two arguments, {0} were given", argc));
                                        }
                                        else
                                        {
                                            val = funcval.PadRight(Int32.Parse(args[1]), (char)Int32.Parse(args[0]));
                                        }
                                        break;

                                    case "substring":     // substring(startindex, length) or substring(startindex)
                                        if (argc != 1 && argc != 2)
                                        {
                                            throw new ArgumentException(I18n.Translate("internal/Context/substringargerror", "Substring function requires one or two arguments, {0} were given", argc));
                                        }
                                        else
                                        {
                                            switch (argc)
                                            {
                                            case 1:
                                                val = funcval.Substring(Int32.Parse(args[0]));
                                                break;

                                            case 2:
                                                val = funcval.Substring(Int32.Parse(args[0]), Int32.Parse(args[1]));
                                                break;
                                            }
                                        }
                                        break;

                                    case "indexof":     // indexof(stringtosearch)
                                        if (argc != 1)
                                        {
                                            throw new ArgumentException(I18n.Translate("internal/Context/indexofargerror", "Indexof function requires one argument, {0} were given", argc));
                                        }
                                        else
                                        {
                                            val = "" + funcval.IndexOf(args[0]);
                                        }
                                        break;

                                    case "trim":     // trim() or trim(charcode,charcode,charcode,...)
                                        if (argc == 0 || args[0] == "")
                                        {
                                            val = funcval.Trim();
                                        }
                                        else
                                        {
                                            string xx = "";
                                            foreach (string xyz in args)
                                            {
                                                xx += (char)Int32.Parse(xyz);
                                            }
                                            val = funcval.Trim(xx.ToCharArray());
                                        }
                                        break;

                                    case "trimleft":     // trimleft() or trimleft(charcode,charcode,charcode,...)
                                        if (argc == 0 || args[0] == "")
                                        {
                                            val = funcval.TrimStart();
                                        }
                                        else
                                        {
                                            string xx = "";
                                            foreach (string xyz in args)
                                            {
                                                xx += (char)Int32.Parse(xyz);
                                            }
                                            val = funcval.TrimStart(xx.ToCharArray());
                                        }
                                        break;

                                    case "trimright":     // trimright() or trimright(charcode,charcode,charcode,...)
                                        if (argc == 0 || args[0] == "")
                                        {
                                            val = funcval.TrimEnd();
                                        }
                                        else
                                        {
                                            string xx = "";
                                            foreach (string xyz in args)
                                            {
                                                xx += (char)Int32.Parse(xyz);
                                            }
                                            val = funcval.TrimEnd(xx.ToCharArray());
                                        }
                                        break;

                                    case "format":     // format(type,formatstring)
                                        if (argc != 2)
                                        {
                                            throw new ArgumentException(I18n.Translate("internal/Context/formatargerror", "Format function requires two arguments, {0} were given", argc));
                                        }
                                        else
                                        {
                                            Type   type      = Type.GetType(args[0]);
                                            object converted = Convert.ChangeType(funcval, type, CultureInfo.InvariantCulture);
                                            val = String.Format("{0:" + args[1] + "}", converted);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        else if (x == "_ffxivplayer")
                        {
                            VariableClump vc = PluginBridges.BridgeFFXIV.GetMyself();
                            if (vc != null)
                            {
                                val = vc.GetValue("name");
                            }
                            found = true;
                        }
                        else if (x == "_ffxivpartyorder")
                        {
                            val   = plug.cfg.FfxivPartyOrdering + " " + plug.cfg.FfxivCustomPartyOrder;
                            found = true;
                        }
                        else if (x == "_incombat")
                        {
                            val   = (plug.mainform.InCombat == true) ? "1" : "0";
                            found = true;
                        }
                        else if (x == "_duration")
                        {
                            try
                            {
                                if (plug.mainform.InCombat == true)
                                {
                                    val = ((int)Math.Floor(plug.mainform.ActiveZone.ActiveEncounter.Duration.TotalSeconds)).ToString();
                                }
                                else
                                {
                                    val = "0";
                                }
                            }
                            catch (Exception)
                            {
                                val = "0";
                            }
                            found = true;
                        }
                        else if (x.IndexOf("_ffxivparty") == 0)
                        {
                            mx = rexnump.Match(x);
                            if (mx.Success == true)
                            {
                                string        gindex = mx.Groups["index"].Value;
                                string        gprop  = mx.Groups["prop"].Value;
                                int           iindex = 0;
                                Int64         honk;
                                VariableClump vc      = null;
                                bool          foundid = false;
                                if (Int64.TryParse(gindex, System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture, out honk) == true)
                                {
                                    vc = PluginBridges.BridgeFFXIV.GetIdPartyMember(gindex, out foundid);
                                }
                                if (foundid == false)
                                {
                                    if (Int32.TryParse(gindex, out iindex) == true)
                                    {
                                        vc = PluginBridges.BridgeFFXIV.GetPartyMember(iindex);
                                    }
                                    else
                                    {
                                        vc = PluginBridges.BridgeFFXIV.GetNamedPartyMember(gindex);
                                    }
                                }
                                if (vc != null)
                                {
                                    val = vc.GetValue(gprop);
                                }
                            }
                            found = true;
                        }
                        else if (x.IndexOf("_ffxiventity") == 0)
                        {
                            mx = rexnump.Match(x);
                            if (mx.Success == true)
                            {
                                string        gindex = mx.Groups["index"].Value;
                                string        gprop  = mx.Groups["prop"].Value;
                                Int64         honk;
                                VariableClump vc      = null;
                                bool          foundid = false;
                                if (Int64.TryParse(gindex, System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture, out honk) == true)
                                {
                                    vc = PluginBridges.BridgeFFXIV.GetIdEntity(gindex, out foundid);
                                }
                                if (foundid == false)
                                {
                                    vc = PluginBridges.BridgeFFXIV.GetNamedEntity(gindex);
                                }
                                if (vc != null)
                                {
                                    val = vc.GetValue(gprop);
                                }
                            }
                            found = true;
                        }
                        else if (x == "_ffxivtime")
                        {
                            TimeSpan ez   = GetEorzeanTime();
                            int      mins = (int)Math.Floor(ez.TotalMinutes);
                            val   = mins.ToString();
                            found = true;
                        }
                        else if (x == "_lastencounter")
                        {
                            Advanced_Combat_Tracker.FormActMain act = Advanced_Combat_Tracker.ActGlobals.oFormActMain;
                            FieldInfo fi   = act.GetType().GetField("defaultTextFormat", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance);
                            dynamic   texf = fi.GetValue(act);
                            val = "";
                            if (texf != null)
                            {
                                int zones = act.ZoneList.Count;
                                for (int ii = zones - 1; ii >= 0; ii--)
                                {
                                    int encs = act.ZoneList[ii].Items.Count;
                                    for (int jj = encs - 1; jj >= 1; jj--)
                                    {
                                        if (act.ZoneList[ii].Items[jj] != act.ActiveZone.ActiveEncounter)
                                        {
                                            val = act.GetTextExport(act.ZoneList[ii].Items[jj], texf);
                                            ii  = 0;
                                            jj  = 0;
                                        }
                                    }
                                }
                            }
                            found = true;
                        }
                        else if (x == "_activeencounter")
                        {
                            Advanced_Combat_Tracker.FormActMain act = Advanced_Combat_Tracker.ActGlobals.oFormActMain;
                            FieldInfo fi   = act.GetType().GetField("defaultTextFormat", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance);
                            dynamic   texf = fi.GetValue(act);
                            val   = act.GetTextExport(act.ActiveZone.ActiveEncounter, texf);
                            found = true;
                        }
                        else if (x.IndexOf("_textaura") == 0)
                        {
                            mx = rexnump.Match(x);
                            if (mx.Success == true)
                            {
                                string gindex = mx.Groups["index"].Value;
                                string gprop  = mx.Groups["prop"].Value.ToLower();
                                val = "";
                                lock (plug.textauras)
                                {
                                    if (plug.textauras.ContainsKey(gindex) == true)
                                    {
                                        Forms.AuraContainerForm acf = plug.textauras[gindex];
                                        switch (gprop)
                                        {
                                        case "x":
                                            val = acf.Left.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "y":
                                            val = acf.Top.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "w":
                                            val = acf.Width.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "h":
                                            val = acf.Height.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "opacity":
                                            val = acf.PresentableOpacity.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "text":
                                            val = acf.CurrentText;
                                            break;
                                        }
                                    }
                                }
                                found = true;
                            }
                        }
                        else if (x.IndexOf("_imageaura") == 0)
                        {
                            mx = rexnump.Match(x);
                            if (mx.Success == true)
                            {
                                string gindex = mx.Groups["index"].Value;
                                string gprop  = mx.Groups["prop"].Value.ToLower();
                                val = "";
                                lock (plug.imageauras)
                                {
                                    if (plug.imageauras.ContainsKey(gindex) == true)
                                    {
                                        Forms.AuraContainerForm acf = plug.imageauras[gindex];
                                        switch (gprop)
                                        {
                                        case "x":
                                            val = acf.Left.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "y":
                                            val = acf.Top.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "w":
                                            val = acf.Width.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "h":
                                            val = acf.Height.ToString(CultureInfo.InvariantCulture);
                                            break;

                                        case "opacity":
                                            val = acf.PresentableOpacity.ToString(CultureInfo.InvariantCulture);
                                            break;
                                        }
                                    }
                                }
                                found = true;
                            }
                        }
                        else if (x == "_screenwidth")
                        {
                            System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;
                            val   = scr.WorkingArea.Width.ToString(CultureInfo.InvariantCulture);
                            found = true;
                        }
                        else if (x == "_screenheight")
                        {
                            System.Windows.Forms.Screen scr = System.Windows.Forms.Screen.PrimaryScreen;
                            val   = scr.WorkingArea.Height.ToString(CultureInfo.InvariantCulture);
                            found = true;
                        }
                        else if (x == "_screenminx")
                        {
                            val   = plug.MinX.ToString(CultureInfo.InvariantCulture);
                            found = true;
                        }
                        else if (x == "_screenminy")
                        {
                            val   = plug.MinY.ToString(CultureInfo.InvariantCulture);
                            found = true;
                        }
                        else if (x == "_screenmaxx")
                        {
                            val   = plug.MaxX.ToString(CultureInfo.InvariantCulture);
                            found = true;
                        }
                        else if (x == "_screenmaxy")
                        {
                            val   = plug.MaxY.ToString(CultureInfo.InvariantCulture);
                            found = true;
                        }
                        else if (x == "_fps")
                        {
                            if (plug.sc != null)
                            {
                                val = plug.sc.FPS.ToString(CultureInfo.InvariantCulture);
                            }
                            else
                            {
                                val = "0";
                            }
                            found = true;
                        }
                    }
                }
                newexpr = newexpr.Substring(0, m.Index) + val + newexpr.Substring(m.Index + m.Length);

                /*
                 * if (logger != null)
                 * {
                 *  logger(o, I18n.Translate("internal/Context/expansionstep", "Expansion step {0} from '{1}' to '{2}' ({3}) = '{4}'", i, expr, newexpr, val, found));
                 * }
                 * else if (plug != null)
                 * {
                 *  plug.FilteredAddToLog(Plugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Context/expansionstep", "Expansion step {0} from '{1}' to '{2}' ({3}) = '{4}'", i, expr, newexpr, val, found));
                 * }*/
                i++;
            }
            ;
            if (trig != null)
            {
                if (trig.DebugLevel == Plugin.DebugLevelEnum.Inherit)
                {
                    if (plug != null)
                    {
                        if (plug.cfg.DebugLevel < Plugin.DebugLevelEnum.Verbose)
                        {
                            return(newexpr);
                        }
                    }
                }
                else
                {
                    if (trig.DebugLevel < Plugin.DebugLevelEnum.Verbose)
                    {
                        return(newexpr);
                    }
                }
            }
            if (newexpr.CompareTo(expr) != 0)
            {
                if (logger != null)
                {
                    logger(o, I18n.Translate("internal/Context/expansion", "Variable expansion from '{0}' to '{1}'", expr, newexpr));
                }
                else if (plug != null)
                {
                    plug.FilteredAddToLog(Plugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Context/expansion", "Variable expansion from '{0}' to '{1}'", expr, newexpr));
                }
            }
            return(newexpr);
        }
Exemplo n.º 9
0
        public override string ToString()
        {
            string desc = "";

            if (ConditionType == CndTypeEnum.ListContains || ConditionType == CndTypeEnum.ListDoesNotContain)
            {
                desc  = I18n.Translate("internal/ConditionSingle/listvar", "List variable specified by");
                desc += " ";
                switch (ExpressionTypeL)
                {
                case ExprTypeEnum.Numeric:
                    desc += I18n.Translate("internal/ConditionSingle/numericexpression", "numeric expression ({0})", ExpressionL);
                    break;

                case ExprTypeEnum.String:
                    desc += I18n.Translate("internal/ConditionSingle/stringexpression", "string expression ({0})", ExpressionL);
                    break;
                }
                desc += " ";
                switch (ConditionType)
                {
                case CndTypeEnum.ListContains:
                    desc += I18n.Translate("internal/ConditionSingle/listmustcontain", "must contain the result from");
                    break;

                case CndTypeEnum.ListDoesNotContain:
                    desc += I18n.Translate("internal/ConditionSingle/listcantcontain", "must not contain the result from");
                    break;
                }
            }
            else
            {
                switch (ExpressionTypeL)
                {
                case ExprTypeEnum.Numeric:
                    desc = Capitalize(I18n.Translate("internal/ConditionSingle/numericexpression", "numeric expression ({0})", ExpressionL));
                    break;

                case ExprTypeEnum.String:
                    desc = Capitalize(I18n.Translate("internal/ConditionSingle/stringexpression", "string expression ({0})", ExpressionL));
                    break;
                }
                desc += " ";
                switch (ConditionType)
                {
                case CndTypeEnum.NumericEqual:
                    desc += I18n.Translate("internal/ConditionSingle/numericequal", "must be numerically equal to");
                    break;

                case CndTypeEnum.NumericNotEqual:
                    desc += I18n.Translate("internal/ConditionSingle/numericnotequal", "must not be numerically equal to");
                    break;

                case CndTypeEnum.NumericGreater:
                    desc += I18n.Translate("internal/ConditionSingle/numericgreater", "must be numerically greater than");
                    break;

                case CndTypeEnum.NumericGreaterEqual:
                    desc += I18n.Translate("internal/ConditionSingle/numericgreaterequal", "must be numerically greater or equal to");
                    break;

                case CndTypeEnum.NumericLess:
                    desc += I18n.Translate("internal/ConditionSingle/numericless", "must be numerically less than");
                    break;

                case CndTypeEnum.NumericLessEqual:
                    desc += I18n.Translate("internal/ConditionSingle/numericlessequal", "must be numerically less or equal to");
                    break;

                case CndTypeEnum.StringEqualCase:
                    desc += I18n.Translate("internal/ConditionSingle/stringequalcase", "must pass case-sensitive string comparison to the string from");
                    break;

                case CndTypeEnum.StringEqualNocase:
                    desc += I18n.Translate("internal/ConditionSingle/stringequalnocase", "must pass case-insensitive string comparison to the string from");
                    break;

                case CndTypeEnum.StringNotEqualCase:
                    desc += I18n.Translate("internal/ConditionSingle/stringnotequalcase", "must not pass case-sensitive string comparison to the string from");
                    break;

                case CndTypeEnum.StringNotEqualNocase:
                    desc += I18n.Translate("internal/ConditionSingle/stringnotequalnocase", "must not pass case-insensitive string comparison to the string from");
                    break;

                case CndTypeEnum.RegexMatch:
                    desc += I18n.Translate("internal/ConditionSingle/regexmatch", "must match the regular expression from");
                    break;

                case CndTypeEnum.RegexNotMatch:
                    desc += I18n.Translate("internal/ConditionSingle/noregexmatch", "must not match the regular expression from");
                    break;
                }
            }
            switch (ExpressionTypeR)
            {
            case ExprTypeEnum.Numeric:
                desc += " " + I18n.Translate("internal/ConditionSingle/numericexpression", "numeric expression ({0})", ExpressionR);
                break;

            case ExprTypeEnum.String:
                desc += " " + I18n.Translate("internal/ConditionSingle/stringexpression", "string expression ({0})", ExpressionR);
                break;
            }
            return(Capitalize(desc));
        }
Exemplo n.º 10
0
 internal static string GetLocalizationFor(string path, string current)
 {
     return(I18n.Translate(path, current));
 }