コード例 #1
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);
            }
        }
コード例 #2
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.");
                }
            }
        }
コード例 #3
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;
     }
 }
コード例 #4
0
 public void ExistsTest(string startupName, bool expected)
 {
     Assert.AreEqual(expected, AFile.Exists(startupName));
 }