diff --git a/src/main/java/com/fangxuele/tool/wechat/push/logic/MsgHisManage.java b/src/main/java/com/fangxuele/tool/wechat/push/logic/MsgHisManage.java index 13a10504..9f5f58c6 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/logic/MsgHisManage.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/logic/MsgHisManage.java @@ -2,6 +2,7 @@ import com.fangxuele.tool.wechat.push.ui.Init; import com.fangxuele.tool.wechat.push.ui.MainWindow; +import com.fangxuele.tool.wechat.push.util.SystemUtil; import com.opencsv.CSVReader; import com.opencsv.CSVWriter; import com.xiaoleilu.hutool.log.Log; @@ -40,8 +41,8 @@ public static MsgHisManage getInstance() { private MsgHisManage() { try { - msgHisFile = new File("data/msg_his.csv"); - File msgHisDir = new File("data/"); + msgHisFile = new File(SystemUtil.configHome + "data" + File.separator + "msg_his.csv"); + File msgHisDir = new File(SystemUtil.configHome + "data" + File.separator); if (!msgHisFile.exists()) { msgHisDir.mkdirs(); msgHisFile.createNewFile(); @@ -100,8 +101,8 @@ public Map readMsgHis() { public List readTemplateData(String msgName) { CSVReader reader = null; List list = new ArrayList<>(); - File dir = new File("data/template_data/"); - File file = new File("data/template_data/" + msgName + ".csv"); + File dir = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator); + File file = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator + msgName + ".csv"); try { if (!file.exists()) { dir.mkdirs(); @@ -146,8 +147,9 @@ public void writeMsgHis(Map map) throws IOException { * @throws IOException */ public void writeTemplateData(String msgName) throws IOException { - File dir = new File("data/template_data/"); - File file = new File("data/template_data/" + msgName + ".csv"); + File dir = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator); + File file = new File(SystemUtil.configHome + "data" + File.separator + "template_data" + File.separator + + msgName + ".csv"); if (!file.exists()) { dir.mkdirs(); file.createNewFile(); diff --git a/src/main/java/com/fangxuele/tool/wechat/push/logic/PushManage.java b/src/main/java/com/fangxuele/tool/wechat/push/logic/PushManage.java index a908200a..c4611bb2 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/logic/PushManage.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/logic/PushManage.java @@ -2,6 +2,7 @@ import com.fangxuele.tool.wechat.push.ui.Init; import com.fangxuele.tool.wechat.push.ui.MainWindow; +import com.fangxuele.tool.wechat.push.util.SystemUtil; import com.opencsv.CSVWriter; import com.taobao.api.DefaultTaobaoClient; import com.taobao.api.TaobaoClient; @@ -349,7 +350,7 @@ public static WxMpService getWxMpService() { * 推送停止或结束后保存数据 */ public static void savePushData() throws IOException { - File pushHisDir = new File("data/push_his"); + File pushHisDir = new File(SystemUtil.configHome + "data" + File.separator + "push_his"); if (!pushHisDir.exists()) { pushHisDir.mkdirs(); } @@ -362,7 +363,9 @@ public static void savePushData() throws IOException { // 保存已发送 if (PushData.sendSuccessList.size() > 0) { - File toSendFile = new File(new StringBuilder("data/push_his/").append(msgName).append("-发送成功-").append(nowTime).append(".csv").toString()); + File toSendFile = new File(new StringBuilder(SystemUtil.configHome).append("data") + .append(File.separator).append("push_his").append(File.separator).append(msgName) + .append("-发送成功-").append(nowTime).append(".csv").toString()); if (!toSendFile.exists()) { toSendFile.createNewFile(); } @@ -382,7 +385,9 @@ public static void savePushData() throws IOException { PushData.toSendList.remove(str); } if (PushData.toSendList.size() > 0) { - File unSendFile = new File(new StringBuilder("data/push_his/").append(msgName).append("-未发送-").append(nowTime).append(".csv").toString()); + File unSendFile = new File(new StringBuilder(SystemUtil.configHome).append("data").append(File.separator) + .append("push_his").append(File.separator).append(msgName).append("-未发送-").append(nowTime) + .append(".csv").toString()); if (!unSendFile.exists()) { unSendFile.createNewFile(); } @@ -395,7 +400,8 @@ public static void savePushData() throws IOException { // 保存发送失败 if (PushData.sendFailList.size() > 0) { - File failSendFile = new File(new StringBuilder("data/push_his/").append(msgName).append("-发送失败-").append(nowTime).append(".csv").toString()); + File failSendFile = new File(new StringBuilder(SystemUtil.configHome).append("data").append(File.separator) + .append("push_his").append(File.separator).append(msgName).append("-发送失败-").append(nowTime).append(".csv").toString()); if (!failSendFile.exists()) { failSendFile.createNewFile(); } diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/ConstantsUI.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/ConstantsUI.java index 46ccd9fb..6a41466e 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/ConstantsUI.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/ConstantsUI.java @@ -6,7 +6,7 @@ /** * UI相关的常量 * - * @author rememberber(https://github.com/rememberber) + * @author rememberber(https : / / github.com / rememberber) */ public class ConstantsUI { @@ -14,13 +14,13 @@ public class ConstantsUI { * 软件名称,版本 */ public final static String APP_NAME = "WePush"; - public final static String APP_VERSION = "v_1.7.0_180226"; + public final static String APP_VERSION = "v_1.8.0_180226"; /** * 主窗口图标 */ public final static Image IMAGE_ICON = Toolkit.getDefaultToolkit() - .getImage(MainWindow.class.getResource("/icon/logo-md.png")); + .getImage(MainWindow.class.getResource("/icon/logo-lg.png")); /** * 软件版本检查url diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/Init.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/Init.java index af2cd4d6..395851b5 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/Init.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/Init.java @@ -334,7 +334,7 @@ public static void initMemberTab() { MainWindow.mainWindow.getMemberHisComboBox().removeAllItems(); - File pushHisDir = new File("data/push_his"); + File pushHisDir = new File(SystemUtil.configHome + "data" + File.separator + "push_his"); if (!pushHisDir.exists()) { pushHisDir.mkdirs(); } @@ -390,7 +390,7 @@ public static void initPushHisTab() { renderer.setPreferredSize(new Dimension(0, 0)); MainWindow.mainWindow.getPushHisLeftTable().getTableHeader().setDefaultRenderer(renderer); - File pushHisDir = new File("data/push_his"); + File pushHisDir = new File(SystemUtil.configHome + "data" + File.separator + "push_his"); if (!pushHisDir.exists()) { pushHisDir.mkdirs(); } @@ -494,7 +494,8 @@ public static void initAllTab() { initMemberTab(); initPushTab(); initScheduleTab(); - initPushHisTab(); + // 初始化后置,切换tab时再触发 + // initPushHisTab(); initSettingTab(); // 检查新版版 diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.form b/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.form index 2ae4deee..7c105fb3 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.form +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.form @@ -645,7 +645,7 @@ - + @@ -673,13 +673,21 @@ - + + + + + + + + + diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.java index 6d1b3767..852d3e5f 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/MainWindow.java @@ -163,6 +163,7 @@ public class MainWindow { private JButton memberImportTagButton; private JComboBox memberImportTagComboBox; private JButton memberImportTagFreshButton; + private JButton memberImportExploreButton; public static JFrame frame; public static MainWindow mainWindow; @@ -1354,4 +1355,12 @@ public JButton getPushHisCopyButton() { public void setPushHisCopyButton(JButton pushHisCopyButton) { this.pushHisCopyButton = pushHisCopyButton; } + + public JButton getMemberImportExploreButton() { + return memberImportExploreButton; + } + + public void setMemberImportExploreButton(JButton memberImportExploreButton) { + this.memberImportExploreButton = memberImportExploreButton; + } } diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/AboutListener.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/AboutListener.java index 18881f00..9aa3319f 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/AboutListener.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/AboutListener.java @@ -48,11 +48,17 @@ public void mouseEntered(MouseEvent e) { }); + // 检查更新 MainWindow.mainWindow.getCheckUpdateLabel().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); - checkUpdate(false); + new Thread(new Runnable() { + @Override + public void run() { + checkUpdate(false); + } + }).start(); } @Override diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/MemberListener.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/MemberListener.java index ea22a19f..ff26006b 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/MemberListener.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/MemberListener.java @@ -5,6 +5,7 @@ import com.fangxuele.tool.wechat.push.ui.Init; import com.fangxuele.tool.wechat.push.ui.MainWindow; import com.fangxuele.tool.wechat.push.util.DbUtilMySQL; +import com.fangxuele.tool.wechat.push.util.SystemUtil; import com.opencsv.CSVReader; import com.xiaoleilu.hutool.io.file.FileReader; import com.xiaoleilu.hutool.log.Log; @@ -17,6 +18,8 @@ import org.apache.commons.lang3.StringUtils; import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; @@ -181,7 +184,8 @@ public static void addListeners() { // 从历史导入按钮事件 MainWindow.mainWindow.getImportFromHisButton().addActionListener(e -> new Thread(() -> { - File file = new File("data/push_his/" + MainWindow.mainWindow.getMemberHisComboBox().getSelectedItem().toString()); + File file = new File(SystemUtil.configHome + "data/push_his" + File.separator + + MainWindow.mainWindow.getMemberHisComboBox().getSelectedItem().toString()); CSVReader reader = null; FileReader fileReader = null; @@ -265,6 +269,27 @@ public static void addListeners() { } } }).start()); + + // 浏览按钮 + MainWindow.mainWindow.getMemberImportExploreButton().addActionListener(e -> { + File beforeFile = new File(MainWindow.mainWindow.getMemberFilePathField().getText()); + JFileChooser fileChooser; + + if (beforeFile.exists()) { + fileChooser = new JFileChooser(beforeFile); + } else { + fileChooser = new JFileChooser(); + } + + FileFilter filter = new FileNameExtensionFilter("*.txt,*.csv", "txt", "csv", "TXT", "CSV"); + fileChooser.setFileFilter(filter); + + int approve = fileChooser.showOpenDialog(MainWindow.mainWindow.getSettingPanel()); + if (approve == JFileChooser.APPROVE_OPTION) { + MainWindow.mainWindow.getMemberFilePathField().setText(fileChooser.getSelectedFile().getAbsolutePath()); + } + + }); } /** diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/PushHisListener.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/PushHisListener.java index c7e50f74..0fddecc1 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/PushHisListener.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/PushHisListener.java @@ -2,6 +2,8 @@ import com.fangxuele.tool.wechat.push.ui.Init; import com.fangxuele.tool.wechat.push.ui.MainWindow; +import com.fangxuele.tool.wechat.push.util.SystemUtil; +import com.xiaoleilu.hutool.io.FileUtil; import com.xiaoleilu.hutool.log.Log; import com.xiaoleilu.hutool.log.LogFactory; import com.xiaoleilu.hutool.util.ClipboardUtil; @@ -9,8 +11,7 @@ import javax.swing.*; import javax.swing.table.DefaultTableModel; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; +import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedReader; @@ -18,6 +19,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * 推送历史管理tab相关事件监听 @@ -37,8 +40,10 @@ public void run() { MainWindow.mainWindow.getPushHisTextArea().setText(""); int selectedRow = MainWindow.mainWindow.getPushHisLeftTable().getSelectedRow(); - String selectedFileName = MainWindow.mainWindow.getPushHisLeftTable().getValueAt(selectedRow, 1).toString(); - File pushHisFile = new File("data/push_his/" + selectedFileName); + String selectedFileName = MainWindow.mainWindow.getPushHisLeftTable() + .getValueAt(selectedRow, 1).toString(); + File pushHisFile = new File(SystemUtil.configHome + "data" + File.separator + + "push_his" + File.separator + selectedFileName); try { BufferedReader br = new BufferedReader(new FileReader(pushHisFile)); @@ -97,7 +102,7 @@ public void run() { boolean delete = (boolean) tableModel.getValueAt(i, 0); if (delete) { String fileName = (String) tableModel.getValueAt(i, 1); - File msgTemplateDataFile = new File("data/push_his/" + fileName); + File msgTemplateDataFile = new File(SystemUtil.configHome + "data" + File.separator + "push_his" + File.separator + fileName); if (msgTemplateDataFile.exists()) { msgTemplateDataFile.delete(); } @@ -136,13 +141,57 @@ public void run() { }).start()); // 推送历史管理-导出按钮 - MainWindow.mainWindow.getPushHisExportButton().addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - // TODO 导出推送历史 - JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "敬请期待!", "提示", - JOptionPane.INFORMATION_MESSAGE); + MainWindow.mainWindow.getPushHisExportButton().addActionListener(e -> { + List toExportFilePathList = new ArrayList<>(); + int selectedCount = 0; + + try { + DefaultTableModel tableModel = (DefaultTableModel) MainWindow.mainWindow.getPushHisLeftTable() + .getModel(); + int rowCount = tableModel.getRowCount(); + for (int i = 0; i < rowCount; i++) { + boolean selected = (boolean) tableModel.getValueAt(i, 0); + if (selected) { + selectedCount++; + String fileName = (String) tableModel.getValueAt(i, 1); + File msgTemplateDataFile = new File(SystemUtil.configHome + "data" + File.separator + "push_his" + File.separator + fileName); + if (msgTemplateDataFile.exists()) { + toExportFilePathList.add(msgTemplateDataFile.getAbsolutePath()); + } + } + } + + if (selectedCount > 0) { + JFileChooser fileChooser = new JFileChooser(); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int approve = fileChooser.showOpenDialog(MainWindow.mainWindow.getSettingPanel()); + String exportPath = ""; + if (approve == JFileChooser.APPROVE_OPTION) { + exportPath = fileChooser.getSelectedFile().getAbsolutePath(); + } + + for (String toExportFilePath : toExportFilePathList) { + FileUtil.copy(toExportFilePath, exportPath, true); + } + JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "导出成功!", "提示", + JOptionPane.INFORMATION_MESSAGE); + try { + Desktop desktop = Desktop.getDesktop(); + desktop.open(new File(exportPath)); + } catch (Exception e2) { + logger.error(e2); + } + } else { + JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "请至少选择一个!", "提示", + JOptionPane.INFORMATION_MESSAGE); + } + + } catch (Exception e1) { + JOptionPane.showMessageDialog(MainWindow.mainWindow.getSettingPanel(), "导出失败!\n\n" + e1.getMessage(), "失败", + JOptionPane.ERROR_MESSAGE); + logger.error(e1); } + }); } diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/SettingListener.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/SettingListener.java index 476a08b3..e521162f 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/SettingListener.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/SettingListener.java @@ -3,6 +3,7 @@ import com.fangxuele.tool.wechat.push.ui.Init; import com.fangxuele.tool.wechat.push.ui.MainWindow; import com.fangxuele.tool.wechat.push.util.DbUtilMySQL; +import com.fangxuele.tool.wechat.push.util.SystemUtil; import com.xiaoleilu.hutool.log.Log; import com.xiaoleilu.hutool.log.LogFactory; @@ -162,7 +163,8 @@ public static void addListeners() { String msgName = (String) tableModel.getValueAt(i, 1); if (msgMap.containsKey(msgName)) { msgMap.remove(msgName); - File msgTemplateDataFile = new File("data/template_data/" + msgName + ".csv"); + File msgTemplateDataFile = new File(SystemUtil.configHome + "data" + + File.separator + "template_data" + File.separator + msgName + ".csv"); if (msgTemplateDataFile.exists()) { msgTemplateDataFile.delete(); } diff --git a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/TabListener.java b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/TabListener.java index d7f4e4a0..c0f0a754 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/TabListener.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/ui/listener/TabListener.java @@ -1,5 +1,6 @@ package com.fangxuele.tool.wechat.push.ui.listener; +import com.fangxuele.tool.wechat.push.ui.Init; import com.fangxuele.tool.wechat.push.ui.MainWindow; import com.xiaoleilu.hutool.log.Log; import com.xiaoleilu.hutool.log.LogFactory; @@ -24,6 +25,7 @@ public void mouseClicked(MouseEvent e) { int index = MainWindow.mainWindow.getTabbedPane().getSelectedIndex(); switch (index) { case 6: + Init.initPushHisTab(); break; default: break; diff --git a/src/main/java/com/fangxuele/tool/wechat/push/util/Config.java b/src/main/java/com/fangxuele/tool/wechat/push/util/Config.java index 212cb2d8..64f23fb9 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/util/Config.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/util/Config.java @@ -1,5 +1,6 @@ package com.fangxuele.tool.wechat.push.util; +import com.xiaoleilu.hutool.io.FileUtil; import com.xiaoleilu.hutool.log.Log; import com.xiaoleilu.hutool.log.LogFactory; import com.xiaoleilu.hutool.setting.dialect.Props; @@ -107,8 +108,26 @@ public static Config getInstance() { } private Config() { - file = new File("config/config.properties"); - File configDir = new File("config/"); + // --旧版本配置文件迁移初始化开始-- + File configHomeDir = new File(SystemUtil.configHome); + if (!configHomeDir.exists()) { + configHomeDir.mkdirs(); + } + File oldConfigDir = new File("config"); + if (oldConfigDir.exists()) { + FileUtil.copy(oldConfigDir.getAbsolutePath(), SystemUtil.configHome, true); + FileUtil.del(oldConfigDir.getAbsolutePath()); + } + + File oldDataDir = new File("data"); + if (oldDataDir.exists()) { + FileUtil.copy(oldDataDir.getAbsolutePath(), SystemUtil.configHome, true); + FileUtil.del(oldDataDir.getAbsolutePath()); + } + // --旧版本配置文件迁移初始化结束-- + + file = new File(SystemUtil.configHome + "config" + File.separator + "config.properties"); + File configDir = new File(SystemUtil.configHome + "config" + File.separator); if (!file.exists()) { try { configDir.mkdirs(); diff --git a/src/main/java/com/fangxuele/tool/wechat/push/util/SystemUtil.java b/src/main/java/com/fangxuele/tool/wechat/push/util/SystemUtil.java index cd183857..d01f0472 100644 --- a/src/main/java/com/fangxuele/tool/wechat/push/util/SystemUtil.java +++ b/src/main/java/com/fangxuele/tool/wechat/push/util/SystemUtil.java @@ -1,10 +1,14 @@ package com.fangxuele.tool.wechat.push.util; +import java.io.File; + /** * 系统工具 */ public class SystemUtil { public static String osName = System.getProperty("os.name"); + public static String configHome = System.getProperty("user.home") + File.separator + ".wepush" + + File.separator; public static boolean isMacOs() { if (osName.contains("Mac")) { diff --git a/src/main/resources/icon/logo-lg.png b/src/main/resources/icon/logo-lg.png new file mode 100644 index 00000000..dea6f888 Binary files /dev/null and b/src/main/resources/icon/logo-lg.png differ diff --git a/src/main/resources/version_summary.json b/src/main/resources/version_summary.json index 69c0942e..fc78b628 100644 --- a/src/main/resources/version_summary.json +++ b/src/main/resources/version_summary.json @@ -1,5 +1,5 @@ { - "currentVersion": "v_1.7.0_180226", + "currentVersion": "v_1.8.0_180226", "versionIndex": { "v_1.1.0_170701": "0", "v_1.2.0_170831": "1", @@ -7,7 +7,8 @@ "v_1.4.0_180209": "3", "v_1.5.0_180209": "4", "v_1.6.0_180222": "5", - "v_1.7.0_180226": "6" + "v_1.7.0_180226": "6", + "v_1.8.0_180226": "7" }, "versionDetailList": [ { @@ -44,6 +45,11 @@ "version": "v_1.7.0_180226", "title": "新增推送历史管理+新增支持按微信公众平台标签导入", "log": "1.新增推送历史管理\n2.准备目标用户:新增支持按微信公众平台标签导入\n3.优化在Mac系统系下的显示,为Mac版发布做准备\n4.优雅的Mac版的安装App就快到来,敬请期待\n5.其他多处优化和修复\n" + }, + { + "version": "v_1.8.0_180226", + "title": "新增Mac版", + "log": "1.Mac版来啦~\n2.推送历史支持导出功能\n3.通过文件导入时支持浏览本地文件\n4.其他多处优化和修复\n" } ] } \ No newline at end of file