Skip to content

Commit 4470163

Browse files
committed
Begin trying to deal with external mac installs
1 parent 4fafccd commit 4470163

File tree

5 files changed

+38
-50
lines changed

5 files changed

+38
-50
lines changed

source/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<key>CFBundlePackageType</key>
2929
<string>APPL</string>
3030
<key>CFBundleShortVersionString</key>
31-
<string>1.55</string>
31+
<string>1.56</string>
3232
<key>CFBundleSignature</key>
3333
<string>UNHn</string>
3434
<key>CFBundleVersion</key>

source/add_install_dlg_derived.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void AddNewInstallDlg::GetAllVersions(){
107107
if (strncmp(r.text.data() + i, match.data(), match.size()) == 0){
108108
// we have found a version, extract its data
109109
auto begin = i + match.size();
110-
auto end = r.text.find_first_of("\"", i + match.size());
110+
auto end = std::min(r.text.find_first_of("\"", i + match.size()), r.text.find_first_of("\\", i + match.size()));
111111
std::string_view versiondata(r.text.data() + begin,end-begin);
112112

113113
// get the version and hashcode
@@ -118,7 +118,8 @@ void AddNewInstallDlg::GetAllVersions(){
118118

119119
auto version = string(string_view(versiondata.data(),slashpos));
120120
if (versionDates.find(version) != versionDates.end()){
121-
versions.emplace_back(version,string(string_view(versiondata.data() + slashpos + 1, versiondata.size() - slashpos - 1)), versionDates.at(version));
121+
auto hashcode = string(string_view(versiondata.data() + slashpos + 1, versiondata.size() - slashpos - 1));
122+
versions.emplace_back(version,hashcode, versionDates.at(version));
122123
}
123124
}
124125
}

source/create_dialog_derived.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ void CreateProjectDialogD::loadTemplates(const editor& e){
168168
templateCtrl->ClearAll();
169169

170170
//open the folder
171+
#if __APPLE__
172+
auto templatesFolder = e.path / templatesDir;
173+
174+
#else
171175
auto templatesFolder = e.path /e.name / templatesDir;
176+
#endif
172177

173178
for(const auto& entry : std::filesystem::directory_iterator{templatesFolder}){
174179
//does the file start with the correct prefix?

source/globals.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
static constexpr std::string_view projectsFile = "projects.txt";
1515
static constexpr std::string_view editorPathsFile = "editorPaths.txt";
1616
static constexpr std::string_view templatePrefix = "com.unity.template";
17-
static constexpr std::string_view AppVersion = "v1.55";
17+
static constexpr std::string_view AppVersion = "v1.56";
1818

1919
struct wxListCtrl;
2020
struct wxWindow;
@@ -117,7 +117,11 @@ struct editor {
117117
std::string name;
118118
std::filesystem::path path;
119119
decltype(path) executablePath() const {
120+
#if __APPLE__
121+
return path / executable;
122+
#else
120123
return path / name / executable;
124+
#endif
121125
}
122126

123127
bool operator==(const editor& other) {

source/interface_derived.cpp

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -395,23 +395,6 @@ void MainFrameDerived::OpenProject(const long& index){
395395
return;
396396
}
397397
}
398-
#if __APPLE__
399-
for (const auto& path : installPaths) {
400-
if (filesystem::exists(path / executable)) {
401-
// mac unlabeled version
402-
auto unlabeledPath = path / executable;
403-
char buffer[16];
404-
auto unlabeledPathInfo = path / "Unity.app" / "Contents" / "Info.plist";
405-
getCFBundleVersionFromPlist(unlabeledPathInfo.string().c_str(), buffer, sizeof(buffer));
406-
if (p.version == buffer) {
407-
string cmd = "\"" + unlabeledPath.string() + "\" -projectpath \"" + p.path.string() + "\"";
408-
launch_process(cmd);
409-
return;
410-
}
411-
}
412-
}
413-
#endif
414-
415398

416399
// prompt the user to choose a new editor because we couldn't locate one
417400
wxCommandEvent evt;
@@ -445,7 +428,7 @@ const char* const PlatToStr(TargetPlatform plat) {
445428
@param e the editor version to use when opening the project
446429
*/
447430
void MainFrameDerived::OpenProject(const project& p, const editor& e, TargetPlatform plat){
448-
string cmd = "\"" + (e.path / e.name / executable).string() + "\" -projectpath \"" + p.path.string() + "\"";
431+
string cmd = "\"" + e.executablePath().string() + "\" -projectpath \"" + p.path.string() + "\"";
449432
if (plat != TargetPlatform::CurrentPlatform) {
450433
auto str = PlatToStr(plat);
451434
cmd += fmt::format(" -buildTarget {}", str);
@@ -595,8 +578,6 @@ void MainFrameDerived::LoadEditorVersions(){
595578
wxCommandEvent e;
596579
OnSelectEditor(e);
597580
editors.clear();
598-
599-
600581

601582
//iterate over the search paths
602583
for (auto& path : installPaths){
@@ -630,38 +611,35 @@ void MainFrameDerived::LoadEditorVersions(){
630611
//is this a folder?
631612
if (dir_entry.is_directory()){
632613
//does this folder have a valid executable inside?
633-
auto p = path / entry.filename() / executable;
634-
if (filesystem::exists(p)){
635-
//add it to the list
614+
615+
//add it to the list
636616
#if __APPLE__
637-
// the Unity Download Assistant on Mac does not allow multiple
638-
// unity versions at once, which sucks. To get the version,
639-
// we need to parse the info.plist inside of Unity.app
640-
auto pathstr = entry.filename().string();
641-
if (pathstr == "."){
642-
auto infopath = path / entry.filename() / "Unity.app" / "Contents" / "Info.plist";
643-
if (filesystem::exists(infopath)){
644-
// read the file and look for CFBundleVersion
645-
char buffer[16]{0};
646-
getCFBundleVersionFromPlist(infopath.string().c_str(), buffer, sizeof(buffer));
647-
648-
//add it to the backing datastructure
649-
editor e = {buffer, path};
650-
addInstall(e);
651-
}
652-
}
653-
else
654-
#endif
655-
{
656-
//add it to the backing datastructure
657-
editor e = {entry.filename(), path};
658-
addInstall(e);
659-
}
617+
// the Unity Download Assistant on Mac does not allow multiple
618+
// unity versions at once, which sucks. To get the version,
619+
// we need to parse the info.plist inside of Unity.app
620+
auto infopath = entry / "Unity.app" / "Contents" / "Info.plist";
621+
if (filesystem::exists(infopath)){
622+
// read the file and look for CFBundleVersion
623+
char buffer[16]{0};
624+
getCFBundleVersionFromPlist(infopath.string().c_str(), buffer, sizeof(buffer));
625+
626+
//add it to the backing datastructure
627+
editor e = {buffer, entry};
628+
addInstall(e);
660629
}
630+
#else
631+
auto p = entry / executable;
632+
if (filesystem::exists(p)){
633+
//add it to the backing datastructure
634+
editor e = {entry.filename(), p};
635+
addInstall(e);
636+
}
637+
#endif
661638
}
662639

663640
installsList->Append(a);
664641
}
642+
665643
}
666644
}
667645

0 commit comments

Comments
 (0)