commit 7ec40106f17dfd79e1a9ca81ce2ce76a041f62b9 Author: Eg <1711788888@qq.com> Date: Sun Aug 29 18:02:09 2021 +0800 Debug diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6909e56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..fa99c1b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,97 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..7f10861 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..132404b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/smartfox_info.xml b/.idea/smartfox_info.xml new file mode 100644 index 0000000..1c2584f --- /dev/null +++ b/.idea/smartfox_info.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/back_config.setting b/back_config.setting new file mode 100644 index 0000000..76a9bd3 --- /dev/null +++ b/back_config.setting @@ -0,0 +1,5 @@ +[] +tokenText = 77190dd0a59a45b0883650647b85522d +pathText = C:\Users\Administrator\Desktop\HKBTest +folderText = backtest +backType = 0 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..8c564d9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,88 @@ + + + 4.0.0 + + com.eg + aliyunpan-autobackup + 1.0-SNAPSHOT + + + UTF-8 + 1.8 + 1.8 + + + + + junit + junit + 4.11 + test + + + + + com.squareup.okhttp3 + okhttp + 4.9.1 + + + + + cn.hutool + hutool-all + 5.6.5 + + + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b5e1fa2 --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.eg.www.App + diff --git a/src/main/java/com/eg/www/AliYunPan.java b/src/main/java/com/eg/www/AliYunPan.java new file mode 100644 index 0000000..f7a9096 --- /dev/null +++ b/src/main/java/com/eg/www/AliYunPan.java @@ -0,0 +1,326 @@ +package com.eg.www; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.setting.Setting; +import com.eg.www.common.CommonConstants; +import com.eg.www.common.utils.AliYunPanUtil; +import com.eg.www.common.utils.FileUtil; + +import javax.swing.*; +import javax.swing.plaf.FontUIResource; +import java.awt.*; +import java.awt.event.*; +import java.util.Enumeration; + +/** + * Description: GUI + * Author: Eg + * Date: 2021/08/29 + */ +public class AliYunPan extends JFrame implements ActionListener { + + private static final int obj_left = 100;//左边距 + private static final int text_width = 400;//文本框框 + private static final int text_high = 30;//文本框高 + private static final int title_left = 10;//标题左边距 + private static final int title_width = 166;//标题宽 + private static final int title_high = 25;//标题高 + private static final int radio_top = 150;//标题高 + private static final int radio_width = 100;//标题高 + private static final int radio_high = 25;//标题高 + + //阿里云工具类 + private AliYunPanUtil aliYunPanUtil=new AliYunPanUtil(); + // 日志界面 + JScrollPane consolePane = CommonConstants.consolePane; + JScrollBar scrollBar = CommonConstants.scrollBar; + //Token文本框 + JTextField tokenText = CommonConstants.tokenText; + // 备份目录 + private JTextField pathText; + // 目录名称 + private JTextField folderText; + //选择文件夹按钮 + private JButton selectBtn; + //选择文件夹 + private JFileChooser selectPathChooser = new JFileChooser(); + + // 迭代一单选框 + private JRadioButton puTongRadio; + // 迭代二单选框 + private JRadioButton fenLeiRadio; + + // 开始备份 + private JButton startBackup = CommonConstants.startBackup; + // 暂停备份 + private JButton pauseBackup; + + //判断系统是否有托盘 + static SystemTray tray = SystemTray.getSystemTray(); + //托盘图标 + private static TrayIcon trayIcon = null; + //配置文件 + Setting setting =CommonConstants.setting; + + public AliYunPan(){ + //GUI默认配置 + initConfig(); + //初始化UI + initUi(); + this.setVisible(true); + //初始化变量 + CommonConstants.PATH = setting.getStr("pathText"); + CommonConstants.REFRESH_TOKEN = setting.getStr("tokenText"); + CommonConstants.BACK_NAME = setting.getStr("folderText"); + if (StrUtil.isNotEmpty(setting.getStr("backType"))){ + CommonConstants.BACK_TYPE = Integer.parseInt(setting.getStr("backType")); + } + //开启目录检测 + aliYunPanUtil.monitorFolder(); + } + + /** + * 程序默认配置 + */ + private void initConfig() { + // 设置界面使用字体 + FontUIResource fontUIResource = new FontUIResource(new Font("宋体", Font.PLAIN, 13)); + for (Enumeration keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) { + Object key = keys.nextElement(); + Object value = UIManager.get(key); + if (value instanceof FontUIResource) { + UIManager.put(key, fontUIResource); + } + } + //设置显示窗口标题 + setTitle("备份助手"); + //设置标题栏的图标 + this.setIconImage(new ImageIcon(getClass().getResource("/images/logo.png")).getImage()); + //设置窗口显示尺寸 + setSize(800,600); + //窗口是否可以关闭 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + //默认居中显示 + setLocationRelativeTo(null); + //禁止改变窗口大小 + this.setResizable(false); + + // 窗口最小化事件 + this.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + + public void windowIconified(WindowEvent e) { + setVisible(false); + miniTray(); + } + + }); + } + + public void initUi() { + // 初始化控件 + Container container = getContentPane(); + container.setLayout(null); + + /** + * 左侧标题 + */ + JLabel pathTitle = new JLabel("选择目录"); + pathText = new JTextField(); + JLabel tokenTitle = new JLabel("阿里云Token"); + //tokenText = new JTextField(); + JLabel folderTitle = new JLabel("备份目录名称"); + folderText = new JTextField(); + JLabel backTitle = new JLabel("备份模式"); + backTitle.setBounds(title_left, 150, title_width, title_high); + container.add(backTitle); + // 路径选择区域 + JPanel selectPanle = new JPanel(); + selectPanle.setLayout(null); + + //选择目录框 + pathTitle.setBounds(title_left, 20, title_width, title_high); + container.add(pathTitle); + pathText.setText(setting.getStr("pathText")); + pathText.setBounds(obj_left, 20, text_width, text_high); + container.add(pathText); + + //token框 + tokenTitle.setBounds(title_left, 60, title_width, title_high); + container.add(tokenTitle); + tokenText.setText(setting.getStr("tokenText")); + tokenText.setBounds(obj_left, 60, text_width, text_high); + container.add(tokenText); + + //目录名称框 + folderTitle.setBounds(title_left, 100, title_width, title_high); + container.add(folderTitle); + folderText.setText(setting.getStr("folderText")); + folderText.setBounds(obj_left, 100, text_width, text_high); + container.add(folderText); + + //选择文件按钮 + selectBtn = new JButton("选择..."); + selectBtn.setBounds(501, 22, 90, 25); + selectBtn.addActionListener(this); + container.add(selectBtn); + + + //读取设置中选中的模式 + String type = setting.getStr("backType"); + boolean pt_checked=false; + boolean fl_checked=false; + if (ObjectUtil.isNotNull(type)){ + if (type.equals("0")){ + pt_checked=true; + }else if (type.equals("1")){ + fl_checked=true; + } + }else { + pt_checked=true; + } + //模式选择 + puTongRadio = new JRadioButton("普通备份",pt_checked); + puTongRadio.setBounds(100, radio_top, radio_width, radio_high); + puTongRadio.setBackground(container.getBackground()); + container.add(puTongRadio); + fenLeiRadio = new JRadioButton("分类备份",fl_checked); + fenLeiRadio.setBounds(250, radio_top, radio_width, radio_high); + fenLeiRadio.setBackground(container.getBackground()); + container.add(fenLeiRadio); + //设置为单选 + ButtonGroup typeGroup = new ButtonGroup(); + typeGroup.add(puTongRadio); + typeGroup.add(fenLeiRadio); + + + //startBackup = new JButton("开始备份"); + startBackup.setFont(new Font("宋体", Font.PLAIN, 13)); + startBackup.setBounds(100, 195, 100, 30); + startBackup.addActionListener(this); + container.add(startBackup); + pauseBackup = new JButton("暂停备份"); + pauseBackup.setBounds(250, 195, 100, 30); + pauseBackup.addActionListener(this); + container.add(pauseBackup); + //日志面板 + consolePane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + scrollBar.setSize(100,100); + consolePane.setBounds(0, 240, 800, 348); + container.add(consolePane); + } + + /** + * 事件处理器 + * @param e + */ + @Override + public void actionPerformed(ActionEvent e) { + //选择文件夹 + if (e.getSource() == selectBtn) { + selectPathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int intRetVal = selectPathChooser.showOpenDialog(this); + if (intRetVal == JFileChooser.APPROVE_OPTION) { + pathText.setText(selectPathChooser.getSelectedFile().getPath()); + } + }else { + if (!checkText()){//验证 + return; + } + + //开始按钮 + if (e.getSource() == startBackup) { + startBackup.setEnabled(false); + startBackup.setText("正在备份"); + CommonConstants.CLEAN_CONSOLE=0; + //获取用户输入的token + CommonConstants.REFRESH_TOKEN=tokenText.getText(); + setting.set("tokenText",CommonConstants.REFRESH_TOKEN); + //获取用户输入的目录 + CommonConstants.PATH=pathText.getText(); + setting.set("pathText",CommonConstants.PATH); + //获取用户输入的目录名称 + CommonConstants.BACK_NAME=folderText.getText(); + setting.set("folderText",CommonConstants.BACK_NAME); + //获取上传模式 + CommonConstants.BACK_TYPE = puTongRadio.isSelected() ? 0 : 1; + setting.set("backType",CommonConstants.BACK_TYPE+""); + //输出模式 + CommonConstants.addConsole("备份模式:"+(puTongRadio.isSelected() ? "普通模式" : "分类模式")); + setting.store(CommonConstants.CONFIG_PATH); + //执行上传文件操作 + try { + Thread backup = new Thread(() -> aliYunPanUtil.startBackup()); + backup.start(); + } catch (Exception exc) { + CommonConstants.addConsole("遇到异常情况:"+exc.toString()); + } + } + + //暂停按钮 + if (e.getSource() == pauseBackup) { + JOptionPane.showMessageDialog(null, "此功能正在开发中...", "提示", JOptionPane.INFORMATION_MESSAGE); + } + } + } + + /** + * 验证文本框输入 + */ + public Boolean checkText(){ + if (StrUtil.isEmpty(pathText.getText())){ + JOptionPane.showMessageDialog(null, "您没有选择需要备份的目录", "错误", JOptionPane.ERROR_MESSAGE); + return false; + } + if (StrUtil.isEmpty(tokenText.getText())){ + JOptionPane.showMessageDialog(null, "您没有输入阿里云token", "错误", JOptionPane.ERROR_MESSAGE); + return false; + } + if (StrUtil.isEmpty(folderText.getText())){ + JOptionPane.showMessageDialog(null, "您没有输入需要备份到阿里云的目录", "错误", JOptionPane.ERROR_MESSAGE); + return false; + } + if (tokenText.getText().length()!=32){ + JOptionPane.showMessageDialog(null, "您输入的token不正确", "错误", JOptionPane.ERROR_MESSAGE); + return false; + } + if (!FileUtil.isDirectory(pathText.getText())){ + JOptionPane.showMessageDialog(null, "请选择正确目录", "错误", JOptionPane.ERROR_MESSAGE); + return false; + } + return true; + } + + //窗口最小化到任务栏托盘 + private void miniTray() { + ImageIcon trayImg = new ImageIcon(JFrame.class.getClass().getResource("/images/logo.png"));//托盘图标 + trayIcon = new TrayIcon(trayImg.getImage(), "备份助手"); + trayIcon.setImageAutoSize(true); + + //鼠标点击事件处理器 + trayIcon.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + //if (e.getClickCount() ==2 ) { + // 鼠标点击一次打开软件 + if (e.getClickCount() == 1) { + // 移去托盘图标 + tray.remove(trayIcon); + setVisible(true); + //还原窗口 + setExtendedState(JFrame.NORMAL); + toFront(); + } + } + }); + + try { + tray.add(trayIcon); + } catch (Exception e) { + System.out.println("发生异常:"+e); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/eg/www/App.java b/src/main/java/com/eg/www/App.java new file mode 100644 index 0000000..865020d --- /dev/null +++ b/src/main/java/com/eg/www/App.java @@ -0,0 +1,59 @@ +package com.eg.www; + +import cn.hutool.cron.CronUtil; + +/** + * 微信备份程序 + * + */ +public class App { + public static void main( String[] args ) { + //加载UI + new AliYunPan(); + //开启定时 + CronUtil.start(); + //支持秒级别定时任务 + CronUtil.setMatchSecond(true); + + + + //获取用户输入的token + /*CommonConstants.REFRESH_TOKEN="ec06dae699d14c8e87e55372d92f4664"; + //获取用户输入的目录 + CommonConstants.PATH="F:\\用户目录\\文档\\WeChat Files\\wxid_3wc96wg6zgf022\\FileStorage\\File\\2021-05"; + //获取用户输入的目录名称 + CommonConstants.BACK_NAME="测试2"; + //获取上传模式 + CommonConstants.BACK_TYPE = 1; + AliYunPanUtil aliYunPanUtil=new AliYunPanUtil(); + try { + aliYunPanUtil.startBackup(); + } catch (Exception e) { + System.out.println("遇到异常情况:"+e.toString()); + }*/ + + /*AliYunPanUtil.getAliYunPanInfo();//登录阿里云 + String wxFileId=AliYunPanUtil.getFileId(CommonConstants.ROOT, "公司-微信备份");//备份目录ID + List folderList = FileUtil.fileFolderList(CommonConstants.PATH,FileUtil.FOLDER); + for (String folderName : folderList) { + System.out.println("folder:"+folderName); + String path = CommonConstants.PATH + FileUtil.FILE_SEPARATOR + folderName;//路径 + List fileList = FileUtil.fileFolderList(path,FileUtil.FILE);//本地文件夹下文件 + for (String filePath : fileList) { + Map map = FileUtil.getFileInfo(filePath); + String type = map.get("type").toString(); + String typeFileId=AliYunPanUtil.getFileId(wxFileId,type);//微信备份-类型 + String dateFileId=AliYunPanUtil.getFileId(typeFileId,folderName);//微信备份-类型-日期 + AliYunPanUtil.doUploadFile(dateFileId,map); + } + String folderFileId = AliYunPanUtil.getFileId(wxFileId, "文件夹");//微信备份-文件夹 + String dateFileId = AliYunPanUtil.getFileId(folderFileId, folderName);//微信备份-文件夹-日期 + AliYunPanUtil.scanFolders(path,dateFileId,false); + } + System.out.println("ok");*/ + } + + public static void Test(){ + System.out.println(111); + } +} diff --git a/src/main/java/com/eg/www/common/CommonConstants.java b/src/main/java/com/eg/www/common/CommonConstants.java new file mode 100644 index 0000000..cd79eb6 --- /dev/null +++ b/src/main/java/com/eg/www/common/CommonConstants.java @@ -0,0 +1,86 @@ +package com.eg.www.common; + + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.file.FileReader; +import cn.hutool.core.io.file.FileWriter; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.setting.Setting; +import com.eg.www.common.utils.FileUtil; + +import javax.swing.*; +import java.io.File; + +/** + * Description: 公共变量 + * Author: Eg + * Date: 2021/08/29 + */ +public class CommonConstants { + + //日志面板 + public static MyConsole console = new MyConsole(); + public static JScrollPane consolePane = new JScrollPane(console); + public static JScrollBar scrollBar = consolePane.getVerticalScrollBar(); + // Token文本框 + public static JTextField tokenText = new JTextField(); + //开始备份按钮 + public static JButton startBackup = new JButton("开始备份"); + //当前路径 + public static String SYSTEM_PATH = System.getProperty("user.dir") + File.separator; + //配置文件路径 + public static String CONFIG_PATH = SYSTEM_PATH + "back_config.setting"; + //配置文件 + public static Setting setting = new Setting(FileUtil.touch(CONFIG_PATH).getPath(), true); + //上传文件日志 + public static String UPLOAD_LOG = SYSTEM_PATH + "uploadLog.txt"; + //写入日志 + public static FileWriter writerLog = FileWriter.create(FileUtil.touch(UPLOAD_LOG), CharsetUtil.CHARSET_UTF_8); + //读日志 + public static FileReader readerLog = new FileReader(UPLOAD_LOG); + //获取token + public final static String TOKEN_URL="https://websv.aliyundrive.com/token/refresh"; + //文件列表 + public final static String FILE_LIST_URL="https://api.aliyundrive.com/v2/file/list"; + //文件上传 + public final static String CREATE_FILE_URL="https://api.aliyundrive.com/v2/file/create"; + //完成上传 + public final static String COMPLETE_FILE_URL="https://api.aliyundrive.com/v2/file/complete"; + //删除文件 + public final static String DELETE_FILE_URL="https://api.aliyundrive.com/v2/recyclebin/trash"; + public static String FILE_ID=""; + //refresh_token + public static String REFRESH_TOKEN=""; + //Token + public static String TOKEN=""; + //driveId + public static String DriveId=""; + //根目录 + public final static String ROOT="root"; + //上传目录 + public static String PATH=""; + //备份目录名称 + public static String BACK_NAME=""; + //备份目录名称 + public static int BACK_TYPE=0;//0是普通备份 1是分类备份 + //输出日志模式 0是覆盖 1追加 + public static int CLEAN_CONSOLE=0; + //备份状态 + public static boolean BACK_STATE = false; + + /** + * 添加控制台日志 + * @param text + */ + public static void addConsole(String text){ + if (CLEAN_CONSOLE==0){ + console.setText("开始运行"+"\n"); + }else { + console.append("["+DateUtil.now()+"] "+text+"\n"); + console.paintImmediately(console.getBounds()); + scrollBar.setValue(scrollBar.getMaximum()); + } + } + + +} diff --git a/src/main/java/com/eg/www/common/CronTask.java b/src/main/java/com/eg/www/common/CronTask.java new file mode 100644 index 0000000..3abf983 --- /dev/null +++ b/src/main/java/com/eg/www/common/CronTask.java @@ -0,0 +1,39 @@ +package com.eg.www.common; + +import cn.hutool.core.util.StrUtil; +import com.eg.www.common.utils.AliYunPanUtil; + +/** + * Description: 定时任务类 + * Author: Eg + * Date: 2021/08/29 + */ +public class CronTask { + + //阿里云工具类 + private AliYunPanUtil aliYunPanUtil=new AliYunPanUtil(); + + /** + * 更新阿里云盘token + */ + public void updateALiYunPanToken(){ + if (StrUtil.isNotEmpty(CommonConstants.REFRESH_TOKEN)){ + CommonConstants.addConsole("定时更新阿里云Token"); + aliYunPanUtil.getAliYunPanInfo(); + } + } + + /** + * 定时备份文件 + */ + public void backFileList(){ + try { + //执行上传文件操作 + Thread backup = new Thread(() -> aliYunPanUtil.startBackup()); + backup.start(); + } catch (Exception e) { + CommonConstants.addConsole("遇到异常情况:"+e.toString()); + } + } + +} diff --git a/src/main/java/com/eg/www/common/MyConsole.java b/src/main/java/com/eg/www/common/MyConsole.java new file mode 100644 index 0000000..c138a7b --- /dev/null +++ b/src/main/java/com/eg/www/common/MyConsole.java @@ -0,0 +1,26 @@ +package com.eg.www.common; + +import javax.swing.*; +import java.awt.*; + +/** + * Description: 模拟控制台类 + * Author: Eg + * Date: 2021/08/29 + */ +public class MyConsole extends JTextArea { + public MyConsole() { + String info="温馨提示:备份目录名称是要备份到阿里云盘那个目录下(不存在则自动创建)\n"; + info+="普通备份:会按本地目录结构上传文件\n"; + info+="分类备份:会将本地文件按文档、压缩包、软件、音乐、图片、视频等分类上传\n"; + info+="运行日志...\n"; + this.setText(info); + this.setForeground(Color.white); + this.setBackground(Color.BLACK); + //启动自动换行 + this.setLineWrap(true); + //换行不断字 + this.setWrapStyleWord(true); + this.setVisible(true); + } +} diff --git a/src/main/java/com/eg/www/common/utils/AliYunPanUtil.java b/src/main/java/com/eg/www/common/utils/AliYunPanUtil.java new file mode 100644 index 0000000..4e331b3 --- /dev/null +++ b/src/main/java/com/eg/www/common/utils/AliYunPanUtil.java @@ -0,0 +1,459 @@ +package com.eg.www.common.utils; + +import cn.hutool.core.io.file.FileReader; +import cn.hutool.core.io.file.FileWriter; +import cn.hutool.core.io.watch.WatchMonitor; +import cn.hutool.core.io.watch.Watcher; +import cn.hutool.core.lang.Console; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.setting.Setting; +import com.eg.www.common.CommonConstants; + +import javax.swing.*; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.WatchEvent; +import java.util.List; +import java.util.Map; + +/** + * Description: 操作阿里云盘工具类 + * Author: Eg + * Date: 2021/08/29 + */ +public class AliYunPanUtil{ + + //配置文件 + Setting setting =CommonConstants.setting; + //Token文本框 + JTextField tokenText = CommonConstants.tokenText; + // 开始备份 + private JButton startBackup = CommonConstants.startBackup; + //请求工具类 + OkHttpUtil okHttpUtil = new OkHttpUtil(); + FileWriter writerLog = CommonConstants.writerLog; + FileReader readerLog = CommonConstants.readerLog; + + /** + * 开始备份 + */ + public void startBackup() { + CommonConstants.CLEAN_CONSOLE=1; + CommonConstants.BACK_STATE = true; + boolean login = this.getAliYunPanInfo();//登录阿里云 + if (!login) return; + if (!checkConfig()) return; + CommonConstants.FILE_ID = this.getFileId(CommonConstants.ROOT, CommonConstants.BACK_NAME);//备份目录ID + if (CommonConstants.BACK_TYPE==0){//普通备份 + this.scanFolders(CommonConstants.PATH,CommonConstants.FILE_ID,true); + }else { + //开始获取文件 + List folderList = FileUtil.fileFolderList(CommonConstants.PATH,FileUtil.FOLDER);//获取用户目录下所有目录 + List folderFileList = FileUtil.fileFolderList(CommonConstants.PATH,FileUtil.FILE);//本地文件夹下文件 + + //上传文件夹下文件 + if (folderFileList.size()!=0){ + CommonConstants.addConsole("获取:"+CommonConstants.PATH+" 下所有文件成功"); + uploadFileList(folderFileList,CommonConstants.FILE_ID,true); + } + + //上传文件夹下所有目录 + if (folderList.size()!=0){ + for (String folderName : folderList) { + String path = CommonConstants.PATH + FileUtil.FILE_SEPARATOR + folderName;//路径 + uploadTwoLevelFolder(CommonConstants.FILE_ID,path); + } + } + + } + CommonConstants.addConsole("本次备份:"+CommonConstants.PATH+" 下所有文件成功!..."); + startBackup.setText("开始备份"); + startBackup.setEnabled(true); + CommonConstants.BACK_STATE = false; + return; + } + + /** + * 上传二级文件夹 + * @param fileId + * @param path + */ + private void uploadTwoLevelFolder(String fileId, String path) { + CommonConstants.addConsole("开始获取:"+path); + List fileList = FileUtil.fileFolderList(path,FileUtil.FILE);//本地文件夹下文件 + uploadFileList(fileList,fileId,true); + String folderFileId = this.getFileId(fileId, "文件夹");//微信备份-文件夹 + String dateFileId = this.getFileId(folderFileId, getFolderName(path));//微信备份-文件夹-folderName + this.scanFolders(path,dateFileId,false); + } + + /** + * 获取阿里云用户信息 + * @return + * @throws Exception + */ + public boolean getAliYunPanInfo(){ + CommonConstants.addConsole("开始登录阿里云盘..."); + CommonConstants.TOKEN=""; + JSONObject data = new JSONObject(); + data.set("refresh_token",CommonConstants.REFRESH_TOKEN); + JSONObject aliYunPanInfo = okHttpUtil.doPost(CommonConstants.TOKEN_URL, data); + if (ObjectUtil.isNull(aliYunPanInfo)){ + CommonConstants.addConsole("登录失败...请检查Token填写是否正确..."); + return false; + } + CommonConstants.TOKEN = aliYunPanInfo.getStr("token_type") + " " + aliYunPanInfo.getStr("access_token"); + CommonConstants.DriveId = aliYunPanInfo.getStr("default_drive_id"); + CommonConstants.REFRESH_TOKEN = aliYunPanInfo.getStr("refresh_token"); + setting.set("tokenText",aliYunPanInfo.getStr("refresh_token")); + tokenText.setText(aliYunPanInfo.getStr("refresh_token")); + setting.store(CommonConstants.CONFIG_PATH); + setting.autoLoad(true); + if (StrUtil.isNotEmpty(CommonConstants.TOKEN)){ + CommonConstants.addConsole("登录阿里云盘成功..."); + } + return true; + } + + /** + * 获取阿里云文件列表 + * @param fileId + * @return + * @throws Exception + */ + public JSONObject getFileList(String fileId){ + JSONObject data = new JSONObject(); + data.set("drive_id",CommonConstants.DriveId); + data.set("parent_file_id",fileId); + data.set("limit",100); + data.set("all",false); + data.set("image_thumbnail_process","image/resize,w_400/format,jpeg"); + data.set("image_url_process","image/resize,w_1920/format,jpeg"); + data.set("video_thumbnail_process","video/snapshot,t_0,f_jpg,ar_auto,w_300"); + data.set("fields","*"); + data.set("order_by","updated_at"); + data.set("order_direction","DESC"); + return okHttpUtil.doPost(CommonConstants.FILE_LIST_URL,data); + } + + /** + * 创建文件夹 + * @param fileId 父级目录ID 根目录为root + * @param name 新文件夹名称 + * @return + * @throws Exception + */ + public JSONObject createFolder(String fileId,String name){ + //创建文件夹 + JSONObject data = new JSONObject(); + data.set("drive_id",CommonConstants.DriveId); + data.set("parent_file_id",fileId); + data.set("name",name); + data.set("type","folder"); + data.set("check_name_mode","refuse"); + return okHttpUtil.doPost(CommonConstants.CREATE_FILE_URL,data); + } + + /** + * 上传文件到阿里云盘 + * @return + * @throws Exception + */ + public JSONObject uploadFile(String fileId, Map fileInfo){ + JSONObject data = new JSONObject(); + JSONObject list = new JSONObject(); + JSONArray array = new JSONArray(); + list.set("part_number",1); + array.add(list); + data.set("drive_id",CommonConstants.DriveId); + data.set("name",fileInfo.get("name")); + data.set("type","file"); + data.set("content_type",fileInfo.get("content_type")); + data.set("size",fileInfo.get("size")); + data.set("parent_file_id",fileId); + data.set("part_info_list",array); + data.set("content_hash_name","sha1"); + data.set("content_hash",fileInfo.get("content_hash")); + data.set("ignoreError",false); + data.set("check_name_mode","refuse"); + return okHttpUtil.doFilePost(CommonConstants.CREATE_FILE_URL,data); + } + + /** + * 完成文件上传 + * @param fileId + * @param uploadId + * @return + * @throws Exception + */ + public JSONObject completeFile(String fileId,String uploadId){ + JSONObject data = new JSONObject(); + JSONArray array = new JSONArray(); + data.set("drive_id",CommonConstants.DriveId); + data.set("file_id",fileId); + data.set("ignoreError",true); + data.set("part_info_list",array); + data.set("upload_id",uploadId); + return okHttpUtil.doPost(CommonConstants.COMPLETE_FILE_URL,data); + } + + /** + * 删除阿里云盘文件 + * @param fileId + * @return + * @throws Exception + */ + public JSONObject deleteFile(String fileId){ + JSONObject data = new JSONObject(); + data.set("drive_id",CommonConstants.DriveId); + data.set("file_id",fileId); + return okHttpUtil.doPost(CommonConstants.DELETE_FILE_URL,data); + } + + /** + * 获取文件夹ID + * @param parentFileId 父级文件夹ID + * @param folderName 文件夹名称 + * @return + * @throws Exception + */ + public String getFileId(String parentFileId,String folderName){ + //CommonConstants.addConsole("开始获取文件夹:"+folderName); + String fileId=""; + JSONObject fileList = getFileList(parentFileId);//获取文件目录 + JSONArray fileArray = fileList.getJSONArray("items"); + if (ObjectUtil.isNotNull(fileArray) && fileArray.size()>0){ + for (int i = 0; i < fileArray.size(); i++) { + JSONObject folder = fileArray.getJSONObject(i); + if ("folder".equals(folder.getStr("type")) && folderName.equals(folder.getStr("name"))){ + fileId = folder.getStr("file_id"); + return fileId; + } + } + } + if (StrUtil.isEmpty(fileId)){ + JSONObject folder = createFolder(parentFileId, folderName); //创建备份目录 + fileId=folder.getStr("file_id"); + } + return fileId; + } + + /** + * 执行文件上传 + * @param fileId 文件夹ID + * @param fileInfo 文件信息 + * @throws Exception + */ + public void doUploadFile(String fileId,Map fileInfo){ + //写入上传文件的路径 + List logList = readerLog.readLines(); + if (!logList.contains(fileInfo.get("path"))){ + CommonConstants.addConsole("开始上传:"+fileInfo.get("path")); + JSONObject uploadFile = uploadFile(fileId,fileInfo); + if(ObjectUtil.isNotNull(uploadFile.getJSONArray("part_info_list"))){//上传新文件 + byte[] fileBytes = FileUtil.readBytes(fileInfo.get("path").toString()); + String uploadUrl = uploadFile.getJSONArray("part_info_list").getJSONObject(0).getStr("upload_url"); + okHttpUtil.uploadFileBytes(uploadUrl,fileBytes); + } + if (StrUtil.isEmpty(uploadFile.getStr("exist"))){//上传完成 + String upFileId = uploadFile.getStr("file_id"); + String uploadId = uploadFile.getStr("upload_id"); + completeFile(upFileId, uploadId); + } + writerLog.append(fileInfo.get("path")+ "\n"); + CommonConstants.addConsole("上传文件成功:"+fileInfo.get("name")); + }else { + CommonConstants.addConsole(fileInfo.get("path")+" 已上传 跳过"); + } + return; + } + + /** + * 扫描子目录 + * @param path 本地路径 + * @param pathId 备份目录 ID + * @param isUploadFile 是否上传文件 + * @throws Exception + */ + public void scanFolders(String path,String pathId,Boolean isUploadFile){ + CommonConstants.addConsole("开始获取:"+path); + //获取文件夹下所有文件 + List fileList = FileUtil.fileFolderList(path,FileUtil.FILE); + //CommonConstants.addConsole("获取:"+path+" 下所有文件成功"); + if (isUploadFile){ + uploadFileList(fileList,pathId,false); + } + //获得目录下所有文件夹 + List folderList = FileUtil.fileFolderList(path,FileUtil.FOLDER); + //循环文件夹 + for (String folder : folderList){ + String fileId = getFileId(pathId, folder);//创建文件夹-文件夹ID + String filePath = path + FileUtil.FILE_SEPARATOR + folder;//路径 + fileList = FileUtil.fileFolderList(path,FileUtil.FILE);//获取当前文件夹下所有文件 + uploadFileList(fileList,fileId,false);//上传当前文件夹内的文件 + //CommonConstants.addConsole("扫描新文件夹:"+filePath); + scanFolders(filePath,fileId,true); + } + } + + /** + * 上传文件夹下文件到某个目录 + * @param fileList 文件list + * @param pathId 阿里云文件夹ID + * @param backType 是否开启分类 + * @throws Exception + */ + public void uploadFileList(List fileList, String pathId,Boolean backType){ + List logList = readerLog.readLines(); + fileList.removeAll(logList); + for (String filePath : fileList) { + try { + Map map = FileUtil.getFileInfo(filePath); + if (backType){//开启分类 + String type = map.get("type").toString(); + String typeFileId=this.getFileId(pathId,type);//微信备份-类型 + String dateFileId=this.getFileId(typeFileId,getFolderName(filePath));//微信备份-类型-文件夹 + doUploadFile(dateFileId,map); + }else { + doUploadFile(pathId,map); + } + } catch (Exception e) { + CommonConstants.addConsole("遇到异常情况:"+e.toString()); + } + } + } + + /** + * 获取文件夹名称 + * @param thisPath + * @return + */ + public String getFolderName(String thisPath) { + String folderName = StrUtil.subAfter(thisPath , CommonConstants.PATH+"\\", false); + if (StrUtil.isNotEmpty(folderName) && !folderName.contains("\\")){ + //写入文件目录 + //writerLog.append(CommonConstants.PATH + FileUtil.FILE_SEPARATOR+folderName + ""); + }else{ + folderName = StrUtil.subBefore(folderName , "\\", false); + } + return folderName; + } + + /** + * 监控目录 + */ + public void monitorFolder() { + if (StrUtil.isEmpty(setting.getStr("pathText"))) return; + try { + Thread.sleep(300); + } catch (InterruptedException e) { + e.printStackTrace(); + } + CommonConstants.CLEAN_CONSOLE=1; + //开启目录检测 开始获取文件夹 + Console.log("开启目录检测"); + CommonConstants.addConsole("开启目录检测"); + File file = FileUtil.file(setting.getStr("pathText")); + //这里只监听文件或目录的修改事件 + WatchMonitor watchMonitor = WatchMonitor.create(file,WatchMonitor.ENTRY_CREATE,WatchMonitor.ENTRY_MODIFY); + watchMonitor.setWatcher(new Watcher(){ + @Override + public void onCreate(WatchEvent event, Path currentPath) { + Object obj = event.context(); + Console.log("创建:{}-> {}", currentPath, obj); + //备份方法不执行时候执行监听 + if (!CommonConstants.BACK_STATE){ + uploadMonitor(currentPath,obj); + } + } + + @Override + public void onModify(WatchEvent event, Path currentPath) { + Object obj = event.context(); + Console.log("修改:{}-> {}", currentPath, obj); + //备份方法不执行时候执行监听 + if (!CommonConstants.BACK_STATE){ + String path = currentPath.toString() + "\\" + obj.toString(); + //CommonConstants.addConsole("检测到:"+path+" 文件发生变化!"); + List logList = readerLog.readLines(); + logList.remove(path); + writerLog.writeLines(logList); + } + //uploadMonitor(currentPath); + } + + @Override + public void onDelete(WatchEvent event, Path currentPath) { + /*Object obj = event.context(); + Console.log("删除:{}-> {}", currentPath, obj);*/ + } + + @Override + public void onOverflow(WatchEvent event, Path currentPath) { + /*Object obj = event.context(); + Console.log("Overflow:{}-> {}", currentPath, obj);*/ + } + }); + //设置监听目录的最大深入,目录层级大于制定层级的变更将不被监听,默认只监听当前层级目录 + //监听所有目录 + watchMonitor.setMaxDepth(Integer.MAX_VALUE); + //启动监听 + watchMonitor.start(); + } + + /** + * 上传监控目录 + * @param currentPath + */ + public void uploadMonitor(Path currentPath,Object obj) { + CommonConstants.addConsole("检测到:"+currentPath.toString()+" 目录有新文件..."); + if (checkConfig()){ + Thread backup = new Thread(() -> { + boolean login = getAliYunPanInfo();//登录阿里云 + if (!login){ + return; + } + CommonConstants.FILE_ID = getFileId(CommonConstants.ROOT, CommonConstants.BACK_NAME);//备份目录ID + uploadTwoLevelFolder(CommonConstants.FILE_ID,currentPath.toString()); + CommonConstants.addConsole("上传 "+obj.toString()+" 成功!"); + }); + backup.start(); + } + } + + /** + * 验证配置文件 + */ + public Boolean checkConfig(){ + if (StrUtil.isEmpty(setting.getStr("pathText"))){ + CommonConstants.addConsole("您没有选择需要备份的目录"); + return false; + } + if (StrUtil.isEmpty(setting.getStr("tokenText"))){ + CommonConstants.addConsole( "您没有输入阿里云token"); + return false; + } + if (StrUtil.isEmpty(setting.getStr("folderText"))){ + CommonConstants.addConsole("您没有输入需要备份到阿里云的目录"); + return false; + } + if (setting.getStr("tokenText").length()!=32){ + CommonConstants.addConsole("您输入的token不正确"); + return false; + } + if (!FileUtil.isDirectory(setting.getStr("pathText"))){ + CommonConstants.addConsole("请选择正确目录"); + return false; + } + CommonConstants.PATH = setting.getStr("pathText"); + CommonConstants.REFRESH_TOKEN = setting.getStr("tokenText"); + CommonConstants.BACK_NAME = setting.getStr("folderText"); + CommonConstants.BACK_TYPE = Integer.parseInt(setting.getStr("backType")); + return true; + } + + +} diff --git a/src/main/java/com/eg/www/common/utils/FileUtil.java b/src/main/java/com/eg/www/common/utils/FileUtil.java new file mode 100644 index 0000000..94fd3f6 --- /dev/null +++ b/src/main/java/com/eg/www/common/utils/FileUtil.java @@ -0,0 +1,178 @@ +package com.eg.www.common.utils; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.crypto.digest.DigestUtil; + +import javax.activation.MimetypesFileTypeMap; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Description: 文件操作工具类 + * Author: Eg + * Date: 2021/08/29 + */ +public class FileUtil extends cn.hutool.core.io.FileUtil { + + public static final String FILE="File";//文件 + public static final String FOLDER="Folder";//文件夹 + static List docTypes = new ArrayList<>();//文档类型 + static List compressTypes = new ArrayList<>();//压缩包类型 + static List imageTypes = new ArrayList<>();//图片类型 + static List musicTypes = new ArrayList<>();//音乐类型 + static List videoTypes = new ArrayList<>();//视频类型 + static List applyTypes = new ArrayList<>();//软件类型 + static List devTypes = new ArrayList<>();//开发类型 + + //文件类型 + static { + /** + * 文档类型 + */ + docTypes.add("xls"); + docTypes.add("xlsx"); + docTypes.add("xlsm"); + docTypes.add("doc"); + docTypes.add("docx"); + docTypes.add("ppt"); + docTypes.add("pptx"); + docTypes.add("txt"); + docTypes.add("pdf"); + docTypes.add("chm"); + docTypes.add("xmind"); + + /** + * 压缩包类型 + */ + compressTypes.add("zip"); + compressTypes.add("rar"); + compressTypes.add("7z"); + compressTypes.add("tar.gz"); + compressTypes.add("gz"); + + /** + * 图片类型 + */ + imageTypes.add("png"); + imageTypes.add("jpg"); + imageTypes.add("jpeg"); + imageTypes.add("gif"); + imageTypes.add("ico"); + imageTypes.add("psd"); + + /** + * 音频类型 + */ + musicTypes.add("mp3"); + musicTypes.add("wma"); + musicTypes.add("aac"); + musicTypes.add("m4a"); + musicTypes.add("amr"); + + /** + * 视频类型 + */ + videoTypes.add("mp4"); + videoTypes.add("avi"); + videoTypes.add("3gp"); + videoTypes.add("flv"); + videoTypes.add("mkv"); + videoTypes.add("mov"); + videoTypes.add("wmv"); + + /** + * 软件类型 + */ + applyTypes.add("1"); + applyTypes.add("apk"); + applyTypes.add("exe"); + applyTypes.add("ipa"); + applyTypes.add("app"); + applyTypes.add("dmg"); + applyTypes.add("rpm"); + + /** + * 开发类型 + */ + devTypes.add("properties"); + devTypes.add("java"); + devTypes.add("php"); + devTypes.add("jsp"); + devTypes.add("js"); + devTypes.add("vue"); + devTypes.add("sh"); + devTypes.add("sql"); + devTypes.add("xml"); + devTypes.add("html"); + devTypes.add("conf"); + devTypes.add("jar"); + devTypes.add("bat"); + devTypes.add("yml"); + devTypes.add("css"); + devTypes.add("json"); + devTypes.add("out"); + devTypes.add("class"); + } + + /** + * 获取文件类型 + * @param name 文件名 + * @return 返回文件类型 + */ + public static String getFileTypes(String name){ + //获取文件的后缀名 + String suffix = getSuffix(name).toLowerCase(); + if (docTypes.contains(suffix)) return "文档"; + if (imageTypes.contains(suffix)) return "图片"; + if (musicTypes.contains(suffix)) return "音频"; + if (videoTypes.contains(suffix)) return "视频"; + if (applyTypes.contains(suffix)) return "软件"; + if (devTypes.contains(suffix)) return "开发"; + if (compressTypes.contains(suffix)) return "压缩包"; + return "其它"; + } + + /** + * 读取目录下的文件 或 文件夹 + * 不含子目录 + * @param path 目录绝对路径或者相对路径 + * @param type 文件或文件夹 为空默认返回文件夹 + * @return 列表 + */ + public static List fileFolderList(String path,String type) { + List List = new ArrayList<>(); + final File[] files = ls(path); + for (File file : files) { + if(FILE.equals(type) && file.isFile()){ + List.add(file.getPath()); + } + if (FOLDER.equals(type) && file.isDirectory()){ + List.add(file.getName()); + } + } + return List; + } + + /** + * 获取文件信息 + * @param path 文件路径 + */ + public static Map getFileInfo(String path) { + String contentType= new MimetypesFileTypeMap().getContentType(new File(path)); + if (StrUtil.isEmpty(contentType)) contentType="application/octet-stream"; + Map map = new HashMap(); + File file = file(path); + String type = getFileTypes(file.getName()); + map.put("name",file.getName()); + map.put("path",file.getPath()); + map.put("size",file.length()); + map.put("type",type); + map.put("content_type",contentType); + map.put("content_hash",DigestUtil.sha1Hex(file).toUpperCase()); + return map; + } + +} diff --git a/src/main/java/com/eg/www/common/utils/OkHttpUtil.java b/src/main/java/com/eg/www/common/utils/OkHttpUtil.java new file mode 100644 index 0000000..e7cb768 --- /dev/null +++ b/src/main/java/com/eg/www/common/utils/OkHttpUtil.java @@ -0,0 +1,127 @@ +package com.eg.www.common.utils; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import okhttp3.*; +import com.eg.www.common.CommonConstants; +import com.eg.www.common.MyConsole; + +import java.util.concurrent.TimeUnit; + +/** + * Description: http请求工具类 + * Author: Eg + * Date: 2021/08/29 + */ +public class OkHttpUtil { + + // 日志界面 + MyConsole console = CommonConstants.console; + + static OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(5, TimeUnit.MINUTES).build(); + static MediaType mediaType = MediaType.parse("application/json"); + static RequestBody body; + static Request request; + + + /** + * 阿里云盘交互的POST请求 + * @param url + * @param data + * @return + * @throws Exception + */ + public JSONObject doPost(String url, JSONObject data){ + int errNum=0; + try { + body = RequestBody.create(mediaType,data.toString()); + request = new Request.Builder() + .url(url) + .method("POST", body) + .addHeader("authorization", CommonConstants.TOKEN) + .addHeader("Content-Type", "application/json").build(); + Response response = client.newCall(request).execute(); + String result = response.body().string(); + CommonConstants.addConsole("请求状态码:"+response.code()); + //System.out.println("result:>>>>>>>>>>>>>>>>>>>"+result); + return JSONUtil.parseObj(result); + } catch (Exception e) { + if (e.toString().contains("A JSONObject text")){ + CommonConstants.addConsole("普通请求遇到异常:"+e.toString()); + return null; + }else { + errNum++; + CommonConstants.addConsole("普通请求遇到异常:"+e.toString()); + if (errNum>5){ + CommonConstants.addConsole("普通请求失败次数超过:"+errNum+" 次....已停止"); + return null; + }else{ + CommonConstants.addConsole("普通请求发起第:"+errNum+" 次重试"); + return doPost(url,data); + } + } + } + } + + /** + * 阿里云盘上传文件的POST请求 + * @param url + * @param data + * @return + * @throws Exception + */ + public JSONObject doFilePost(String url,JSONObject data){ + int errNum=0; + try { + RequestBody body = RequestBody.create(mediaType, data.toString()); + request = new Request.Builder() + .url(url) + .method("POST", body) + .addHeader("authorization",CommonConstants.TOKEN) + .addHeader("Content-Type", "multipart/form-data").build(); + Response response = client.newCall(request).execute(); + String result = response.body().string(); + CommonConstants.addConsole("请求状态码:"+response.code()); + //System.out.println("result:>>>>>>>>>>>>>>>>>>>"+result); + return JSONUtil.parseObj(result); + } catch (Exception e) { + errNum++; + CommonConstants.addConsole("上传请求遇到异常:"+e.toString()); + if (errNum>5){ + CommonConstants.addConsole("上传请求失败次数超过:"+errNum+" 次....已停止"); + return null; + }else{ + CommonConstants.addConsole("上传请求发起第:"+errNum+" 次重试"); + return doFilePost(url,data); + } + } + } + + /** + * 阿里云盘上传二进制文件 + * @param url + * @param fileBytes + * @return + * @throws Exception + */ + public void uploadFileBytes(String url,byte[] fileBytes){ + int errNum=0; + try { + RequestBody body = RequestBody.create(fileBytes); + Request request = new Request.Builder().url(url).method("PUT",body).build(); + Response response = client.newCall(request).execute(); + //String result=response.body().string(); + CommonConstants.addConsole("上传文件请求状态码:"+response.code()); + } catch (Exception e) { + errNum++; + CommonConstants.addConsole("上传文件遇到异常:"+e.toString()); + if (errNum>5){ + CommonConstants.addConsole("上传文件失败次数超过:"+errNum+" 次....已停止"); + return; + }else{ + CommonConstants.addConsole("上传文件发起第:"+errNum+" 次重试"); + uploadFileBytes(url,fileBytes); + } + } + } +} diff --git a/src/main/java/com/eg/www/common/utils/getToken.java b/src/main/java/com/eg/www/common/utils/getToken.java new file mode 100644 index 0000000..a3eb4c4 --- /dev/null +++ b/src/main/java/com/eg/www/common/utils/getToken.java @@ -0,0 +1,10 @@ +package com.eg.www.common.utils; + +/** + * @author: Eg + * @Date: 2021/8/29 17:50 + */ +public class getToken { + + +} diff --git a/src/main/resources/config/cron.setting b/src/main/resources/config/cron.setting new file mode 100644 index 0000000..a9f36f8 --- /dev/null +++ b/src/main/resources/config/cron.setting @@ -0,0 +1,13 @@ +#我是注释 +#执行的类或对象方法所在包的名字 +#[com.eg.www] +#需要执行的类名和方法名 +#App.Test = * * * * * ? * +#执行的类或对象方法所在包的名字 +[com.eg.www.common] +#每小时刷新阿里云盘登录信息 +CronTask.updateALiYunPanToken = 0 0 0/1 * * ? +#执行的类或对象方法所在包的名字 +[com.eg.www.common] +#每天晚上八点自动备份文件 +CronTask.backFileList = 0 0 20 * * ? * diff --git a/src/main/resources/images/logo.png b/src/main/resources/images/logo.png new file mode 100644 index 0000000..a884f98 Binary files /dev/null and b/src/main/resources/images/logo.png differ diff --git a/target/classes/com/eg/www/AliYunPan$1.class b/target/classes/com/eg/www/AliYunPan$1.class new file mode 100644 index 0000000..78f34e7 Binary files /dev/null and b/target/classes/com/eg/www/AliYunPan$1.class differ diff --git a/target/classes/com/eg/www/AliYunPan$2.class b/target/classes/com/eg/www/AliYunPan$2.class new file mode 100644 index 0000000..6d0447f Binary files /dev/null and b/target/classes/com/eg/www/AliYunPan$2.class differ diff --git a/target/classes/com/eg/www/AliYunPan.class b/target/classes/com/eg/www/AliYunPan.class new file mode 100644 index 0000000..74f2f82 Binary files /dev/null and b/target/classes/com/eg/www/AliYunPan.class differ diff --git a/target/classes/com/eg/www/App.class b/target/classes/com/eg/www/App.class new file mode 100644 index 0000000..b5720ba Binary files /dev/null and b/target/classes/com/eg/www/App.class differ diff --git a/target/classes/com/eg/www/common/CommonConstants.class b/target/classes/com/eg/www/common/CommonConstants.class new file mode 100644 index 0000000..cab59ab Binary files /dev/null and b/target/classes/com/eg/www/common/CommonConstants.class differ diff --git a/target/classes/com/eg/www/common/CronTask.class b/target/classes/com/eg/www/common/CronTask.class new file mode 100644 index 0000000..7451e4c Binary files /dev/null and b/target/classes/com/eg/www/common/CronTask.class differ diff --git a/target/classes/com/eg/www/common/MyConsole.class b/target/classes/com/eg/www/common/MyConsole.class new file mode 100644 index 0000000..e0ce80e Binary files /dev/null and b/target/classes/com/eg/www/common/MyConsole.class differ diff --git a/target/classes/com/eg/www/common/utils/AliYunPanUtil$1.class b/target/classes/com/eg/www/common/utils/AliYunPanUtil$1.class new file mode 100644 index 0000000..a2a9bc2 Binary files /dev/null and b/target/classes/com/eg/www/common/utils/AliYunPanUtil$1.class differ diff --git a/target/classes/com/eg/www/common/utils/AliYunPanUtil.class b/target/classes/com/eg/www/common/utils/AliYunPanUtil.class new file mode 100644 index 0000000..b8307ca Binary files /dev/null and b/target/classes/com/eg/www/common/utils/AliYunPanUtil.class differ diff --git a/target/classes/com/eg/www/common/utils/FileUtil.class b/target/classes/com/eg/www/common/utils/FileUtil.class new file mode 100644 index 0000000..0c4ce3c Binary files /dev/null and b/target/classes/com/eg/www/common/utils/FileUtil.class differ diff --git a/target/classes/com/eg/www/common/utils/OkHttpUtil.class b/target/classes/com/eg/www/common/utils/OkHttpUtil.class new file mode 100644 index 0000000..1914610 Binary files /dev/null and b/target/classes/com/eg/www/common/utils/OkHttpUtil.class differ diff --git a/target/classes/config/cron.setting b/target/classes/config/cron.setting new file mode 100644 index 0000000..a9f36f8 --- /dev/null +++ b/target/classes/config/cron.setting @@ -0,0 +1,13 @@ +#我是注释 +#执行的类或对象方法所在包的名字 +#[com.eg.www] +#需要执行的类名和方法名 +#App.Test = * * * * * ? * +#执行的类或对象方法所在包的名字 +[com.eg.www.common] +#每小时刷新阿里云盘登录信息 +CronTask.updateALiYunPanToken = 0 0 0/1 * * ? +#执行的类或对象方法所在包的名字 +[com.eg.www.common] +#每天晚上八点自动备份文件 +CronTask.backFileList = 0 0 20 * * ? * diff --git a/target/classes/images/logo.png b/target/classes/images/logo.png new file mode 100644 index 0000000..a884f98 Binary files /dev/null and b/target/classes/images/logo.png differ diff --git a/uploadLog.txt b/uploadLog.txt new file mode 100644 index 0000000..bb4b90b --- /dev/null +++ b/uploadLog.txt @@ -0,0 +1,3 @@ +C:\Users\Administrator\Desktop\HKBTest\HKBTest.exe +C:\Users\Administrator\Desktop\HKBTest\Kbhk.dll +C:\Users\Administrator\Desktop\HKBTest\KE.ini