This patch for sshout
Finish in 2019.02.21
common.h | 5 +++++ | |
externalsshclient.cpp | 2 +- | |
main.cpp | 19 ++++++++++++++----- | |
messagelog.cpp | 14 ++++++++++++++ | |
settingsdialog.cpp | 2 +- | |
5 files changed, 35 insertions(+), 7 deletions(-) | |
diff --git a/common.h b/common.h | |
index 16ac144..baea8d3 100644 | |
--- a/common.h | |
+++ b/common.h | |
@@ -1,7 +1,12 @@ | |
#ifndef COMMON_H | |
#define COMMON_H | |
+#include <QtCore/qglobal.h> | |
+#ifdef Q_OS_WIN | |
+#define DEFAULT_SSH_PROGRAM_PATH "C:\\Windows\\System32\\OpenSSH\\ssh.exe" | |
+#else | |
#define DEFAULT_SSH_PROGRAM_PATH "/usr/bin/ssh" | |
+#endif | |
#define DEFAULT_SSH_USER_NAME "sshout" | |
#define PROJECT_PAGE_URL "https://sourceforge.net/projects/sshout/" | |
diff --git a/externalsshclient.cpp b/externalsshclient.cpp | |
index 2073af8..7cf81ce 100644 | |
--- a/externalsshclient.cpp | |
+++ b/externalsshclient.cpp | |
@@ -80,9 +80,9 @@ bool ExternalSSHClient::connect(const QString &host, quint16 port, const QString | |
ssh_args << "-T"; | |
if(!ssh_args_extra.isEmpty()) ssh_args << ssh_args_extra; | |
if(!command.isEmpty()) ssh_args << "--" << command; | |
+ QIODevice::open(QIODevice::ReadWrite); | |
ssh_process->start(ssh_program_path, ssh_args, QIODevice::ReadWrite); | |
//QIODevice::open(QIODevice::ReadWrite | QIODevice::Unbuffered); | |
- QIODevice::open(QIODevice::ReadWrite); | |
return true; | |
} | |
diff --git a/main.cpp b/main.cpp | |
index 1f9e9a3..8ec22a4 100644 | |
--- a/main.cpp | |
+++ b/main.cpp | |
@@ -32,6 +32,11 @@ | |
#include <QtCore/QDir> | |
#include <QtCore/QTranslator> | |
#include <QtCore/QDebug> | |
+#include <string> | |
+ | |
+#ifdef Q_OS_WIN | |
+ #include <windows.h> | |
+#endif | |
#define CONFIG_FILE_NAME "sshout.cfg" | |
@@ -49,16 +54,20 @@ static void print_usage(const char *name) { | |
QString config_dir() { | |
QString appath = QApplication::applicationDirPath(); | |
-#ifndef Q_OS_WINCE | |
if(QFile::exists(appath + "/" CONFIG_FILE_NAME)) { | |
-#endif | |
return appath; | |
-#ifndef Q_OS_WINCE | |
} | |
QString in_home = QDir::homePath() + "/.sshout"; | |
- if(!QFile::exists(in_home)) mkdir(in_home.toLocal8Bit().data(), 0750); | |
- return in_home; | |
+ if(!QFile::exists(in_home)) { | |
+#ifndef Q_OS_WIN | |
+ std::string in_home_ = in_home.toStdString(); | |
+ mkdir(in_home_.c_str(), 0750); | |
+#else | |
+ std::wstring in_home_ = in_home.toStdWString(); | |
+ CreateDirectoryW(in_home_.c_str(), NULL); | |
#endif | |
+ } | |
+ return in_home; | |
} | |
void get_translations_directories(QStringList &directories) { | |
diff --git a/messagelog.cpp b/messagelog.cpp | |
index 46bad18..dce9e1c 100644 | |
--- a/messagelog.cpp | |
+++ b/messagelog.cpp | |
@@ -7,6 +7,10 @@ | |
#include <QtCore/QCoreApplication> | |
#include <signal.h> | |
+#ifdef Q_OS_WIN | |
+ #include <windows.h> | |
+#endif | |
+ | |
MessageLog::MessageLog() { | |
//database = new QSqlDatabase; | |
//QSQLiteDriver *driver = new QSQLiteDriver; | |
@@ -30,10 +34,20 @@ bool MessageLog::open(const QString &path) { | |
lock_file->close(); | |
if(!content.isEmpty()) { | |
int pid = content.toInt(); | |
+#ifndef Q_OS_WIN | |
if(pid && kill(pid, 0) == 0) { | |
qWarning("MessageLog::open: database file is locked by process %d via lock file '%s'", pid, lock_path_ba.data()); | |
return false; | |
} | |
+#else | |
+ UINT tPid = static_cast<UINT>(pid); | |
+ HANDLE pHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, tPid); | |
+ CloseHandle(pHandle); | |
+ if (tPid && pHandle == NULL) { | |
+ qWarning("MessageLog::open: database file is locked by process %d via lock file '%s'", pid, lock_path_ba.data()); | |
+ return false; | |
+ } | |
+#endif | |
} | |
//lock_file->remove(); | |
} | |
diff --git a/settingsdialog.cpp b/settingsdialog.cpp | |
index ff15637..07e4d77 100644 | |
--- a/settingsdialog.cpp | |
+++ b/settingsdialog.cpp | |
@@ -151,7 +151,7 @@ void SettingsDialog::use_internal_ssh_library_checked(bool t) { | |
ui->button_add_env_item->setEnabled(!t); | |
ui->button_remove_env_item->setEnabled(!t); | |
ui->checkBox_use_separete_known_hosts->setEnabled(!t); | |
- ui->checkBox_use_separete_known_hosts->setChecked(t ? : config->value("UseSeparateKnownHosts", false).toBool()); | |
+ ui->checkBox_use_separete_known_hosts->setChecked(t ? t : config->value("UseSeparateKnownHosts", false).toBool()); | |
} | |
void SettingsDialog::add_environment_variable(const QString &name, const QString &value) { |