コード例 #1
0
        public static void OpenWithNPP(HitFile hitFile)
        {
            if (hitFile == null)
            {
                return;
            }
            if (!File.Exists(hitFile?.FilePathAndName))
            {
                return;
            }

            try
            {
                var settings    = AppSettings.GetSettings();
                var notePadPath = settings.NotePadPP_Path;
                var notePadExe  = settings.NotePadPP_Exe;

                var startInfo = new ProcessStartInfo(hitFile.FilePathAndName)
                {
                    UseShellExecute = false
                };
                startInfo.FileName  = $"{notePadPath}\\{notePadExe}";
                startInfo.Arguments = $"-n{hitFile?.SearchPosition.Line} -c{hitFile?.SearchPosition.Column} {hitFile?.FilePathAndName}";
                using (var p = new Process())
                {
                    p.StartInfo = startInfo;
                    p.Start();
                }
            }
            catch (Exception)
            {
                OpenWithDefault(hitFile);  // fallback to default application for file.
            }
        }
コード例 #2
0
        public static void OpenWithDefault(HitFile hitFile)
        {
            if (!File.Exists(hitFile?.FilePathAndName))
            {
                return;
            }

            var startInfo = new ProcessStartInfo(hitFile.FilePathAndName)
            {
                UseShellExecute = true
            };

            using (var p = new Process())
            {
                p.StartInfo = startInfo;
                p.Start();
            }
        }
コード例 #3
0
        public async Task SearchInList(List <string> list, CancellationToken cancel)
        {
            foreach (var file in list)
            {
                try
                {
                    // check if cancellation is requested
                    if (cancel.IsCancellationRequested)
                    {
                        throw new TaskCanceledException();
                    }

                    using (var reader = File.OpenText(file))
                    {
                        var fileContent = await reader.ReadToEndAsync();

                        if (fileContent.Contains(searchProfile.SearchString))
                        {
                            // locate the line and col of first occurence
                            var hit = new HitFile(file);
                            hit.SearchPosition = await FindLine(fileContent);

                            HitList.Add(hit);
                        }
                    }
                }
                catch (TaskCanceledException e)
                {
                    MessageBox.Show("User Cancelled Search!");
                    return;
                }
                catch (Exception e)
                {
                    continue;
                }
            }
        }