Cleanup: Split fsmenu.c before C++ conversion
The complication is that `Carbon.h` also defines its own`Collection` type, which is visible in this file as a forward declaration in `UI_interface_icons.h`. To fix that, move the code that needs to include platform specific includes to a separate file that includes fewer Blender headers. See #103343 Pull Request: https://projects.blender.org/blender/blender/pulls/110731
This commit is contained in:
parent
42dfa740c4
commit
97769581f5
@ -36,6 +36,7 @@ set(SRC
|
||||
filesel.cc
|
||||
folder_history.cc
|
||||
fsmenu.c
|
||||
fsmenu_system.c
|
||||
space_file.cc
|
||||
|
||||
file_indexer.hh
|
||||
|
@ -23,30 +23,11 @@
|
||||
|
||||
#include "ED_fileselect.h"
|
||||
|
||||
#ifdef WIN32
|
||||
/* Need to include windows.h so _WIN32_IE is defined. */
|
||||
# include <windows.h>
|
||||
/* For SHGetSpecialFolderPath, has to be done before BLI_winstuff
|
||||
* because 'near' is disabled through BLI_windstuff. */
|
||||
# include "BLI_winstuff.h"
|
||||
# include <shlobj.h>
|
||||
# include <shlwapi.h>
|
||||
#endif
|
||||
|
||||
#include "UI_interface_icons.h"
|
||||
#include "UI_resources.h"
|
||||
#include "WM_api.h"
|
||||
#include "WM_types.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
# include <Carbon/Carbon.h>
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#ifdef __linux__
|
||||
# include "BLI_fileops_types.h"
|
||||
# include <mntent.h>
|
||||
#endif
|
||||
|
||||
#include "fsmenu.h" /* include ourselves */
|
||||
|
||||
/* FSMENU HANDLING */
|
||||
@ -93,109 +74,6 @@ FSMenuEntry *ED_fsmenu_get_category(FSMenu *fsmenu, FSMenuCategory category)
|
||||
return fsm_head;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name XDG User Directory Support (Unix)
|
||||
*
|
||||
* Generic Unix, Use XDG when available, otherwise fallback to the home directory.
|
||||
* \{ */
|
||||
|
||||
/**
|
||||
* Look for `user-dirs.dirs`, where localized or custom user folders are defined,
|
||||
* and store their paths in a GHash.
|
||||
*/
|
||||
static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
|
||||
{
|
||||
/* Add to the default for variable, equals & quotes. */
|
||||
char l[128 + FILE_MAXDIR];
|
||||
FILE *fp;
|
||||
|
||||
/* Check if the config file exists. */
|
||||
{
|
||||
char filepath[FILE_MAX];
|
||||
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home != NULL) {
|
||||
BLI_path_join(filepath, sizeof(filepath), xdg_config_home, "user-dirs.dirs");
|
||||
}
|
||||
else {
|
||||
BLI_path_join(filepath, sizeof(filepath), home, ".config", "user-dirs.dirs");
|
||||
}
|
||||
fp = BLI_fopen(filepath, "r");
|
||||
if (!fp) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* By default there are 8 paths. */
|
||||
GHash *xdg_map = BLI_ghash_str_new_ex(__func__, 8);
|
||||
while (fgets(l, sizeof(l), fp) != NULL) { /* read a line */
|
||||
|
||||
/* Avoid inserting invalid values. */
|
||||
if (STRPREFIX(l, "XDG_")) {
|
||||
char *l_value = strchr(l, '=');
|
||||
if (l_value != NULL) {
|
||||
*l_value = '\0';
|
||||
l_value++;
|
||||
|
||||
BLI_str_rstrip(l_value);
|
||||
const uint l_value_len = strlen(l_value);
|
||||
if ((l_value[0] == '"') && (l_value_len > 0) && (l_value[l_value_len - 1] == '"')) {
|
||||
l_value[l_value_len - 1] = '\0';
|
||||
l_value++;
|
||||
|
||||
char l_value_expanded[FILE_MAX];
|
||||
char *l_value_final = l_value;
|
||||
|
||||
/* This is currently the only variable used.
|
||||
* Based on the 'user-dirs.dirs' man page,
|
||||
* there is no need to resolve arbitrary environment variables. */
|
||||
if (STRPREFIX(l_value, "$HOME" SEP_STR)) {
|
||||
BLI_path_join(l_value_expanded, sizeof(l_value_expanded), home, l_value + 6);
|
||||
l_value_final = l_value_expanded;
|
||||
}
|
||||
|
||||
BLI_ghash_insert(xdg_map, BLI_strdup(l), BLI_strdup(l_value_final));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return xdg_map;
|
||||
}
|
||||
|
||||
static void fsmenu_xdg_user_dirs_free(GHash *xdg_map)
|
||||
{
|
||||
if (xdg_map != NULL) {
|
||||
BLI_ghash_free(xdg_map, MEM_freeN, MEM_freeN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fsmenu entry for system folders on linux.
|
||||
* - Check if a path is stored in the #GHash generated from `user-dirs.dirs`.
|
||||
* - If not, check for a default path in `$HOME`.
|
||||
*
|
||||
* \param key: Use `user-dirs.dirs` format "XDG_EXAMPLE_DIR"
|
||||
* \param default_path: Directory name to check in $HOME, also used for the menu entry name.
|
||||
*/
|
||||
static void fsmenu_xdg_insert_entry(GHash *xdg_map,
|
||||
FSMenu *fsmenu,
|
||||
const char *key,
|
||||
const char *default_path,
|
||||
int icon,
|
||||
const char *home)
|
||||
{
|
||||
char xdg_path_buf[FILE_MAXDIR];
|
||||
const char *xdg_path = xdg_map ? BLI_ghash_lookup(xdg_map, key) : NULL;
|
||||
if (xdg_path == NULL) {
|
||||
BLI_path_join(xdg_path_buf, sizeof(xdg_path_buf), home, default_path);
|
||||
xdg_path = xdg_path_buf;
|
||||
}
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, xdg_path, N_(default_path), icon, FS_INSERT_LAST);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
void ED_fsmenu_set_category(FSMenu *fsmenu, FSMenuCategory category, FSMenuEntry *fsm_head)
|
||||
{
|
||||
switch (category) {
|
||||
@ -617,454 +495,6 @@ void fsmenu_read_bookmarks(FSMenu *fsmenu, const char *filepath)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
/* Add a Windows known folder path to the System list. */
|
||||
static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
|
||||
FSMenuCategory category,
|
||||
REFKNOWNFOLDERID rfid,
|
||||
const char *name,
|
||||
const int icon,
|
||||
FSMenuInsert flag)
|
||||
{
|
||||
LPWSTR pPath;
|
||||
char line[FILE_MAXDIR];
|
||||
if (SHGetKnownFolderPath(rfid, 0, NULL, &pPath) == S_OK) {
|
||||
BLI_strncpy_wchar_as_utf8(line, pPath, FILE_MAXDIR);
|
||||
CoTaskMemFree(pPath);
|
||||
fsmenu_insert_entry(fsmenu, category, line, name, icon, flag);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
|
||||
{
|
||||
char line[FILE_MAXDIR];
|
||||
#ifdef WIN32
|
||||
/* Add the drive names to the listing */
|
||||
{
|
||||
wchar_t wline[FILE_MAXDIR];
|
||||
__int64 tmp;
|
||||
char tmps[4], *name;
|
||||
|
||||
tmp = GetLogicalDrives();
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if ((tmp >> i) & 1) {
|
||||
tmps[0] = 'A' + i;
|
||||
tmps[1] = ':';
|
||||
tmps[2] = '\\';
|
||||
tmps[3] = '\0';
|
||||
name = NULL;
|
||||
|
||||
/* Skip over floppy disks A & B. */
|
||||
if (i > 1) {
|
||||
/* Friendly volume descriptions without using SHGetFileInfoW (#85689). */
|
||||
BLI_strncpy_wchar_from_utf8(wline, tmps, 4);
|
||||
IShellFolder *desktop;
|
||||
if (SHGetDesktopFolder(&desktop) == S_OK) {
|
||||
PIDLIST_RELATIVE volume;
|
||||
if (desktop->lpVtbl->ParseDisplayName(
|
||||
desktop, NULL, NULL, wline, NULL, &volume, NULL) == S_OK) {
|
||||
STRRET volume_name;
|
||||
volume_name.uType = STRRET_WSTR;
|
||||
if (desktop->lpVtbl->GetDisplayNameOf(
|
||||
desktop, volume, SHGDN_FORADDRESSBAR, &volume_name) == S_OK) {
|
||||
wchar_t *volume_name_wchar;
|
||||
if (StrRetToStrW(&volume_name, volume, &volume_name_wchar) == S_OK) {
|
||||
BLI_strncpy_wchar_as_utf8(line, volume_name_wchar, FILE_MAXDIR);
|
||||
name = line;
|
||||
CoTaskMemFree(volume_name_wchar);
|
||||
}
|
||||
}
|
||||
CoTaskMemFree(volume);
|
||||
}
|
||||
desktop->lpVtbl->Release(desktop);
|
||||
}
|
||||
}
|
||||
if (name == NULL) {
|
||||
name = tmps;
|
||||
}
|
||||
|
||||
int icon = ICON_DISK_DRIVE;
|
||||
switch (GetDriveType(tmps)) {
|
||||
case DRIVE_REMOVABLE:
|
||||
icon = ICON_EXTERNAL_DRIVE;
|
||||
break;
|
||||
case DRIVE_CDROM:
|
||||
icon = ICON_DISC;
|
||||
break;
|
||||
case DRIVE_FIXED:
|
||||
case DRIVE_RAMDISK:
|
||||
icon = ICON_DISK_DRIVE;
|
||||
break;
|
||||
case DRIVE_REMOTE:
|
||||
icon = ICON_NETWORK_DRIVE;
|
||||
break;
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM,
|
||||
tmps,
|
||||
name,
|
||||
icon,
|
||||
FS_INSERT_SORTED | FS_INSERT_NO_VALIDATE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get Special Folder Locations. */
|
||||
if (read_bookmarks) {
|
||||
|
||||
/* These items are shown in System List. */
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Profile,
|
||||
N_("Home"),
|
||||
ICON_HOME,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Desktop,
|
||||
N_("Desktop"),
|
||||
ICON_DESKTOP,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Documents,
|
||||
N_("Documents"),
|
||||
ICON_DOCUMENTS,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Downloads,
|
||||
N_("Downloads"),
|
||||
ICON_IMPORT,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Music,
|
||||
N_("Music"),
|
||||
ICON_FILE_SOUND,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Pictures,
|
||||
N_("Pictures"),
|
||||
ICON_FILE_IMAGE,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Videos,
|
||||
N_("Videos"),
|
||||
ICON_FILE_MOVIE,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Fonts,
|
||||
N_("Fonts"),
|
||||
ICON_FILE_FONT,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_SkyDrive,
|
||||
N_("OneDrive"),
|
||||
ICON_URL,
|
||||
FS_INSERT_LAST);
|
||||
|
||||
/* These items are just put in path cache for thumbnail views and if bookmarked. */
|
||||
|
||||
fsmenu_add_windows_folder(
|
||||
fsmenu, FS_CATEGORY_OTHER, &FOLDERID_UserProfiles, NULL, ICON_COMMUNITY, FS_INSERT_LAST);
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
{
|
||||
/* We store some known macOS system paths and corresponding icons
|
||||
* and names in the FS_CATEGORY_OTHER (not displayed directly) category. */
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_OTHER, "/Library/Fonts/", N_("Fonts"), ICON_FILE_FONT, FS_INSERT_LAST);
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_OTHER,
|
||||
"/Applications/",
|
||||
N_("Applications"),
|
||||
ICON_FILE_FOLDER,
|
||||
FS_INSERT_LAST);
|
||||
|
||||
const char *home = BLI_getenv("HOME");
|
||||
if (home) {
|
||||
# define FS_MACOS_PATH(path, name, icon) \
|
||||
SNPRINTF(line, path, home); \
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, line, name, icon, FS_INSERT_LAST);
|
||||
|
||||
FS_MACOS_PATH("%s/", NULL, ICON_HOME)
|
||||
FS_MACOS_PATH("%s/Desktop/", N_("Desktop"), ICON_DESKTOP)
|
||||
FS_MACOS_PATH("%s/Documents/", N_("Documents"), ICON_DOCUMENTS)
|
||||
FS_MACOS_PATH("%s/Downloads/", N_("Downloads"), ICON_IMPORT)
|
||||
FS_MACOS_PATH("%s/Movies/", N_("Movies"), ICON_FILE_MOVIE)
|
||||
FS_MACOS_PATH("%s/Music/", N_("Music"), ICON_FILE_SOUND)
|
||||
FS_MACOS_PATH("%s/Pictures/", N_("Pictures"), ICON_FILE_IMAGE)
|
||||
FS_MACOS_PATH("%s/Library/Fonts/", N_("Fonts"), ICON_FILE_FONT)
|
||||
|
||||
# undef FS_MACOS_PATH
|
||||
}
|
||||
|
||||
/* Get mounted volumes better method OSX 10.6 and higher, see:
|
||||
* https://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFURLRef/Reference/reference.html
|
||||
*/
|
||||
|
||||
/* We get all volumes sorted including network and do not relay
|
||||
* on user-defined finder visibility, less confusing. */
|
||||
|
||||
CFURLRef cfURL = NULL;
|
||||
CFURLEnumeratorResult result = kCFURLEnumeratorSuccess;
|
||||
CFURLEnumeratorRef volEnum = CFURLEnumeratorCreateForMountedVolumes(
|
||||
NULL, kCFURLEnumeratorSkipInvisibles, NULL);
|
||||
|
||||
while (result != kCFURLEnumeratorEnd) {
|
||||
char defPath[FILE_MAX];
|
||||
|
||||
result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, NULL);
|
||||
if (result != kCFURLEnumeratorSuccess) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CFURLGetFileSystemRepresentation(cfURL, false, (UInt8 *)defPath, FILE_MAX);
|
||||
|
||||
/* Get name of the volume. */
|
||||
char display_name[FILE_MAXFILE] = "";
|
||||
CFStringRef nameString = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeLocalizedNameKey, &nameString, NULL);
|
||||
if (nameString != NULL) {
|
||||
CFStringGetCString(nameString, display_name, sizeof(display_name), kCFStringEncodingUTF8);
|
||||
CFRelease(nameString);
|
||||
}
|
||||
|
||||
/* Set icon for regular, removable or network drive. */
|
||||
int icon = ICON_DISK_DRIVE;
|
||||
CFBooleanRef localKey = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsLocalKey, &localKey, NULL);
|
||||
if (localKey != NULL) {
|
||||
if (!CFBooleanGetValue(localKey)) {
|
||||
icon = ICON_NETWORK_DRIVE;
|
||||
}
|
||||
else {
|
||||
CFBooleanRef ejectableKey = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsEjectableKey, &ejectableKey, NULL);
|
||||
if (ejectableKey != NULL) {
|
||||
if (CFBooleanGetValue(ejectableKey)) {
|
||||
icon = ICON_EXTERNAL_DRIVE;
|
||||
}
|
||||
CFRelease(ejectableKey);
|
||||
}
|
||||
}
|
||||
CFRelease(localKey);
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM,
|
||||
defPath,
|
||||
display_name[0] ? display_name : NULL,
|
||||
icon,
|
||||
FS_INSERT_SORTED);
|
||||
}
|
||||
|
||||
CFRelease(volEnum);
|
||||
|
||||
/* kLSSharedFileListFavoriteItems is deprecated, but available till macOS 10.15.
|
||||
* Will have to find a new method to sync the Finder Favorites with File Browser. */
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
/* Finally get user favorite places */
|
||||
if (read_bookmarks) {
|
||||
UInt32 seed;
|
||||
LSSharedFileListRef list = LSSharedFileListCreate(
|
||||
NULL, kLSSharedFileListFavoriteItems, NULL);
|
||||
CFArrayRef pathesArray = LSSharedFileListCopySnapshot(list, &seed);
|
||||
CFIndex pathesCount = CFArrayGetCount(pathesArray);
|
||||
|
||||
for (CFIndex i = 0; i < pathesCount; i++) {
|
||||
LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(
|
||||
pathesArray, i);
|
||||
|
||||
CFURLRef cfURL = NULL;
|
||||
OSErr err = LSSharedFileListItemResolve(itemRef,
|
||||
kLSSharedFileListNoUserInteraction |
|
||||
kLSSharedFileListDoNotMountVolumes,
|
||||
&cfURL,
|
||||
NULL);
|
||||
if (err != noErr || !cfURL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CFStringRef pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
|
||||
|
||||
if (pathString == NULL ||
|
||||
!CFStringGetCString(pathString, line, sizeof(line), kCFStringEncodingUTF8))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Exclude "all my files" as it makes no sense in blender file-selector. */
|
||||
/* Exclude "airdrop" if wlan not active as it would show "" ) */
|
||||
if (!strstr(line, "myDocuments.cannedSearch") && (*line != '\0')) {
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_FILE_FOLDER, FS_INSERT_LAST);
|
||||
}
|
||||
|
||||
CFRelease(pathString);
|
||||
CFRelease(cfURL);
|
||||
}
|
||||
|
||||
CFRelease(pathesArray);
|
||||
CFRelease(list);
|
||||
}
|
||||
# pragma GCC diagnostic pop
|
||||
}
|
||||
#else
|
||||
/* unix */
|
||||
{
|
||||
const char *home = BLI_getenv("HOME");
|
||||
|
||||
if (read_bookmarks && home) {
|
||||
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, home, N_("Home"), ICON_HOME, FS_INSERT_LAST);
|
||||
|
||||
/* Follow the XDG spec, check if these are available. */
|
||||
GHash *xdg_map = fsmenu_xdg_user_dirs_parse(home);
|
||||
|
||||
struct {
|
||||
const char *key;
|
||||
const char *default_path;
|
||||
BIFIconID icon;
|
||||
} xdg_items[] = {
|
||||
{"XDG_DESKTOP_DIR", "Desktop", ICON_DESKTOP},
|
||||
{"XDG_DOCUMENTS_DIR", "Documents", ICON_DOCUMENTS},
|
||||
{"XDG_DOWNLOAD_DIR", "Downloads", ICON_IMPORT},
|
||||
{"XDG_VIDEOS_DIR", "Videos", ICON_FILE_MOVIE},
|
||||
{"XDG_PICTURES_DIR", "Pictures", ICON_FILE_IMAGE},
|
||||
{"XDG_MUSIC_DIR", "Music", ICON_FILE_SOUND},
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(xdg_items); i++) {
|
||||
fsmenu_xdg_insert_entry(
|
||||
xdg_map, fsmenu, xdg_items[i].key, xdg_items[i].default_path, xdg_items[i].icon, home);
|
||||
}
|
||||
|
||||
fsmenu_xdg_user_dirs_free(xdg_map);
|
||||
}
|
||||
|
||||
{
|
||||
int found = 0;
|
||||
# ifdef __linux__
|
||||
/* loop over mount points */
|
||||
struct mntent *mnt;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent(MOUNTED, "r");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "could not get a list of mounted file-systems\n");
|
||||
}
|
||||
else {
|
||||
while ((mnt = getmntent(fp))) {
|
||||
if (STRPREFIX(mnt->mnt_dir, "/boot")) {
|
||||
/* Hide share not usable to the user. */
|
||||
continue;
|
||||
}
|
||||
if (!STRPREFIX(mnt->mnt_fsname, "/dev")) {
|
||||
continue;
|
||||
}
|
||||
if (STRPREFIX(mnt->mnt_fsname, "/dev/loop")) {
|
||||
/* The dev/loop* entries are SNAPS used by desktop environment
|
||||
* (Gnome) no need for them to show up in the list. */
|
||||
continue;
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
|
||||
found = 1;
|
||||
}
|
||||
if (endmntent(fp) == 0) {
|
||||
fprintf(stderr, "could not close the list of mounted file-systems\n");
|
||||
}
|
||||
}
|
||||
/* Check `gvfs` shares. */
|
||||
const char *const xdg_runtime_dir = BLI_getenv("XDG_RUNTIME_DIR");
|
||||
if (xdg_runtime_dir != NULL) {
|
||||
struct direntry *dirs;
|
||||
char filepath[FILE_MAX];
|
||||
BLI_path_join(filepath, sizeof(filepath), xdg_runtime_dir, "gvfs/");
|
||||
/* Avoid error message if the directory doesn't exist as this isn't a requirement. */
|
||||
if (BLI_is_dir(filepath)) {
|
||||
const uint dirs_num = BLI_filelist_dir_contents(filepath, &dirs);
|
||||
for (uint i = 0; i < dirs_num; i++) {
|
||||
if ((dirs[i].type & S_IFDIR) == 0) {
|
||||
continue;
|
||||
}
|
||||
const char *dirname = dirs[i].relname;
|
||||
if (dirname[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Directory names contain a lot of unwanted text.
|
||||
* Assuming every entry ends with the share name. */
|
||||
const char *label = strstr(dirname, "share=");
|
||||
if (label != NULL) {
|
||||
/* Move pointer so `share=` is trimmed off or use full `dirname` as label. */
|
||||
const char *label_test = label + 6;
|
||||
label = *label_test ? label_test : dirname;
|
||||
}
|
||||
SNPRINTF(line, "%s%s", filepath, dirname);
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, line, label, ICON_NETWORK_DRIVE, FS_INSERT_SORTED);
|
||||
found = 1;
|
||||
}
|
||||
BLI_filelist_free(dirs, dirs_num);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
/* fallback */
|
||||
if (!found) {
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, "/", NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
/* Quiet warnings. */
|
||||
UNUSED_VARS(fsmenu_xdg_insert_entry, fsmenu_xdg_user_dirs_parse, fsmenu_xdg_user_dirs_free);
|
||||
#endif
|
||||
|
||||
/* For all platforms, we add some directories from User Preferences to
|
||||
* the FS_CATEGORY_OTHER category so that these directories
|
||||
* have the appropriate icons when they are added to the Bookmarks. */
|
||||
#define FS_UDIR_PATH(dir, icon) \
|
||||
if (BLI_strnlen(dir, 3) > 2) { \
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, dir, NULL, icon, FS_INSERT_LAST); \
|
||||
}
|
||||
|
||||
FS_UDIR_PATH(U.fontdir, ICON_FILE_FONT)
|
||||
FS_UDIR_PATH(U.textudir, ICON_FILE_IMAGE)
|
||||
LISTBASE_FOREACH (bUserScriptDirectory *, script_dir, &U.script_directories) {
|
||||
if (UNLIKELY(script_dir->dir_path[0] == '\0')) {
|
||||
continue;
|
||||
}
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_OTHER,
|
||||
script_dir->dir_path,
|
||||
script_dir->name,
|
||||
ICON_FILE_SCRIPT,
|
||||
FS_INSERT_LAST);
|
||||
}
|
||||
FS_UDIR_PATH(U.sounddir, ICON_FILE_SOUND)
|
||||
FS_UDIR_PATH(U.tempdir, ICON_TEMP)
|
||||
|
||||
#undef FS_UDIR_PATH
|
||||
}
|
||||
|
||||
static void fsmenu_free_category(FSMenu *fsmenu, FSMenuCategory category)
|
||||
{
|
||||
FSMenuEntry *fsm_iter = ED_fsmenu_get_category(fsmenu, category);
|
||||
|
610
source/blender/editors/space_file/fsmenu_system.c
Normal file
610
source/blender/editors/space_file/fsmenu_system.c
Normal file
@ -0,0 +1,610 @@
|
||||
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup spfile
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_fileops.h"
|
||||
#include "BLI_ghash.h"
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_path_util.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_string_utf8.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "DNA_userdef_types.h"
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
#include "BKE_appdir.h"
|
||||
|
||||
#include "ED_fileselect.h"
|
||||
|
||||
#ifdef WIN32
|
||||
/* Need to include windows.h so _WIN32_IE is defined. */
|
||||
# include <windows.h>
|
||||
/* For SHGetSpecialFolderPath, has to be done before BLI_winstuff
|
||||
* because 'near' is disabled through BLI_windstuff. */
|
||||
# include "BLI_winstuff.h"
|
||||
# include <shlobj.h>
|
||||
# include <shlwapi.h>
|
||||
#endif
|
||||
|
||||
#include "UI_resources.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
# include <Carbon/Carbon.h>
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#ifdef __linux__
|
||||
# include "BLI_fileops_types.h"
|
||||
# include <mntent.h>
|
||||
#endif
|
||||
|
||||
#include "fsmenu.h"
|
||||
|
||||
struct FSMenu;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name XDG User Directory Support (Unix)
|
||||
*
|
||||
* Generic Unix, Use XDG when available, otherwise fallback to the home directory.
|
||||
* \{ */
|
||||
|
||||
/**
|
||||
* Look for `user-dirs.dirs`, where localized or custom user folders are defined,
|
||||
* and store their paths in a GHash.
|
||||
*/
|
||||
static GHash *fsmenu_xdg_user_dirs_parse(const char *home)
|
||||
{
|
||||
/* Add to the default for variable, equals & quotes. */
|
||||
char l[128 + FILE_MAXDIR];
|
||||
FILE *fp;
|
||||
|
||||
/* Check if the config file exists. */
|
||||
{
|
||||
char filepath[FILE_MAX];
|
||||
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home != NULL) {
|
||||
BLI_path_join(filepath, sizeof(filepath), xdg_config_home, "user-dirs.dirs");
|
||||
}
|
||||
else {
|
||||
BLI_path_join(filepath, sizeof(filepath), home, ".config", "user-dirs.dirs");
|
||||
}
|
||||
fp = BLI_fopen(filepath, "r");
|
||||
if (!fp) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
/* By default there are 8 paths. */
|
||||
GHash *xdg_map = BLI_ghash_str_new_ex(__func__, 8);
|
||||
while (fgets(l, sizeof(l), fp) != NULL) { /* read a line */
|
||||
|
||||
/* Avoid inserting invalid values. */
|
||||
if (STRPREFIX(l, "XDG_")) {
|
||||
char *l_value = strchr(l, '=');
|
||||
if (l_value != NULL) {
|
||||
*l_value = '\0';
|
||||
l_value++;
|
||||
|
||||
BLI_str_rstrip(l_value);
|
||||
const uint l_value_len = strlen(l_value);
|
||||
if ((l_value[0] == '"') && (l_value_len > 0) && (l_value[l_value_len - 1] == '"')) {
|
||||
l_value[l_value_len - 1] = '\0';
|
||||
l_value++;
|
||||
|
||||
char l_value_expanded[FILE_MAX];
|
||||
char *l_value_final = l_value;
|
||||
|
||||
/* This is currently the only variable used.
|
||||
* Based on the 'user-dirs.dirs' man page,
|
||||
* there is no need to resolve arbitrary environment variables. */
|
||||
if (STRPREFIX(l_value, "$HOME" SEP_STR)) {
|
||||
BLI_path_join(l_value_expanded, sizeof(l_value_expanded), home, l_value + 6);
|
||||
l_value_final = l_value_expanded;
|
||||
}
|
||||
|
||||
BLI_ghash_insert(xdg_map, BLI_strdup(l), BLI_strdup(l_value_final));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return xdg_map;
|
||||
}
|
||||
|
||||
static void fsmenu_xdg_user_dirs_free(GHash *xdg_map)
|
||||
{
|
||||
if (xdg_map != NULL) {
|
||||
BLI_ghash_free(xdg_map, MEM_freeN, MEM_freeN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fsmenu entry for system folders on linux.
|
||||
* - Check if a path is stored in the #GHash generated from `user-dirs.dirs`.
|
||||
* - If not, check for a default path in `$HOME`.
|
||||
*
|
||||
* \param key: Use `user-dirs.dirs` format "XDG_EXAMPLE_DIR"
|
||||
* \param default_path: Directory name to check in $HOME, also used for the menu entry name.
|
||||
*/
|
||||
static void fsmenu_xdg_insert_entry(GHash *xdg_map,
|
||||
struct FSMenu *fsmenu,
|
||||
const char *key,
|
||||
const char *default_path,
|
||||
int icon,
|
||||
const char *home)
|
||||
{
|
||||
char xdg_path_buf[FILE_MAXDIR];
|
||||
const char *xdg_path = (const char *)(xdg_map ? BLI_ghash_lookup(xdg_map, key) : NULL);
|
||||
if (xdg_path == NULL) {
|
||||
BLI_path_join(xdg_path_buf, sizeof(xdg_path_buf), home, default_path);
|
||||
xdg_path = xdg_path_buf;
|
||||
}
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, xdg_path, N_(default_path), icon, FS_INSERT_LAST);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
#ifdef WIN32
|
||||
/* Add a Windows known folder path to the System list. */
|
||||
static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
|
||||
FSMenuCategory category,
|
||||
REFKNOWNFOLDERID rfid,
|
||||
const char *name,
|
||||
const int icon,
|
||||
FSMenuInsert flag)
|
||||
{
|
||||
LPWSTR pPath;
|
||||
char line[FILE_MAXDIR];
|
||||
if (SHGetKnownFolderPath(rfid, 0, NULL, &pPath) == S_OK) {
|
||||
BLI_strncpy_wchar_as_utf8(line, pPath, FILE_MAXDIR);
|
||||
CoTaskMemFree(pPath);
|
||||
fsmenu_insert_entry(fsmenu, category, line, name, icon, flag);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
|
||||
{
|
||||
char line[FILE_MAXDIR];
|
||||
#ifdef WIN32
|
||||
/* Add the drive names to the listing */
|
||||
{
|
||||
wchar_t wline[FILE_MAXDIR];
|
||||
__int64 tmp;
|
||||
char tmps[4], *name;
|
||||
|
||||
tmp = GetLogicalDrives();
|
||||
|
||||
for (int i = 0; i < 26; i++) {
|
||||
if ((tmp >> i) & 1) {
|
||||
tmps[0] = 'A' + i;
|
||||
tmps[1] = ':';
|
||||
tmps[2] = '\\';
|
||||
tmps[3] = '\0';
|
||||
name = NULL;
|
||||
|
||||
/* Skip over floppy disks A & B. */
|
||||
if (i > 1) {
|
||||
/* Friendly volume descriptions without using SHGetFileInfoW (#85689). */
|
||||
BLI_strncpy_wchar_from_utf8(wline, tmps, 4);
|
||||
IShellFolder *desktop;
|
||||
if (SHGetDesktopFolder(&desktop) == S_OK) {
|
||||
PIDLIST_RELATIVE volume;
|
||||
if (desktop->lpVtbl->ParseDisplayName(
|
||||
desktop, NULL, NULL, wline, NULL, &volume, NULL) == S_OK) {
|
||||
STRRET volume_name;
|
||||
volume_name.uType = STRRET_WSTR;
|
||||
if (desktop->lpVtbl->GetDisplayNameOf(
|
||||
desktop, volume, SHGDN_FORADDRESSBAR, &volume_name) == S_OK) {
|
||||
wchar_t *volume_name_wchar;
|
||||
if (StrRetToStrW(&volume_name, volume, &volume_name_wchar) == S_OK) {
|
||||
BLI_strncpy_wchar_as_utf8(line, volume_name_wchar, FILE_MAXDIR);
|
||||
name = line;
|
||||
CoTaskMemFree(volume_name_wchar);
|
||||
}
|
||||
}
|
||||
CoTaskMemFree(volume);
|
||||
}
|
||||
desktop->lpVtbl->Release(desktop);
|
||||
}
|
||||
}
|
||||
if (name == NULL) {
|
||||
name = tmps;
|
||||
}
|
||||
|
||||
int icon = ICON_DISK_DRIVE;
|
||||
switch (GetDriveType(tmps)) {
|
||||
case DRIVE_REMOVABLE:
|
||||
icon = ICON_EXTERNAL_DRIVE;
|
||||
break;
|
||||
case DRIVE_CDROM:
|
||||
icon = ICON_DISC;
|
||||
break;
|
||||
case DRIVE_FIXED:
|
||||
case DRIVE_RAMDISK:
|
||||
icon = ICON_DISK_DRIVE;
|
||||
break;
|
||||
case DRIVE_REMOTE:
|
||||
icon = ICON_NETWORK_DRIVE;
|
||||
break;
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM,
|
||||
tmps,
|
||||
name,
|
||||
icon,
|
||||
FS_INSERT_SORTED | FS_INSERT_NO_VALIDATE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get Special Folder Locations. */
|
||||
if (read_bookmarks) {
|
||||
|
||||
/* These items are shown in System List. */
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Profile,
|
||||
N_("Home"),
|
||||
ICON_HOME,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Desktop,
|
||||
N_("Desktop"),
|
||||
ICON_DESKTOP,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Documents,
|
||||
N_("Documents"),
|
||||
ICON_DOCUMENTS,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Downloads,
|
||||
N_("Downloads"),
|
||||
ICON_IMPORT,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Music,
|
||||
N_("Music"),
|
||||
ICON_FILE_SOUND,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Pictures,
|
||||
N_("Pictures"),
|
||||
ICON_FILE_IMAGE,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Videos,
|
||||
N_("Videos"),
|
||||
ICON_FILE_MOVIE,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_Fonts,
|
||||
N_("Fonts"),
|
||||
ICON_FILE_FONT,
|
||||
FS_INSERT_LAST);
|
||||
fsmenu_add_windows_folder(fsmenu,
|
||||
FS_CATEGORY_SYSTEM_BOOKMARKS,
|
||||
&FOLDERID_SkyDrive,
|
||||
N_("OneDrive"),
|
||||
ICON_URL,
|
||||
FS_INSERT_LAST);
|
||||
|
||||
/* These items are just put in path cache for thumbnail views and if bookmarked. */
|
||||
|
||||
fsmenu_add_windows_folder(
|
||||
fsmenu, FS_CATEGORY_OTHER, &FOLDERID_UserProfiles, NULL, ICON_COMMUNITY, FS_INSERT_LAST);
|
||||
}
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
{
|
||||
/* We store some known macOS system paths and corresponding icons
|
||||
* and names in the FS_CATEGORY_OTHER (not displayed directly) category. */
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_OTHER, "/Library/Fonts/", N_("Fonts"), ICON_FILE_FONT, FS_INSERT_LAST);
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_OTHER,
|
||||
"/Applications/",
|
||||
N_("Applications"),
|
||||
ICON_FILE_FOLDER,
|
||||
FS_INSERT_LAST);
|
||||
|
||||
const char *home = BLI_getenv("HOME");
|
||||
if (home) {
|
||||
# define FS_MACOS_PATH(path, name, icon) \
|
||||
\
|
||||
SNPRINTF(line, path, home); \
|
||||
\
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, line, name, icon, FS_INSERT_LAST);
|
||||
|
||||
FS_MACOS_PATH("%s/", NULL, ICON_HOME)
|
||||
FS_MACOS_PATH("%s/Desktop/", N_("Desktop"), ICON_DESKTOP)
|
||||
FS_MACOS_PATH("%s/Documents/", N_("Documents"), ICON_DOCUMENTS)
|
||||
FS_MACOS_PATH("%s/Downloads/", N_("Downloads"), ICON_IMPORT)
|
||||
FS_MACOS_PATH("%s/Movies/", N_("Movies"), ICON_FILE_MOVIE)
|
||||
FS_MACOS_PATH("%s/Music/", N_("Music"), ICON_FILE_SOUND)
|
||||
FS_MACOS_PATH("%s/Pictures/", N_("Pictures"), ICON_FILE_IMAGE)
|
||||
FS_MACOS_PATH("%s/Library/Fonts/", N_("Fonts"), ICON_FILE_FONT)
|
||||
|
||||
# undef FS_MACOS_PATH
|
||||
}
|
||||
|
||||
/* Get mounted volumes better method OSX 10.6 and higher, see:
|
||||
* https://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFURLRef/Reference/reference.html
|
||||
*/
|
||||
|
||||
/* We get all volumes sorted including network and do not relay
|
||||
* on user-defined finder visibility, less confusing. */
|
||||
|
||||
CFURLRef cfURL = NULL;
|
||||
CFURLEnumeratorResult result = kCFURLEnumeratorSuccess;
|
||||
CFURLEnumeratorRef volEnum = CFURLEnumeratorCreateForMountedVolumes(
|
||||
NULL, kCFURLEnumeratorSkipInvisibles, NULL);
|
||||
|
||||
while (result != kCFURLEnumeratorEnd) {
|
||||
char defPath[FILE_MAX];
|
||||
|
||||
result = CFURLEnumeratorGetNextURL(volEnum, &cfURL, NULL);
|
||||
if (result != kCFURLEnumeratorSuccess) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CFURLGetFileSystemRepresentation(cfURL, false, (UInt8 *)defPath, FILE_MAX);
|
||||
|
||||
/* Get name of the volume. */
|
||||
char display_name[FILE_MAXFILE] = "";
|
||||
CFStringRef nameString = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeLocalizedNameKey, &nameString, NULL);
|
||||
if (nameString != NULL) {
|
||||
CFStringGetCString(nameString, display_name, sizeof(display_name), kCFStringEncodingUTF8);
|
||||
CFRelease(nameString);
|
||||
}
|
||||
|
||||
/* Set icon for regular, removable or network drive. */
|
||||
int icon = ICON_DISK_DRIVE;
|
||||
CFBooleanRef localKey = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsLocalKey, &localKey, NULL);
|
||||
if (localKey != NULL) {
|
||||
if (!CFBooleanGetValue(localKey)) {
|
||||
icon = ICON_NETWORK_DRIVE;
|
||||
}
|
||||
else {
|
||||
CFBooleanRef ejectableKey = NULL;
|
||||
CFURLCopyResourcePropertyForKey(cfURL, kCFURLVolumeIsEjectableKey, &ejectableKey, NULL);
|
||||
if (ejectableKey != NULL) {
|
||||
if (CFBooleanGetValue(ejectableKey)) {
|
||||
icon = ICON_EXTERNAL_DRIVE;
|
||||
}
|
||||
CFRelease(ejectableKey);
|
||||
}
|
||||
}
|
||||
CFRelease(localKey);
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_SYSTEM,
|
||||
defPath,
|
||||
display_name[0] ? display_name : NULL,
|
||||
icon,
|
||||
FS_INSERT_SORTED);
|
||||
}
|
||||
|
||||
CFRelease(volEnum);
|
||||
|
||||
/* kLSSharedFileListFavoriteItems is deprecated, but available till macOS 10.15.
|
||||
* Will have to find a new method to sync the Finder Favorites with File Browser. */
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
/* Finally get user favorite places */
|
||||
if (read_bookmarks) {
|
||||
UInt32 seed;
|
||||
LSSharedFileListRef list = LSSharedFileListCreate(
|
||||
NULL, kLSSharedFileListFavoriteItems, NULL);
|
||||
CFArrayRef pathesArray = LSSharedFileListCopySnapshot(list, &seed);
|
||||
CFIndex pathesCount = CFArrayGetCount(pathesArray);
|
||||
|
||||
for (CFIndex i = 0; i < pathesCount; i++) {
|
||||
LSSharedFileListItemRef itemRef = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(
|
||||
pathesArray, i);
|
||||
|
||||
CFURLRef cfURL = NULL;
|
||||
OSErr err = LSSharedFileListItemResolve(itemRef,
|
||||
kLSSharedFileListNoUserInteraction |
|
||||
kLSSharedFileListDoNotMountVolumes,
|
||||
&cfURL,
|
||||
NULL);
|
||||
if (err != noErr || !cfURL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CFStringRef pathString = CFURLCopyFileSystemPath(cfURL, kCFURLPOSIXPathStyle);
|
||||
|
||||
if (pathString == NULL ||
|
||||
!CFStringGetCString(pathString, line, sizeof(line), kCFStringEncodingUTF8))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Exclude "all my files" as it makes no sense in blender file-selector. */
|
||||
/* Exclude "airdrop" if wlan not active as it would show "" ) */
|
||||
if (!strstr(line, "myDocuments.cannedSearch") && (*line != '\0')) {
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_FILE_FOLDER, FS_INSERT_LAST);
|
||||
}
|
||||
|
||||
CFRelease(pathString);
|
||||
CFRelease(cfURL);
|
||||
}
|
||||
|
||||
CFRelease(pathesArray);
|
||||
CFRelease(list);
|
||||
}
|
||||
# pragma GCC diagnostic pop
|
||||
}
|
||||
#else
|
||||
/* unix */
|
||||
{
|
||||
const char *home = BLI_getenv("HOME");
|
||||
|
||||
if (read_bookmarks && home) {
|
||||
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, home, N_("Home"), ICON_HOME, FS_INSERT_LAST);
|
||||
|
||||
/* Follow the XDG spec, check if these are available. */
|
||||
GHash *xdg_map = fsmenu_xdg_user_dirs_parse(home);
|
||||
|
||||
struct {
|
||||
const char *key;
|
||||
const char *default_path;
|
||||
BIFIconID icon;
|
||||
} xdg_items[] = {
|
||||
{"XDG_DESKTOP_DIR", "Desktop", ICON_DESKTOP},
|
||||
{"XDG_DOCUMENTS_DIR", "Documents", ICON_DOCUMENTS},
|
||||
{"XDG_DOWNLOAD_DIR", "Downloads", ICON_IMPORT},
|
||||
{"XDG_VIDEOS_DIR", "Videos", ICON_FILE_MOVIE},
|
||||
{"XDG_PICTURES_DIR", "Pictures", ICON_FILE_IMAGE},
|
||||
{"XDG_MUSIC_DIR", "Music", ICON_FILE_SOUND},
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(xdg_items); i++) {
|
||||
fsmenu_xdg_insert_entry(
|
||||
xdg_map, fsmenu, xdg_items[i].key, xdg_items[i].default_path, xdg_items[i].icon, home);
|
||||
}
|
||||
|
||||
fsmenu_xdg_user_dirs_free(xdg_map);
|
||||
}
|
||||
|
||||
{
|
||||
int found = 0;
|
||||
# ifdef __linux__
|
||||
/* loop over mount points */
|
||||
struct mntent *mnt;
|
||||
FILE *fp;
|
||||
|
||||
fp = setmntent(MOUNTED, "r");
|
||||
if (fp == NULL) {
|
||||
fprintf(stderr, "could not get a list of mounted file-systems\n");
|
||||
}
|
||||
else {
|
||||
while ((mnt = getmntent(fp))) {
|
||||
if (STRPREFIX(mnt->mnt_dir, "/boot")) {
|
||||
/* Hide share not usable to the user. */
|
||||
continue;
|
||||
}
|
||||
if (!STRPREFIX(mnt->mnt_fsname, "/dev")) {
|
||||
continue;
|
||||
}
|
||||
if (STRPREFIX(mnt->mnt_fsname, "/dev/loop")) {
|
||||
/* The dev/loop* entries are SNAPS used by desktop environment
|
||||
* (Gnome) no need for them to show up in the list. */
|
||||
continue;
|
||||
}
|
||||
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, mnt->mnt_dir, NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
|
||||
found = 1;
|
||||
}
|
||||
if (endmntent(fp) == 0) {
|
||||
fprintf(stderr, "could not close the list of mounted file-systems\n");
|
||||
}
|
||||
}
|
||||
/* Check `gvfs` shares. */
|
||||
const char *const xdg_runtime_dir = BLI_getenv("XDG_RUNTIME_DIR");
|
||||
if (xdg_runtime_dir != NULL) {
|
||||
struct direntry *dirs;
|
||||
char filepath[FILE_MAX];
|
||||
BLI_path_join(filepath, sizeof(filepath), xdg_runtime_dir, "gvfs/");
|
||||
/* Avoid error message if the directory doesn't exist as this isn't a requirement. */
|
||||
if (BLI_is_dir(filepath)) {
|
||||
const uint dirs_num = BLI_filelist_dir_contents(filepath, &dirs);
|
||||
for (uint i = 0; i < dirs_num; i++) {
|
||||
if ((dirs[i].type & S_IFDIR) == 0) {
|
||||
continue;
|
||||
}
|
||||
const char *dirname = dirs[i].relname;
|
||||
if (dirname[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Directory names contain a lot of unwanted text.
|
||||
* Assuming every entry ends with the share name. */
|
||||
const char *label = strstr(dirname, "share=");
|
||||
if (label != NULL) {
|
||||
/* Move pointer so `share=` is trimmed off or use full `dirname` as label. */
|
||||
const char *label_test = label + 6;
|
||||
label = *label_test ? label_test : dirname;
|
||||
}
|
||||
SNPRINTF(line, "%s%s", filepath, dirname);
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, line, label, ICON_NETWORK_DRIVE, FS_INSERT_SORTED);
|
||||
found = 1;
|
||||
}
|
||||
BLI_filelist_free(dirs, dirs_num);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
/* fallback */
|
||||
if (!found) {
|
||||
fsmenu_insert_entry(
|
||||
fsmenu, FS_CATEGORY_SYSTEM, "/", NULL, ICON_DISK_DRIVE, FS_INSERT_SORTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
/* Quiet warnings. */
|
||||
UNUSED_VARS(fsmenu_xdg_insert_entry, fsmenu_xdg_user_dirs_parse, fsmenu_xdg_user_dirs_free);
|
||||
#endif
|
||||
|
||||
/* For all platforms, we add some directories from User Preferences to
|
||||
* the FS_CATEGORY_OTHER category so that these directories
|
||||
* have the appropriate icons when they are added to the Bookmarks. */
|
||||
#define FS_UDIR_PATH(dir, icon) \
|
||||
\
|
||||
if (BLI_strnlen(dir, 3) > 2) { \
|
||||
\
|
||||
fsmenu_insert_entry(fsmenu, FS_CATEGORY_OTHER, dir, NULL, icon, FS_INSERT_LAST); \
|
||||
}
|
||||
|
||||
FS_UDIR_PATH(U.fontdir, ICON_FILE_FONT)
|
||||
FS_UDIR_PATH(U.textudir, ICON_FILE_IMAGE)
|
||||
LISTBASE_FOREACH (bUserScriptDirectory *, script_dir, &U.script_directories) {
|
||||
if (UNLIKELY(script_dir->dir_path[0] == '\0')) {
|
||||
continue;
|
||||
}
|
||||
fsmenu_insert_entry(fsmenu,
|
||||
FS_CATEGORY_OTHER,
|
||||
script_dir->dir_path,
|
||||
script_dir->name,
|
||||
ICON_FILE_SCRIPT,
|
||||
FS_INSERT_LAST);
|
||||
}
|
||||
FS_UDIR_PATH(U.sounddir, ICON_FILE_SOUND)
|
||||
FS_UDIR_PATH(U.tempdir, ICON_TEMP)
|
||||
|
||||
#undef FS_UDIR_PATH
|
||||
}
|
Loading…
Reference in New Issue
Block a user