/// <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; }