wasSharpNET – Diff between revs 21 and 22

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 21 Rev 22
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 //
3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // 3 // Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
4 // rights of fair usage, the disclaimer and warranty conditions. // 4 // rights of fair usage, the disclaimer and warranty conditions. //
5 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
6   -  
7 using System; 6  
8 using System.IO; 7 using System.IO;
9   8  
10 namespace wasSharpNET.IO.Utilities 9 namespace wasSharpNET.IO.Utilities
11 { 10 {
12 public static class IOExtensions 11 public static class IOExtensions
13 { 12 {
14 public static bool isRootedIn(this string path, string root) 13 public static bool isRootedIn(this string path, string root)
15 { 14 {
16 // Path is empty and root is empty. 15 // Path is empty and root is empty.
17 if (string.IsNullOrEmpty(path) && string.IsNullOrEmpty(root)) 16 if (string.IsNullOrEmpty(path) && string.IsNullOrEmpty(root))
18 return true; 17 return true;
19   18  
20 // Path is empty but the root path is not empty. 19 // Path is empty but the root path is not empty.
21 if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(root)) 20 if (string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(root))
22 return true; 21 return true;
23   22  
24 // The supplied root path is empty. 23 // The supplied root path is empty.
25 if (string.IsNullOrEmpty(root)) 24 if (string.IsNullOrEmpty(root))
26 return false; 25 return false;
27   26  
28 // The path is empty and the root is not. 27 // The path is empty and the root is not.
29 if (string.IsNullOrEmpty(path)) 28 if (string.IsNullOrEmpty(path))
30 return true; 29 return true;
31   30  
32 DirectoryInfo p = new DirectoryInfo(path); 31 DirectoryInfo p = new DirectoryInfo(path);
33 DirectoryInfo r = new DirectoryInfo(root); 32 DirectoryInfo r = new DirectoryInfo(root);
34   33  
35 return string.Equals(p.Parent?.FullName, r.Parent?.FullName) || isRootedIn(p.Parent?.FullName, root); 34 return string.Equals(p.Parent?.FullName, r.Parent?.FullName) || isRootedIn(p.Parent?.FullName, root);
36 } 35 }
37   36  
38 public static void Empty(this string directory) 37 public static void Empty(this string directory)
39 { 38 {
40 DirectoryInfo dir = new DirectoryInfo(directory); 39 DirectoryInfo dir = new DirectoryInfo(directory);
41   40  
42 foreach (FileInfo fi in dir.GetFiles()) 41 foreach (FileInfo fi in dir.GetFiles())
43 { 42 {
44 fi.Delete(); 43 fi.Delete();
45 } 44 }
46   45  
47 foreach (DirectoryInfo di in dir.GetDirectories()) 46 foreach (DirectoryInfo di in dir.GetDirectories())
48 { 47 {
49 Empty(di.FullName); 48 Empty(di.FullName);
50 di.Delete(); 49 di.Delete();
51 } 50 }
52 } 51 }
53 } 52 }
54 } 53 }
55   54