Commit 9c532254 authored by Ziirish's avatar Ziirish

split the 'file relative' code in a specific source file

parent e35e6ae9
......@@ -63,6 +63,8 @@ cid_SOURCES = \
cid-asynchrone.h \
cid-callbacks.c \
cid-callbacks.h \
cid-file-utilities.c \
cid-file-utilities.h \
cid-gui-factory.c \
cid-gui-factory.h \
cid-config.c \
......
......@@ -42,7 +42,7 @@ _cid_quit (GtkWidget *p_widget, gpointer user_data)
{
cid_save_data (&cid);
cid_remove_file (DEFAULT_DOWNLOADED_IMAGE_LOCATION);
cid_file_remove (DEFAULT_DOWNLOADED_IMAGE_LOCATION);
cid_sortie (&cid, CID_EXIT_SUCCESS);
......@@ -202,7 +202,7 @@ on_dragNdrop_data_received (GtkWidget *wgt, GdkDragContext *context, int x, int
cid_debug("Le fichier est local");
gchar *cFileSrc = (**cReceivedDataList == '/' ? *cReceivedDataList : g_filename_from_uri (*cReceivedDataList, NULL, NULL));
gchar *cFileDst = g_strdup_printf ("/tmp/\"%s - %s.jpg\"",musicData.playing_artist,musicData.playing_album);
cid_copy_file (cFileSrc,cFileDst);
cid_file_copy (cFileSrc,cFileDst);
g_free (cFileSrc);
g_free (cFileDst);
}
......
......@@ -40,7 +40,7 @@ cid_check_file (const gchar *f)
g_free (cCompareWith);
gchar *cSrc = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_debug ("Copying file from %s to %s",cSrc,f);
cid_copy_file (cSrc,f);
cid_file_copy (cSrc,f);
g_free (cSrc);
return;
}
......@@ -106,7 +106,7 @@ cid_check_file (const gchar *f)
g_free (cFileTest);
gchar *cSrc = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_debug ("Copying file from %s to %s",cSrc,f);
cid_copy_file (cSrc,f);
cid_file_copy (cSrc,f);
g_free (cSrc);
}
}
......@@ -133,9 +133,9 @@ cid_check_conf_file_version (CidMainContainer **pCid, const gchar *f)
if (strcmp(line_f1,line_f2)!=0 || bUnvalidKey)
{
cid_warning ("bad file version, building a new one\n");
cid_remove_file (f);
cid_file_remove (f);
gchar *cTmpPath = g_strdup_printf("%s/%s",CID_DATA_DIR,CID_CONFIG_FILE);
cid_copy_file(cTmpPath,f);
cid_file_copy(cTmpPath,f);
g_free (cTmpPath);
cid_save_data (pCid);
......
......@@ -31,7 +31,7 @@ cid_get_xml_file (const gchar *artist,
{
if (g_file_test (DEFAULT_DOWNLOADED_IMAGE_LOCATION, G_FILE_TEST_EXISTS))
{
cid_remove_file (DEFAULT_DOWNLOADED_IMAGE_LOCATION);
cid_file_remove (DEFAULT_DOWNLOADED_IMAGE_LOCATION);
}
if (g_strcasecmp("Unknown",artist)==0
......@@ -134,7 +134,7 @@ cid_search_xml_xpath (const char *filename,
va_start(args,xpath);
doc = xmlParseFile(filename);
cid_remove_file (filename);
cid_file_remove (filename);
if (doc == NULL)
{
......@@ -249,8 +249,8 @@ cid_db_store_cover (CidMainContainer **pCid,
gchar *cDestFile = g_strdup_printf ("%s/%s",
cid->config->cDLPath,
md5);
cid_copy_file (cCoverPath, cDestFile);
cid_remove_file (cCoverPath);
cid_file_copy (cCoverPath, cDestFile);
cid_file_remove (cCoverPath);
g_key_file_set_value (pKeyFile, "DB", cKey, md5);
cid_write_keys_to_file (pKeyFile, cDBFile);
g_key_file_free (pKeyFile);
......
/*
*
* cid-file-utilities.c
* -------
* Conky Images Display
* --------------------------
*
*/
#include "cid-file-utilities.h"
#include "cid-messages.h"
#include "cid-md5.h"
gboolean
cid_file_copy (const gchar *cSrc, const gchar *cDst)
{
gboolean ret = TRUE;
if (!cSrc || !cDst)
{
cid_warning ("Unable to copy file due to missing field ! (%s,%s)",cSrc,cDst);
return FALSE;
}
FILE *src = fopen (cSrc,"rb");
if (!src)
{
cid_warning ("Unable to open file: %s",cSrc);
return FALSE;
}
FILE *dst = fopen (cDst,"wb");
if (!dst)
{
cid_warning ("Unable to open file: %s",cDst);
fclose (src);
return FALSE;
}
char ch;
while(!feof(src)) {
ch = fgetc(src);
if(ferror(src)) {
cid_warning ("Error reading source file.");
ret = FALSE;
break;
}
if(!feof(src)) fputc(ch, dst);
if(ferror(dst)) {
cid_warning ("Error writing destination file.");
ret = FALSE;
break;
}
}
fclose (src);
fclose (dst);
gchar *sum1, *sum2;
sum1 = cid_md5sum (cSrc);
sum2 = cid_md5sum (cDst);
if (g_strcmp0 (sum1, sum2) != 0)
{
cid_warning ("An unknown error occured while copying files... aborting");
cid_file_remove (cDst);
ret = FALSE;
}
g_free (sum1);
g_free (sum2);
return ret;
}
void
cid_file_remove (const gchar* cFilePath)
{
if (!g_file_test (cFilePath, G_FILE_TEST_EXISTS))
{
cid_warning ("The file '%s' does not exist", cFilePath);
return;
}
if (remove(cFilePath) == -1)
{
cid_warning ("Error while removing %s",cFilePath);
}
}
/*
*
* cid-file-utilities.h
* -------
* Conky Images Display
* --------------------------
*
*/
#ifndef __CID_FILE_UTILITIES__
#define __CID_FILE_UTILITIES__
#include <gtk/gtk.h>
G_BEGIN_DECLS
/**
* Permet de copier un fichier.
* @param cSrc Le fichier source.
* @param cDst Le fichier destination.
* @return TRUE si la copie s'est bien passée.
*/
gboolean cid_file_copy (const gchar *cSrc, const gchar *cDst);
/**
* Permet de supprimer un fichier.
* @param cSrc Le fichier a supprimer.
*/
void cid_file_remove (const gchar* cFilePath);
G_END_DECLS
#endif
......@@ -123,58 +123,6 @@ cid_free_main_structure (CidMainContainer *pCid)
pCid = NULL;
}
void
cid_copy_file (const gchar *cSrc, const gchar *cDst)
{
if (!cSrc || !cDst)
{
cid_warning ("Unable to copy file due to missing field ! (%s,%s)",cSrc,cDst);
return;
}
FILE *src = fopen (cSrc,"rb");
if (!src)
{
cid_warning ("Unable to open file: %s",cSrc);
return;
}
FILE *dst = fopen (cDst,"wb");
if (!dst)
{
cid_warning ("Unable to open file: %s",cDst);
return;
}
char ch;
while(!feof(src)) {
ch = fgetc(src);
if(ferror(src)) {
cid_warning ("Error reading source file.");
return;
}
if(!feof(src)) fputc(ch, dst);
if(ferror(dst)) {
cid_warning ("Error writing destination file.");
return;
}
}
fclose (src);
fclose (dst);
}
void
cid_remove_file (const gchar* cFilePath)
{
if (!g_file_test (cFilePath, G_FILE_TEST_EXISTS))
{
cid_warning ("The file '%s' does not exist", cFilePath);
return;
}
if (remove(cFilePath) == -1)
{
cid_warning ("Error while removing %s",cFilePath);
}
}
void
cid_read_parameters (int *argc, char ***argv)
{
......
......@@ -27,19 +27,6 @@ G_BEGIN_DECLS
*/
#define cid_launch_command(cCommand,...) cid_launch_command_full(cCommand, NULL, ##__VA_ARGS__)
/**
* Permet de copier un fichier
* @param cSrc Le fichier source
* @param cDst Le fichier destination
*/
void cid_copy_file (const gchar *cSrc, const gchar *cDst);
/**
* Permet de supprimer un fichier
* @param cSrc Le fichier a supprimer
*/
void cid_remove_file (const gchar* cFilePath);
/**
* converti une chaine en son equivalent MAJUSCULE
* @param cSrc chaine source
......
......@@ -20,7 +20,6 @@
#include "cid-applet-canvas.h"
#include "cid-asynchrone.h"
#include "cid-callbacks.h"
#include "cid-gui-factory.h"
#include "cid-config.h"
#include "cid-console-call.h"
#include "cid-constantes.h"
......@@ -28,12 +27,14 @@
#include "cid-dbus.h"
#include "cid-draw.h"
#include "cid-exaile.h"
#include "cid-file-utilities.h"
#include "cid-gui-callback.h"
#include "cid-gui-factory.h"
#include "cid-md5.h"
#include "cid-menu-factory.h"
#include "cid-messages.h"
#include "cid-modules.h"
#include "cid-mpd.h"
#include "cid-gui-callback.h"
#include "cid-rhythmbox.h"
#include "cid-struct.h"
#include "cid-utilities.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment