~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpcom/tests/nsIFileEnumerator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

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