Skip to content

Commit

Permalink
Preliminary implementation for #31
Browse files Browse the repository at this point in the history
~ 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
  • Loading branch information
Ravbug committed May 21, 2023
1 parent c482a8d commit da75dd8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
6 changes: 3 additions & 3 deletions source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleGetInfoString</key>
<string>$(PRODUCT_NAME) (c) 2022 Ravbug</string>
<string>$(PRODUCT_NAME) (c) 2023 Ravbug</string>
<key>CFBundleIconFile</key>
<string>wxmac.icns</string>
<key>CFBundleIdentifier</key>
Expand All @@ -22,7 +22,7 @@
<string>it</string>
</array>
<key>CFBundleLongVersionString</key>
<string>(c) 2022 Ravbug</string>
<string>(c) 2023 Ravbug</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
Expand All @@ -36,7 +36,7 @@
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2022 Ravbug</string>
<string>Copyright 2023 Ravbug</string>
<key>NSPrincipalClass</key>
<string>wxNSApplication</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion source/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void PersonalActivationDlg::OnCreateHit(wxCommandEvent& evt)
wxSetWorkingDirectory(root.string());
wxProcess proc(wxPROCESS_DEFAULT);
wxExecute(cmd, wxEXEC_SYNC);
reveal_in_explorer(wxGetCwd());
reveal_in_explorer(std::filesystem::path(wxGetCwd().ToStdString()));
wxSetWorkingDirectory(cwd);
}
}
Expand Down
13 changes: 10 additions & 3 deletions source/globals.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "globals.h"
#include <fmt/format.h>
#include <wx/listctrl.h>
#include <wx/msgdlg.h>

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

void reveal_in_explorer(const std::string& path) {
void reveal_in_explorer(const std::filesystem::path& path) {
#if defined __APPLE__
std::string command = "open \"" + path + "\"";

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

#elif defined _WIN32
//do not surround the paths in quotes, it will not work
std::string command = "\\Windows\\explorer.exe \"" + path + "\"";
std::string command = "\\Windows\\explorer.exe \"" + path.string() + "\"";
#endif
launch_process(command);
if (std::filesystem::exists(path)) {
launch_process(command);
}
else {
wxMessageBox("The project at " + path.string() + " could not be found.", "Cannot Reveal Project", wxOK | wxICON_ERROR);
}

}

long wxListCtrl_get_selected(wxListCtrl* listCtrl) {
Expand Down
4 changes: 2 additions & 2 deletions source/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
static constexpr std::string_view projectsFile = "projects.txt";
static constexpr std::string_view editorPathsFile = "editorPaths.txt";
static constexpr std::string_view templatePrefix = "com.unity.template";
static constexpr std::string_view AppVersion = "v1.52";
static constexpr std::string_view AppVersion = "v1.53";

struct wxListCtrl;
struct wxWindow;
Expand Down Expand Up @@ -96,7 +96,7 @@ void launch_process(const std::string& command, int flags = 0);
* Open system file explorer to path
* @param path the item to show
*/
void reveal_in_explorer(const std::string& path);
void reveal_in_explorer(const std::filesystem::path& path);

/**
Gets the first selected item in a wxListCtrl. If the wxListCtrl is set to single selection, this method will retrive the only selected item.
Expand Down
58 changes: 22 additions & 36 deletions source/interface_derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,10 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
vector<string> erroredProjects;
//load each project (each path is on its own line)
while (getline(in, line)){
try{
project pr = LoadProject(line);
AddProject(pr,filter);
}
catch(runtime_error& e){
//remove project
erroredProjects.push_back(line);
}
}
//alert user if projects could not be loaded
if (erroredProjects.size() > 0){
//build string
string str;
for (const auto& s : erroredProjects){
str += s + "\n";
}
//message box
wxMessageBox("The following projects could not be loaded. They have been removed from the list.\n\n"+str, "Loading error", wxOK | wxICON_WARNING );

//save to remove the broken projects
SaveProjects();

project pr = LoadProject(line);
AddProject(pr,filter);

}
}
}
Expand All @@ -243,7 +226,7 @@ void MainFrameDerived::OnAbout(wxCommandEvent& event)
{
wxAboutDialogInfo aboutInfo;
aboutInfo.SetName("Unity Hub Native");
aboutInfo.SetCopyright("(C) Ravbug 2022");
aboutInfo.SetCopyright("(C) Ravbug 2023");
aboutInfo.SetDescription("Developed with wxWidgets in C++");
#if defined __linux__
aboutInfo.SetWebSite("https://github.com/ravbug/UnityHubNative");
Expand Down Expand Up @@ -365,7 +348,7 @@ void MainFrameDerived::OnRevealProject(wxCommandEvent& event){
long selectedIndex = wxListCtrl_get_selected(projectsList);
if (selectedIndex > -1){
project& p = projects[selectedIndex];
reveal_in_explorer(p.path.string());
reveal_in_explorer(p.path);
}
}

Expand Down Expand Up @@ -393,6 +376,11 @@ void MainFrameDerived::OnOpenWith(wxCommandEvent& event){
void MainFrameDerived::OpenProject(const long& index){
//get the project
project p = projects[index];

if (!std::filesystem::exists(p.path)) {
wxMessageBox("Cannot open project at " + p.path.string() + " because it could not be found.", "Cannot Open Project", wxOK | wxICON_ERROR);
return;
}

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

//the name is the final part of the path
string name = p_as_fs.filename().string();

string version = "??";

//Load ProjectSettings/ProjectVersion.txt to get the editor version, if it exists
std::filesystem::path projSettings = p_as_fs / "ProjectSettings" / "ProjectVersion.txt";
if (!filesystem::exists(projSettings)){
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.");
if (filesystem::exists(projSettings)){
//the first line of ProjectVersion.txt contains the editor verison as plain text
ifstream inFile;
inFile.open(projSettings);
getline(inFile, version);
version = version.substr(17);
}

//the first line of ProjectVersion.txt contains the editor verison as plain text
string version;
ifstream inFile;
inFile.open(projSettings);
getline(inFile,version);
version = version.substr(17);

//get the modification date
struct stat fileInfo;
struct stat fileInfo {};
if (stat(p_as_fs.string().c_str(), &fileInfo) != 0) {
throw runtime_error("Cannot get modification date. Ensure this program has access to "+p_as_fs.string());
//throw runtime_error("Cannot get modification date. Ensure this program has access to "+p_as_fs.string());
}

project p = {name,version,ctime(&fileInfo.st_mtime),p_as_fs,};
Expand Down
6 changes: 3 additions & 3 deletions source/interface_derived.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class MainFrameDerived : public MainFrame{
editor& e = editors[id];
std::filesystem::path path = e.path / e.name;
if (!std::filesystem::exists(path)){
reveal_in_explorer(e.path.string());
reveal_in_explorer(e.path);
}
else{
reveal_in_explorer(path.string());
reveal_in_explorer(path);
}
}
}
Expand All @@ -153,7 +153,7 @@ class MainFrameDerived : public MainFrame{
void OnRevealInstallLocation(wxCommandEvent& event){
int id = installsPathsList->GetSelection();
if (id != wxNOT_FOUND){
reveal_in_explorer(installPaths[id].string());
reveal_in_explorer(installPaths[id]);
}
}
void OnOpenHub(wxCommandEvent& event);
Expand Down

0 comments on commit da75dd8

Please sign in to comment.