diff --git a/ndn/log.txt b/ndn/log.txt new file mode 100644 index 0000000..b3241cd --- /dev/null +++ b/ndn/log.txt @@ -0,0 +1,4 @@ +文件名:/wechat.jpg 文件操作:下载 文件耗时:252ms +文件名:C:\Users\wefree\Pictures\test_2M.html 文件操作:上传 文件耗时:1661ms +文件名:C:\Users\wefree\Pictures\7000字节文件.txt 文件操作:上传 文件耗时:191ms +文件名:C:\Users\wefree\Pictures\test.jpg 文件操作:上传 文件耗时:468ms diff --git a/ndn/pid/pib.db b/ndn/pid/pib.db index 32d7588..dce6e54 100644 Binary files a/ndn/pid/pib.db and b/ndn/pid/pib.db differ diff --git a/src/main/java/cn/minoa/view/mine/MyCloudFileController.java b/src/main/java/cn/minoa/view/mine/MyCloudFileController.java index c7f5f81..dad10a5 100644 --- a/src/main/java/cn/minoa/view/mine/MyCloudFileController.java +++ b/src/main/java/cn/minoa/view/mine/MyCloudFileController.java @@ -3,8 +3,7 @@ package cn.minoa.view.mine; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.LinkedList; +import java.util.*; /* * 数据格式说明: * f 普通文件 @@ -12,13 +11,12 @@ import java.util.LinkedList; * d 文件夹目录 * .前端一个listview表项是一个pane,其id是"路径+纯文件名+@文件类型" */ -import java.util.List; -import java.util.Map; import cn.minoa.model.SingleFile; import cn.minoa.util.FileUtil; import cn.minoa.util.StringByteLengthUtil; import cn.minoa.view.login.LoginOverviewController; +import javafx.scene.control.*; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -27,9 +25,6 @@ import cn.minoa.MainApp; import cn.minoa.dataRequestInterface.OrderInfo; import cn.minoa.dataRequestInterface.ResponseData; import javafx.fxml.FXML; -import javafx.scene.control.Alert; -import javafx.scene.control.Button; -import javafx.scene.control.ListView; import javafx.scene.control.Alert.AlertType; import javafx.scene.layout.Pane; import javafx.scene.text.Text; @@ -56,6 +51,8 @@ public class MyCloudFileController { private Button deleteSelectedButton; @FXML private Button downloadTheFileButton; + @FXML + private Button deleteFolderButton; // 构造函数 public MyCloudFileController() { @@ -81,6 +78,8 @@ public class MyCloudFileController { */ public void setMainApp(MainApp mainApp) { this.mainApp = mainApp; + // 设置删除文件夹按钮属性 + deleteFolderButton.setDisable(true); // 发送命令请求主目录下的文件夹列表,赋值给filePathnameList lsFolder(currentPath); // 更新显示到前端 @@ -95,6 +94,12 @@ public class MyCloudFileController { */ public void setMainApp(MainApp mainApp, String iniCurrentPath) { this.mainApp = mainApp; + // 设置删除文件夹按钮属性 + if(iniCurrentPath.equals("/")){ + deleteFolderButton.setDisable(true); + }else{ + deleteFolderButton.setDisable(false); + } // 发送命令请求主目录下的文件夹列表,赋值给filePathnameList this.currentPath = iniCurrentPath; lsFolder(currentPath); @@ -180,7 +185,11 @@ public class MyCloudFileController { // 版2【无进度条】: // Integer r=mainApp.uploadFileToServerPath(file, currentPath + "/"); // 版3【有进度条】: - mainApp.uploadFileToServerPathWithProgressBar(file, currentPath + "/"); + if(currentPath.equals("/")){ + mainApp.uploadFileToServerPathWithProgressBar(file, currentPath); + }else{ + mainApp.uploadFileToServerPathWithProgressBar(file, currentPath + "/"); + } // 判断是否手动取消了上传,是的话就不进行下面的判断 if(mainApp.isCancelFileTransferFlag){ return; @@ -398,7 +407,71 @@ public class MyCloudFileController { alert.showAndWait(); } } + } + // 删除当前路径所代表的文件夹 + @FXML + private void deleteSelectedFolderItem() { + if(currentPath.equals("/")){ + // 弹窗参考:https://code.makery.ch/blog/javafx-dialogs-official/ + Alert alert = new Alert(AlertType.ERROR); + alert.setTitle("根目录不可删除"); + alert.setHeaderText("根目录不可删除"); + alert.setContentText("根目录不可删除"); + alert.showAndWait(); + return ; + } +// // 提醒用户是否确认删除 +// Dialog choiceDialog=new ChoiceDialog(); +// choiceDialog.setTitle("确认弹窗"); +// choiceDialog.setHeaderText("文件夹删除确认弹窗"); +// choiceDialog.setContentText("您确认删除文件夹\""+currentPath +// +"\"吗?"); +// choiceDialog.showAndWait(); + System.out.println("开始发送删除请求到服务器..."); + // 获取当前文件夹路径 + String pathfilename = currentPath; + // 请求数据 + OrderInfo orderInfo = new OrderInfo(); + ResponseData responseData = new ResponseData(); + Long seqLong = mainApp.getNewDataReqId(); + orderInfo.setSeq(seqLong); + orderInfo.setJsonString(getFileActionJson("rm", pathfilename)); + System.out.println("getFileActionJson: " + getFileActionJson("rm", pathfilename)); + mainApp.minoaDataAPI.executeOrder("/fileAction", orderInfo); + responseData = mainApp.minoaDataAPI.dataCacheQueue.getResponseDataBySeq(seqLong); + JSONObject jsonObject = responseData.praseRequestData(); + responseData.printSelf(); + // 解析数据 + Integer codeInteger = null; + try { + codeInteger = jsonObject.getInt("code"); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (codeInteger == 200) { +// 弹窗参考:https://code.makery.ch/blog/javafx-dialogs-official/ + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("删除成功"); + alert.setHeaderText("删除文件夹成功"); + alert.setContentText("已从云端删除您当前所在路径的文件夹。"); + alert.showAndWait(); + // 根据当前路径,重新加载整个界面,来刷新listview + try { + mainApp.reloadCloudFileOverview(getUpperLevelPath(currentPath)); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } else { +// 弹窗参考:https://code.makery.ch/blog/javafx-dialogs-official/ + Alert alert = new Alert(AlertType.WARNING); + alert.setTitle("删除失败"); + alert.setHeaderText("删除文件失败"); + alert.setContentText("由于未知原因,您选中的文件不能被删除"); + alert.showAndWait(); + } } @@ -583,7 +656,7 @@ public class MyCloudFileController { if (foldername.charAt(foldername.length() - 1) != '/'){ foldername=foldername+"/"; } - if(type.equals("f")){ +// if(type.equals("f")){ // filePathnameList String fileId=foldername + filename + "@" + type; filePathnameList.add(fileId); @@ -595,7 +668,7 @@ public class MyCloudFileController { singleFile.setSize(size); singleFile.setTime(time); detailedFileListMap.put(fileId,singleFile); - } +// } } return true; } catch (JSONException e) { @@ -846,9 +919,9 @@ public class MyCloudFileController { headYInteger = 10; textXInteger = 70; textYInteger = 28; - fileszTextXInteger=textXInteger+150; + fileszTextXInteger=textXInteger+110; fileszTextYInteger=textYInteger; - filetimeTextXInteger=textXInteger+280; + filetimeTextXInteger=textXInteger+220; filetimeTextYInteger=textYInteger; pane = new Pane(); @@ -890,7 +963,11 @@ public class MyCloudFileController { setHeadPortrait(head, getFileTypeFromPaneId(name)); // 文件大小 Long size=detailedFileListMap.get(name).getSize(); - filesizeText.setText(FileUtil.sizeToShowSize(size)); + String sizeString=FileUtil.sizeToShowSize(size); + if(sizeString.equals("0 B")){ + sizeString="- "; + } + filesizeText.setText(sizeString); // 文件创建时间 Long time=detailedFileListMap.get(name).getTime(); filetimeText.setText(FileUtil.timeToDateString(time)); diff --git a/src/main/java/cn/minoa/view/mine/NewFolderDialogController.java b/src/main/java/cn/minoa/view/mine/NewFolderDialogController.java index 895a252..156ae65 100644 --- a/src/main/java/cn/minoa/view/mine/NewFolderDialogController.java +++ b/src/main/java/cn/minoa/view/mine/NewFolderDialogController.java @@ -33,7 +33,7 @@ public class NewFolderDialogController { */ @FXML private void handleExit() { - String newFolderNameString="新建文件夹"; + String newFolderNameString=""; if(!newFolderName.getText().trim().equals("")) { newFolderNameString=newFolderName.getText().trim(); } diff --git a/src/main/resources/fxml/mine/MyCloudFileOverview.fxml b/src/main/resources/fxml/mine/MyCloudFileOverview.fxml index a51afea..dac679f 100644 --- a/src/main/resources/fxml/mine/MyCloudFileOverview.fxml +++ b/src/main/resources/fxml/mine/MyCloudFileOverview.fxml @@ -30,5 +30,6 @@