/// <summary> /// 转换文件名 /// </summary> /// <returns>是否转换成功</returns> private bool ConvertFileName() { if (cboConverterType.SelectedIndex == -1) { return(false); } if (SourceFilePath == String.Empty || !File.Exists(SourceFilePath)) { return(false); } ConverterMaps converterMaps = (ConverterMaps)cboConverterMapsList.SelectedItem; Converter converter = (Converter)cboConverterType.SelectedItem; string destFilePath = ConverterMapsList.ConvertText(SourceFilePath, converterMaps.Maps, converter.SourceMapId, converter.DestMapId); if (SourceFilePath == destFilePath) { return(true); } else { try { File.Copy(SourceFilePath, destFilePath, true); File.Delete(SourceFilePath); } catch (Exception) { return(false); } SourceFilePath = destFilePath; lblFilePath.Text = SourceFilePath; return(true); } }
/// <summary> /// 转换文本 /// </summary> private void ConvertSourceToDestText() { if (cboConverterType.SelectedIndex == -1) { return; } string sourceContent = txtSource.Text; string destContent = ""; ConverterMaps converterMaps = (ConverterMaps)cboConverterMapsList.SelectedItem; Converter converter = (Converter)cboConverterType.SelectedItem; if (cboRegex.Text.Trim() != String.Empty) { Regex regex = null; try { regex = new Regex(cboRegex.Text, RegexOptions.IgnoreCase | RegexOptions.Multiline); } catch (Exception) { ShowErrorMsg("正则表达式错误!"); cboRegex.SelectAll(); cboRegex.Focus(); return; } if (chkIsExclude.Checked) { StringBuilder strBuilder = new StringBuilder(ConverterMapsList.ConvertText(sourceContent, converterMaps.Maps, converter.SourceMapId, converter.DestMapId)); foreach (Match match in regex.Matches(sourceContent)) { if (match.Value == String.Empty) { continue; } strBuilder.Replace(ConverterMapsList.ConvertText(match.Value, converterMaps.Maps, converter.SourceMapId, converter.DestMapId), match.Value); } destContent = strBuilder.ToString(); } else { destContent = regex.Replace(sourceContent, match => ConverterMapsList.ConvertText(match.Value, converterMaps.Maps, converter.SourceMapId, converter.DestMapId)); } } else { destContent = ConverterMapsList.ConvertText(sourceContent, converterMaps.Maps, converter.SourceMapId, converter.DestMapId); } txtDest.Text = destContent; }
/// <summary> /// 读取字符对照表配置列表 /// </summary> private void ReadConverterMapsList() { if (!ConverterMapsList.ReadConverterMapsList()) { ShowErrorMsg("字符对照表读取失败!"); return; } cboConverterMapsList.Tag = true; BindingSource bs = new BindingSource(); bs.DataSource = ConverterMapsList.MapsList; cboConverterMapsList.DataSource = bs; cboConverterMapsList.DisplayMember = "Name"; cboConverterMapsList.ValueMember = "ConfigPath"; cboConverterMapsList.SelectedIndex = 0; cboConverterMapsList.Tag = false; cboConverterMapsList_SelectedIndexChanged(null, null); }