|
1 #include "nsIFile.h" |
|
2 #include "nsStringGlue.h" |
|
3 |
|
4 #include <stdio.h> |
|
5 #include "nsIComponentRegistrar.h" |
|
6 #include "nsIComponentManager.h" |
|
7 #include "nsIServiceManager.h" |
|
8 #include "nsMemory.h" |
|
9 #include "nsISimpleEnumerator.h" |
|
10 #include "nsCOMPtr.h" |
|
11 |
|
12 bool LoopInDir(nsIFile* file) |
|
13 { |
|
14 nsresult rv; |
|
15 nsCOMPtr<nsISimpleEnumerator> entries; |
|
16 rv = file->GetDirectoryEntries(getter_AddRefs(entries)); |
|
17 if(NS_FAILED(rv) || !entries) |
|
18 return false; |
|
19 |
|
20 bool hasMore; |
|
21 while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) |
|
22 { |
|
23 nsCOMPtr<nsISupports> sup; |
|
24 entries->GetNext(getter_AddRefs(sup)); |
|
25 if(!sup) |
|
26 return false; |
|
27 |
|
28 nsCOMPtr<nsIFile> file = do_QueryInterface(sup); |
|
29 if(!file) |
|
30 return false; |
|
31 |
|
32 nsAutoCString name; |
|
33 if(NS_FAILED(file->GetNativeLeafName(name))) |
|
34 return false; |
|
35 |
|
36 bool isDir; |
|
37 printf("%s\n", name.get()); |
|
38 rv = file->IsDirectory(&isDir); |
|
39 if (NS_FAILED(rv)) |
|
40 { |
|
41 printf("IsDirectory Failed!!!\n"); |
|
42 return false; |
|
43 } |
|
44 |
|
45 if (isDir) |
|
46 { |
|
47 LoopInDir(file); |
|
48 } |
|
49 } |
|
50 return true; |
|
51 } |
|
52 |
|
53 |
|
54 int |
|
55 main(int argc, char* argv[]) |
|
56 { |
|
57 nsresult rv; |
|
58 { |
|
59 nsCOMPtr<nsIFile> topDir; |
|
60 |
|
61 nsCOMPtr<nsIServiceManager> servMan; |
|
62 rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); |
|
63 if (NS_FAILED(rv)) return -1; |
|
64 |
|
65 if (argc > 1 && argv[1] != nullptr) |
|
66 { |
|
67 char* pathStr = argv[1]; |
|
68 NS_NewNativeLocalFile(nsDependentCString(pathStr), false, getter_AddRefs(topDir)); |
|
69 } |
|
70 |
|
71 if (!topDir) |
|
72 { |
|
73 printf("No Top Dir\n"); |
|
74 return -1; |
|
75 } |
|
76 int32_t startTime = PR_IntervalNow(); |
|
77 |
|
78 LoopInDir(topDir); |
|
79 |
|
80 int32_t endTime = PR_IntervalNow(); |
|
81 |
|
82 printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime)); |
|
83 } // this scopes the nsCOMPtrs |
|
84 // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM |
|
85 rv = NS_ShutdownXPCOM(nullptr); |
|
86 NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); |
|
87 return 0; |
|
88 } |