11//
2- // globals.cpp
32// Unity Hub Native (Dynamic)
43//
54// Copyright © 2019 Ravbug. All rights reserved.
65//
76#pragma once
8- using namespace std ;
97
108#include < sys/stat.h>
119#include < wx/listctrl.h>
1210#include < string>
1311#include < filesystem>
1412
1513// data file names
16- static const string projectsFile = " projects.txt" ;
17- static const string editorPathsFile = " editorPaths.txt" ;
18- static const string templatePrefix = " com.unity.template" ;
19- static const string AppVersion = " v1.36 " ;
14+ static const std:: string projectsFile = " projects.txt" ;
15+ static const std:: string editorPathsFile = " editorPaths.txt" ;
16+ static const std:: string templatePrefix = " com.unity.template" ;
17+ static const std:: string AppVersion = " v1.4 " ;
2018
2119// structure for representing an editor and for locating it
2220struct editor {
23- string name;
24- string path;
21+ std:: string name;
22+ std:: string path;
2523};
2624
2725#if defined __APPLE__
2826 #include < pwd.h>
2927 // the location to store application data
30- static const string datapath = getpwuid(getuid())->pw_dir + string(" /Library/Application Support/UnityHubNative" );
28+ static const std:: string datapath = getpwuid(getuid())->pw_dir + string(" /Library/Application Support/UnityHubNative" );
3129 static const char dirsep = ' /' ;
3230
33- static const string cachedir = getpwuid(getuid())->pw_dir + string(" /Library/Caches/com.ravbug.UnityHubNative" );
31+ static const std::string cachedir = getpwuid(getuid())->pw_dir + string(" /Library/Caches/com.ravbug.UnityHubNative" );
32+ static const std::string installerExt = " dmg" ;
3433
3534 // where to find various Unity things on macOS
36- static const string executable = " Unity.app/Contents/MacOS/Unity" ;
37- static const string defaultInstall = " /Applications/Unity/Hub/Editor" ;
35+ static const std:: string executable = " Unity.app/Contents/MacOS/Unity" ;
36+ static const std:: string defaultInstall = " /Applications/Unity/Hub/Editor" ;
3837 // TODO: make this a preference?
39- static const string hubDefault = " /Applications/Unity Hub.app" ;
40- static const string templatesDir = " Unity.app/Contents/Resources/PackageManager/ProjectTemplates/" ;
38+ static const std:: string hubDefault = " /Applications/Unity Hub.app" ;
39+ static const std:: string templatesDir = " Unity.app/Contents/Resources/PackageManager/ProjectTemplates/" ;
4140
4241 // for stream redirecting to dev/null
43- static const string null_device = " >/dev/null 2>&1" ;
42+ static const std:: string null_device = " >/dev/null 2>&1" ;
4443
4544#elif defined _WIN32
4645// naming conflicts
4746#define popen _popen
4847#define pclose _pclose
4948#define mkdir _mkdir
50- #include < windows .h>
49+ #include < Windows .h>
5150#include < gdiplus.h>
5251#include < wx/wx.h>
53- static const string datapath = getenv(" HOMEPATH" ) + string(" \\ AppData\\ Roaming\\ UnityHubNative" );
52+ static const std:: string datapath = getenv(" HOMEPATH" ) + std:: string(" \\ AppData\\ Roaming\\ UnityHubNative" );
5453 static const char dirsep = ' \\ ' ;
5554
55+ static const std::string cachedir = std::filesystem::temp_directory_path().string();
56+ static const std::string installerExt = " exe" ;
57+
5658 // where to find various Unity things on windows
57- static const string executable = " Editor\\ Unity.exe" ;
58- static const string defaultInstall = " \\ Program Files\\ Unity\\ Hub\\ Editor" ;
59+ static const std:: string executable = " Editor\\ Unity.exe" ;
60+ static const std:: string defaultInstall = " \\ Program Files\\ Unity\\ Hub\\ Editor" ;
5961
60- static const string hubDefault = " \\ Program Files\\ Unity Hub\\ Unity Hub.exe" ;
61- static const string templatesDir = " Editor\\ Data\\ Resources\\ PackageManager\\ ProjectTemplates\\ " ;
62+ static const std:: string hubDefault = " \\ Program Files\\ Unity Hub\\ Unity Hub.exe" ;
63+ static const std:: string templatesDir = " Editor\\ Data\\ Resources\\ PackageManager\\ ProjectTemplates\\ " ;
6264
6365 /* *
6466 @returns the calculated display scale factor using GDI+
@@ -95,7 +97,7 @@ struct editor{
9597 @param from the string to be replaced
9698 @param to the string to replace `from` with
9799 */
98- inline string ReplaceAll (std::string str, const std::string& from, const std::string& to) {
100+ inline std:: string ReplaceAll (std::string str, const std::string& from, const std::string& to) {
99101 size_t start_pos = 0 ;
100102 while ((start_pos = str.find (from, start_pos)) != std::string::npos) {
101103 str.replace (start_pos, from.length (), to);
@@ -109,41 +111,41 @@ struct editor{
109111 @param path the windows path to escape
110112 @return the escaped path
111113 */
112- inline string WinEscapePath (string& path) {
113- return ReplaceAll (path, string (" " ), string (" ^ " ));
114+ inline std:: string WinEscapePath (std:: string& path) {
115+ return ReplaceAll (path, std:: string (" " ), std:: string (" ^ " ));
114116 }
115117
116118#elif defined __linux__
117119 #include < pwd.h>
118- static const string datapath = getpwuid(getuid())->pw_dir + string(" /UnityHubNative" );
119- static const string null_device = " >/dev/null 2>&1" ;
120+ static const std:: string datapath = getpwuid(getuid())->pw_dir + string(" /UnityHubNative" );
121+ static const std:: string null_device = " >/dev/null 2>&1" ;
120122 static const char dirsep = ' /' ;
121123
122- static const string executable = " Editor/Unity" ;
123- static const string defaultInstall = getpwuid(getuid())->pw_dir +string(" /Unity/Hub/Editor" );
124+ static const std:: string executable = " Editor/Unity" ;
125+ static const std:: string defaultInstall = getpwuid(getuid())->pw_dir +string(" /Unity/Hub/Editor" );
124126 // TODO: make this a preference?
125- static const string hubDefault = " /Applications/Unity Hub.app" ;
126- static const string templatesDir = " Editor/Data/Resources/PackageManager/ProjectTemplates/" ;
127+ static const std:: string hubDefault = " /Applications/Unity Hub.app" ;
128+ static const std:: string templatesDir = " Editor/Data/Resources/PackageManager/ProjectTemplates/" ;
127129
128130#else
129131 // disalow compilation for unsupported platforms
130- #error You are compiling on an unsupported operating system. Currently only macOS and Windows are supported. If you know how to support your system, submit a pull request.
132+ #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.
131133#endif
132134
133135// structure containing all the info needed to display a project
134136struct project {
135- string name;
136- string version;
137- string modifiedDate;
138- string path;
137+ std:: string name;
138+ std:: string version;
139+ std:: string modifiedDate;
140+ std:: string path;
139141};
140142
141143/* *
142144 Determines if a file exists at a path using stat()
143145 @param name the path to the file
144146 @return true if the file exists, false if it does not
145147 */
146- inline bool file_exists (const string& name){
148+ inline bool file_exists (const std:: string& name){
147149 struct stat buffer;
148150 return (stat (name.c_str (), &buffer) == 0 );
149151}
@@ -155,7 +157,7 @@ inline bool file_exists(const string& name){
155157 @param command the shell command to run on the system
156158 @note The command passed to this function must be correct for the system it is running on. If it is not correct, the function will appear to do nothing.
157159 */
158- inline void launch_process (const string& command) {
160+ inline void launch_process (const std:: string& command) {
159161#if defined __APPLE__ || defined __linux__
160162 // the '&' runs the command nonblocking, and >/dev/null 2>&1 destroys output
161163 FILE* stream = popen (string (command + null_device + " &" ).c_str (), " r" );
@@ -168,7 +170,7 @@ inline void launch_process(const string& command) {
168170#endif
169171}
170172
171- inline void reveal_in_explorer (const string& path){
173+ inline void reveal_in_explorer (const std:: string& path){
172174#if defined __APPLE__
173175 string command = " open \" " + path + " \" " ;
174176
@@ -177,7 +179,7 @@ inline void reveal_in_explorer(const string& path){
177179
178180#elif defined _WIN32
179181 // do not surround the paths in quotes, it will not work
180- string command = " \\ Windows\\ explorer.exe \" " + path + " \" " ;
182+ std:: string command = " \\ Windows\\ explorer.exe \" " + path + " \" " ;
181183#endif
182184 launch_process (command);
183185}
0 commit comments