Skip to content

Commit

Permalink
Fix xtd::environment::get_folder_path method with xtd::environment::s…
Browse files Browse the repository at this point in the history
…pecial_folder::application_resources parameter on macOS
  • Loading branch information
gammasoft71 committed Nov 8, 2024
1 parent 796d472 commit 5cbe0df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/xtd.core/include/xtd/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,14 +604,14 @@ namespace xtd {
/// @param folder One of enumeration values that identifies a system special folder.
/// @return The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string ("").
/// @remarks This method retrieves the path to a system special folder, such as Program Files, Programs, System, or Startup, which can be used to access common information. Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows.
static xtd::string get_folder_path(environment::special_folder folder);
static xtd::string get_folder_path(environment::special_folder folder) {return get_folder_path_(folder, environment::special_folder_option::none);}

/// @brief Gets the path to the system special folder that is identified by the specified enumeration, and uses a specified option for accessing special folders.
/// @param folder One of the enumeration values that identifies a system special folder.
/// @param option One of the enumeration values that specifies options to use for accessing a special folder.
/// @return The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string ("").
/// @remarks This method retrieves the path to a system special folder, such as Program Files, Programs, System, or Startup, which can be used to access common information. Special folders are set by default by the system, or explicitly by the user, when installing a version of Windows.
static xtd::string get_folder_path(environment::special_folder folder, environment::special_folder_option option);
static xtd::string get_folder_path(environment::special_folder folder, environment::special_folder_option option) {return get_folder_path_(folder, option);}

/// @brief Returns an array of string containing the names of the logical drives on the current computer.
/// @return An array of strings where each element contains the name of a logical drive. For example, if the computer's hard drive is the first logical drive, the first element returned is "C:\".
Expand Down Expand Up @@ -659,7 +659,7 @@ namespace xtd {
static void on_cancel_signal(signal_cancel_event_args& e);
static void on_program_exit(const program_exit_event_args& e);

inline static bool is_gui_application() noexcept {return target_type().is_guid_application();}
static xtd::string get_folder_path_(environment::special_folder folder, environment::special_folder_option option, bool is_gui_application = target_type().is_guid_application());
inline static const string xtd_root_path() {return xtd::io::path::get_full_path(string::is_empty(__XTD_ROOT_PATH__) ? (string::is_empty(get_environment_variable("XTD_ROOT_PATH")) ? io::path::get_full_path(io::path::combine(io::path::get_directory_name(__FILE__), "..", "..")) : get_environment_variable("XTD_ROOT_PATH")) : __XTD_ROOT_PATH__);}
static signal_catcher signal_catcher_;
};
Expand Down
68 changes: 32 additions & 36 deletions src/xtd.core/src/xtd/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,40 +347,6 @@ std::map<std::string, std::string>& environment::get_environment_variables(envir
return native::environment::get_environment_variables(as<int32>(target));
}

xtd::string environment::get_folder_path(environment::special_folder folder) {
return get_folder_path(folder, environment::special_folder_option::none);
}

string environment::get_folder_path(environment::special_folder folder, environment::special_folder_option option) {
switch (folder) {
case environment::special_folder::application_resources: return path::get_full_path(native::environment::get_resources_path(is_gui_application()));
case environment::special_folder::xtd_install: return xtd_root_path();
case environment::special_folder::xtd_locale: return path::combine(xtd_root_path(), "share", "xtd", "locale");
case environment::special_folder::xtd_reference_guide: return path::combine(xtd_root_path(), "share", "xtd", "reference_guide");
case environment::special_folder::xtd_themes: return path::combine(xtd_root_path(), "share", "xtd", "themes");
case environment::special_folder::xtd_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_resources: return path::combine(xtd_root_path(), "share", "xtd", "resources");
case environment::special_folder::xtd_console_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_console_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_drawing_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_drawing_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_drawing_resources: return path::combine(xtd_root_path(), "share", "xtd", "resources");
case environment::special_folder::xtd_forms_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_forms_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_forms_resources: return path::combine(xtd_root_path(), "share", "xtd", "resources");
case environment::special_folder::xtd_tunit_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_tunit_libraries: return path::combine(xtd_root_path(), "lib");
default: break;
}

auto path = native::environment::get_know_folder_path(static_cast<int32>(folder));
if (path.empty()) return path;
if (option == environment::special_folder_option::none) return !xtd::io::directory::exists(path) ? "" : path;
if (option == environment::special_folder_option::create && !xtd::io::directory::exists(path)) xtd::io::directory::create_directory(path);
return path;
}

xtd::collections::specialized::string_collection environment::get_logical_drives() {
return io::directory::get_logical_drives();
}
Expand Down Expand Up @@ -421,6 +387,10 @@ void environment::set_environment_variable(const string& variable, const string&
}
}

void environment::__signal_catcher_check__() {
unused_(signal_catcher_);
}

void environment::on_cancel_signal(signal_cancel_event_args& e) {
auto signal = cancel_signal;
if (!signal.is_empty()) signal(e);
Expand All @@ -431,6 +401,32 @@ void environment::on_program_exit(const program_exit_event_args& e) {
if (!event.is_empty()) event(e);
}

void environment::__signal_catcher_check__() {
unused_(signal_catcher_);
string environment::get_folder_path_(environment::special_folder folder, environment::special_folder_option option, bool is_gui_application) {
switch (folder) {
case environment::special_folder::application_resources: return path::get_full_path(native::environment::get_resources_path(is_gui_application));
case environment::special_folder::xtd_install: return xtd_root_path();
case environment::special_folder::xtd_locale: return path::combine(xtd_root_path(), "share", "xtd", "locale");
case environment::special_folder::xtd_reference_guide: return path::combine(xtd_root_path(), "share", "xtd", "reference_guide");
case environment::special_folder::xtd_themes: return path::combine(xtd_root_path(), "share", "xtd", "themes");
case environment::special_folder::xtd_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_resources: return path::combine(xtd_root_path(), "share", "xtd", "resources");
case environment::special_folder::xtd_console_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_console_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_drawing_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_drawing_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_drawing_resources: return path::combine(xtd_root_path(), "share", "xtd", "resources");
case environment::special_folder::xtd_forms_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_forms_libraries: return path::combine(xtd_root_path(), "lib");
case environment::special_folder::xtd_forms_resources: return path::combine(xtd_root_path(), "share", "xtd", "resources");
case environment::special_folder::xtd_tunit_include: return path::combine(xtd_root_path(), "include");
case environment::special_folder::xtd_tunit_libraries: return path::combine(xtd_root_path(), "lib");
default: break;
}

auto path = native::environment::get_know_folder_path(static_cast<int32>(folder));
if (path.empty()) return path;
if (option == environment::special_folder_option::none) return !xtd::io::directory::exists(path) ? "" : path;
if (option == environment::special_folder_option::create && !xtd::io::directory::exists(path)) xtd::io::directory::create_directory(path);
return path;
}

0 comments on commit 5cbe0df

Please sign in to comment.