add: can handle dependent, install to desktop not complete.
This commit is contained in:
parent
f885eeb8b1
commit
7134fc594d
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -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"
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -4,6 +4,13 @@
|
||||
|
||||
#include "FunctionImp.h"
|
||||
#include <wx/tokenzr.h>
|
||||
#include <wx/filename.h>
|
||||
#include <wx/log.h>
|
||||
#include <filesystem>
|
||||
#include <wx/base64.h>
|
||||
#include <wx/msgdlg.h>
|
||||
|
||||
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<wxString> 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<wxString>& rets, const wxString& dest_dir)
|
||||
{
|
||||
std::vector<fs::path> 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<const char*>(decodeData.GetData()), decodeData.GetBufSize());
|
||||
|
||||
wxString desktop_content =
|
||||
"W0Rlc2t0b3AgRW50cnldCk5hbWU9cmVfbmFtZQpDb21tZW50PXJlX2Rlc2NyaWJlCkV4ZWM9cmVfcGF0aApJY29uPXJlX2ljb24KVGVybWluYWw9ZmFsc2UKVHlwZT1BcHBsaWNhdGlv"
|
||||
"bgpDYXRlZ29yaWVzPXJlX2NhdGVnb3J5Owo=";
|
||||
wxMemoryBuffer decodeData2 = wxBase64Decode(script_content);
|
||||
desktop_content = wxString::FromUTF8(static_cast<const char*>(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;
|
||||
}
|
||||
|
@ -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<wxString> parse_result(const wxArrayString& array);
|
||||
bool handle_copy(const std::list<wxString>& 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
|
||||
|
@ -131,4 +131,3 @@ void CInstallDialog::selectIcoFile(wxCommandEvent& event)
|
||||
wxString filePath = openFileDialog.GetPath();
|
||||
text_ico_file_->SetValue(filePath);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ class CInstallDialog : public wxDialog
|
||||
{
|
||||
private:
|
||||
CFunInstall* handle_{};
|
||||
|
||||
private:
|
||||
wxPanel* panel_{};
|
||||
wxBoxSizer* top_sizer_{};
|
||||
|
@ -11,6 +11,7 @@ class CMainFrame : public wxFrame
|
||||
{
|
||||
private:
|
||||
CMainPanel* panel_{};
|
||||
|
||||
public:
|
||||
explicit CMainFrame(const wxString& title);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user