diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:49:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:49:04 +0000 |
commit | 16f504a9dca3fe3b70568f67b7d41241ae485288 (patch) | |
tree | c60f36ada0496ba928b7161059ba5ab1ab224f9d /src/libs/xpcom18a4/xpcom/tests/nsIFileEnumerator.cpp | |
parent | Initial commit. (diff) | |
download | virtualbox-16f504a9dca3fe3b70568f67b7d41241ae485288.tar.xz virtualbox-16f504a9dca3fe3b70568f67b7d41241ae485288.zip |
Adding upstream version 7.0.6-dfsg.upstream/7.0.6-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libs/xpcom18a4/xpcom/tests/nsIFileEnumerator.cpp')
-rw-r--r-- | src/libs/xpcom18a4/xpcom/tests/nsIFileEnumerator.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/libs/xpcom18a4/xpcom/tests/nsIFileEnumerator.cpp b/src/libs/xpcom18a4/xpcom/tests/nsIFileEnumerator.cpp new file mode 100644 index 00000000..a5f3551d --- /dev/null +++ b/src/libs/xpcom18a4/xpcom/tests/nsIFileEnumerator.cpp @@ -0,0 +1,95 @@ +#include "nsILocalFile.h" +#include "nsDependentString.h" +#include "nsString.h" + +#include <stdio.h> +#include "nsIComponentRegistrar.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsMemory.h" +#include "nsXPIDLString.h" +#include "nsISimpleEnumerator.h" + + +PRBool LoopInDir(nsILocalFile* file) +{ + nsresult rv; + nsCOMPtr<nsISimpleEnumerator> entries; + rv = file->GetDirectoryEntries(getter_AddRefs(entries)); + if(NS_FAILED(rv) || !entries) + return PR_FALSE; + + PRBool hasMore; + while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) + { + nsCOMPtr<nsISupports> sup; + entries->GetNext(getter_AddRefs(sup)); + if(!sup) + return PR_FALSE; + + nsCOMPtr<nsILocalFile> file = do_QueryInterface(sup); + if(!file) + return PR_FALSE; + + nsCAutoString name; + if(NS_FAILED(file->GetNativeLeafName(name))) + return PR_FALSE; + + PRBool isDir; + printf("%s\n", name.get()); + rv = file->IsDirectory(&isDir); + if (NS_FAILED(rv)) + { + printf("IsDirectory Failed!!!\n"); + return PR_FALSE; + } + + if (isDir == PR_TRUE) + { + nsCOMPtr<nsILocalFile> lfile = do_QueryInterface(file); + LoopInDir(lfile); + } + } + return PR_TRUE; +} + + +int +main(int argc, char* argv[]) +{ + nsresult rv; + { + nsCOMPtr<nsILocalFile> topDir; + + nsCOMPtr<nsIServiceManager> servMan; + rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); + if (NS_FAILED(rv)) return -1; + nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); + NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); + if (registrar) + registrar->AutoRegister(nsnull); + + if (argc > 1 && argv[1] != nsnull) + { + char* pathStr = argv[1]; + NS_NewNativeLocalFile(nsDependentCString(pathStr), PR_FALSE, getter_AddRefs(topDir)); + } + + if (!topDir) + { + printf("No Top Dir\n"); + return -1; + } + PRInt32 startTime = PR_IntervalNow(); + + LoopInDir(topDir); + + PRInt32 endTime = PR_IntervalNow(); + + printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime)); + } // this scopes the nsCOMPtrs + // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + return 0; +} |