forked from gdevic/GitForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormNewRepoScanProgress.cs
93 lines (86 loc) · 2.7 KB
/
FormNewRepoScanProgress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GitForce
{
/// <summary>
/// Scan for the list of directories that potentially host Git repositories
/// </summary>
public partial class FormNewRepoScanProgress : Form
{
/// <summary>
/// List of potential candidates to contain a git repository
/// </summary>
public readonly List<string> Gits = new List<string>();
private readonly string _dir;
private readonly bool _deepScan;
private bool _enableScan;
public FormNewRepoScanProgress(string dir, bool fDeepScan)
{
InitializeComponent();
_dir = dir;
_deepScan = fDeepScan;
}
/// <summary>
/// Recursively search folders starting at the given directory and
/// add all paths that end with .git to the list of potential candidates
/// </summary>
private void SearchGit(string dir)
{
// Silently ignore unreachable directories
try
{
foreach (var d in Directory.GetDirectories(dir))
{
textDir.Text = d;
Application.DoEvents();
if(_enableScan==false)
return;
if (d.EndsWith(Path.DirectorySeparatorChar + ".git"))
{
Gits.Add(d.Substring(0, d.Length - 5));
if (_deepScan == false)
break;
}
else
SearchGit(d);
}
}
catch (Exception) {}
}
/// <summary>
/// Start scanning at the time the form is first shown
/// </summary>
private void FormNewRepoScanProgressShown(object sender, EventArgs e)
{
Gits.Clear();
_enableScan = true;
try
{
SearchGit(_dir);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
_enableScan = false;
}
DialogResult = DialogResult.OK;
Close();
}
/// <summary>
/// Stop scanning and exit the dialog
/// </summary>
private void BtStopClick(object sender, EventArgs e)
{
_enableScan = false;
Application.DoEvents();
DialogResult = DialogResult.OK;
}
}
}