Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to zip logfiles to home directory. #6440

Merged
merged 1 commit into from Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import bisq.common.UserThread;
import bisq.common.config.Config;
import bisq.common.util.Utilities;

import com.google.protobuf.ByteString;

Expand Down Expand Up @@ -62,11 +63,15 @@ public FileTransferSender(NetworkNode networkNode,
String traderRole,
@Nullable FileTransferSession.FtpCallback callback) {
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
zipFilePath = Config.appDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
zipFilePath = Utilities.getUserDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
updateProgress();
}

public void createZipFileToSend() {
createZipFileOfLogs(zipFilePath, zipId, fullTradeId);
}

public static void createZipFileOfLogs(String zipFilePath, String zipId, String fullTradeId) {
try {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
Expand All @@ -80,6 +85,7 @@ public void createZipFileToSend() {
try {
// always include bisq.log; and other .log files if they contain the TradeId
if (externalTxtFile.getFileName().toString().equals("bisq.log") ||
(fullTradeId == null && externalTxtFile.getFileName().toString().matches(".*.log")) ||
(externalTxtFile.getFileName().toString().matches(".*.log") &&
doesFileContainKeyword(externalTxtFile.toFile(), fullTradeId))) {
Path pathInZipfile = zipfs.getPath(zipId + "/" + externalTxtFile.getFileName().toString());
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,7 @@ account.backup.backupNow=Backup now (backup is not encrypted!)
account.backup.appDir=Application data directory
account.backup.openDirectory=Open directory
account.backup.openLogFile=Open Log file
account.backup.zipLogFiles=Zip Log files
account.backup.success=Backup successfully saved at:\n{0}
account.backup.directoryNotAccessible=The directory you have chosen is not accessible. {0}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import bisq.desktop.util.Layout;

import bisq.core.locale.Res;
import bisq.core.support.dispute.mediation.FileTransferSender;
import bisq.core.user.Preferences;

import bisq.common.config.Config;
import bisq.common.file.FileUtil;
import bisq.common.persistence.PersistenceManager;
import bisq.common.util.Tuple2;
import bisq.common.util.Tuple3;
import bisq.common.util.Utilities;

import javax.inject.Inject;
Expand All @@ -43,6 +45,7 @@

import java.text.SimpleDateFormat;

import java.nio.file.FileSystems;
import java.nio.file.Paths;

import java.io.File;
Expand All @@ -52,10 +55,7 @@

import javax.annotation.Nullable;

import static bisq.desktop.util.FormBuilder.add2Buttons;
import static bisq.desktop.util.FormBuilder.add2ButtonsAfterGroup;
import static bisq.desktop.util.FormBuilder.addInputTextField;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
import static bisq.desktop.util.FormBuilder.*;

@FxmlView
public class BackupView extends ActivatableView<GridPane, Void> {
Expand All @@ -64,7 +64,7 @@ public class BackupView extends ActivatableView<GridPane, Void> {
private final Preferences preferences;
private Button selectBackupDir, backupNow;
private TextField backUpLocationTextField;
private Button openDataDirButton, openLogsButton;
private Button openDataDirButton, openLogsButton, zipLogsButton;
private ChangeListener<Boolean> backUpLocationTextFieldFocusListener;


Expand Down Expand Up @@ -102,11 +102,15 @@ public void initialize() {

addTitledGroupBg(root, ++gridRow, 2, Res.get("account.backup.appDir"), Layout.GROUP_DISTANCE);

final Tuple2<Button, Button> applicationDataDirTuple2 = add2Buttons(root, gridRow, Res.get("account.backup.openDirectory"),
Res.get("account.backup.openLogFile"), Layout.TWICE_FIRST_ROW_AND_GROUP_DISTANCE, false);
final Tuple3<Button, Button, Button> applicationDataDirTuple2 = add3Buttons(root, gridRow,
Res.get("account.backup.openDirectory"),
Res.get("account.backup.openLogFile"),
Res.get("account.backup.zipLogFiles"),
Layout.TWICE_FIRST_ROW_AND_GROUP_DISTANCE);

openDataDirButton = applicationDataDirTuple2.first;
openLogsButton = applicationDataDirTuple2.second;
zipLogsButton = applicationDataDirTuple2.third;
}

@Override
Expand Down Expand Up @@ -151,6 +155,19 @@ protected void activate() {
});
}
});
zipLogsButton.setOnAction(event -> {
String zipId = "BisqLogsArchive_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String zipFilePath = Utilities.getSystemHomeDirectory() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
String tradeId = null;
FileTransferSender.createZipFileOfLogs(zipFilePath, zipId, tradeId);
try {
Utilities.openFile(new File(Utilities.getSystemHomeDirectory()));
} catch (IOException e) {
e.printStackTrace();
log.error(e.getMessage());
showWrongPathWarningAndReset(e);
}
});
}

private void openFileOrShowWarning(Button button, File dataDir) {
Expand Down