Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sun, 25 Oct 2020 09:25:26 UTC Commit: ad54ee5999d41e635f46a131b62067bb145c6050 https://github.com/geany/geany/commit/ad54ee5999d41e635f46a131b62067bb145c60...
Log Message: ----------- Merge pull request #2618 from codebrainz/os-info-improvements
OS Info Improvements
Modified Paths: -------------- src/libmain.c src/utils.c src/utils.h
Modified: src/libmain.c 16 lines changed, 7 insertions(+), 9 deletions(-) =================================================================== @@ -1068,6 +1068,7 @@ gint main_lib(gint argc, gchar **argv) gint config_dir_result; const gchar *locale; gchar *utf8_configdir; + gchar *os_info;
#if ! GLIB_CHECK_VERSION(2, 36, 0) g_type_init(); @@ -1161,15 +1162,12 @@ gint main_lib(gint argc, gchar **argv) gtk_major_version, gtk_minor_version, gtk_micro_version, glib_major_version, glib_minor_version, glib_micro_version);
-#if GLIB_CHECK_VERSION(2, 64, 0) - gchar *os_prettyname = g_get_os_info(G_OS_INFO_KEY_PRETTY_NAME); - gchar *os_codename = g_get_os_info(G_OS_INFO_KEY_VERSION_CODENAME); - geany_debug("OS: %s (%s)", - os_prettyname ? os_prettyname : "Unknown", - os_codename ? os_codename : "Unknown"); - g_free(os_prettyname); - g_free(os_codename); -#endif + os_info = utils_get_os_info_string(); + if (os_info != NULL) + { + geany_debug("OS: %s", os_info); + g_free(os_info); + }
geany_debug("System data dir: %s", app->datadir); utf8_configdir = utils_get_utf8_from_locale(app->configdir);
Modified: src/utils.c 68 lines changed, 68 insertions(+), 0 deletions(-) =================================================================== @@ -2406,3 +2406,71 @@ gchar *utils_get_real_path(const gchar *file_name) { return tm_get_real_path(file_name); } + + +/* + * Get a string describing the OS. + * + * If the OS can be determined, a string which describes the OS will + * be returned. If no OS can be determined then `NULL` will be returned. + * + * @note The format of the returned string is unspecified and is only + * meant to provide diagnostic information to the user. + * + * @return A newly-allocated string containing a description of the + * OS if it can be determined or `NULL` if it cannot. + * + * @since 1.37 + */ +gchar *utils_get_os_info_string(void) +{ + gchar *os_info = NULL; + +#if GLIB_CHECK_VERSION(2, 64, 0) +# if ! defined(__APPLE__) + /* on non-macOS operating systems */ + { + GString *os_str; + gchar *pretty_name; + gchar *code_name; + + pretty_name = g_get_os_info(G_OS_INFO_KEY_PRETTY_NAME); + if (pretty_name == NULL) + return NULL; + + os_str = g_string_new(pretty_name); + g_free(pretty_name); + + code_name = g_get_os_info(G_OS_INFO_KEY_VERSION_CODENAME); + if (code_name != NULL) + { + g_string_append_printf(os_str, " (%s)", code_name); + g_free(code_name); + } + + os_info = g_string_free(os_str, FALSE); + } +# else + /* on macOS, only `G_OS_INFO_KEY_NAME` is supported and returns the + * fixed string `macOS` */ + os_info = g_get_os_info(G_OS_INFO_KEY_NAME); +# endif +#else + /* if g_get_os_info() is not available, do it the old-fashioned way */ +# if defined(_WIN64) + os_info = g_strdup("Microsoft Windows (64-bit)"); +# elif defined(_WIN32) + os_info = g_strdup("Microsoft Windows"); +# elif defined(__APPLE__) + os_info = g_strdup("Apple macOS"); +# elif defined(__linux__) + os_info = g_strdup("Linux"); +# elif defined(__FreeBSD__) + os_info = g_strdup("FreeBSD"); +# elif defined(__ANDROID__) + os_info = g_strdup("Android"); +# endif +#endif + + return os_info; +}
Modified: src/utils.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -332,6 +332,8 @@ const gchar *utils_resource_dir(GeanyResourceDirType type);
void utils_start_new_geany_instance(const gchar *doc_path);
+gchar *utils_get_os_info_string(void); + #endif /* GEANY_PRIVATE */
G_END_DECLS
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).