Skip to content

Commit 277458a

Browse files
committed
Remove using namespace from headers
1 parent 0e8942d commit 277458a

7 files changed

+67
-64
lines changed

CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 3.17)
22

33
project("UnityHubNative")
44
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
5-
set(CMAKE_CXX_STANDARD 17)
6-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
75
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
86
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
97

@@ -14,6 +12,7 @@ endif()
1412

1513
file(GLOB source "source/*.cpp" "source/*.hpp" "source/*.h")
1614
add_executable("${PROJECT_NAME}" WIN32 ${source} "source/wxmac.icns" "source/windows.rc")
15+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
1716

1817
#wxwidgets
1918
set(wxBUILD_SHARED OFF CACHE INTERNAL "")

source/add_install_dlg_derived.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ void AddNewInstallDlg::InstallSelected(wxCommandEvent&){
150150

151151
thread th([=]{
152152
// download the file
153-
string url = "https://download.unity3d.com/download_unity/" + data.hashcode +
153+
string url = "https://download.unity3d.com/download_unity/" + data.hashcode + "/UnityDownloadAssistant" +
154154
#ifdef __APPLE__
155-
"/UnityDownloadAssistant.dmg";
155+
".dmg";
156156
#elif defined _WIN32
157-
157+
".exe";
158158
#elif __linux__
159159

160160
#else
@@ -170,7 +170,7 @@ void AddNewInstallDlg::InstallSelected(wxCommandEvent&){
170170
}
171171
else{
172172
// write the file to temp location
173-
auto outpath = fmt::format("{}{}{}{}{}", cachedir,dirsep,"UnityDownloadAssistant",data.hashcode,".dmg");
173+
auto outpath = fmt::format("{}{}{}{}.{}", cachedir,dirsep,"UnityDownloadAssistant",data.hashcode,installerExt);
174174
ofstream outfile(outpath, std::ios::binary);
175175
outfile.write(r.text.c_str(),r.text.size());
176176

source/create_dialog_derived.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#endif
1313
#include <wx/msgdlg.h>
1414

15+
using namespace std;
16+
1517
//Declare events here
1618
wxBEGIN_EVENT_TABLE(CreateProjectDialogD, wxDialog)
1719
EVT_BUTTON(wxID_CANCEL,CreateProjectDialogD::OnCancel)

source/globals.h

+41-39
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,66 @@
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
2220
struct 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
134136
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;
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
}

source/interface_derived.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#else
1616
#include <dirent.h>
1717
#endif
18+
using namespace std;
1819

1920
#define LEARN_TAB 2
2021
#define WEBVIEW 2000

source/interface_derived.hpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#pragma once
1010

11-
#include "interface.h"
1211
#include "globals.h"
12+
#include "interface.h"
1313
#include <functional>
1414
#include <wx/webview.h>
1515
#include <wx/timer.h>
@@ -23,32 +23,30 @@
2323
#define TIMER 2001
2424

2525

26-
using namespace std;
27-
2826
class MainFrameDerived : public MainFrame{
2927
public:
3028
//constructor (takes no args)
3129
MainFrameDerived();
3230

33-
static string GetPathFromDialog(const string& message);
31+
static std::string GetPathFromDialog(const std::string& message);
3432

3533
private:
3634
void AddProject(const project& p);
37-
project LoadProject(const string& path);
35+
project LoadProject(const std::string& path);
3836
void SaveProjects();
3937
void OpenProject(const long& index);
4038
void OpenProject(const project& p, const editor& e);
4139
void SaveEditorVersions();
42-
void LoadEditorPath(const string& path);
40+
void LoadEditorPath(const std::string& path);
4341
void LoadEditorVersions();
4442
void ReloadData();
4543

4644
//will store the list of projects
47-
vector<project> projects;
48-
vector<string> installPaths;
49-
vector<editor> editors;
45+
std::vector<project> projects;
46+
std::vector<std::string> installPaths;
47+
std::vector<editor> editors;
5048
wxWebView* learnView = NULL;
51-
const string homeurl = "https://learn.unity.com";
49+
const std::string homeurl = "https://learn.unity.com";
5250
wxString lastURL = wxString(homeurl);
5351
wxTimer* timeout;
5452

@@ -127,8 +125,8 @@ class MainFrameDerived : public MainFrame{
127125
Locates a Unity install path and adds it to the list and UI
128126
*/
129127
void OnLocateInstall(wxCommandEvent& event){
130-
string msg = "Select the folder containing Unity installs";
131-
string path = GetPathFromDialog(msg);
128+
std::string msg = "Select the folder containing Unity installs";
129+
std::string path = GetPathFromDialog(msg);
132130
if (path != ""){
133131
LoadEditorPath(path);
134132
}
@@ -142,7 +140,7 @@ class MainFrameDerived : public MainFrame{
142140
int id = installsList->GetSelection();
143141
if (id != wxNOT_FOUND){
144142
editor& e = editors[id];
145-
string path = e.path + dirsep + e.name;
143+
std::string path = e.path + dirsep + e.name;
146144
reveal_in_explorer(path);
147145
}
148146
}
@@ -167,18 +165,18 @@ class MainFrameDerived : public MainFrame{
167165
CreateProjectDialog derived class
168166
Defines the functionality for the project creation dialog
169167
*/
170-
typedef std::function<void(const string&,const project&)> DialogCallback;
168+
typedef std::function<void(const std::string&,const project&)> DialogCallback;
171169
class CreateProjectDialogD : CreateProjectDialog{
172170
public:
173-
CreateProjectDialogD(wxWindow* parent, const vector<editor>& versions, const DialogCallback& callback);
171+
CreateProjectDialogD(wxWindow* parent, const std::vector<editor>& versions, const DialogCallback& callback);
174172
void show(){
175173
this->ShowModal();
176174
}
177175
private:
178-
string validateForm();
176+
std::string validateForm();
179177
void loadTemplates(const editor& e);
180178
DialogCallback callback;
181-
vector<editor> editors;
179+
std::vector<editor> editors;
182180

183181
//events
184182
void OnCancel(wxCommandEvent& event){
@@ -195,12 +193,12 @@ class CreateProjectDialogD : CreateProjectDialog{
195193
typedef std::function<void(const project&, const editor&)> OpenWithCallback;
196194
class OpenWithDlg : OpenWithEditorDlgBase{
197195
public:
198-
OpenWithDlg(wxWindow* parent, const project& project, const vector<editor>& versions, const OpenWithCallback& callback);
196+
OpenWithDlg(wxWindow* parent, const project& project, const std::vector<editor>& versions, const OpenWithCallback& callback);
199197
void show(){
200198
this->ShowModal();
201199
}
202200
private:
203-
vector<editor> editors;
201+
std::vector<editor> editors;
204202
project p;
205203
OpenWithCallback callback;
206204

source/open_with_dlg.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//
66

77
#include "interface_derived.hpp"
8+
using namespace std;
89

910
wxBEGIN_EVENT_TABLE(OpenWithDlg, wxDialog)
1011
EVT_BUTTON(wxID_CANCEL,OpenWithDlg::OnCancel)

0 commit comments

Comments
 (0)