Debug
This commit is contained in:
commit
7ec40106f1
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -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/
|
13
.idea/compiler.xml
Normal file
13
.idea/compiler.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="aliyunpan-autobackup" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/encodings.xml
Normal file
7
.idea/encodings.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
97
.idea/inspectionProfiles/Project_Default.xml
Normal file
97
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="AliAccessStaticViaInstance" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliArrayNamingShouldHaveBracket" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliControlFlowStatementWithoutBraces" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliDeprecation" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliEqualsAvoidNull" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliLongLiteralsEndingWithLowercaseL" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliMissingOverrideAnnotation" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AliWrapperTypeEquality" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAbstractClassShouldStartWithAbstractNaming" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidApacheBeanUtilsCopy" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidCallStaticSimpleDateFormat" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidCommentBehindStatement" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidComplexCondition" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidConcurrentCompetitionRandom" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidDoubleOrFloatEqualCompare" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidManuallyCreateThread" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidMissUseOfMathRandom" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidNegationOperator" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidNewDateGetTime" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidPatternCompileInMethod" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidReturnInFinally" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidStartWithDollarAndUnderLineNaming" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaAvoidUseTimer" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaBigDecimalAvoidDoubleConstructor" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaBooleanPropertyShouldNotStartWithIs" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaClassCastExceptionWithSubListToArrayList" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaClassCastExceptionWithToArray" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaClassMustHaveAuthor" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaClassNamingShouldBeCamel" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaCollectionInitShouldAssignCapacity" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaCommentsMustBeJavadocFormat" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaConcurrentExceptionWithModifyOriginSubList" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaConstantFieldShouldBeUpperCase" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaCountDownShouldInFinally" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaDontModifyInForeachCircle" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaEnumConstantsMustHaveComment" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaExceptionClassShouldEndWithException" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaIbatisMethodQueryForList" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaLockShouldWithTryFinally" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaLowerCamelCaseVariableNaming" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaMethodReturnWrapperType" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaMethodTooLong" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaPackageNaming" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaPojoMustOverrideToString" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaPojoMustUsePrimitiveField" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaPojoNoDefaultValue" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaRemoveCommentedCode" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaServiceOrDaoClassShouldEndWithImpl" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaStringConcat" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaSwitchStatement" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaTestClassShouldEndWithTestNaming" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaThreadLocalShouldRemove" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaThreadPoolCreation" enabled="false" level="BLOCKER" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaThreadShouldSetName" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaTransactionMustHaveRollback" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaUndefineMagicConstant" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaUnsupportedExceptionWithModifyAsList" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaUseQuietReferenceNotation" enabled="false" level="MAJOR" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="AlibabaUseRightCaseForDateFormat" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="TOP_LEVEL_CLASS_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="INNER_CLASS_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="METHOD_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="FIELD_OPTIONS">
|
||||||
|
<value>
|
||||||
|
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
|
||||||
|
<option name="REQUIRED_TAGS" value="" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="IGNORE_DEPRECATED" value="false" />
|
||||||
|
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
|
||||||
|
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
|
||||||
|
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
|
||||||
|
<option name="myAdditionalJavadocTags" value="date" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="MapOrSetKeyShouldOverrideHashCodeEquals" enabled="false" level="CRITICAL" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
25
.idea/jarRepositories.xml
Normal file
25
.idea/jarRepositories.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="alimaven" />
|
||||||
|
<option name="name" value="alimaven" />
|
||||||
|
<option name="url" value="https://maven.aliyun.com/repository/public" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
14
.idea/misc.xml
Normal file
14
.idea/misc.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/smartfox_info.xml
Normal file
6
.idea/smartfox_info.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SmartFoxProjectConfig">
|
||||||
|
<option name="projectInspectionClosed" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
5
back_config.setting
Normal file
5
back_config.setting
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
[]
|
||||||
|
tokenText = 77190dd0a59a45b0883650647b85522d
|
||||||
|
pathText = C:\Users\Administrator\Desktop\HKBTest
|
||||||
|
folderText = backtest
|
||||||
|
backType = 0
|
88
pom.xml
Normal file
88
pom.xml
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.eg</groupId>
|
||||||
|
<artifactId>aliyunpan-autobackup</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.11</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--okhttp3-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>4.9.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!--工具类-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.6.5</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
|
<plugins>
|
||||||
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.0</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
|
<version>2.5.2</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</plugin>
|
||||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
|
||||||
|
</build>
|
||||||
|
</project>
|
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: com.eg.www.App
|
||||||
|
|
326
src/main/java/com/eg/www/AliYunPan.java
Normal file
326
src/main/java/com/eg/www/AliYunPan.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
59
src/main/java/com/eg/www/App.java
Normal file
59
src/main/java/com/eg/www/App.java
Normal file
@ -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<String> 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<String> fileList = FileUtil.fileFolderList(path,FileUtil.FILE);//本地文件夹下文件
|
||||||
|
for (String filePath : fileList) {
|
||||||
|
Map<String, Object> 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);
|
||||||
|
}
|
||||||
|
}
|
86
src/main/java/com/eg/www/common/CommonConstants.java
Normal file
86
src/main/java/com/eg/www/common/CommonConstants.java
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
39
src/main/java/com/eg/www/common/CronTask.java
Normal file
39
src/main/java/com/eg/www/common/CronTask.java
Normal file
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
26
src/main/java/com/eg/www/common/MyConsole.java
Normal file
26
src/main/java/com/eg/www/common/MyConsole.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
459
src/main/java/com/eg/www/common/utils/AliYunPanUtil.java
Normal file
459
src/main/java/com/eg/www/common/utils/AliYunPanUtil.java
Normal file
@ -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<String> folderList = FileUtil.fileFolderList(CommonConstants.PATH,FileUtil.FOLDER);//获取用户目录下所有目录
|
||||||
|
List<String> 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<String> 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<String, Object> 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<String, Object> fileInfo){
|
||||||
|
//写入上传文件的路径
|
||||||
|
List<String> 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<String> fileList = FileUtil.fileFolderList(path,FileUtil.FILE);
|
||||||
|
//CommonConstants.addConsole("获取:"+path+" 下所有文件成功");
|
||||||
|
if (isUploadFile){
|
||||||
|
uploadFileList(fileList,pathId,false);
|
||||||
|
}
|
||||||
|
//获得目录下所有文件夹
|
||||||
|
List<String> 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<String> fileList, String pathId,Boolean backType){
|
||||||
|
List<String> logList = readerLog.readLines();
|
||||||
|
fileList.removeAll(logList);
|
||||||
|
for (String filePath : fileList) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> 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<String> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
178
src/main/java/com/eg/www/common/utils/FileUtil.java
Normal file
178
src/main/java/com/eg/www/common/utils/FileUtil.java
Normal file
@ -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<String> docTypes = new ArrayList<>();//文档类型
|
||||||
|
static List<String> compressTypes = new ArrayList<>();//压缩包类型
|
||||||
|
static List<String> imageTypes = new ArrayList<>();//图片类型
|
||||||
|
static List<String> musicTypes = new ArrayList<>();//音乐类型
|
||||||
|
static List<String> videoTypes = new ArrayList<>();//视频类型
|
||||||
|
static List<String> applyTypes = new ArrayList<>();//软件类型
|
||||||
|
static List<String> 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<String> fileFolderList(String path,String type) {
|
||||||
|
List<String> 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<String, Object> getFileInfo(String path) {
|
||||||
|
String contentType= new MimetypesFileTypeMap().getContentType(new File(path));
|
||||||
|
if (StrUtil.isEmpty(contentType)) contentType="application/octet-stream";
|
||||||
|
Map<String, Object> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
127
src/main/java/com/eg/www/common/utils/OkHttpUtil.java
Normal file
127
src/main/java/com/eg/www/common/utils/OkHttpUtil.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/main/java/com/eg/www/common/utils/getToken.java
Normal file
10
src/main/java/com/eg/www/common/utils/getToken.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.eg.www.common.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: Eg
|
||||||
|
* @Date: 2021/8/29 17:50
|
||||||
|
*/
|
||||||
|
public class getToken {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
13
src/main/resources/config/cron.setting
Normal file
13
src/main/resources/config/cron.setting
Normal file
@ -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 * * ? *
|
BIN
src/main/resources/images/logo.png
Normal file
BIN
src/main/resources/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
target/classes/com/eg/www/AliYunPan$1.class
Normal file
BIN
target/classes/com/eg/www/AliYunPan$1.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/AliYunPan$2.class
Normal file
BIN
target/classes/com/eg/www/AliYunPan$2.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/AliYunPan.class
Normal file
BIN
target/classes/com/eg/www/AliYunPan.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/App.class
Normal file
BIN
target/classes/com/eg/www/App.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/CommonConstants.class
Normal file
BIN
target/classes/com/eg/www/common/CommonConstants.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/CronTask.class
Normal file
BIN
target/classes/com/eg/www/common/CronTask.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/MyConsole.class
Normal file
BIN
target/classes/com/eg/www/common/MyConsole.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/utils/AliYunPanUtil$1.class
Normal file
BIN
target/classes/com/eg/www/common/utils/AliYunPanUtil$1.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/utils/AliYunPanUtil.class
Normal file
BIN
target/classes/com/eg/www/common/utils/AliYunPanUtil.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/utils/FileUtil.class
Normal file
BIN
target/classes/com/eg/www/common/utils/FileUtil.class
Normal file
Binary file not shown.
BIN
target/classes/com/eg/www/common/utils/OkHttpUtil.class
Normal file
BIN
target/classes/com/eg/www/common/utils/OkHttpUtil.class
Normal file
Binary file not shown.
13
target/classes/config/cron.setting
Normal file
13
target/classes/config/cron.setting
Normal file
@ -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 * * ? *
|
BIN
target/classes/images/logo.png
Normal file
BIN
target/classes/images/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
3
uploadLog.txt
Normal file
3
uploadLog.txt
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user