Skip to content

Commit 05fc424

Browse files
committed
Unity launching!
globals.cpp + constants for executable path and installations paths interface_derived.hpp + OnOpenProject, OpenProject function declaration interface_derived.cpp + event table for OnOpenProject + OpenProject now launches Unity. If it cannot find the unity version, it will alert the user. ~ fixed bug where substring length to get editor version was wrong ~ AddProject now inserts at beginning to match UI interface.h, interface.cpp ~ wxID changes
1 parent bcdb28d commit 05fc424

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

source/form.fbp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
<property name="font"></property>
290290
<property name="gripper">0</property>
291291
<property name="hidden">0</property>
292-
<property name="id">wxID_ANY</property>
292+
<property name="id">wxID_HARDDISK</property>
293293
<property name="max_size"></property>
294294
<property name="maximize_button">0</property>
295295
<property name="maximum_size"></property>
@@ -608,6 +608,19 @@
608608
<property name="shortcut"></property>
609609
<property name="unchecked_bitmap"></property>
610610
</object>
611+
<object class="wxMenuItem" expanded="1">
612+
<property name="bitmap"></property>
613+
<property name="checked">0</property>
614+
<property name="enabled">1</property>
615+
<property name="help"></property>
616+
<property name="id">wxID_OPEN</property>
617+
<property name="kind">wxITEM_NORMAL</property>
618+
<property name="label">Open Project</property>
619+
<property name="name">openMenu</property>
620+
<property name="permission">none</property>
621+
<property name="shortcut">Ctrl-O</property>
622+
<property name="unchecked_bitmap"></property>
623+
</object>
611624
</object>
612625
</object>
613626
</object>

source/globals.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ static const string projectsFile = "projects.txt";
1818
//the location to store application data
1919
static const string datapath = getpwuid(getuid())->pw_dir + string("/Library/Application Support/UnityHubNative");
2020
static const char dirsep = '/';
21+
static const string executable = "Unity.app/Contents/MacOS/Unity";
22+
23+
//TODO: make this a preference
24+
static const string installsPath = "/Applications/Unity/Hub/Editor";
25+
2126

2227
#elif defined __WIN32__
2328
static const string datapath = getenv("HOMEPATH") + string("\\AppData\\Roaming\\UnityHubNative");

source/interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, co
3232

3333
gbSizer1->Add( m_staticText2, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxALL|wxALIGN_CENTER_VERTICAL, 5 );
3434

35-
projectsList = new wxListCtrl( projects_pane, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
35+
projectsList = new wxListCtrl( projects_pane, wxID_HARDDISK, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
3636
gbSizer1->Add( projectsList, wxGBPosition( 1, 0 ), wxGBSpan( 1, 3 ), wxALL|wxEXPAND, 5 );
3737

3838
wxBoxSizer* pManSizer;

source/interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
///////////////////////////////////////////////////////////////////////////
3131

32+
#define wxID_HARDDISK 1000
3233

3334
///////////////////////////////////////////////////////////////////////////////
3435
/// Class MainFrame

source/interface_derived.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ wxBEGIN_EVENT_TABLE(MainFrameDerived, wxFrame)
1414
EVT_MENU(wxID_ABOUT, MainFrameDerived::OnAbout)
1515
EVT_BUTTON(wxID_ADD,MainFrameDerived::OnAddProject)
1616
EVT_BUTTON(wxID_NEW,MainFrameDerived::OnCreateProject)
17+
EVT_LIST_ITEM_ACTIVATED(wxID_HARDDISK, MainFrameDerived::OnOpenProject)
1718
wxEND_EVENT_TABLE()
1819

1920
//call superclass constructor
@@ -39,8 +40,8 @@ MainFrameDerived::MainFrameDerived() : MainFrame(NULL){
3940
AddProject(pr);
4041
}
4142
}
42-
//TODO: load the existing projects from file
4343
}
44+
//if no projects to load, the interface will be blank
4445
}
4546

4647
//definitions for the events
@@ -59,10 +60,47 @@ void MainFrameDerived::OnAddProject(wxCommandEvent& event){
5960
}
6061
}
6162

63+
/**
64+
Called to create a new project
65+
*/
6266
void MainFrameDerived::OnCreateProject(wxCommandEvent& event){
6367
wxMessageBox( "Replace with project creation dialog", "Create Project", wxOK | wxICON_INFORMATION );
6468
}
6569

70+
/**
71+
Called when you double click or press Enter on a cell in the ListView
72+
*/
73+
void MainFrameDerived::OnOpenProject(wxListEvent& event){
74+
OpenProject(event.m_itemIndex);
75+
}
76+
77+
/**
78+
Launches Unity with a project
79+
@param index the integer representing which project in the projects Vector to load
80+
*/
81+
void MainFrameDerived::OpenProject(long& index){
82+
//get the project
83+
project p = projects[index];
84+
85+
string editorPath = installsPath + dirsep + p.version + dirsep + executable;
86+
87+
//check that the unity editor exists at that location
88+
if (file_exists(editorPath)){
89+
string cmd = editorPath + " -projectpath " + p.path;
90+
91+
//start the process
92+
int status = fork();
93+
if (status == 0){
94+
//find a method that does not use system(), some antivirus don't like that
95+
system(cmd.c_str());
96+
}
97+
}
98+
else{
99+
//alert user
100+
wxMessageBox("The editor version " + p.version + " could not be found. Check that it is installed.", "Unable to start Unity", wxOK | wxICON_ERROR);
101+
}
102+
}
103+
66104
/** Brings up a folder selection dialog with a prompt
67105
* @param message the prompt for the user
68106
* @return path selected, or an empty string if nothing chosen
@@ -106,7 +144,7 @@ project MainFrameDerived::LoadProject(string &path){
106144
ifstream inFile;
107145
inFile.open(projSettings);
108146
getline(inFile,version);
109-
version = version.substr(16);
147+
version = version.substr(17);
110148

111149
//get the modification date
112150
struct stat fileInfo;
@@ -138,7 +176,7 @@ void MainFrameDerived::SaveProjects(){
138176
*/
139177
void MainFrameDerived::AddProject(project& p){
140178
//add to the vector backing the UI
141-
projects.push_back(p);
179+
projects.insert(projects.begin(),p);
142180

143181
//save to file
144182
SaveProjects();

source/interface_derived.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ class MainFrameDerived : public MainFrame{
2424
void OnAbout(wxCommandEvent& event);
2525
void OnAddProject(wxCommandEvent& event);
2626
void OnCreateProject(wxCommandEvent& event);
27+
void OnOpenProject(wxListEvent& event);
2728
static string GetPathFromDialog(string& message);
2829
wxDECLARE_EVENT_TABLE();
2930
private:
3031
void AddProject(project& p);
3132
project LoadProject(string& path);
3233
void SaveProjects();
34+
void OpenProject(long& index);
3335

3436
//will store the list of projects
3537
vector<project> projects;

0 commit comments

Comments
 (0)