import java.io.File;
import com.denova.io.Log;
import com.denova.runtime.UnixCommands;
import com.denova.util.PropertyList;
import com.denova.JExpress.Installer.StatusPanel;


/**
    Change the file permissions on Unix.

    Important Note: Include this panel "after menus".

    Copyright (C) 1998-2011 DeNova.com
    
*/
public class ChangePermissions extends StatusPanel
{
    private static final String Permissions = "0755";
    private static final Log log = new Log("permissions.log");
    
    public ChangePermissions(PropertyList properties)
    {
        super (properties);
    }
    
    /** 
     * Enter the panel. 
     */
     public synchronized void enter()
     {
        File appDir = new File(getPropertyList().getProperty(ApplicationDirectory, ""));
        changePermissions(appDir);
        
        showNextPanel ();
    }

    private void changePermissions(File dir)
    {
        String[] fileList = dir.list();
        for (int i = 0; i < fileList.length; ++i)
        {
            File f = new File(dir, fileList[i]);
            if (f.isDirectory())
            {
                changePermissions(f);
            }
            UnixCommands.chmod(Permissions, f.getPath());
            log.write(f.getPath());
        }
        UnixCommands.chmod(Permissions, dir.getPath());
        log.write(dir.getPath());
    }
    
}  // ChangePermissions