Skip to content

Commit 2d9d13c

Browse files
committed
Launch installer on Windows
add_install_dlg_derived.cpp, interface_derived.hpp + correctly execute process to invoke UAC globals.hpp - disable DPI scaling due to Windows.h lunacy
1 parent 10d89c9 commit 2d9d13c

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

source/add_install_dlg_derived.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
using namespace std;
1010
#define UPDATEEVT 2004
1111
#define REENABLEEVT 2005
12+
#define EXECUTEEVT 2006
1213
wxDEFINE_EVENT(updateEvt, wxCommandEvent);
1314
wxDEFINE_EVENT(reenableEvt, wxCommandEvent);
15+
wxDEFINE_EVENT(executeEvt, wxCommandEvent);
1416

1517
//Declare events here
1618
wxBEGIN_EVENT_TABLE(AddNewInstallDlg, wxDialog)
1719
EVT_COMMAND(UPDATEEVT, updateEvt, AddNewInstallDlg::PopulateTable)
1820
EVT_COMMAND(REENABLEEVT, reenableEvt, AddNewInstallDlg::Reenable)
21+
EVT_COMMAND(EXECUTEEVT, executeEvt, AddNewInstallDlg::ExecuteProc)
1922
EVT_BUTTON(wxID_FILE,AddNewInstallDlg::InstallSelected)
2023
EVT_BUTTON(INSTALLVIAHUB,AddNewInstallDlg::InstallSelectedWithHub)
2124
EVT_SEARCHCTRL_SEARCH_BTN(wxID_FIND,AddNewInstallDlg::Filter)
@@ -172,12 +175,20 @@ void AddNewInstallDlg::InstallSelected(wxCommandEvent&){
172175
}
173176
else{
174177
// write the file to temp location
175-
auto outpath = fmt::format("{}{}{}{}.{}", cachedir,dirsep,"UnityDownloadAssistant",data.hashcode,installerExt);
178+
auto outpath = fmt::format("{}{}{}.{}", cachedir,"UnityDownloadAssistant",data.hashcode,installerExt);
176179
ofstream outfile(outpath, std::ios::binary);
177180
outfile.write(r.text.c_str(),r.text.size());
178181

179182
// open the file
180-
launch_process(fmt::format("open \"{}\"", outpath));
183+
wxCommandEvent lnevt(executeEvt);
184+
#ifdef __APPLE__
185+
lnevt.SetString(fmt::format("open \"{}\"", outpath));
186+
#elif defined _WIN32
187+
lnevt.SetString(fmt::format("\"{}\"", outpath));
188+
#endif
189+
lnevt.SetId(EXECUTEEVT);
190+
wxPostEvent(this,lnevt);
191+
181192
wxCommandEvent evt(reenableEvt);
182193
evt.SetId(REENABLEEVT);
183194
wxPostEvent(this, evt);
@@ -206,3 +217,13 @@ void AddNewInstallDlg::Reenable(wxCommandEvent &){
206217
installViaHubBtn->Enable();
207218
installBtn->SetLabel("Install Selected");
208219
}
220+
221+
void AddNewInstallDlg::ExecuteProc(wxCommandEvent& evt)
222+
{
223+
auto cmd = evt.GetString();
224+
#ifdef _WIN32
225+
ShellExecute(0, 0, cmd.c_str(), NULL, 0, SW_SHOW);
226+
#else
227+
launch_process(cmd.ToStdString());
228+
#endif
229+
}

source/globals.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct editor{
2828
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 + std::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
@@ -46,8 +46,6 @@ struct editor{
4646
#define popen _popen
4747
#define pclose _pclose
4848
#define mkdir _mkdir
49-
#include <Windows.h>
50-
#include <gdiplus.h>
5149
#include <wx/wx.h>
5250
static const std::string datapath = getenv("HOMEPATH") + std::string("\\AppData\\Roaming\\UnityHubNative");
5351
static const char dirsep = '\\';
@@ -66,11 +64,13 @@ struct editor{
6664
@returns the calculated display scale factor using GDI+
6765
*/
6866
inline float get_WIN_dpi_multiple() {
67+
return 1;
68+
/*
6969
FLOAT dpiX;
7070
HDC screen = GetDC(0);
7171
dpiX = static_cast<FLOAT>(GetDeviceCaps(screen, LOGPIXELSX));
7272
ReleaseDC(0, screen);
73-
return dpiX / 96;
73+
return dpiX / 96;*/
7474
}
7575

7676
/**
@@ -157,15 +157,15 @@ inline bool file_exists(const std::string& name){
157157
@param command the shell command to run on the system
158158
@note The command passed to this function must be correct for the system it is running on. If it is not correct, the function will appear to do nothing.
159159
*/
160-
inline void launch_process(const std::string& command) {
160+
inline void launch_process(const std::string& command, int flags = 0) {
161161
#if defined __APPLE__ || defined __linux__
162162
//the '&' runs the command nonblocking, and >/dev/null 2>&1 destroys output
163163
FILE* stream = popen(std::string(command + null_device + " &").c_str(), "r");
164164
pclose(stream);
165165

166166
#elif _WIN32
167167
//call wxExecute with the Async flag
168-
wxExecute(wxString(command),0);
168+
wxExecute(wxString(command),flags);
169169

170170
#endif
171171
}

source/interface_derived.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class AddNewInstallDlg : AddNewInstallDlgBase{
239239
void InstallSelectedWithHub(wxCommandEvent&);
240240
void Filter(wxCommandEvent&);
241241
void Reenable(wxCommandEvent&);
242+
void ExecuteProc(wxCommandEvent&);
242243

243244
void PopulateWithFilter(const std::function<bool(const version&)>);
244245
wxDECLARE_EVENT_TABLE();

0 commit comments

Comments
 (0)