/// <summary>
        /// 更新命令信息
        /// </summary>
        /// <param name="configKeyAndValue"></param>
        /// <param name="xmlDoc"></param>
        private void UpdateCommandInfos(Dictionary <string, string> configKeyAndValue, XmlDocument xmlDoc)
        {
            bool isAddSuccessful = TryAddCommandAndPathInfosNode(xmlDoc);

            if (!isAddSuccessful)
            {
                return;
            }

            XmlNode commandInfosNode = xmlDoc.GetElementsByTagName(CommandInfos)[0];
            XmlNode pathInfosNode    = xmlDoc.GetElementsByTagName(PathInfos)[0];

            foreach (var configs in configKeyAndValue)
            {
                string     commandValue = configs.Value;
                XmlElement newNode      = xmlDoc.CreateElement(CommandInfo);
                newNode.SetAttribute(Command, commandValue);
                newNode.SetAttribute(ShortName, configs.Key);
                //添加到路径信息
                if (FileAndDirectoryHelper.PathIsExists(commandValue))
                {
                    pathInfosNode.AppendChild(newNode);
                }
                else
                {
                    commandInfosNode.AppendChild(newNode);
                }
            }

            xmlDoc.Save(filePath);
        }
Esempio n. 2
0
        private static string CommandNotInConfig(string originalShortName)
        {
            //输入是URL网址或文件路径,则直接打开
            if (IsWellFormedUriString(originalShortName) || FileAndDirectoryHelper.PathIsExists(originalShortName))
            {
                return(ConvertCommandWithQuote(originalShortName));
            }

            return(GetSearchCommand(originalShortName));
        }
Esempio n. 3
0
        /// <summary>
        /// 获取命令
        /// </summary>
        /// <param name="originalShortName">简称</param>
        /// <returns></returns>
        private string GetCommand(string originalShortName)
        {
            string command = GetCommandFormSetting(originalShortName);

            //简称对应的命令不存在
            if (string.IsNullOrEmpty(command))
            {
                //简称是URL网址或文件路径,则直接打开
                if (IsWellFormedUriString(originalShortName) || FileAndDirectoryHelper.PathIsExists(originalShortName))
                {
                    return(ConvertCommandWithQuote(originalShortName));
                }

                //搜索该简称
                return(GetSearchCommand(originalShortName));
            }

            //满足URI格式
            if (IsWellFormedUriString(command))
            {
                return(ConvertCommandWithQuote(command));
            }

            //是目录或文件路径
            if (FileAndDirectoryHelper.IsDirectoryOrFilePath(command))
            {
                //路径不存在
                if (FileAndDirectoryHelper.PathIsNotExists(command))
                {
                    MessageBoxHelper.ShowErrorMessageBox(string.Format(@"对应路径不存在:{0}", command));
                    return(string.Empty);
                }

                return(ConvertCommandWithQuote(command));
            }

            return(string.Format("start \"\" {0}", command));
        }