Hi, ALL,
I have 2 follow-up questions on the other thread here: Difference between volume and drive - #34 by oneeyeman1.
- From the get_mounts() documentation:
The returned list should be freed with g_list_free(), after its
elements have been unreffed with g_object_unref()
for( volumes = volumelist; volumes != NULL; volumes = volumes->next )
g_object_unref( volumes );
g_list_free( volumelist );
I presume the code adobe is wrong as it throws an exception
on the g_object_unref().
But I can’t just call g_list_free(), right?
I also tried this:
if( volumelist )
{
g_list_foreach( volumes, g_object_unref, NULL );
g_list_free( volumelist );
}
which resulted in
error: invalid conversion from ‘void ()(gpointer)’ {aka ‘void
()(void*)’} to ‘GFunc’ {aka ‘void ()(void, void*)’} [-fpermissive]
66 | g_list_foreach( volumes, g_object_unref, nullptr );
| ^~~~~~~~~~~~~~
| |
| void ()(gpointer) {aka void
()(void*)}
In file included from /usr/include/glib-2.0/glib/ghash.h:36,
from /usr/include/glib-2.0/glib.h:52,
from /usr/include/glib-2.0/gobject/gbinding.h:30,
from /usr/include/glib-2.0/glib-object.h:24,
from /usr/include/glib-2.0/gio/gioenums.h:30,
from /usr/include/glib-2.0/gio/giotypes.h:30,
from /usr/include/glib-2.0/gio/gio.h:28,
/usr/include/glib-2.0/glib/glist.h:139:60: note: initializing
argument 2 of ‘void g_list_foreach(GList*, GFunc, gpointer)’
139 | GFunc func,
| ~~~~~~~~~~~~~~~~^~
make: *** [Makefile:28049: coredll_volumeenum.o] Error 1
-
How do I uniquely identify the mounted volume?
auto monitor = g_volume_monitor_get();
GList *volumes, *volumelist;
// On some systems, partition is mounted hidden by default
// If “volumelist” comes back as “nullptr”, it is normal behavior
if( flagsSet & wxFS_VOL_MOUNTED && !( flagsUnset & wxFS_VOL_MOUNTED ) )
{
volumelist = g_volume_monitor_get_mounts( monitor );
for( volumes = volumelist; volumes != NULL; volumes = volumes->next )
{
gpointer volume = volumes->data;
char *name = g_mount_get_name( (GMount *) volume );
// store the name in some containter
g_free( name );
}
}
doing this will return a very generic name “XXXGB hard drive”.
And so when I later on loop thru the container, I will not be able to
identify which mount/volume I’m looking at/
Will I be able to do something like this:
GFile *file = g_mount_get_root( (GMount *) volume );
g_file_get_basename( file );
?
Thank you.