Skip to content

Commit 85bf027

Browse files
committed
Fix windows build, codebase cleanup
globals.h, globals.cpp ~ move more stuff out to globals.cpp create_dialog_derived.cpp, interface_derived ~ fix build error
1 parent fb210f3 commit 85bf027

File tree

5 files changed

+102
-101
lines changed

5 files changed

+102
-101
lines changed

source/create_dialog_derived.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,20 @@ void CreateProjectDialogD::OnCreate(wxCommandEvent& event){
9494
templateName
9595
);
9696
#elif defined _WIN32
97-
auto fullProj = std::filesystem::path("\"") / projPath / projName / "\"";
98-
auto fullTemplate = std::filesystem::path("\"") / executableTemplatesPath / (templatePrefix + "." + templateName + "\"");
99-
string command = "\"" + executablePath.string() + "\" -createproject " + fullProj.string() + " -cloneFromTemplate \"" + fullTemplate.string();
97+
auto fullProj = filesystem::path(projPath) / projName;
98+
auto fullTemplate = executableTemplatesPath / fmt::format("{}.{}",templatePrefix,templateName);
99+
string command = fmt::format("\"{}\" -createproject {} -cloneFromTemplate \"{}\"",
100+
executablePath.string(),
101+
fullProj.string(),
102+
fullTemplate.string());
100103
#elif defined __linux__
101-
string command = "\"" + executablePath.string() + "\" -createproject \"" + (filesystem::path(projPath) / projName).string() + "\" -cloneFromTemplate \"" + executableTemplatesPath.string() + templatePrefix + "." + templateName + "\"";
104+
string command = fmt::format("\"{}\" -createproject \"{}\" -cloneFromTemplate \"{}{}.{}\"",
105+
executablePath.string(),
106+
(filesystem::path(projPath) / projName).string(),
107+
executableTemplatesPath.string(),
108+
templatePrefix,
109+
templateName
110+
);
102111
#endif
103112
//TODO: return this command to what summoned this dialog
104113
project p = {projName,e.name,"",filesystem::path(projPath) / filesystem::path(projName)};

source/globals.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "globals.h"
22
#include <fmt/format.h>
3+
#include <wx/listctrl.h>
34

45
void launch_process(const std::string& command, int flags) {
56
#if defined __APPLE__ || defined __linux__
@@ -14,3 +15,60 @@ void launch_process(const std::string& command, int flags) {
1415

1516
#endif
1617
}
18+
19+
void reveal_in_explorer(const std::string& path) {
20+
#if defined __APPLE__
21+
std::string command = "open \"" + path + "\"";
22+
23+
#elif defined __linux__
24+
std::string command = "xdg-open \"" + path + "\"";
25+
26+
#elif defined _WIN32
27+
//do not surround the paths in quotes, it will not work
28+
std::string command = "\\Windows\\explorer.exe \"" + path + "\"";
29+
#endif
30+
launch_process(command);
31+
}
32+
33+
long wxListCtrl_get_selected(wxListCtrl* listCtrl) {
34+
long itemIndex = -1;
35+
while ((itemIndex = listCtrl->GetNextItem(itemIndex, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != wxNOT_FOUND) {
36+
break;
37+
}
38+
return itemIndex;
39+
}
40+
41+
void fitWindowMinSize(wxWindow* window) {
42+
//fit size to children
43+
window->Fit();
44+
45+
//constrain minimum size to the minimum fitting size
46+
wxSize size = window->GetSize();
47+
48+
window->SetSizeHints(size);
49+
}
50+
51+
/**
52+
@returns the calculated display scale factor using GDI+
53+
*/
54+
float get_WIN_dpi_multiple() {
55+
return 1;
56+
/*
57+
FLOAT dpiX;
58+
HDC screen = GetDC(0);
59+
dpiX = static_cast<FLOAT>(GetDeviceCaps(screen, LOGPIXELSX));
60+
ReleaseDC(0, screen);
61+
return dpiX / 96;*/
62+
}
63+
64+
void dpi_scale(wxWindow* window){
65+
//fit size to children
66+
window->Fit();
67+
68+
//calculate the scaled min size
69+
float fac = get_WIN_dpi_multiple();
70+
float minh = window->GetMinHeight() * fac;
71+
float minw = window->GetMinWidth() * fac;
72+
//set the minimum size
73+
window->SetSizeHints(wxSize(minw, minh));
74+
}

source/globals.h

Lines changed: 29 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
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";
1615
static constexpr std::string_view templatePrefix = "com.unity.template";
1716
static 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
*/
14790
void 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
/**
178107
Fits 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
191113
struct 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+
};

source/interface_derived.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ void MainFrameDerived::OnAbout(wxCommandEvent& event)
249249
aboutInfo.SetIcon(wxIcon(wxICON(wxlin)));
250250
aboutInfo.SetVersion(AppVersion);
251251
#elif defined _WIN32
252-
aboutInfo.SetVersion(AppVersion);
252+
aboutInfo.SetVersion(AppVersion.data());
253253
aboutInfo.SetIcon(wxIcon("IDI_WXWIN"));
254254
#endif
255255
wxAboutBox(aboutInfo);

source/interface_derived.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <wx/timer.h>
1616
#include <wx/msgdlg.h>
1717
#include <functional>
18+
#include <deque>
1819

1920
#if defined __linux__
2021
#include "wxlin.xpm"

0 commit comments

Comments
 (0)