66#pragma once
77
88#include < sys/stat.h>
9- #include < wx/listctrl.h>
109#include < string>
1110#include < filesystem>
1211
@@ -16,6 +15,9 @@ static constexpr std::string_view editorPathsFile = "editorPaths.txt";
1615static constexpr std::string_view templatePrefix = " com.unity.template" ;
1716static constexpr std::string_view AppVersion = " v1.51" ;
1817
18+ struct wxListCtrl ;
19+ struct wxWindow ;
20+
1921#if defined __APPLE__
2022 #include < pwd.h>
2123 // the location to store application data
@@ -39,82 +41,34 @@ static constexpr std::string_view AppVersion = "v1.51";
3941#define popen _popen
4042#define pclose _pclose
4143#define mkdir _mkdir
42- #include < wx/wx.h>
4344 static const std::filesystem::path homepath = getenv(" HOMEPATH" );
4445 static const std::filesystem::path homedrive = getenv(" HOMEDRIVE" );
4546 static const std::filesystem::path homedir = homedrive / homepath;
4647
4748 static const std::filesystem::path datapath = homedir / std::filesystem::path(" AppData\\ Roaming\\ UnityHubNative" );
4849
4950 static const std::filesystem::path cachedir = std::filesystem::temp_directory_path();
50- static const std::string installerExt = " exe" ;
51+ static constexpr std::string_view installerExt = " exe" ;
5152
5253 // where to find various Unity things on windows
5354 static const std::filesystem::path executable = " Editor\\ Unity.exe" ;
5455 static const std::vector<std::filesystem::path> defaultInstall = {" \\ Program Files\\ Unity\\ Hub\\ Editor" };
5556
5657 static const std::filesystem::path hubDefault = " \\ Program Files\\ Unity Hub\\ Unity Hub.exe" ;
5758 static const std::filesystem::path templatesDir = " Editor\\ Data\\ Resources\\ PackageManager\\ ProjectTemplates\\ " ;
58-
59- /* *
60- @returns the calculated display scale factor using GDI+
61- */
62- inline float get_WIN_dpi_multiple () {
63- return 1 ;
64- /*
65- FLOAT dpiX;
66- HDC screen = GetDC(0);
67- dpiX = static_cast<FLOAT>(GetDeviceCaps(screen, LOGPIXELSX));
68- ReleaseDC(0, screen);
69- return dpiX / 96;*/
70- }
7159
7260 /* *
7361 Scales a wxWindow to the correct size using the monitor's DPI factor (Windows only)
7462 This preserves the defined size of the window. To simply fit the window to contents, regardless
7563 of DPI, use fitWindowMinSize.
7664 @param window the wxWindow to scale
7765 */
78- inline void dpi_scale (wxWindow* window) {
79- // fit size to children
80- window->Fit ();
81-
82- // calculate the scaled min size
83- float fac = get_WIN_dpi_multiple ();
84- float minh = window->GetMinHeight () * fac;
85- float minw = window->GetMinWidth () * fac;
86- // set the minimum size
87- window->SetSizeHints (wxSize (minw,minh));
88- }
89-
90- /* *
91- Replaces all instances of a string with another string, within a string
92- @param str the string to operate on
93- @param from the string to be replaced
94- @param to the string to replace `from` with
95- */
96- inline std::string ReplaceAll (std::string str, const std::string& from, const std::string& to) {
97- size_t start_pos = 0 ;
98- while ((start_pos = str.find (from, start_pos)) != std::string::npos) {
99- str.replace (start_pos, from.length (), to);
100- start_pos += to.length (); // Handles case where 'to' is a substring of 'from'
101- }
102- return str;
103- }
104-
105- /* *
106- Escapes Windows paths by replacing spaces ' ' with '^ '
107- @param path the windows path to escape
108- @return the escaped path
109- */
110- inline std::string WinEscapePath (std::string& path) {
111- return ReplaceAll (path, std::string (" " ), std::string (" ^ " ));
112- }
66+ void dpi_scale (wxWindow* window);
11367
11468#elif defined __linux__
11569 #include < pwd.h>
11670 static const std::filesystem::path datapath = std::filesystem::path(getpwuid(getuid())->pw_dir) / " UnityHubNative" ;
117- static const std::string null_device = " >/dev/null 2>&1" ;
71+ static constexpr std::string_view null_device = " >/dev/null 2>&1" ;
11872
11973 static const std::filesystem::path executable = " Editor/Unity" ;
12074 static const std::vector<std::filesystem::path> defaultInstall = {std::filesystem::path (getpwuid (getuid ())->pw_dir ) / " Unity/Hub/Editor" };
@@ -127,17 +81,6 @@ static constexpr std::string_view AppVersion = "v1.51";
12781#error You are compiling on an unsupported operating system. Currently only macOS, Windows, and Linux are supported. If you know how to support your system, submit a pull request.
12882#endif
12983
130- // structure containing all the info needed to display a project
131- struct project {
132- std::string name;
133- std::string version;
134- std::string modifiedDate;
135- std::filesystem::path path;
136- bool operator ==(const project& other) const {
137- return this ->path == other.path ;
138- }
139- };
140-
14184/* *
14285 Launches a shell command as a separate, non-connected process. The output of this
14386 command is not captured (sent to the system's null device)
@@ -146,56 +89,46 @@ struct project{
14689 */
14790void launch_process (const std::string& command, int flags = 0 );
14891
149- inline void reveal_in_explorer (const std::string& path){
150- #if defined __APPLE__
151- std::string command = " open \" " + path + " \" " ;
152-
153- #elif defined __linux__
154- std::string command = " xdg-open \" " + path + " \" " ;
155-
156- #elif defined _WIN32
157- // do not surround the paths in quotes, it will not work
158- std::string command = " \\ Windows\\ explorer.exe \" " + path + " \" " ;
159- #endif
160- launch_process (command);
161- }
92+ /* *
93+ * Open system file explorer to path
94+ * @param path the item to show
95+ */
96+ void reveal_in_explorer (const std::string& path);
16297
16398/* *
16499 Gets the first selected item in a wxListCtrl. If the wxListCtrl is set to single selection, this method will retrive the only selected item.
165100 @param listCtrl pointer to the wxListCtrl to get the selected item from.
166101 @return index of the first selected item, or -1 if no item is selected.
167102 @note wxListCtrl does not have a built in method for this.
168103 */
169- inline long wxListCtrl_get_selected (wxListCtrl* listCtrl){
170- long itemIndex = -1 ;
171- while ((itemIndex = listCtrl->GetNextItem (itemIndex,wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != wxNOT_FOUND) {
172- break ;
173- }
174- return itemIndex;
175- }
104+ long wxListCtrl_get_selected (wxListCtrl* listCtrl);
176105
177106/* *
178107Fits a wxWindow to its contents, and then sets that size as the window's minimum size
179108@param window the wxWindow to apply size changes
180109*/
181- inline void fitWindowMinSize (wxWindow* window) {
182- // fit size to children
183- window->Fit ();
184-
185- // constrain minimum size to the minimum fitting size
186- wxSize size = window->GetSize ();
187- window->SetSizeHints (size);
188- }
110+ void fitWindowMinSize (wxWindow* window);
189111
190112// structure for representing an editor and for locating it
191113struct editor {
192114 std::string name;
193115 std::filesystem::path path;
194- decltype (path) executablePath() const {
116+ decltype (path) executablePath() const {
195117 return path / name / executable;
196118 }
197-
198- bool operator ==(const editor& other){
199- return this ->name == other.name ; // many editors can share a root path
200- }
119+
120+ bool operator ==(const editor& other) {
121+ return this ->name == other.name ; // many editors can share a root path
122+ }
201123};
124+
125+ // structure containing all the info needed to display a project
126+ struct project {
127+ std::string name;
128+ std::string version;
129+ std::string modifiedDate;
130+ std::filesystem::path path;
131+ bool operator ==(const project& other) const {
132+ return this ->path == other.path ;
133+ }
134+ };
0 commit comments