michael@0: #include "nsIFile.h" michael@0: #include "nsStringGlue.h" michael@0: michael@0: #include michael@0: #include "nsIComponentRegistrar.h" michael@0: #include "nsIComponentManager.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsMemory.h" michael@0: #include "nsISimpleEnumerator.h" michael@0: #include "nsCOMPtr.h" michael@0: michael@0: bool LoopInDir(nsIFile* file) michael@0: { michael@0: nsresult rv; michael@0: nsCOMPtr entries; michael@0: rv = file->GetDirectoryEntries(getter_AddRefs(entries)); michael@0: if(NS_FAILED(rv) || !entries) michael@0: return false; michael@0: michael@0: bool hasMore; michael@0: while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) michael@0: { michael@0: nsCOMPtr sup; michael@0: entries->GetNext(getter_AddRefs(sup)); michael@0: if(!sup) michael@0: return false; michael@0: michael@0: nsCOMPtr file = do_QueryInterface(sup); michael@0: if(!file) michael@0: return false; michael@0: michael@0: nsAutoCString name; michael@0: if(NS_FAILED(file->GetNativeLeafName(name))) michael@0: return false; michael@0: michael@0: bool isDir; michael@0: printf("%s\n", name.get()); michael@0: rv = file->IsDirectory(&isDir); michael@0: if (NS_FAILED(rv)) michael@0: { michael@0: printf("IsDirectory Failed!!!\n"); michael@0: return false; michael@0: } michael@0: michael@0: if (isDir) michael@0: { michael@0: LoopInDir(file); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: michael@0: int michael@0: main(int argc, char* argv[]) michael@0: { michael@0: nsresult rv; michael@0: { michael@0: nsCOMPtr topDir; michael@0: michael@0: nsCOMPtr servMan; michael@0: rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); michael@0: if (NS_FAILED(rv)) return -1; michael@0: michael@0: if (argc > 1 && argv[1] != nullptr) michael@0: { michael@0: char* pathStr = argv[1]; michael@0: NS_NewNativeLocalFile(nsDependentCString(pathStr), false, getter_AddRefs(topDir)); michael@0: } michael@0: michael@0: if (!topDir) michael@0: { michael@0: printf("No Top Dir\n"); michael@0: return -1; michael@0: } michael@0: int32_t startTime = PR_IntervalNow(); michael@0: michael@0: LoopInDir(topDir); michael@0: michael@0: int32_t endTime = PR_IntervalNow(); michael@0: michael@0: printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime)); michael@0: } // this scopes the nsCOMPtrs michael@0: // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM michael@0: rv = NS_ShutdownXPCOM(nullptr); michael@0: NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); michael@0: return 0; michael@0: }