Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravbug committed Nov 10, 2023
2 parents 7152d09 + 298b97c commit e700d6f
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 66 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project("UnityHubNative")
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<CONFIGURATION>)
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym" CACHE INTERNAL "")

option(BUILD_SHARED_LIBS OFF "Build static")

Expand Down Expand Up @@ -101,7 +102,6 @@ INSTALL(CODE
EXE \"${CMAKE_INSTALL_PREFIX}/$<CONFIGURATION>/${PROJECT_NAME}\"
NAME \"${PROJECT_NAME}\"
ICON \"${CMAKE_CURRENT_SOURCE_DIR}/source/wxlin.xpm\"
DIR_ICON \"${CMAKE_CURRENT_SOURCE_DIR}/source/wxlin.xpm\"
OUTPUT_NAME \"${CMAKE_INSTALL_PREFIX}/$<CONFIGURATION>/${PROJECT_NAME}.AppImage\"
ASSETS \"\"
)
Expand Down
23 changes: 13 additions & 10 deletions appimage.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function(make_appimage)
set(optional)
set(args EXE NAME DIR_ICON ICON OUTPUT_NAME)
set(args EXE NAME ICON OUTPUT_NAME)
set(list_args ASSETS)
cmake_parse_arguments(
PARSE_ARGV 0
Expand All @@ -22,10 +22,13 @@ function(make_appimage)
execute_process(COMMAND chmod +x ${AIT_PATH})
endif()

# make the AppDir
# make the AppDir and icons directory
set(APPDIR "${CMAKE_BINARY_DIR}/AppDir")
set(RICONDIR "usr/share/icons/hicolor/512x512/apps") # relative icon dir
set(ICONDIR "${APPDIR}/${RICONDIR}")
file(REMOVE_RECURSE "${APPDIR}") # remove if leftover
file(MAKE_DIRECTORY "${APPDIR}")
file(MAKE_DIRECTORY "${ICONDIR}")

# copy executable to appdir
file(COPY "${ARGS_EXE}" DESTINATION "${APPDIR}" FOLLOW_SYMLINK_CHAIN)
Expand All @@ -42,23 +45,23 @@ cd \"$(dirname \"$0\")\";
# copy assets to appdir
file(COPY ${ARGS_ASSETS} DESTINATION "${APPDIR}")

# copy icon thumbnail
file(COPY ${ARGS_DIR_ICON} DESTINATION "${APPDIR}")
get_filename_component(THUMB_NAME "${ARGS_DIR_ICON}" NAME)
file(RENAME "${APPDIR}/${THUMB_NAME}" "${APPDIR}/.DirIcon")

# copy icon highres
file(COPY ${ARGS_ICON} DESTINATION "${APPDIR}")
# copy icon
file(COPY ${ARGS_ICON} DESTINATION "${ICONDIR}")
get_filename_component(ICON_NAME "${ARGS_ICON}" NAME)
get_filename_component(ICON_EXT "${ARGS_ICON}" EXT)
file(RENAME "${APPDIR}/${ICON_NAME}" "${APPDIR}/${ARGS_NAME}${ICON_EXT}")
file(RENAME "${ICONDIR}/${ICON_NAME}" "${ICONDIR}/${ARGS_NAME}${ICON_EXT}")

# create icon symlinks
file(CREATE_LINK "${RICONDIR}/${ARGS_NAME}${ICON_EXT}" "${APPDIR}/.DirIcon" SYMBOLIC)
file(CREATE_LINK "${RICONDIR}/${ARGS_NAME}${ICON_EXT}" "${APPDIR}/${ARGS_NAME}${ICON_EXT}" SYMBOLIC)

# Create the .desktop file
file(WRITE "${APPDIR}/${ARGS_NAME}.desktop"
"[Desktop Entry]
Type=Application
Name=${ARGS_NAME}
Icon=${ARGS_NAME}
Exec=AppRun
Categories=X-None;"
)

Expand Down
8 changes: 4 additions & 4 deletions source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundleGetInfoString</key>
<string>$(PRODUCT_NAME) (c) 2022 Ravbug</string>
<string>$(PRODUCT_NAME) (c) 2023 Ravbug</string>
<key>CFBundleIconFile</key>
<string>wxmac.icns</string>
<key>CFBundleIdentifier</key>
Expand All @@ -22,21 +22,21 @@
<string>it</string>
</array>
<key>CFBundleLongVersionString</key>
<string>(c) 2022 Ravbug</string>
<string>(c) 2023 Ravbug</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.52</string>
<string>1.53</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright 2022 Ravbug</string>
<string>Copyright 2023 Ravbug</string>
<key>NSPrincipalClass</key>
<string>wxNSApplication</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion source/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void PersonalActivationDlg::OnCreateHit(wxCommandEvent& evt)
wxSetWorkingDirectory(root.string());
wxProcess proc(wxPROCESS_DEFAULT);
wxExecute(cmd, wxEXEC_SYNC);
reveal_in_explorer(wxGetCwd());
reveal_in_explorer(std::filesystem::path(wxGetCwd().ToStdString()));
wxSetWorkingDirectory(cwd);
}
}
Expand Down
17 changes: 12 additions & 5 deletions source/globals.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "globals.h"
#include <fmt/format.h>
#include <wx/listctrl.h>
#include <wx/msgdlg.h>

void launch_process(const std::string& command, int flags) {
#if defined __APPLE__ || defined __linux__
Expand All @@ -16,18 +17,24 @@ void launch_process(const std::string& command, int flags) {
#endif
}

void reveal_in_explorer(const std::string& path) {
void reveal_in_explorer(const std::filesystem::path& path) {
#if defined __APPLE__
std::string command = "open \"" + path + "\"";
std::string command = "open \"" + path.string() + "\"";

#elif defined __linux__
std::string command = "xdg-open \"" + path + "\"";
std::string command = "xdg-open \"" + path.string() + "\"";

#elif defined _WIN32
//do not surround the paths in quotes, it will not work
std::string command = "\\Windows\\explorer.exe \"" + path + "\"";
std::string command = "\\Windows\\explorer.exe \"" + path.string() + "\"";
#endif
launch_process(command);
if (std::filesystem::exists(path)) {
launch_process(command);
}
else {
wxMessageBox("The project at " + path.string() + " could not be found.", "Cannot Reveal Project", wxOK | wxICON_ERROR);
}

}

long wxListCtrl_get_selected(wxListCtrl* listCtrl) {
Expand Down
4 changes: 2 additions & 2 deletions source/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
static constexpr std::string_view projectsFile = "projects.txt";
static constexpr std::string_view editorPathsFile = "editorPaths.txt";
static constexpr std::string_view templatePrefix = "com.unity.template";
static constexpr std::string_view AppVersion = "v1.52";
static constexpr std::string_view AppVersion = "v1.53";

struct wxListCtrl;
struct wxWindow;
Expand Down Expand Up @@ -96,7 +96,7 @@ void launch_process(const std::string& command, int flags = 0);
* Open system file explorer to path
* @param path the item to show
*/
void reveal_in_explorer(const std::string& path);
void reveal_in_explorer(const std::filesystem::path& path);

/**
Gets the first selected item in a wxListCtrl. If the wxListCtrl is set to single selection, this method will retrive the only selected item.
Expand Down
63 changes: 23 additions & 40 deletions source/interface_derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,10 @@ void MainFrameDerived::LoadProjects(const std::string &filter){
vector<string> erroredProjects;
//load each project (each path is on its own line)
while (getline(in, line)){
try{
project pr = LoadProject(line);
AddProject(pr,filter);
}
catch(runtime_error& e){
//remove project
erroredProjects.push_back(line);
}
}
//alert user if projects could not be loaded
if (erroredProjects.size() > 0){
//build string
string str;
for (const auto& s : erroredProjects){
str += s + "\n";
}
//message box
wxMessageBox("The following projects could not be loaded. They have been removed from the list.\n\n"+str, "Loading error", wxOK | wxICON_WARNING );

//save to remove the broken projects
SaveProjects();

project pr = LoadProject(line);
AddProject(pr,filter);

}
}
}
Expand All @@ -243,7 +226,7 @@ void MainFrameDerived::OnAbout(wxCommandEvent& event)
{
wxAboutDialogInfo aboutInfo;
aboutInfo.SetName("Unity Hub Native");
aboutInfo.SetCopyright("(C) Ravbug 2022");
aboutInfo.SetCopyright("(C) Ravbug 2023");
aboutInfo.SetDescription("Developed with wxWidgets in C++");
#if defined __linux__
aboutInfo.SetWebSite("https:/ravbug/UnityHubNative");
Expand Down Expand Up @@ -365,7 +348,7 @@ void MainFrameDerived::OnRevealProject(wxCommandEvent& event){
long selectedIndex = wxListCtrl_get_selected(projectsList);
if (selectedIndex > -1){
project& p = projects[selectedIndex];
reveal_in_explorer(p.path.string());
reveal_in_explorer(p.path);
}
}

Expand Down Expand Up @@ -472,33 +455,33 @@ string MainFrameDerived::GetPathFromDialog(const string& message)
*/
project MainFrameDerived::LoadProject(const std::filesystem::path &p_as_fs){
//error if the file does not exist
if (!filesystem::exists(p_as_fs)){
throw runtime_error(p_as_fs.string() + " does not exist.");
}


//the name is the final part of the path
string name = p_as_fs.filename().string();

string version = "??";

//Load ProjectSettings/ProjectVersion.txt to get the editor version, if it exists
std::filesystem::path projSettings = p_as_fs / "ProjectSettings" / "ProjectVersion.txt";
if (!filesystem::exists(projSettings)){
throw runtime_error("No ProjectVersion.txt found at " + p_as_fs.string() + "\n\nEnsure the folder you selected is the root folder of a complete Unity project.");
if (filesystem::exists(projSettings)){
//the first line of ProjectVersion.txt contains the editor verison as plain text
ifstream inFile;
inFile.open(projSettings);
getline(inFile, version);
version = version.substr(17);
}

//the first line of ProjectVersion.txt contains the editor verison as plain text
string version;
ifstream inFile;
inFile.open(projSettings);
getline(inFile,version);
version = version.substr(17);

//get the modification date
struct stat fileInfo;
if (stat(p_as_fs.string().c_str(), &fileInfo) != 0) {
throw runtime_error("Cannot get modification date. Ensure this program has access to "+p_as_fs.string());
string modifyDate;
struct stat fileInfo {};
if (filesystem::exists(p_as_fs)) {
if (stat(p_as_fs.string().c_str(), &fileInfo) == 0) {
modifyDate = ctime(&fileInfo.st_mtime);
}
}

project p = {name,version,ctime(&fileInfo.st_mtime),p_as_fs,};

project p = {name,version,modifyDate,p_as_fs,};
return p;
}

Expand Down
6 changes: 3 additions & 3 deletions source/interface_derived.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ class MainFrameDerived : public MainFrame{
editor& e = editors[id];
std::filesystem::path path = e.path / e.name;
if (!std::filesystem::exists(path)){
reveal_in_explorer(e.path.string());
reveal_in_explorer(e.path);
}
else{
reveal_in_explorer(path.string());
reveal_in_explorer(path);
}
}
}
Expand All @@ -153,7 +153,7 @@ class MainFrameDerived : public MainFrame{
void OnRevealInstallLocation(wxCommandEvent& event){
int id = installsPathsList->GetSelection();
if (id != wxNOT_FOUND){
reveal_in_explorer(installPaths[id].string());
reveal_in_explorer(installPaths[id]);
}
}
void OnOpenHub(wxCommandEvent& event);
Expand Down

0 comments on commit e700d6f

Please sign in to comment.