aboutsummaryrefslogtreecommitdiffstats
path: root/src/ensorcel_tree_create.c
blob: 6d7aec64cf13e2aa9ec5cdd97534c0bd1353e2b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "ensorcel.h"

int ensorcel_grimoire_row_create (Ensorcel_Tree_Skel * Tree_Skel)
{
    FILE                   *fd;
    char                    line[ENSORCELMAXLINE];
    char                   *ptr = NULL;
    char                    sep = '=';

    if (!ecore_file_exists (ENSORCELGRIMOIREFILE))
    {
        printf ("no %s found\n", ENSORCELGRIMOIREFILE);
        return (EXIT_FAILURE);
    }

    fd = fopen (ENSORCELGRIMOIREFILE, "r");
    if (!fd)
    {
        printf ("%s can't be opened\n", ENSORCELGRIMOIREFILE);
        return (EXIT_FAILURE);
    }

    while (!feof (fd))
    {
        if (!fgets (line, sizeof (line), fd))
            break;
        ptr = strchr (line, sep) + 1;
        ptr[strlen (ptr) - 1] = '\0';
        if (ecore_file_is_dir (ptr))
        {
            //printf("DEBUG DEBUG DEBUG %s\n", LOGOGRIMOIREENSORCEL);
            Tree_Skel->row_grimoire =
                // etk_tree_append (ETK_TREE (Tree_Skel->tree), Tree_Skel->col1, LOGOGRIMOIREENSORCEL,
                etk_tree_append (ETK_TREE (Tree_Skel->tree), Tree_Skel->col1,
                                 ecore_file_get_file (ptr), Tree_Skel->col2, "---", Tree_Skel->col3,
                                 "---", Tree_Skel->col4, "---", NULL);
            ensorcel_section_row_create (ptr, Tree_Skel);


            if (!Tree_Skel->row_grimoire)
                return (EXIT_FAILURE);
        }
    }

    fclose (fd);
    /* VALGRIND SAYD INVALID FREE  
     * if (ptr)
     * free (ptr);
     */
    return (EXIT_SUCCESS);
}

int ensorcel_section_row_create (const char *grimoire_dir, Ensorcel_Tree_Skel * Tree_Skel)
{

    char                   *name;
    char                    dir[256];

    Ecore_List             *el_files;

    if (ecore_file_is_dir (grimoire_dir))
    {
        el_files = ecore_file_ls (grimoire_dir);

        if (!el_files)
            return (EXIT_FAILURE);

        ecore_list_goto_first (el_files);

        while ((name = ecore_list_next (el_files)))
        {
            sprintf (dir, "%s/%s", grimoire_dir, name);

            if (ecore_file_is_dir (dir))
            {
                Tree_Skel->row_section =
                    etk_tree_append_to_row (Tree_Skel->row_grimoire, Tree_Skel->col1, name,
                                            Tree_Skel->col2, "--", Tree_Skel->col3, "--",
                                            Tree_Skel->col4, "--", NULL);
                ensorcel_spell_row_create (dir, Tree_Skel);

                if (!Tree_Skel)
                    return (EXIT_FAILURE);
            }
        }
        ecore_list_destroy (el_files);  // ICI //
        return (EXIT_SUCCESS);
    }
    else
    {
        return (EXIT_FAILURE);
    }
}

void ensorcel_spell_row_create (char *section_dir, Ensorcel_Tree_Skel * Tree_Skel)
{
    char                   *name;
    char                    dir[256];

    Ecore_List             *el;
    Ecore_List             *el_spell_info;
    Ecore_List             *el_package_list;

    el_package_list = ensorcel_packages_info_get ();

    if (ecore_file_is_dir (section_dir))
    {
        el = ecore_file_ls (section_dir);

        if (!el)
            return;

        ecore_list_goto_first (el);

        while ((name = ecore_dlist_next (el)))
        {

            sprintf (dir, "%s/%s", section_dir, name);

            el_spell_info = ensorcel_spell_info_get (el_package_list, name, dir);
	    if	(!el_spell_info)
		    ensorcel_error_popup("FATAL ERROR");

            if (ecore_file_is_dir (dir))
                etk_tree_append_to_row (Tree_Skel->row_section, Tree_Skel->col1, name,
                                        Tree_Skel->col2,
                                        ensorcel_spell_installed_version_get (el_spell_info),
                                        Tree_Skel->col3, ensorcel_spell_lastest_get (el_spell_info),
                                        Tree_Skel->col4, ensorcel_spell_status_get (el_spell_info),
                                        NULL);
            if (el_spell_info)
                ecore_list_destroy (el_spell_info);
        }
    }
    if (el_package_list)
        ecore_list_destroy (el_package_list);
}