upgrader2

public class XXUpdate
{
    /**
     * 命令行入口
     * 输入参数:新版本XX路径、旧版本XX路径、更新文件路径
     * 
     * @param args
     */
    public static void main(String args[])
    {
        String newXXPath = args[0];
        String oldXXPath = args[1];
        String updatePath = args[2];
        
        File newXX = new File(newXXPath);
        if (!newXX.exists())
        {
            System.out.println("输入的文件路径有误!");
            return;
        }
        
        if (!copyNewFiles(newXX, newXXPath, oldXXPath, updatePath))
        {
            System.out.println("拷贝失败!");
        }
    }
    
    /**
     * 拷贝所有更新的文件
     * 
     * @param newXX
     * @param newXXPath
     * @param oldXXPath
     * @param updatePath
     * @return
     */
    private static boolean copyNewFiles(File newXX, String newXXPath,
            String oldXXPath, String updatePath)
    {
        boolean isSucceed = true;
        if (newXX.isDirectory())
        {
            File[] subFiles = newXX.listFiles();
            int len = subFiles.length;
            File newXXFile;
            File oldXXFile;
            for (int i = 0; (i < len) && isSucceed; i++)
            {
                newXXFile = subFiles[i];
                String relativePathStr = FileUtils.getRelativePath(newXXPath,
                        newXXFile.getAbsolutePath());
                oldXXFile = new File(oldXXPath + "/" + relativePathStr);
                
                if (newXXFile.isDirectory())
                {
                    isSucceed = copyNewFiles(newXXFile,
                            newXXPath,
                            oldXXPath,
                            updatePath);
                }
                else
                {
                    if (!oldXXFile.exists()
                            || !MD5Utils.getMD5(newXXFile)
                                    .equals(MD5Utils.getMD5(oldXXFile)))
                    {
                        isSucceed = FileUtils.copyFile(newXXFile.getAbsolutePath(),
                                updatePath + "/" + relativePathStr);
                    }
                    
                }
            }
        }
        
        return isSucceed;
    }
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值