[easytag] Make crc32_file_with_ID3_tag() accept a GFile
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Make crc32_file_with_ID3_tag() accept a GFile
- Date: Sun, 14 Dec 2014 18:39:49 +0000 (UTC)
commit 935318961603f506a3bdba80d4b46eed34131ae3
Author: David King <amigadave amigadave com>
Date: Sun Dec 14 18:03:38 2014 +0000
Make crc32_file_with_ID3_tag() accept a GFile
src/crc32.c | 53 ++++++++++++++++++++------------------------
src/crc32.h | 62 ++++++++++++++++++++++++++++------------------------
src/scan_dialog.c | 8 +++++-
3 files changed, 63 insertions(+), 60 deletions(-)
---
diff --git a/src/crc32.c b/src/crc32.c
index 88469cf..2fc91a6 100644
--- a/src/crc32.c
+++ b/src/crc32.c
@@ -1,25 +1,23 @@
-/* crc32.c - the crc check algorithm for cksfv modified by oliver for easytag
-
- Copyright (C) 2000 Bryan Call <bc fodder org>
- Copyright (C) 2003 Oliver Schinagl <oliver are-b org>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014 David King <amigadave amigadave com>
+ * Copyright (C) 2000 Bryan Call <bc fodder org>
+ * Copyright (C) 2003 Oliver Schinagl <oliver are-b org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
-#include <stdio.h>
-#include <glib.h>
-#include <gio/gio.h>
#include "crc32.h"
#define BUFFERSIZE 16384 /* (16k) buffer size for reading from the file */
@@ -96,7 +94,7 @@ static const guint32 crc32table[] = {
/*
* crc32_file_with_ID3_tag:
- * @filename: (type filename): an absolute path
+ * @file: a file from which to read audio data
* @main_val: (out): the CRC32 value
*
* Calculate the CRC32 value of audio data (skips the ID3v2 and ID3v1 tags).
@@ -104,12 +102,13 @@ static const guint32 crc32table[] = {
* Returns: %TRUE if the CRC calculation was successful, %FALSE otherwise
*/
gboolean
-crc32_file_with_ID3_tag (const gchar *filename, guint32 *crc32, GError **err)
+crc32_file_with_ID3_tag (GFile *file,
+ guint32 *crc32,
+ GError **err)
{
gchar buf[BUFFERSIZE], *p;
gint nr;
guint32 crc = ~0, crc32_total = ~0;
- GFile *file;
guchar tmp_id3[4];
glong id3v2size = 0;
GFileInfo *info;
@@ -118,16 +117,14 @@ crc32_file_with_ID3_tag (const gchar *filename, guint32 *crc32, GError **err)
gsize bytes_read;
gboolean has_id3v1 = FALSE;
- g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (file != NULL, FALSE);
g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
- file = g_file_new_for_path (filename);
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
G_FILE_QUERY_INFO_NONE, NULL, err);
if (!info)
{
- g_object_unref (file);
g_assert (err == NULL || *err != NULL);
return FALSE;
}
@@ -138,7 +135,6 @@ crc32_file_with_ID3_tag (const gchar *filename, guint32 *crc32, GError **err)
if (!istream)
{
g_object_unref (info);
- g_object_unref (file);
g_assert (err == NULL || *err != NULL);
return FALSE;
}
@@ -249,7 +245,6 @@ crc32_file_with_ID3_tag (const gchar *filename, guint32 *crc32, GError **err)
out:
g_object_unref (info);
g_object_unref (istream);
- g_object_unref (file);
*crc32 = ~crc;
return nr == 0;
diff --git a/src/crc32.h b/src/crc32.h
index 0560106..bd39f85 100644
--- a/src/crc32.h
+++ b/src/crc32.h
@@ -1,29 +1,33 @@
-/* crc32.h - the crc check algorithm for cksfv modified by oliver for easytag
-
- Copyright (C) 2000 Bryan Call <bc fodder org>
- Copyright (C) 2003 Oliver Schinagl <oliver are-b org>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
-
-
-#ifndef __CRC32_H__
-#define __CRC32_H__
-
-
-gboolean crc32_file_with_ID3_tag (const gchar *filename, guint32 *crc32,
- GError **err);
-
-
-#endif /* __CRC32_H__ */
+/* EasyTAG - tag editor for audio files
+ * Copyright (C) 2014 David King <amigadave amigadave com>
+ * Copyright (C) 2000 Bryan Call <bc fodder org>
+ * Copyright (C) 2003 Oliver Schinagl <oliver are-b org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ET_CRC32_H_
+#define ET_CRC32_H_
+
+#include <glib.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+gboolean crc32_file_with_ID3_tag (GFile *file, guint32 *crc32, GError **err);
+
+G_END_DECLS
+
+#endif /* ET_CRC32_H_ */
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 3eb74d7..cf964ba 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -284,6 +284,7 @@ Scan_Tag_With_Mask (EtScanDialog *self, ET_File *ETFile)
&& (g_settings_get_boolean (MainSettings, "fill-overwrite-tag-fields")
|| FileTag->comment == NULL || strlen (FileTag->comment) == 0))
{
+ GFile *file;
GError *error = NULL;
guint32 crc32_value;
gchar *buffer;
@@ -293,8 +294,9 @@ Scan_Tag_With_Mask (EtScanDialog *self, ET_File *ETFile)
switch (ETFileDescription->TagType)
{
case ID3_TAG:
- if (crc32_file_with_ID3_tag (((File_Name *)((GList *)ETFile->FileNameNew)->data)->value,
- &crc32_value, &error))
+ file = g_file_new_for_path (((File_Name *)((GList *)ETFile->FileNameNew)->data)->value);
+
+ if (crc32_file_with_ID3_tag (file, &crc32_value, &error))
{
buffer = g_strdup_printf ("%.8" G_GUINT32_FORMAT,
crc32_value);
@@ -308,6 +310,8 @@ Scan_Tag_With_Mask (EtScanDialog *self, ET_File *ETFile)
error->message);
g_error_free (error);
}
+
+ g_object_unref (file);
break;
default:
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]