@@ -12,7 +12,7 @@ public string RootDir
12
12
{
13
13
get ;
14
14
private set ;
15
- } = string . Empty ;
15
+ }
16
16
17
17
public ScanRepositories ( string rootDir )
18
18
{
@@ -28,7 +28,7 @@ public override Task<bool> Sure()
28
28
29
29
return Task . Run ( ( ) =>
30
30
{
31
- // If it is too fast, the panel will dispear very quickly, the we'll have a bad experience.
31
+ // If it is too fast, the panel will disappear very quickly, then we'll have a bad experience.
32
32
Task . Delay ( 500 ) . Wait ( ) ;
33
33
34
34
var rootDir = new DirectoryInfo ( RootDir ) ;
@@ -42,14 +42,24 @@ public override Task<bool> Sure()
42
42
Dispatcher . UIThread . Invoke ( ( ) =>
43
43
{
44
44
var normalizedRoot = rootDir . FullName . Replace ( "\\ " , "/" ) ;
45
- var prefixLen = normalizedRoot . EndsWith ( '/' ) ? normalizedRoot . Length : normalizedRoot . Length + 1 ;
46
-
45
+
47
46
foreach ( var f in founded )
48
47
{
49
- var fullpath = new DirectoryInfo ( f ) ;
50
- var relative = fullpath . Parent ! . FullName . Replace ( "\\ " , "/" ) . Substring ( prefixLen ) ;
51
- var group = FindOrCreateGroupRecursive ( Preference . Instance . RepositoryNodes , relative ) ;
52
- Preference . Instance . FindOrAddNodeByRepositoryPath ( f , group , false ) ;
48
+ var parent = new DirectoryInfo ( f ) . Parent ! . FullName . Replace ( "\\ " , "/" ) ;
49
+ if ( parent . Equals ( normalizedRoot , StringComparison . Ordinal ) )
50
+ {
51
+ Preference . Instance . FindOrAddNodeByRepositoryPath ( f , null , false ) ;
52
+ }
53
+ else if ( parent . StartsWith ( normalizedRoot , StringComparison . Ordinal ) )
54
+ {
55
+ var relative = parent . Substring ( normalizedRoot . Length ) . TrimStart ( '/' ) ;
56
+ var group = FindOrCreateGroupRecursive ( Preference . Instance . RepositoryNodes , relative ) ;
57
+ Preference . Instance . FindOrAddNodeByRepositoryPath ( f , group , false ) ;
58
+ }
59
+ else
60
+ {
61
+ // Should not happen.
62
+ }
53
63
}
54
64
55
65
Welcome . Instance . Refresh ( ) ;
@@ -61,7 +71,7 @@ public override Task<bool> Sure()
61
71
62
72
private void GetManagedRepositories ( List < RepositoryNode > group , HashSet < string > repos )
63
73
{
64
- foreach ( RepositoryNode node in group )
74
+ foreach ( var node in group )
65
75
{
66
76
if ( node . IsRepository )
67
77
repos . Add ( node . Id ) ;
0 commit comments