mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add function to create an absolute file path
Add function to create an absolute file path from a prefix path and a relative one. If the prefix is null, then the root directory of the current path is used.
This commit is contained in:
@@ -728,6 +728,7 @@ static std::string migrate_gnc_datahome()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined G_OS_WIN32 ||defined MAC_INTEGRATION
|
#if defined G_OS_WIN32 ||defined MAC_INTEGRATION
|
||||||
constexpr auto path_package = PACKAGE_NAME;
|
constexpr auto path_package = PACKAGE_NAME;
|
||||||
#else
|
#else
|
||||||
@@ -1017,6 +1018,35 @@ gnc_userdata_dir_as_path (void)
|
|||||||
return gnc_userdata_home;
|
return gnc_userdata_home;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *gnc_file_path_absolute (const gchar *prefix, const gchar *relative)
|
||||||
|
{
|
||||||
|
bfs::path path_relative (relative);
|
||||||
|
path_relative.imbue (bfs_locale);
|
||||||
|
bfs::path path_absolute;
|
||||||
|
bfs::path path_head;
|
||||||
|
|
||||||
|
if (prefix == nullptr)
|
||||||
|
{
|
||||||
|
const gchar *doc_dir = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
|
||||||
|
if (doc_dir == nullptr)
|
||||||
|
path_head = bfs::path (gnc_userdata_dir ()); // running as root maybe
|
||||||
|
else
|
||||||
|
path_head = bfs::path (doc_dir);
|
||||||
|
|
||||||
|
path_head.imbue (bfs_locale);
|
||||||
|
path_absolute = absolute (path_relative, path_head);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bfs::path path_head (prefix);
|
||||||
|
path_head.imbue (bfs_locale);
|
||||||
|
path_absolute = absolute (path_relative, path_head);
|
||||||
|
}
|
||||||
|
path_absolute.imbue (bfs_locale);
|
||||||
|
|
||||||
|
return g_strdup (path_absolute.string().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
/** @fn gchar * gnc_build_userdata_path (const gchar *filename)
|
/** @fn gchar * gnc_build_userdata_path (const gchar *filename)
|
||||||
* @brief Make a path to filename in the user's configuration directory.
|
* @brief Make a path to filename in the user's configuration directory.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -49,6 +49,15 @@ gchar *gnc_resolve_file_path (const gchar *filefrag);
|
|||||||
*/
|
*/
|
||||||
gchar *gnc_file_path_relative_part (const gchar *prefix, const gchar *path);
|
gchar *gnc_file_path_relative_part (const gchar *prefix, const gchar *path);
|
||||||
|
|
||||||
|
/** Given a prefix and a relative path, return the absolute path.
|
||||||
|
* @param prefix The prefix that is the head of the path
|
||||||
|
* @param relative The path to add to the prefix to form an absolute path
|
||||||
|
* @return a char* that must be g_freed containing the absolute path.
|
||||||
|
*
|
||||||
|
* If prefix is null, then the gnc_userdata_home is used as the prefix.
|
||||||
|
*/
|
||||||
|
gchar *gnc_file_path_absolute (const gchar *prefix, const gchar *relative);
|
||||||
|
|
||||||
/** @brief Find an absolute path to a localized version of a given
|
/** @brief Find an absolute path to a localized version of a given
|
||||||
* relative path to a html or html related file.
|
* relative path to a html or html related file.
|
||||||
* If no localized version exists, an absolute path to the file
|
* If no localized version exists, an absolute path to the file
|
||||||
|
|||||||
Reference in New Issue
Block a user