1
1
//
2
- // globals.cpp
3
2
// Unity Hub Native (Dynamic)
4
3
//
5
4
// Copyright © 2019 Ravbug. All rights reserved.
6
5
//
7
6
#pragma once
8
- using namespace std ;
9
7
10
8
#include < sys/stat.h>
11
9
#include < wx/listctrl.h>
12
10
#include < string>
13
11
#include < filesystem>
14
12
15
13
// 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 " ;
20
18
21
19
// structure for representing an editor and for locating it
22
20
struct editor {
23
- string name;
24
- string path;
21
+ std:: string name;
22
+ std:: string path;
25
23
};
26
24
27
25
#if defined __APPLE__
28
26
#include < pwd.h>
29
27
// 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" );
31
29
static const char dirsep = ' /' ;
32
30
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" ;
34
33
35
34
// 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" ;
38
37
// 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/" ;
41
40
42
41
// 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" ;
44
43
45
44
#elif defined _WIN32
46
45
// naming conflicts
47
46
#define popen _popen
48
47
#define pclose _pclose
49
48
#define mkdir _mkdir
50
- #include < windows .h>
49
+ #include < Windows .h>
51
50
#include < gdiplus.h>
52
51
#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" );
54
53
static const char dirsep = ' \\ ' ;
55
54
55
+ static const std::string cachedir = std::filesystem::temp_directory_path().string();
56
+ static const std::string installerExt = " exe" ;
57
+
56
58
// 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" ;
59
61
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\\ " ;
62
64
63
65
/* *
64
66
@returns the calculated display scale factor using GDI+
@@ -95,7 +97,7 @@ struct editor{
95
97
@param from the string to be replaced
96
98
@param to the string to replace `from` with
97
99
*/
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) {
99
101
size_t start_pos = 0 ;
100
102
while ((start_pos = str.find (from, start_pos)) != std::string::npos) {
101
103
str.replace (start_pos, from.length (), to);
@@ -109,41 +111,41 @@ struct editor{
109
111
@param path the windows path to escape
110
112
@return the escaped path
111
113
*/
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 (" ^ " ));
114
116
}
115
117
116
118
#elif defined __linux__
117
119
#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" ;
120
122
static const char dirsep = ' /' ;
121
123
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" );
124
126
// 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/" ;
127
129
128
130
#else
129
131
// 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.
131
133
#endif
132
134
133
135
// structure containing all the info needed to display a project
134
136
struct 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;
139
141
};
140
142
141
143
/* *
142
144
Determines if a file exists at a path using stat()
143
145
@param name the path to the file
144
146
@return true if the file exists, false if it does not
145
147
*/
146
- inline bool file_exists (const string& name){
148
+ inline bool file_exists (const std:: string& name){
147
149
struct stat buffer;
148
150
return (stat (name.c_str (), &buffer) == 0 );
149
151
}
@@ -155,7 +157,7 @@ inline bool file_exists(const string& name){
155
157
@param command the shell command to run on the system
156
158
@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.
157
159
*/
158
- inline void launch_process (const string& command) {
160
+ inline void launch_process (const std:: string& command) {
159
161
#if defined __APPLE__ || defined __linux__
160
162
// the '&' runs the command nonblocking, and >/dev/null 2>&1 destroys output
161
163
FILE* stream = popen (string (command + null_device + " &" ).c_str (), " r" );
@@ -168,7 +170,7 @@ inline void launch_process(const string& command) {
168
170
#endif
169
171
}
170
172
171
- inline void reveal_in_explorer (const string& path){
173
+ inline void reveal_in_explorer (const std:: string& path){
172
174
#if defined __APPLE__
173
175
string command = " open \" " + path + " \" " ;
174
176
@@ -177,7 +179,7 @@ inline void reveal_in_explorer(const string& path){
177
179
178
180
#elif defined _WIN32
179
181
// 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 + " \" " ;
181
183
#endif
182
184
launch_process (command);
183
185
}
0 commit comments