moo_save_user_data_file() and moo_get_user_data_file()

master
Yevgen Muntyan 2006-04-09 04:00:52 -05:00
parent 930d82bfb6
commit 171f8428c8
2 changed files with 62 additions and 5 deletions

View File

@ -16,6 +16,7 @@
#endif
#include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-fs.h"
#include "mooutils/moologwindow-glade.h"
#include "mooutils/mooglade.h"
#include <gtk/gtk.h>
@ -1313,6 +1314,54 @@ moo_get_data_subdirs (const char *subdir,
}
char *
moo_get_user_data_file (const char *basename)
{
char *dir, *file;
g_return_val_if_fail (basename && basename[0], NULL);
dir = moo_get_user_data_dir ();
g_return_val_if_fail (dir != NULL, NULL);
file = g_build_filename (dir, basename, NULL);
g_free (dir);
return file;
}
gboolean
moo_save_user_data_file (const char *basename,
const char *content,
gssize len,
GError **error)
{
char *dir, *file;
gboolean result = FALSE;
g_return_val_if_fail (basename != NULL, FALSE);
g_return_val_if_fail (content != NULL, FALSE);
dir = moo_get_user_data_dir ();
file = moo_get_user_data_file (basename);
g_return_val_if_fail (dir && file, FALSE);
if (!moo_mkdir (dir, error))
goto out;
if (!moo_save_file_utf8 (file, content, len, error))
goto out;
result = TRUE;
out:
g_free (dir);
g_free (file);
return FALSE;
}
GType
moo_data_dir_type_get_type (void)
{

View File

@ -57,19 +57,27 @@ typedef enum {
MOO_DATA_LIB
} MooDataDirType;
GType moo_data_dir_type_get_type (void) G_GNUC_CONST;
GType moo_data_dir_type_get_type (void) G_GNUC_CONST;
/* application directory on win32 */
char *moo_get_app_dir (void);
char *moo_get_app_dir (void);
/* ~/.appname */
char *moo_get_user_data_dir (void);
char *moo_get_user_data_dir (void);
char *moo_get_user_data_file (const char *basename);
gboolean moo_save_user_data_file (const char *basename,
const char *content,
gssize len,
GError **error);
/* $MOO_APP_DIR:$MOO_DATA_DIRS:$prefix/share/appname or
$MOO_APP_DIR:$MOO_LIB_DIRS:$prefix/lib/appname */
char **moo_get_data_dirs (MooDataDirType type,
char **moo_get_data_dirs (MooDataDirType type,
guint *n_dirs);
char **moo_get_data_subdirs (const char *subdir,
char **moo_get_data_subdirs (const char *subdir,
MooDataDirType type,
guint *n_dirs);
#define moo_get_data_files moo_get_data_subdirs
void moo_selection_data_set_pointer (GtkSelectionData *data,