Skip to content

Commit 5360451

Browse files
committed
Properly handle editors installed via DownloadAssistant on Mac
1 parent 075b508 commit 5360451

File tree

7 files changed

+56
-9
lines changed

7 files changed

+56
-9
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/wxWidgets/build/cmake/modules"
2424
message("module path = ${CMAKE_MODULE_PATH}")
2525

2626
file(GLOB source "source/*.cpp" "source/*.hpp" "source/*.h")
27-
add_executable("${PROJECT_NAME}" WIN32 ${source} "source/wxmac.icns" "source/windows.rc")
27+
if (APPLE)
28+
set(OBJCPP "source/AppleUtilities.h" "source/AppleUtilities.mm")
29+
endif()
30+
add_executable("${PROJECT_NAME}" WIN32 ${source} "source/wxmac.icns" "source/windows.rc" ${OBJCPP})
2831
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
2932

3033
#wxwidgets

source/AppleUtilities.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
#include <cstdint>
3+
4+
void getCFBundleVersionFromPlist(const char* path, char* outbuf, uint8_t outbuf_size);

source/AppleUtilities.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "AppleUtilities.h"
2+
#import <Cocoa/Cocoa.h>
3+
4+
void getCFBundleVersionFromPlist(const char* path, char* outbuf, uint8_t outbuf_size){
5+
NSString* pstr = [NSString stringWithUTF8String:path];
6+
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:pstr];
7+
NSString* item = dict[@"CFBundleVersion"];
8+
9+
memset(outbuf, 0, outbuf_size);
10+
strncpy(outbuf, [item cStringUsingEncoding:NSUTF8StringEncoding], outbuf_size);
11+
}

source/add_install_dlg_derived.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ AddNewInstallDlg::AddNewInstallDlg(wxWindow* parent) : AddNewInstallDlgBase(pare
3939
this->GetAllVersions();
4040
});
4141
th.detach();
42-
4342
}
4443

4544
void AddNewInstallDlg::PopulateTable(wxCommandEvent&){

source/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
static const std::string projectsFile = "projects.txt";
1515
static const std::string editorPathsFile = "editorPaths.txt";
1616
static const std::string templatePrefix = "com.unity.template";
17-
static const std::string AppVersion = "v1.41";
17+
static const std::string AppVersion = "v1.42";
1818

1919
//structure for representing an editor and for locating it
2020
struct editor{

source/interface_derived.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#include <fmt/format.h>
2020
#include <filesystem>
21+
#if __APPLE__
22+
#include "AppleUtilities.h"
23+
#endif
2124
using namespace std;
2225
using namespace std::filesystem;
2326

@@ -495,11 +498,33 @@ void MainFrameDerived::LoadEditorVersions(){
495498
auto p = path / entry->d_name / executable;
496499
if (filesystem::exists(p)){
497500
//add it to the list
498-
a.Add(string(entry->d_name) + " - " + path.string());
499-
500-
//add it to the backing datastructure
501-
editor e = {entry->d_name, path};
502-
editors.push_back(e);
501+
#if __APPLE__
502+
// the Unity Download Assistant on Mac does not allow multiple
503+
// unity versions at once, which sucks. To get the version,
504+
// we need to parse the info.plist inside of Unity.app
505+
if (strcmp(entry->d_name, ".") == 0){
506+
auto infopath = path / entry->d_name / "Unity.app" / "Contents" / "Info.plist";
507+
if (filesystem::exists(infopath)){
508+
// read the file and look for CFBundleVersion
509+
char buffer[16];
510+
getCFBundleVersionFromPlist(infopath.string().c_str(), buffer, sizeof(buffer));
511+
512+
a.Add(string(buffer) + " - " + path.string());
513+
//add it to the backing datastructure
514+
editor e = {buffer, path};
515+
516+
editors.push_back(e);
517+
}
518+
}
519+
else
520+
#endif
521+
{
522+
a.Add(string(entry->d_name) + " - " + path.string());
523+
//add it to the backing datastructure
524+
editor e = {entry->d_name, path};
525+
526+
editors.push_back(e);
527+
}
503528
}
504529
}
505530
entry = readdir(dir);

source/interface_derived.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ class MainFrameDerived : public MainFrame{
142142
if (id != wxNOT_FOUND){
143143
editor& e = editors[id];
144144
std::filesystem::path path = e.path / e.name;
145-
reveal_in_explorer(path.string());
145+
if (!std::filesystem::exists(path)){
146+
reveal_in_explorer(e.path);
147+
}
148+
else{
149+
reveal_in_explorer(path.string());
150+
}
146151
}
147152
}
148153
/**

0 commit comments

Comments
 (0)