fix :
1.某些程序自己目录下有动态库,所以为了通用性,将启动运行改为sh脚本。 2.修正了当使用自定义图标时,没有链接到备份图标路径的问题。
This commit is contained in:
parent
84bc4936c5
commit
1fdc0988f2
@ -279,11 +279,19 @@ void MainWidget::generate()
|
||||
// 复制主体文件
|
||||
fs::path out_binary = fs::path(out_dir).append(fs::path(binary_.toStdString()).filename());
|
||||
fs::copy_file(binary_.toStdString(), out_binary, fs::copy_options::overwrite_existing);
|
||||
if (!add_run_sh(out_dir.string(), filename)) {
|
||||
return;
|
||||
}
|
||||
message(this, "完成");
|
||||
}
|
||||
|
||||
|
||||
bool MainWidget::add_run_sh(const std::string& out_dir, const std::string& exe_name)
|
||||
{
|
||||
// 生成一个启动文件夹
|
||||
QFile file("://resource/run.sh");
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
QTextStream in(&file);
|
||||
// 读取文件内容
|
||||
@ -291,15 +299,15 @@ void MainWidget::generate()
|
||||
file.close();
|
||||
|
||||
std::string run_sh = content.toStdString();
|
||||
boost::replace_all(run_sh, "replace_string", filename);
|
||||
boost::replace_all(run_sh, "replace_string", exe_name);
|
||||
|
||||
std::string out_sh = fs::path(out_dir).append("run.sh").string();
|
||||
std::ofstream out(out_sh, std::ios::out);
|
||||
if (!out.is_open()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
out << run_sh;
|
||||
out.close();
|
||||
cmd_exec(std::string("chmod +x " + out_sh));
|
||||
message(this, "完成");
|
||||
}
|
||||
return true;
|
||||
}
|
@ -49,6 +49,7 @@ public:
|
||||
static bool isOk(QWidget* parent, const QString& title, const QString& content);
|
||||
static void message(QWidget* parent, const QString& content);
|
||||
static void cmd_exec(const std::string& cmd);
|
||||
static bool add_run_sh(const std::string& out_dir, const std::string& exe_name);
|
||||
|
||||
private:
|
||||
Ui::MainWidget* ui;
|
||||
|
@ -37,7 +37,7 @@ AddDesktop::AddDesktop(QWidget* parent) : QDialog(parent), ui(new Ui::AddDesktop
|
||||
connect(ui->btnSelectBinary, &QPushButton::clicked, this,
|
||||
[=]() { MainWidget::SelectFile(this, ui->edBinary, "请选择二进制文件", "所有文件 (*)"); });
|
||||
connect(ui->btnSelectIco, &QPushButton::clicked, this,
|
||||
[=]() { MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件", "图标文件(*.ico);;所有文件 (*)"); });
|
||||
[=]() { MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件", "ico图标(*.ico);;svg图标(*.svg);;所有文件 (*)"); });
|
||||
connect(ui->btnInstall, &QPushButton::clicked, this, &AddDesktop::install_to_desktop);
|
||||
}
|
||||
|
||||
@ -59,6 +59,12 @@ void AddDesktop::install_to_desktop()
|
||||
return;
|
||||
}
|
||||
|
||||
std::string binaryPath = ui->edBinary->text().trimmed().toStdString();
|
||||
std::string binaryName = fs::path(binaryPath).filename().string();
|
||||
fs::path sh_path = fs::path(binaryPath).parent_path().append("run.sh");
|
||||
if (!fs::exists(sh_path)) {
|
||||
MainWidget::add_run_sh(sh_path.parent_path().string(), binaryName);
|
||||
}
|
||||
fs::path tmp = fs::path(QDir::homePath().toStdString()).append(".config");
|
||||
if (!fs::exists(tmp)) {
|
||||
fs::create_directories(tmp);
|
||||
@ -68,10 +74,9 @@ void AddDesktop::install_to_desktop()
|
||||
QString content = stream.readAll();
|
||||
file.close();
|
||||
std::string ct = content.toStdString();
|
||||
std::string tool_name = fs::path(ui->edBinary->text().trimmed().toStdString()).filename().string();
|
||||
boost::replace_all(ct, "re_name", tool_name);
|
||||
boost::replace_all(ct, "re_describe", tool_name);
|
||||
boost::replace_all(ct, "re_path", ui->edBinary->text().trimmed().toStdString());
|
||||
boost::replace_all(ct, "re_name", binaryName);
|
||||
boost::replace_all(ct, "re_describe", binaryName);
|
||||
boost::replace_all(ct, "re_path", "sh " + sh_path.string());
|
||||
|
||||
fs::path default_ico_path = fs::path(tmp).append("packqt");
|
||||
if (!fs::exists(default_ico_path)) {
|
||||
@ -84,13 +89,13 @@ void AddDesktop::install_to_desktop()
|
||||
|
||||
} else {
|
||||
std::string icn = ui->edIco->text().trimmed().toStdString();
|
||||
boost::replace_all(ct, "re_icon", icn);
|
||||
default_ico_path.append(fs::path(icn).filename());
|
||||
boost::replace_all(ct, "re_icon", default_ico_path.string());
|
||||
fs::copy_file(icn, default_ico_path, fs::copy_options::overwrite_existing);
|
||||
}
|
||||
|
||||
boost::replace_all(ct, "re_category", ui->cbCategories->currentText().toStdString());
|
||||
tmp.append(tool_name + ".desktop");
|
||||
tmp.append(binaryName + ".desktop");
|
||||
;
|
||||
std::ofstream out(tmp.string(), std::ios::out);
|
||||
if (!out.is_open()) {
|
||||
|
@ -1,10 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 获取脚本所在目录的绝对路径
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
# 切换到脚本所在目录
|
||||
cd "$SCRIPT_DIR" || exit
|
||||
|
||||
# 打印当前目录
|
||||
echo "当前目录是:$SCRIPT_DIR"
|
||||
|
||||
# 将脚本所在目录添加到 LD_LIBRARY_PATH 环境变量
|
||||
export LD_LIBRARY_PATH="$SCRIPT_DIR"
|
||||
|
||||
# 定义 replace_string 脚本的绝对路径
|
||||
REPLACE_STRING_SCRIPT="$SCRIPT_DIR/replace_string"
|
||||
|
||||
# 执行其他操作
|
||||
./replace_string
|
||||
"$REPLACE_STRING_SCRIPT"
|
||||
|
Loading…
x
Reference in New Issue
Block a user