<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication 
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#eeeeee"
 viewSourceURL="srcview/index.html">
    
    <mx:ViewStack id="vs" width="100%" height="100%">
        <mx:VBox width="100%" height="100%" id="directoryView" >
            <mx:Text width="100%" fontWeight="bold">
                <mx:htmlText>
                    <![CDATA[<p>This is a simple AIR tool to clean the Subversion meta data files from a project folder.</p>]]>
                </mx:htmlText>
            </mx:Text>
            <mx:Label text="Select project directory you want to clean..." width="100%" />
            <mx:FileSystemTree id="fileSystemTree" width="100%" height="100%" showHidden="true" />
            <mx:Button label="Run SubSweep..." id="runButton" click="runButtonClickHandler(event)" enabled="{fileSystemTree.selectedItem}" width="100%" />
        </mx:VBox>
        <mx:VBox width="100%" height="100%" id="workingView">
            <mx:Label text="Working... please wait..." />
            <mx:TextArea width="100%" height="100%" id="statusOfWork" htmlText="{statusOfWorkText}" />
            <mx:Button label="Go back" id="goBack" click="goBackHandler(event)" width="100%" />
        </mx:VBox>    
    </mx:ViewStack>
    
    <mx:Script>
        <![CDATA[
            [Bindable] private var dirSelected:Boolean = false;
            [Bindable] private var statusOfWorkText:String = "";
            
            /**
             * START sweeping the subversion meta data files
             */
            protected function runSubSweep():void
            {
                vs.selectedIndex = 1;
                statusOfWorkText = "";
                var dirToClean:File = File.documentsDirectory.resolvePath(this.fileSystemTree.selectedPath);
                
                this.enabled = false;
                cleanDirectory(dirToClean);
                this.enabled = true;
                
                statusOfWorkText += "*** ALL DONE ! ***";
            }
            
            //--------------------------------------------------------------------------------
            
            /**
             * Function that calls itself in order to go in depth of the directory structure
             */
            protected function cleanDirectory(dir:File):void
            {
                var contents:Array = dir.getDirectoryListing();
                for (var i:uint = 0; i < contents.length; i++)
                {
                    var myFile:File = contents[i] as File;
                    
                    if(myFile.isDirectory)
                    {
                        if(myFile.name == ".svn")
                        {
                            statusOfWorkText += "Cleaning folder "+dir.name+"<br />";
                            myFile.deleteDirectoryAsync(true);
                        }
                        else
                        {             
                            cleanDirectory(myFile); // move one level deeper
                        }
                    }
                }
            }

            //--------------------------------------------------------------------------------
            
            /**
             * Run button click handler
             */
            private function runButtonClickHandler(e:Event):void
            {
                runSubSweep();
            }
            
            //--------------------------------------------------------------------------------
            
            /**
             * Switch the view back to the beginning...
             */
            private function goBackHandler(e:Event):void
            {
                vs.selectedIndex = 0;
            }
        ]]>
    </mx:Script>
</mx:WindowedApplication>