コード例 #1
0
        private bool CleanRegionAreas(string path, string searchRegionName, string newRegionText)
        {
            if (IsValidFile(path))
            {
                TextInfo          info = new TextInfo(path);
                RegionAreaManager regionAreaManager = new RegionAreaManager(info.DefaultText);
                List <RegionArea> regionAreas       = regionAreaManager.GetRegionAreas();
                int offset = 0;

                foreach (RegionArea regionArea in regionAreas)
                {
                    if (regionArea.RegionName.IndexOf(searchRegionName, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        regionArea.RegionIndexOffset = offset;
                        string regionAreaTextRemoved = regionArea.RemoveRegionText();
                        offset += -regionArea.RegionLength;
                        regionAreaManager.Text = regionAreaTextRemoved;
                    }
                }

                info.NewText = newRegionText + "\r\n\r\n" + regionAreaManager.Text.Trim();

                if (info.IsDifferent)
                {
                    lvResults.Items.Add(path).Tag = info;
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: yoykiee/ShareX
        private bool CleanRegionAreas(string path, string searchRegionName, string newRegionText)
        {
            if (IsValidFile(path))
            {
                TextInfo info = new TextInfo(path);
                RegionAreaManager regionAreaManager = new RegionAreaManager(info.DefaultText);
                List<RegionArea> regionAreas = regionAreaManager.GetRegionAreas();
                int offset = 0;

                foreach (RegionArea regionArea in regionAreas)
                {
                    if (regionArea.RegionName.IndexOf(searchRegionName, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        regionArea.RegionIndexOffset = offset;
                        string regionAreaTextRemoved = regionArea.RemoveRegionText();
                        offset += -regionArea.RegionLength;
                        regionAreaManager.Text = regionAreaTextRemoved;
                    }
                }

                info.NewText = newRegionText + "\r\n\r\n" + regionAreaManager.Text.Trim();

                if (info.IsDifferent)
                {
                    lvResults.Items.Add(path).Tag = info;
                    return true;
                }
            }

            return false;
        }