예제 #1
0
        private void ExecuteMacroLocate()
        {
            List <string> macroInstructionParametersRaw = GetMacroInstructionParametersList();

            foreach (string item in macroInstructionParametersRaw)
            {
                if (AFile.Exists(item))
                {
                    AFile.ShowInExplorer(item);
                }
                else
                {
                    reportType = ReportType.ERROR;
                    ReportInfo.Add("Startup item [" + item + "] is not exist.");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 执行宏设置指令
        /// </summary>
        private void ExecuteMacroSet()
        {
            // get: @set settingItem
            // set: @set settingItem value
            List <string> paramList = GetMacroInstructionParametersList();

            switch (paramList.Count)
            {
            case 0:
                // List setting items.
                //string retnMessage = "可用的设置项: \n";
                string retnMessage = "Available setting items: ";
                foreach (string propertyName in ASettings.GetSettingsPropertiesName())
                {
                    retnMessage += propertyName + " ";
                }
                throw new NotImplementedException(retnMessage);

            case 1:
                // List available value and current value.
                if (0 == ASettings.GetSettingsPropertiesName().Where(p => p == paramList[0]).Count())
                {
                    //throw new NotImplementedException("设置项 [" + paramList[0] + "] 没有找到。");
                    throw new NotImplementedException("Setting item [" + paramList[0] + "] is not found.");
                }
                string targetPropertyName = paramList[0].Trim();
                //string availableValues = "可选值: ";
                string availableValues = "Available values: ";
                Type   t = typeof(ASettings).GetProperty(paramList[0]).GetValue(null).GetType();
                if (t.Equals(true.GetType()))
                {
                    availableValues += "True / False";
                }
                else if (t.Equals(typeof(AlterfulTheme)))
                {
                    foreach (AlterfulTheme theme in Enum.GetValues(typeof(AlterfulTheme)))
                    {
                        availableValues += theme + " / ";
                    }
                    availableValues = availableValues.Substring(0, availableValues.Length - 3);
                }
                throw new NotImplementedException(targetPropertyName + ": " + typeof(ASettings).GetProperty(paramList[0]).GetValue(null) as string + Environment.NewLine + availableValues);

            case 2:
                // Set value.
                if (0 == ASettings.GetSettingsPropertiesName().Where(p => p == paramList[0]).Count())
                {
                    //throw new NotImplementedException("设置项 [" + paramList[0] + "] 没有找到。");
                    throw new NotImplementedException("Setting item [" + paramList[0] + "] is not found.");
                }
                string targetPropertyName2 = paramList[0].Trim();
                string setValue            = paramList[1].Trim();
                //string availableValues2 = "可选值: ";
                string availableValues2 = "Available values: ";
                Type   t2 = typeof(ASettings).GetProperty(paramList[0]).GetValue(null).GetType();
                if (t2.Equals(true.GetType()))
                {
                    switch (setValue)
                    {
                    case "True":
                    case "true":
                        typeof(ASettings).GetProperty(paramList[0]).SetValue(null, true);
                        break;

                    case "False":
                    case "false":
                        typeof(ASettings).GetProperty(paramList[0]).SetValue(null, false);
                        break;

                    default:
                        // throw new NotImplementedException("无效的值。");
                        throw new NotImplementedException("Invalid value.");
                    }
                    availableValues2 += "True / False";
                }
                else if (t2.Equals(typeof(AlterfulTheme)))
                {
                    bool found = false;
                    foreach (AlterfulTheme theme in Enum.GetValues(typeof(AlterfulTheme)))
                    {
                        string a = theme.ToString();
                        if (theme.ToString().ToLower().Trim() == setValue.ToLower())
                        {
                            ATheme.Theme = theme;
                            found        = true;
                            //ReportInfo.Add("主题设置已经生效,但之前的内容样式不会更新,可用 @restart 来重启 Alterful。");
                            ReportInfo.Add("Theme config have changed, but early content won't be appply, you can @restart Alterful.");
                        }
                    }
                    if (!found)
                    {
                        throw new NotImplementedException("Theme [" + setValue + "] is not found.");             //throw new NotImplementedException("主题 [" + setValue + "] 没有找到。");
                    }
                }
                break;

            default:
                throw new MacroFormatException();
            }
        }