From 7134fc594dd631d2e06883a5b3afc86d17251c43 Mon Sep 17 00:00:00 2001 From: taynpg Date: Wed, 23 Oct 2024 16:56:38 +0800 Subject: [PATCH] add: can handle dependent, install to desktop not complete. --- .vscode/settings.json | 4 +-- CMakeLists.txt | 3 +- FunctionImp.cpp | 66 +++++++++++++++++++++++++++++++++++++++---- FunctionImp.h | 8 ++++-- InstallWidget.cpp | 1 - InstallWidget.h | 1 + MainFrame.h | 1 + MainPanel.cpp | 12 ++------ MainPanel.h | 2 ++ main.cpp | 2 +- 10 files changed, 79 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 2deef03..e5ca32f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,6 @@ { "files.autoSave": "onFocusChange", - "editor.fontSize": 13, + "editor.fontSize": 15, "editor.fontFamily": "'FiraCode Nerd Font Mono', 'FiraCode Nerd Font Mono', 'FiraCode Nerd Font Mono'", "cmake.configureOnOpen": true, "cmake.debugConfig": { @@ -21,7 +21,7 @@ }, "cmake.environment": { "PATH": "${env:PATH};D:/library/wxWidgets/lib/vc_x64_dll", - "LD_LIBRARY_PATH": "$LD_LIBRARY_PATH:" + "LD_LIBRARY_PATH": "$LD_LIBRARY_PATH:/home/lebo/library/wxWidgets/lib" }, // "cmake.configureSettings": { // "CMAKE_TOOLCHAIN_FILE": "${env:VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" diff --git a/CMakeLists.txt b/CMakeLists.txt index 245f4d8..503dfb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,11 @@ -cmake_minimum_required(VERSION 3.28) +cmake_minimum_required(VERSION 3.16) project(LinuxPack) set(CMAKE_CXX_STANDARD 17) set(CMAKE_PREFIX_PATH "/home/taynpg/mlib/wxwidget" + "/home/lebo/library/wxWidgets" "D:/Code/wxWidgets-install" ) diff --git a/FunctionImp.cpp b/FunctionImp.cpp index dd62f00..d2a8c50 100644 --- a/FunctionImp.cpp +++ b/FunctionImp.cpp @@ -4,6 +4,13 @@ #include "FunctionImp.h" #include +#include +#include +#include +#include +#include + +namespace fs = std::filesystem; CFunPack::CFunPack() = default; @@ -11,11 +18,13 @@ bool CFunPack::gen(const wxString& bin, const wxString& out_dir, const wxArraySt { auto ret_source = get_depend_on(bin, dirs); auto result = parse_result(ret_source); - return true; + return handle_copy(result, out_dir.ToStdString()); } wxArrayString CFunPack::get_depend_on(const wxString& bin, const wxArrayString& dirs) { + filename_ = fs::path(bin).filename().wstring(); + wxArrayString array; wxString cmd; if (!dirs.empty()) { @@ -37,7 +46,7 @@ wxArrayString CFunPack::get_depend_on(const wxString& bin, const wxArrayString& result.append(buffer); } - array = wxStringTokenize(result, "\t"); + array = wxStringTokenize(result, wxT("\t"), wxTOKEN_DEFAULT); return array; } @@ -76,9 +85,56 @@ std::list CFunPack::parse_result(const wxArrayString& array) return ret; } -CFunInstall::CFunInstall() = default; - -bool CFunInstall::install(const wxString& file, const wxString& ico) +bool CFunPack::handle_copy(const std::list& rets, const wxString& dest_dir) { + std::vector need_copy; + for (const auto& item : rets) { + // fs::path item_path(item); + // if (fs::is_symlink(item.ToStdString())) { + // auto real = fs::read_symlink(item.ToStdWstring()); + // auto read_full = fs::path(item).parent_path().append(real.wstring()); + // need_copy.push_back(read_full); + // wxMessageBox(wxString(read_full.wstring())); + // } + need_copy.push_back(item.ToStdWstring()); + } + + dest_dir_ = fs::path(dest_dir).append(filename_.ToStdWstring()).wstring(); + fs::create_directories(dest_dir_.ToStdWstring()); + for (const auto& item : need_copy) { + std::wstring new_path = fs::path(dest_dir_).append(item.filename().wstring()).wstring(); + fs::copy_file(item, new_path, fs::copy_options::overwrite_existing); + } + return true; +} + +CFunInstall::CFunInstall() = default; + +bool CFunInstall::install(const wxString& file, const wxString& category, const wxString& ico) +{ + fs::path full_path(file.ToStdWstring()); + wxString file_name = full_path.filename().wstring(); + wxString script_name = file_name + ".sh"; + wxString script_full_path = fs::path(file).parent_path().append(script_name.ToStdWstring()).wstring(); + + wxString script_content = + "IyEvYmluL2Jhc2gKU0NSSVBUX0RJUj0kKGNkICIkKGRpcm5hbWUgIiQwIikiICYmIHB3ZCkKY2QgIiRTQ1JJUFRfRElSIiB8fCBleGl0CmV4cG9ydCBMRF9MSUJSQVJZX1BBVEg9JExE" + "X0xJQlJBUllfUEFUSDoiJFNDUklQVF9ESVIiClJFUExBQ0VfU1RSSU5HX1NDUklQVD0iJFNDUklQVF9ESVIvcmVwbGFjZV9zdHJpbmciCiIkUkVQTEFDRV9TVFJJTkdfU0NSSVBUIgo" + "K"; + wxMemoryBuffer decodeData = wxBase64Decode(script_content); + script_content = wxString::FromUTF8(static_cast(decodeData.GetData()), decodeData.GetBufSize()); + + wxString desktop_content = + "W0Rlc2t0b3AgRW50cnldCk5hbWU9cmVfbmFtZQpDb21tZW50PXJlX2Rlc2NyaWJlCkV4ZWM9cmVfcGF0aApJY29uPXJlX2ljb24KVGVybWluYWw9ZmFsc2UKVHlwZT1BcHBsaWNhdGlv" + "bgpDYXRlZ29yaWVzPXJlX2NhdGVnb3J5Owo="; + wxMemoryBuffer decodeData2 = wxBase64Decode(script_content); + desktop_content = wxString::FromUTF8(static_cast(decodeData2.GetData()), decodeData2.GetBufSize()); + + script_content.Replace("replace_string", script_name); + desktop_content.Replace("Name", file_name); + desktop_content.Replace("Comment", ""); + desktop_content.Replace("Exec", ""); + desktop_content.Replace("Icon", ""); + desktop_content.Replace("Categories", ""); return true; } diff --git a/FunctionImp.h b/FunctionImp.h index e261fcb..cf0217e 100644 --- a/FunctionImp.h +++ b/FunctionImp.h @@ -11,11 +11,15 @@ class CFunPack { public: CFunPack(); +private: + wxString filename_; + wxString dest_dir_; public: bool gen(const wxString& bin, const wxString& out_dir, const wxArrayString& dirs); wxArrayString get_depend_on(const wxString& bin, const wxArrayString& dirs); std::list parse_result(const wxArrayString& array); + bool handle_copy(const std::list& rets, const wxString& dest_dir); }; class CFunInstall @@ -24,7 +28,7 @@ public: CFunInstall(); public: - bool install(const wxString& file, const wxString& ico = ""); + bool install(const wxString& file, const wxString& category, const wxString& ico = ""); }; -#endif //FUNCTIONIMP_H +#endif // FUNCTIONIMP_H diff --git a/InstallWidget.cpp b/InstallWidget.cpp index 21704a5..d3d9501 100644 --- a/InstallWidget.cpp +++ b/InstallWidget.cpp @@ -131,4 +131,3 @@ void CInstallDialog::selectIcoFile(wxCommandEvent& event) wxString filePath = openFileDialog.GetPath(); text_ico_file_->SetValue(filePath); } - diff --git a/InstallWidget.h b/InstallWidget.h index 9bb9b84..87100b0 100644 --- a/InstallWidget.h +++ b/InstallWidget.h @@ -15,6 +15,7 @@ class CInstallDialog : public wxDialog { private: CFunInstall* handle_{}; + private: wxPanel* panel_{}; wxBoxSizer* top_sizer_{}; diff --git a/MainFrame.h b/MainFrame.h index 4f0e40a..21550e5 100644 --- a/MainFrame.h +++ b/MainFrame.h @@ -11,6 +11,7 @@ class CMainFrame : public wxFrame { private: CMainPanel* panel_{}; + public: explicit CMainFrame(const wxString& title); diff --git a/MainPanel.cpp b/MainPanel.cpp index e839eeb..8adfe11 100644 --- a/MainPanel.cpp +++ b/MainPanel.cpp @@ -15,7 +15,6 @@ CMainPanel::~CMainPanel() delete handle_; } - void CMainPanel::InitPanel() { // 创建 wxStaticBoxSizer,并设置标题 @@ -80,7 +79,7 @@ void CMainPanel::InitPanel() // 创建一个伸缩的占位符 sizer auto* stretch_sizer = new wxBoxSizer(wxHORIZONTAL); - stretch_sizer->AddStretchSpacer(1); // 添加伸缩空间 + stretch_sizer->AddStretchSpacer(1); // 添加伸缩空间 // 添加伸缩的占位符 sizer 到主 sizer oper_sizer_->Add(btn_install_, 0, wxALL, g_Border); oper_sizer_->Add(stretch_sizer, 1, wxALL | wxEXPAND); @@ -173,14 +172,9 @@ void CMainPanel::addEnv(wxCommandEvent& event) void CMainPanel::selectBinaryFile(wxCommandEvent& event) { - wxFileDialog openFileDialog( - this, _("Open file"), "", "", - "*", - wxFD_OPEN | wxFD_FILE_MUST_EXIST - ); + wxFileDialog openFileDialog(this, _("Open file"), "", "", "*", wxFD_OPEN | wxFD_FILE_MUST_EXIST); - if (openFileDialog.ShowModal() == wxID_CANCEL) - return; + if (openFileDialog.ShowModal() == wxID_CANCEL) return; wxString filePath = openFileDialog.GetPath(); text_select_ctrl_->SetValue(filePath); diff --git a/MainPanel.h b/MainPanel.h index a3d47e8..5464efd 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -37,10 +37,12 @@ protected: wxButton* btn_gen_{}; wxButton* btn_exit_{}; wxButton* btn_install_{}; + public: explicit CMainPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(g_Width, g_Heigh), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString); ~CMainPanel() override; + public: void InitPanel(); diff --git a/main.cpp b/main.cpp index 7ff3b8c..064846b 100644 --- a/main.cpp +++ b/main.cpp @@ -6,7 +6,7 @@ class CLinuxPack : public wxApp public: bool OnInit() override { - auto* frame = new CMainFrame(wxT("Linux二进制工具")); + auto* frame = new CMainFrame(wxT("Linux二进制工具 v1.0.1")); frame->Show(true); return true; }