Skip to content

Commit da75dd8

Browse files
author
Ravbug
committed
Preliminary implementation for #31
~ do not remove projects from the list if they cannot be found + error checking around project launching and reveal in explorer if the path cannot be found
1 parent c482a8d commit da75dd8

File tree

6 files changed

+41
-48
lines changed

6 files changed

+41
-48
lines changed

source/Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleExecutable</key>
88
<string>$(PRODUCT_NAME)</string>
99
<key>CFBundleGetInfoString</key>
10-
<string>$(PRODUCT_NAME) (c) 2022 Ravbug</string>
10+
<string>$(PRODUCT_NAME) (c) 2023 Ravbug</string>
1111
<key>CFBundleIconFile</key>
1212
<string>wxmac.icns</string>
1313
<key>CFBundleIdentifier</key>
@@ -22,7 +22,7 @@
2222
<string>it</string>
2323
</array>
2424
<key>CFBundleLongVersionString</key>
25-
<string>(c) 2022 Ravbug</string>
25+
<string>(c) 2023 Ravbug</string>
2626
<key>CFBundleName</key>
2727
<string>$(PRODUCT_NAME)</string>
2828
<key>CFBundlePackageType</key>
@@ -36,7 +36,7 @@
3636
<key>LSApplicationCategoryType</key>
3737
<string>public.app-category.developer-tools</string>
3838
<key>NSHumanReadableCopyright</key>
39-
<string>Copyright 2022 Ravbug</string>
39+
<string>Copyright 2023 Ravbug</string>
4040
<key>NSPrincipalClass</key>
4141
<string>wxNSApplication</string>
4242
</dict>

source/activation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void PersonalActivationDlg::OnCreateHit(wxCommandEvent& evt)
4949
wxSetWorkingDirectory(root.string());
5050
wxProcess proc(wxPROCESS_DEFAULT);
5151
wxExecute(cmd, wxEXEC_SYNC);
52-
reveal_in_explorer(wxGetCwd());
52+
reveal_in_explorer(std::filesystem::path(wxGetCwd().ToStdString()));
5353
wxSetWorkingDirectory(cwd);
5454
}
5555
}

source/globals.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "globals.h"
22
#include <fmt/format.h>
33
#include <wx/listctrl.h>
4+
#include <wx/msgdlg.h>
45

56
void launch_process(const std::string& command, int flags) {
67
#if defined __APPLE__ || defined __linux__
@@ -16,7 +17,7 @@ void launch_process(const std::string& command, int flags) {
1617
#endif
1718
}
1819

19-
void reveal_in_explorer(const std::string& path) {
20+
void reveal_in_explorer(const std::filesystem::path& path) {
2021
#if defined __APPLE__
2122
std::string command = "open \"" + path + "\"";
2223

@@ -25,9 +26,15 @@ void reveal_in_explorer(const std::string& path) {
2526

2627
#elif defined _WIN32
2728
//do not surround the paths in quotes, it will not work
28-
std::string command = "\\Windows\\explorer.exe \"" + path + "\"";
29+
std::string command = "\\Windows\\explorer.exe \"" + path.string() + "\"";
2930
#endif
30-
launch_process(command);
31+
if (std::filesystem::exists(path)) {
32+
launch_process(command);
33+
}
34+
else {
35+
wxMessageBox("The project at " + path.string() + " could not be found.", "Cannot Reveal Project", wxOK | wxICON_ERROR);
36+
}
37+
3138
}
3239

3340
long wxListCtrl_get_selected(wxListCtrl* listCtrl) {

source/globals.h

Lines changed: 2 additions & 2 deletions
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.52";
17+
static constexpr std::string_view AppVersion = "v1.53";
1818

1919
struct wxListCtrl;
2020
struct wxWindow;
@@ -96,7 +96,7 @@ void launch_process(const std::string& command, int flags = 0);
9696
* Open system file explorer to path
9797
* @param path the item to show
9898
*/
99-
void reveal_in_explorer(const std::string& path);
99+
void reveal_in_explorer(const std::filesystem::path& path);
100100

101101
/**
102102
Gets the first selected item in a wxListCtrl. If the wxListCtrl is set to single selection, this method will retrive the only selected item.

source/interface_derived.cpp

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -203,27 +203,10 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
203203
vector<string> erroredProjects;
204204
//load each project (each path is on its own line)
205205
while (getline(in, line)){
206-
try{
207-
project pr = LoadProject(line);
208-
AddProject(pr,filter);
209-
}
210-
catch(runtime_error& e){
211-
//remove project
212-
erroredProjects.push_back(line);
213-
}
214-
}
215-
//alert user if projects could not be loaded
216-
if (erroredProjects.size() > 0){
217-
//build string
218-
string str;
219-
for (const auto& s : erroredProjects){
220-
str += s + "\n";
221-
}
222-
//message box
223-
wxMessageBox("The following projects could not be loaded. They have been removed from the list.\n\n"+str, "Loading error", wxOK | wxICON_WARNING );
224-
225-
//save to remove the broken projects
226-
SaveProjects();
206+
207+
project pr = LoadProject(line);
208+
AddProject(pr,filter);
209+
227210
}
228211
}
229212
}
@@ -243,7 +226,7 @@ void MainFrameDerived::OnAbout(wxCommandEvent& event)
243226
{
244227
wxAboutDialogInfo aboutInfo;
245228
aboutInfo.SetName("Unity Hub Native");
246-
aboutInfo.SetCopyright("(C) Ravbug 2022");
229+
aboutInfo.SetCopyright("(C) Ravbug 2023");
247230
aboutInfo.SetDescription("Developed with wxWidgets in C++");
248231
#if defined __linux__
249232
aboutInfo.SetWebSite("https://github.com/ravbug/UnityHubNative");
@@ -365,7 +348,7 @@ void MainFrameDerived::OnRevealProject(wxCommandEvent& event){
365348
long selectedIndex = wxListCtrl_get_selected(projectsList);
366349
if (selectedIndex > -1){
367350
project& p = projects[selectedIndex];
368-
reveal_in_explorer(p.path.string());
351+
reveal_in_explorer(p.path);
369352
}
370353
}
371354

@@ -393,6 +376,11 @@ void MainFrameDerived::OnOpenWith(wxCommandEvent& event){
393376
void MainFrameDerived::OpenProject(const long& index){
394377
//get the project
395378
project p = projects[index];
379+
380+
if (!std::filesystem::exists(p.path)) {
381+
wxMessageBox("Cannot open project at " + p.path.string() + " because it could not be found.", "Cannot Open Project", wxOK | wxICON_ERROR);
382+
return;
383+
}
396384

397385
for (const auto& path : installPaths) {
398386
auto editorPath = path / p.version / executable;
@@ -463,29 +451,27 @@ string MainFrameDerived::GetPathFromDialog(const string& message)
463451
project MainFrameDerived::LoadProject(const std::filesystem::path &p_as_fs){
464452
//error if the file does not exist
465453
if (!filesystem::exists(p_as_fs)){
466-
throw runtime_error(p_as_fs.string() + " does not exist.");
454+
//throw runtime_error(p_as_fs.string() + " does not exist.");
467455
}
468456

469457
//the name is the final part of the path
470458
string name = p_as_fs.filename().string();
471-
459+
string version = "??";
460+
472461
//Load ProjectSettings/ProjectVersion.txt to get the editor version, if it exists
473462
std::filesystem::path projSettings = p_as_fs / "ProjectSettings" / "ProjectVersion.txt";
474-
if (!filesystem::exists(projSettings)){
475-
throw runtime_error("No ProjectVersion.txt found at " + p_as_fs.string() + "\n\nEnsure the folder you selected is the root folder of a complete Unity project.");
463+
if (filesystem::exists(projSettings)){
464+
//the first line of ProjectVersion.txt contains the editor verison as plain text
465+
ifstream inFile;
466+
inFile.open(projSettings);
467+
getline(inFile, version);
468+
version = version.substr(17);
476469
}
477470

478-
//the first line of ProjectVersion.txt contains the editor verison as plain text
479-
string version;
480-
ifstream inFile;
481-
inFile.open(projSettings);
482-
getline(inFile,version);
483-
version = version.substr(17);
484-
485471
//get the modification date
486-
struct stat fileInfo;
472+
struct stat fileInfo {};
487473
if (stat(p_as_fs.string().c_str(), &fileInfo) != 0) {
488-
throw runtime_error("Cannot get modification date. Ensure this program has access to "+p_as_fs.string());
474+
//throw runtime_error("Cannot get modification date. Ensure this program has access to "+p_as_fs.string());
489475
}
490476

491477
project p = {name,version,ctime(&fileInfo.st_mtime),p_as_fs,};

source/interface_derived.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ class MainFrameDerived : public MainFrame{
139139
editor& e = editors[id];
140140
std::filesystem::path path = e.path / e.name;
141141
if (!std::filesystem::exists(path)){
142-
reveal_in_explorer(e.path.string());
142+
reveal_in_explorer(e.path);
143143
}
144144
else{
145-
reveal_in_explorer(path.string());
145+
reveal_in_explorer(path);
146146
}
147147
}
148148
}
@@ -153,7 +153,7 @@ class MainFrameDerived : public MainFrame{
153153
void OnRevealInstallLocation(wxCommandEvent& event){
154154
int id = installsPathsList->GetSelection();
155155
if (id != wxNOT_FOUND){
156-
reveal_in_explorer(installPaths[id].string());
156+
reveal_in_explorer(installPaths[id]);
157157
}
158158
}
159159
void OnOpenHub(wxCommandEvent& event);

0 commit comments

Comments
 (0)