diff options
author | teuf <teuf@f01d2545-417e-4e96-918e-98f8d0dbbcb6> | 2008-07-06 14:04:46 +0000 |
---|---|---|
committer | teuf <teuf@f01d2545-417e-4e96-918e-98f8d0dbbcb6> | 2008-07-06 14:04:46 +0000 |
commit | dd59f19e0855d3e65cc569c7c92c7f3614b2c6fb (patch) | |
tree | 020cc9b46576e4188f7c0b479c385bf1df519ec1 | |
parent | 35a75d4a7a0bfa12f04d65235f14fe10de079653 (diff) | |
download | libgpod-dd59f19e0855d3e65cc569c7c92c7f3614b2c6fb.tar.gz libgpod-dd59f19e0855d3e65cc569c7c92c7f3614b2c6fb.tar.xz libgpod-dd59f19e0855d3e65cc569c7c92c7f3614b2c6fb.zip |
Pick itdb_device_get_storage_info from songbird
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@2041 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | src/itdb_device.c | 54 | ||||
-rw-r--r-- | src/itdb_device.h | 1 | ||||
-rw-r--r-- | src/itdb_itunesdb.c | 16 |
4 files changed, 70 insertions, 10 deletions
@@ -1,5 +1,14 @@ 2008-07-06 Christophe Fergeau <teuf@gnome.org> + * src/itdb_device.c: + * src/itdb_device.h: add itdb_device_get_storage_info method + * src/itdb_itunesdb.c: use that method instead of directly using + statvfs, makes it easier to port things over to MSVC8 + +2008-07-05 Christophe Fergeau <teuf@gnome.org> + + Patch from: Songbird (http://getsongbird.com/) + * src/db-itunes-parser.h: remove unused constant * src/db-parse-context.c: * src/db-parse-context.h: use GMappedFile instead of directly using diff --git a/src/itdb_device.c b/src/itdb_device.c index d15375d..f1c403b 100644 --- a/src/itdb_device.c +++ b/src/itdb_device.c @@ -1413,3 +1413,57 @@ G_GNUC_INTERNAL gboolean itdb_device_requires_checksum (Itdb_Device *device) return FALSE; } + +#ifdef WIN32 +#include <windows.h> +#else +#include <sys/statvfs.h> +#endif + +/** + * itdb_device_get_storage_info: + * + * @device: an #Itdb_Device + * @capacity: returned capacity in bytes + * @free: returned free space in bytes + * + * Return the storage info for this iPod + * + * Return value: TRUE if storage info could be obtained, FALSE otherwise + **/ +gboolean itdb_device_get_storage_info (Itdb_Device *device, guint64 *capacity, guint64 *free) +{ +#ifdef WIN32 + ULARGE_INTEGER u_free, u_capacity; +#else + struct statvfs info; + guint64 block_size; +#endif + + g_return_val_if_fail (device, FALSE); + g_return_val_if_fail (capacity, FALSE); + g_return_val_if_fail (free, FALSE); + +#ifdef WIN32 + if (GetDiskFreeSpaceEx(device->mountpoint, &u_free, &u_capacity, NULL) == 0) { + return FALSE; + } + *free = u_free.QuadPart; + *capacity = u_capacity.QuadPart; + return TRUE; +#else + if (statvfs(device->mountpoint, &info)) + return FALSE; + + if (info.f_frsize > 0) + block_size = info.f_frsize; + else + block_size = info.f_bsize; + + *capacity = info.f_blocks * block_size; + *free = info.f_bfree * block_size; + + return TRUE; +#endif +} + diff --git a/src/itdb_device.h b/src/itdb_device.h index c48acd3..c67585f 100644 --- a/src/itdb_device.h +++ b/src/itdb_device.h @@ -119,6 +119,7 @@ G_GNUC_INTERNAL gint itdb_device_musicdirs_number (Itdb_Device *device); G_GNUC_INTERNAL void itdb_device_autodetect_endianess (Itdb_Device *device); G_GNUC_INTERNAL guint64 itdb_device_get_firewire_id (const Itdb_Device *device); G_GNUC_INTERNAL gboolean itdb_device_supports_sparse_artwork (const Itdb_Device *device); +G_GNUC_INTERNAL gboolean itdb_device_get_storage_info (Itdb_Device *device, guint64 *capacity, guint64 *free); G_END_DECLS #endif diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c index 6bbba84..e8d7e9b 100644 --- a/src/itdb_itunesdb.c +++ b/src/itdb_itunesdb.c @@ -119,7 +119,6 @@ #include <glib/gstdio.h> #include <stdio.h> #include <string.h> -#include <sys/statvfs.h> #include <sys/types.h> #include <time.h> #ifdef HAVE_UNISTD_H @@ -6911,17 +6910,14 @@ static gboolean itdb_create_directories (Itdb_Device *device, GError **error) /* Build the directories that hold the music files */ dirnum = info->musicdirs; if (dirnum == 0) - { /* do a guess */ - struct statvfs stat; - if (statvfs (mp, &stat) != 0) - { /* why should this fail !? */ - dirnum = 20; - } - else - { - gdouble size = ((gdouble)stat.f_blocks * stat.f_frsize) / 1073741824; + { + guint64 capacity, free_space; + if (itdb_device_get_storage_info(device, &capacity, &free_space)) { + gdouble size = ((gdouble)capacity) / 1073741824; if (size < 20) dirnum = 20; else dirnum = 50; + } else { + dirnum = 20; } } |