示例#1
0
        public void ConstQuoteItemParseTest()
        {
            string constQuoteMapConfigSingleLine = "constQuoteName#constQuoteString";

            AConstQuote.ConstQuoteItem actual = AConstQuote.ConstQuoteItemParse(constQuoteMapConfigSingleLine);
            Assert.AreEqual("constQuoteName", actual.constQuoteName);
            Assert.AreEqual("constQuoteString", actual.constQuoteString);
        }
示例#2
0
        public void GetConstQuoteMapConfigLinesTest()
        {
            string        constQuoteMapConfigString = "testLine1\ntestLine2\ntestLine3";
            List <string> actual = AConstQuote.GetConstQuoteMapConfigLines(constQuoteMapConfigString);

            Assert.AreEqual(3, actual.Count);
            Assert.AreEqual("testLine1", actual[0]);
            Assert.AreEqual("testLine2", actual[1]);
            Assert.AreEqual("testLine3", actual[2]);
        }
示例#3
0
        /// <summary>
        /// 执行宏新建指令
        /// </summary>
        /// <exception cref="UnauthorizedAccessException"></exception>
        private void ExecuteMacroNew()
        {
            List <string> macroInstructionParameters = GetMacroInstructionParametersList();

            // Handle [in] sytex
            string inWhere = AFile.ATEMP_PATH;

            if (macroInstructionParameters.Count >= 3 && "in" == macroInstructionParameters[macroInstructionParameters.Count - 2])
            {
                string lastParam = macroInstructionParameters[macroInstructionParameters.Count - 1];
                if (AFile.Exists(lastParam))
                {
                    // If the item is already a directory
                    string itemPath = AFile.GetFullPath(lastParam);
                    if (Directory.Exists(itemPath))
                    {
                        inWhere = itemPath;
                    }
                    // If the item is exist
                    else if (File.Exists(itemPath))
                    {
                        inWhere = Path.GetDirectoryName(itemPath);
                    }
                    else
                    {
                        throw new NotImplementedException("The startup item [" + lastParam + "] is not found in disk.");
                    }
                }
                else if (Directory.Exists(lastParam))
                {
                    inWhere = lastParam;
                }
                else
                {
                    throw new NotImplementedException("The directory [" + lastParam + "] is not exist.");
                }
                macroInstructionParameters.RemoveRange(macroInstructionParameters.Count - 2, 2);
            }
            // Remove the last '\'
            if (inWhere.Last() == '\\')
            {
                inWhere = inWhere.Substring(0, inWhere.Length - 1);
            }

            foreach (string newFileName in macroInstructionParameters)
            {
                string fileName = AConstQuote.ConstQuoteParse(newFileName);
                string filePath = inWhere + @"\" + fileName;
                using (StreamWriter streamWriter = new StreamWriter(filePath, false)) { }
                AFile.StartupProcess(filePath);
                //AFile.LaunchTempFile(fileName);
            }
        }
示例#4
0
 /// <summary>
 /// 执行宏添加常引用指令
 /// </summary>
 /// <param name="macroInstructionParameters"></param>
 /// <exception cref="FileNotFoundException"></exception>
 /// <exception cref="UnauthorizedAccessException"></exception>
 /// <exception cref="ConstQuoteNameAlreadyExistsException"></exception>
 private void ExecuteMacroAddConstQuote(List <string> macroInstructionParameters)
 {
     try
     {
         if (macroInstructionParameters.Count != 2)
         {
             throw new MacroFormatException();
         }
         string constQuoteName = AConstQuote.ConstQuoteNamePull(macroInstructionParameters[0]);
         AConstQuote.Add(constQuoteName, macroInstructionParameters[1]);
     }
     catch (Exception) { throw; }
 }
示例#5
0
        /// <summary>
        /// 获取可执行的Alterful指令
        /// </summary>
        /// <param name="instruction"></param>
        /// <returns></returns>
        public static AInstruction GetInstruction(string instruction)
        {
            switch (GetType(instruction))
            {
            case InstructionType.MACRO: return(new AInstruction_Macro(instruction));

            case InstructionType.STARTUP: return(new AInstruction_Startup(AConstQuote.ConstQuoteParse(instruction)));

            case InstructionType.CONST: return(new AInstruction_Const(instruction));

            case InstructionType.CMD: return(new AInstruction_CMD(instruction));

            default: return(new AInstruction_Startup(AConstQuote.ConstQuoteParse(instruction)));
            }
        }
示例#6
0
        public static void Initialize(AppendString appendString)
        {
            // Floder Check
            if (!Directory.Exists(BASE_PATH + @"\Config"))
            {
                // First start alterful
                ASettings.DisplayRightMenu  = true;
                ASettings.AutoRunWithSystem = true;
                CreateShortcut(APATH_PATH + @"\alterful" + AFile.LNK_EXTENTION, BASE_PATH + @"\Alterful.exe");
                CreateShortcut(APATH_PATH + @"\atemp" + AFile.LNK_EXTENTION, ATEMP_PATH);
                CreateShortcut(APATH_PATH + @"\desktop" + AFile.LNK_EXTENTION, Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
                IS_FIRST_START = true;
            }

            // Old version auto startup alterful.exe but new version startup AlterfulPiple.exe,
            // so over execute to overwrite the old auto startup register configurate.
            if (ASettings.AutoRunWithSystem)
            {
                ASettings.AutoRunWithSystem = true;
            }

            Directory.CreateDirectory(BASE_PATH + @"\APath");
            Directory.CreateDirectory(BASE_PATH + @"\ATemp");
            Directory.CreateDirectory(BASE_PATH + @"\Config");
            Directory.CreateDirectory(CONST_INSTRUCTION_PATH);

            // File Check
            AConstQuote.CreateConstQuoteFile();
            ATheme.CreateThemeConfigFile();

            // Config Check
            AConstQuote.ReadAllConfig();
            ATheme.ReadAllConfig();

            // Enviroment Check
            SysEnviroment.SetPathAfter(APATH_PATH);

            // Regedit Check

            // Others
            System.IO.File.Delete(@".\restart.bat");
            ShowANew(appendString);
            ShowANotification("Alterful 正在后台运行", "Press Alt+A to active Alterful");
        }
示例#7
0
        /// <summary>
        /// 执行指令,启动失败的启动项在ReportInfo中查看
        /// </summary>
        /// <exception cref="ConstInstructionParameterParseException"></exception>
        public override string Execute()
        {
            ReportInfo.Clear();
            AHelper.InstructionHistory.Insert(0, Instruction);

            ConstInstruction ci = new ConstInstruction();

            if (AConstInstruction.GetConstInstructionFrame(Instruction, ref ci))
            {
                bool allRight = true;
                try
                {
                    foreach (string instructionLine in ci.instructionLines)
                    {
                        // Instruction here firstly need to be parse (const quote / parameter parse).
                        // Const quote parse.
                        string instructionLine_cqp = AConstQuote.ConstQuoteParse(instructionLine);
                        // Parameter parse
                        ConstInstruction instructionAttribute   = AConstInstruction.ConstInstructionFileNameParse(Instruction, false);
                        string           instructionLine_cpq_pp = AConstInstruction.ConstInstructionParameterParse(ci, instructionLine_cqp, instructionAttribute.parameterList);
                        // Execute
                        AInstruction.GetInstruction(instructionLine_cpq_pp).Execute();
                        if (reportType != ReportType.OK)
                        {
                            allRight = false;
                        }
                    }
                }
                catch (Exception exception) { throw exception; }
                finally { if (!allRight)
                          {
                              reportType = ReportType.WARNING;
                          }
                }
                return(AInstruction.MSG_EXECUTE_SUCCESSFULLY);
            }
            else
            {
                reportType = ReportType.ERROR;
                throw new ConstInstructionNotFoundException(Instruction);
            }
        }
示例#8
0
 /// <summary>
 /// 执行宏启动项添加指令
 /// </summary>
 /// <param name="macroInstructionParameters">宏添加指令参数列表</param>
 /// <exception cref="FileNotFoundException"></exception>
 /// <exception cref="ConstQuoteParseError"></exception>
 private void ExecuteMacroAddStartup(List <string> macroInstructionParameters)
 {
     try
     {
         string startupName = AConstQuote.ConstQuoteParse(macroInstructionParameters[0]);
         string targetPath  = AConstQuote.ConstQuoteParse(macroInstructionParameters[1]);
         if (AFile.Exists(startupName))
         {
             //throw new NotImplementedException("添加失败,因为启动名 [" + startupName + "] 已经存在。");
             throw new NotImplementedException("Failed to add, because item [" + startupName + "] is already exist.");
         }
         AFile.Add(startupName, targetPath);
         reportType = ReportType.OK;
     }
     catch (FileNotFoundException)
     {
         throw;
     }
     catch (ConstQuoteParseError)
     {
         throw;
     }
 }
示例#9
0
 /// <summary>
 /// 执行宏删除常引用指令
 /// </summary>
 /// <param name="delConstQuoteName"></param>
 private void ExecuteMacroDelConstQuote(string delConstQuoteName)
 {
     AConstQuote.Delete(AConstQuote.ConstQuoteNamePull(delConstQuoteName));
 }
示例#10
0
 public void ConstQuoteNamePullTest(string nameMayWithStuffix, string excepted)
 {
     Assert.AreEqual(excepted, AConstQuote.ConstQuoteNamePull(nameMayWithStuffix));
 }