Пример #1
0
/**
 * gwy_resource_class_load:
 * @klass: A resource class.
 *
 * Loads resources of a resources class from disk.
 *
 * Resources are loaded from system directory (and marked constant) and from
 * user directory (marked modifiable).
 **/
void
gwy_resource_class_load(GwyResourceClass *klass)
{
    gpointer type;
    gchar *path, *datadir;

    g_return_if_fail(GWY_IS_RESOURCE_CLASS(klass));
    g_return_if_fail(klass->inventory);

    gwy_inventory_forget_order(klass->inventory);

    type = GSIZE_TO_POINTER(G_TYPE_FROM_CLASS(klass));
    if (!g_slist_find(all_resources, type))
        all_resources = g_slist_prepend(all_resources, type);

    datadir = gwy_find_self_dir("data");
    path = g_build_filename(datadir, klass->name, NULL);
    g_free(datadir);
    gwy_resource_class_load_dir(path, klass, TRUE);
    g_free(path);

    path = g_build_filename(gwy_get_user_dir(), klass->name, NULL);
    gwy_resource_class_load_dir(path, klass, FALSE);
    g_free(path);

    gwy_inventory_restore_order(klass->inventory);
}
Пример #2
0
/**
 * gwy_resource_class_mkdir:
 * @klass: A resource class.
 *
 * Creates directory for user resources if it does not exist.
 *
 * Returns: %TRUE if the directory exists or has been successfully created.
 *          %FALSE if it doesn't exist and cannot be created, consult errno
 *          for reason.
 **/
gboolean
gwy_resource_class_mkdir(GwyResourceClass *klass)
{
    gchar *path;
    gint ok;

    g_return_val_if_fail(GWY_IS_RESOURCE_CLASS(klass), FALSE);

    path = g_build_filename(gwy_get_user_dir(), klass->name, NULL);
    if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
        g_free(path);
        return TRUE;
    }

    ok = !g_mkdir(path, 0700);
    g_free(path);

    return ok;
}
Пример #3
0
/**
 * gwy_resource_class_load:
 * @klass: A resource class.
 *
 * Loads resources of a resources class from disk.
 *
 * Resources are loaded from system directory (and marked constant) and from
 * user directory (marked modifiable).
 **/
void
gwy_resource_class_load(GwyResourceClass *klass)
{
    gchar *path, *datadir;

    g_return_if_fail(GWY_IS_RESOURCE_CLASS(klass));
    g_return_if_fail(klass->inventory);

    gwy_inventory_forget_order(klass->inventory);

    datadir = gwy_find_self_dir("data");
    path = g_build_filename(datadir, klass->name, NULL);
    g_free(datadir);
    gwy_resource_class_load_dir(path, klass, TRUE);
    g_free(path);

    path = g_build_filename(gwy_get_user_dir(), klass->name, NULL);
    gwy_resource_class_load_dir(path, klass, FALSE);
    g_free(path);

    gwy_inventory_restore_order(klass->inventory);
}
Пример #4
0
/**
 * gwy_resource_class_get_item_type:
 * @klass: A resource class.
 *
 * Gets inventory item type for a resource class.
 *
 * Returns: Inventory item type.
 **/
const GwyInventoryItemType*
gwy_resource_class_get_item_type(GwyResourceClass *klass)
{
    g_return_val_if_fail(GWY_IS_RESOURCE_CLASS(klass), NULL);
    return &klass->item_type;
}
Пример #5
0
/**
 * gwy_resource_class_get_inventory:
 * @klass: A resource class.
 *
 * Gets inventory which holds resources of a resource class.
 *
 * Returns: Resource class inventory.
 **/
GwyInventory*
gwy_resource_class_get_inventory(GwyResourceClass *klass)
{
    g_return_val_if_fail(GWY_IS_RESOURCE_CLASS(klass), NULL);
    return klass->inventory;
}
Пример #6
0
/**
 * gwy_resource_class_get_name:
 * @klass: A resource class.
 *
 * Gets the name of resource class.
 *
 * This is an simple identifier usable for example as directory name.
 *
 * Returns: Resource class name, as a constant string that must not be modified
 *          nor freed.
 **/
const gchar*
gwy_resource_class_get_name(GwyResourceClass *klass)
{
    g_return_val_if_fail(GWY_IS_RESOURCE_CLASS(klass), NULL);
    return klass->name;
}