2000-07-11 00:10:34 +00:00
|
|
|
#include "nsILocalFile.h"
|
2005-11-08 18:17:49 +00:00
|
|
|
#include "nsStringGlue.h"
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2001-11-23 22:36:54 +00:00
|
|
|
#include <stdio.h>
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIComponentRegistrar.h"
|
2000-07-11 00:10:34 +00:00
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsMemory.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-11-08 18:17:49 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool LoopInDir(nsILocalFile* file)
|
2000-07-11 00:10:34 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
rv = file->GetDirectoryEntries(getter_AddRefs(entries));
|
|
|
|
if(NS_FAILED(rv) || !entries)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasMore;
|
2000-07-11 00:10:34 +00:00
|
|
|
while(NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> sup;
|
|
|
|
entries->GetNext(getter_AddRefs(sup));
|
|
|
|
if(!sup)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCOMPtr<nsILocalFile> file = do_QueryInterface(sup);
|
2000-07-11 00:10:34 +00:00
|
|
|
if(!file)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-04-27 05:33:09 +00:00
|
|
|
nsCAutoString name;
|
|
|
|
if(NS_FAILED(file->GetNativeLeafName(name)))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isDir;
|
2002-04-27 05:33:09 +00:00
|
|
|
printf("%s\n", name.get());
|
2000-07-11 00:10:34 +00:00
|
|
|
rv = file->IsDirectory(&isDir);
|
2000-11-15 22:39:43 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
printf("IsDirectory Failed!!!\n");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2000-11-15 22:39:43 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 15:52:43 +00:00
|
|
|
if (isDir)
|
2000-07-11 00:10:34 +00:00
|
|
|
{
|
2000-09-14 22:56:56 +00:00
|
|
|
nsCOMPtr<nsILocalFile> lfile = do_QueryInterface(file);
|
|
|
|
LoopInDir(lfile);
|
2000-07-11 00:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2000-07-11 00:10:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-07-04 14:29:25 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> topDir;
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
nsCOMPtr<nsIServiceManager> servMan;
|
|
|
|
rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return -1;
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
if (argc > 1 && argv[1] != nsnull)
|
|
|
|
{
|
|
|
|
char* pathStr = argv[1];
|
2011-10-17 14:59:28 +00:00
|
|
|
NS_NewNativeLocalFile(nsDependentCString(pathStr), false, getter_AddRefs(topDir));
|
2002-07-04 14:29:25 +00:00
|
|
|
}
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
if (!topDir)
|
|
|
|
{
|
|
|
|
printf("No Top Dir\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
PRInt32 startTime = PR_IntervalNow();
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
LoopInDir(topDir);
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
PRInt32 endTime = PR_IntervalNow();
|
2000-07-11 00:10:34 +00:00
|
|
|
|
2002-07-04 14:29:25 +00: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
|
|
|
|
rv = NS_ShutdownXPCOM(nsnull);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
|
2000-07-11 00:10:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|