Skip to content

Commit 9da9c76

Browse files
committed
Fix mac compile errors, implement uninstall on mac
1 parent 277458a commit 9da9c76

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

source/form.fbp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,8 @@
12281228
<property name="font"></property>
12291229
<property name="gripper">0</property>
12301230
<property name="hidden">0</property>
1231-
<property name="id">wxID_ANY</property>
1232-
<property name="label">Remove</property>
1231+
<property name="id">wxID_NO</property>
1232+
<property name="label">Uninstall</property>
12331233
<property name="margins"></property>
12341234
<property name="markup">0</property>
12351235
<property name="max_size"></property>

source/globals.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ struct editor{
2525
#if defined __APPLE__
2626
#include <pwd.h>
2727
//the location to store application data
28-
static const std::string datapath = getpwuid(getuid())->pw_dir + string("/Library/Application Support/UnityHubNative");
28+
static const std::string datapath = getpwuid(getuid())->pw_dir + std::string("/Library/Application Support/UnityHubNative");
2929
static const char dirsep = '/';
3030

31-
static const std::string cachedir = getpwuid(getuid())->pw_dir + string("/Library/Caches/com.ravbug.UnityHubNative");
31+
static const std::string cachedir = getpwuid(getuid())->pw_dir + std::string("/Library/Caches/com.ravbug.UnityHubNative");
3232
static const std::string installerExt = "dmg";
3333

3434
//where to find various Unity things on macOS
@@ -160,7 +160,7 @@ inline bool file_exists(const std::string& name){
160160
inline void launch_process(const std::string& command) {
161161
#if defined __APPLE__ || defined __linux__
162162
//the '&' runs the command nonblocking, and >/dev/null 2>&1 destroys output
163-
FILE* stream = popen(string(command + null_device + " &").c_str(), "r");
163+
FILE* stream = popen(std::string(command + null_device + " &").c_str(), "r");
164164
pclose(stream);
165165

166166
#elif _WIN32
@@ -172,10 +172,10 @@ inline void launch_process(const std::string& command) {
172172

173173
inline void reveal_in_explorer(const std::string& path){
174174
#if defined __APPLE__
175-
string command = "open \"" + path + "\"";
175+
std::string command = "open \"" + path + "\"";
176176

177177
#elif defined __linux__
178-
string command = "xdg-open \"" + path + "\"";
178+
std::string command = "xdg-open \"" + path + "\"";
179179

180180
#elif defined _WIN32
181181
//do not surround the paths in quotes, it will not work

source/interface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
108108
launchHubBtn = new wxButton( installs_pane, wxID_BACKWARD, wxT("Add New"), wxDefaultPosition, wxDefaultSize, 0 );
109109
bSizer5->Add( launchHubBtn, 0, wxALL|wxEXPAND, 5 );
110110

111-
removeInstallBtn = new wxButton( installs_pane, wxID_ANY, wxT("Remove"), wxDefaultPosition, wxDefaultSize, 0 );
111+
removeInstallBtn = new wxButton( installs_pane, wxID_NO, wxT("Uninstall"), wxDefaultPosition, wxDefaultSize, 0 );
112112
bSizer5->Add( removeInstallBtn, 0, wxALL|wxEXPAND, 5 );
113113

114114
wxButton* reloadInstalls;

source/interface_derived.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#else
1616
#include <dirent.h>
1717
#endif
18+
19+
#include <fmt/format.h>
1820
using namespace std;
1921

2022
#define LEARN_TAB 2
@@ -38,6 +40,7 @@ EVT_BUTTON(wxID_NEW,MainFrameDerived::OnCreateProject)
3840
EVT_BUTTON(wxID_FIND,MainFrameDerived::OnLocateInstall)
3941
EVT_BUTTON(wxID_CLEAR,MainFrameDerived::OnRemoveInstallPath)
4042
EVT_BUTTON(wxID_DELETE,MainFrameDerived::OnRemoveProject)
43+
EVT_BUTTON(wxID_NO,MainFrameDerived::OnUninstall)
4144
EVT_BUTTON(wxID_JUMP_TO,MainFrameDerived::OnRevealProject)
4245
EVT_BUTTON(wxID_BACKWARD,MainFrameDerived::OnOpenHub)
4346
EVT_BUTTON(wxID_RELOAD,MainFrameDerived::OnReloadEditors)
@@ -505,3 +508,28 @@ void MainFrameDerived::OnOpenHub(wxCommandEvent &event){
505508
AddNewInstallDlg dlg(this);
506509
dlg.Show();
507510
}
511+
512+
void MainFrameDerived::OnUninstall(wxCommandEvent &){
513+
auto selected = installsList->GetSelection();
514+
if (selected != -1){
515+
auto name = installsList->GetString(selected);
516+
517+
auto pathsep = name.find_last_of("-");
518+
519+
string_view container(name.data() + pathsep + 2,name.size() - pathsep - 2);
520+
string_view version(name.data(),pathsep - 2);
521+
522+
#ifdef __APPLE__
523+
// delete the folder
524+
auto path = fmt::format("{}/{}",container,version);
525+
int answer = wxMessageBox(fmt::format("Will delete {}, is this ok?", path), "Confirm deletion", wxYES | wxNO | wxICON_ERROR);
526+
if (answer == wxYES){
527+
std::filesystem::remove_all(path);
528+
ReloadData();
529+
}
530+
#elif defined _WIN32
531+
// execute the uninstaller
532+
#endif
533+
}
534+
535+
}

source/interface_derived.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class MainFrameDerived : public MainFrame{
9292
void OnRevealProject(wxCommandEvent& event);
9393
void OnOpenWith(wxCommandEvent& event);
9494
void OnPageChanging(wxBookCtrlEvent& event);
95+
void OnUninstall(wxCommandEvent&);
9596
void OnUpdate(wxCommandEvent& event){
9697
wxLaunchDefaultBrowser("https://github.com/ravbug/unityhubnative/releases/latest");
9798
}

0 commit comments

Comments
 (0)