2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2005-11-08 21:17:49 +03:00
|
|
|
#include "nsStringGlue.h"
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2001-11-24 01:36:54 +03:00
|
|
|
#include <stdio.h>
|
2002-01-30 00:22:13 +03:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2000-07-11 04:10:34 +04:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsMemory.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-11-08 21:17:49 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2015-09-08 09:56:16 +03:00
|
|
|
static bool LoopInDir(nsIFile* aFile)
|
2000-07-11 04:10:34 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
2015-09-08 09:56:16 +03:00
|
|
|
rv = aFile->GetDirectoryEntries(getter_AddRefs(entries));
|
2000-07-11 04:10:34 +04:00
|
|
|
if(NS_FAILED(rv) || !entries)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasMore;
|
2000-07-11 04:10:34 +04:00
|
|
|
while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> sup;
|
|
|
|
entries->GetNext(getter_AddRefs(sup));
|
|
|
|
if(!sup)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2015-09-08 09:56:16 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> nextFile = do_QueryInterface(sup);
|
|
|
|
if (!nextFile)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString name;
|
2015-09-08 09:56:16 +03:00
|
|
|
if(NS_FAILED(nextFile->GetNativeLeafName(name)))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDir;
|
2002-04-27 09:33:09 +04:00
|
|
|
printf("%s\n", name.get());
|
2015-09-08 09:56:16 +03:00
|
|
|
rv = nextFile->IsDirectory(&isDir);
|
2000-11-16 01:39:43 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
printf("IsDirectory Failed!!!\n");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2000-11-16 01:39:43 +03:00
|
|
|
}
|
|
|
|
|
2010-02-07 18:52:43 +03:00
|
|
|
if (isDir)
|
2000-07-11 04:10:34 +04:00
|
|
|
{
|
2015-09-08 09:56:16 +03:00
|
|
|
LoopInDir(nextFile);
|
|
|
|
}
|
2000-07-11 04:10:34 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2000-07-11 04:10:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-07-04 18:29:25 +04:00
|
|
|
{
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> topDir;
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr);
|
2002-07-04 18:29:25 +04:00
|
|
|
if (NS_FAILED(rv)) return -1;
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (argc > 1 && argv[1] != nullptr)
|
2002-07-04 18:29:25 +04:00
|
|
|
{
|
|
|
|
char* pathStr = argv[1];
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(pathStr), false, getter_AddRefs(topDir));
|
2002-07-04 18:29:25 +04:00
|
|
|
}
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
if (!topDir)
|
|
|
|
{
|
|
|
|
printf("No Top Dir\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startTime = PR_IntervalNow();
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
LoopInDir(topDir);
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t endTime = PR_IntervalNow();
|
2000-07-11 04:10:34 +04:00
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
printf("\nTime: %d\n", PR_IntervalToMilliseconds(endTime - startTime));
|
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = NS_ShutdownXPCOM(nullptr);
|
2002-07-04 18:29:25 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
2000-07-11 04:10:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|