import java.io.*;
public class Decode
{
    static String is_jadpath;
public static void main(String[] args) 
{
    try{
         if (args.length>1)
         {
             is_jadpath=args[0];
             File f=new File(args[1]);
             if (f.isDirectory())
             {
                    File newdic=new File(args[1]+"_src");
                    newdic.mkdir();
                    recursionFileList(newdic.getPath(),f);
             }
             else
             {
                    Runtime r=Runtime.getRuntime();
                    String dimpath=args[1].substring(0,args[1].lastIndexOf('\\'));
                    String cmd=is_jadpath+" -d "+dimpath+" -s java "+args[1];
                    r.exec(cmd);
             }
         }
         else
         {
             System.out.println("please input argument");
             System.out.println("example d:\\jadhome\\jad c:\\yourdic\\yourclass.class");
         }
     }catch(Exception e)
     {System.out.println("wrong:"+e);}
    
    }
    private static boolean recursionFileList(String dimparentpath,File f)
    throws Exception
    {
        boolean hasClassFile=false;
        File flist[]=f.listFiles();
    for(int i=0;i<flist.length;i++)
    {
            if (flist[i].isDirectory()) 
            {
                String srcpath=flist[i].getPath();
                String dimpath=dimparentpath+srcpath.substring(srcpath.lastIndexOf('\\'));
                File newdic=new File(dimpath);
                newdic.mkdir();
                if (!recursionFileList(dimpath,flist[i])) 
                    newdic.delete();
                else
                {
                    Runtime r=Runtime.getRuntime();
                    String cmd=is_jadpath+" -d "+dimpath+" -s java "+srcpath+"\\*.class";
                    r.exec(cmd);
                }
            }
            else if (flist[i].getPath().endsWith(".class"))
            {
                hasClassFile=true;
                Runtime r=Runtime.getRuntime();
                String cmd=is_jadpath+" -d "+dimparentpath+" -s java "+flist[i].getPath();
                r.exec(cmd);
            }
        }
        return hasClassFile;
    }
}