File: first-time.c

package info (click to toggle)
gpredict 2.3-72-gc596101-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 12,264 kB
  • sloc: ansic: 39,918; makefile: 469; python: 143; sh: 85
file content (822 lines) | stat: -rw-r--r-- 26,931 bytes parent folder | download | duplicates (2)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
/*
    Gpredict: Real-time satellite tracking and orbit prediction program

    Copyright (C)  2001-2017  Alexandru Csete, OZ9AEC.

    Comments, questions and bugreports should be submitted via
    http://sourceforge.net/projects/gpredict/
    More details can be found at the project home page:

            http://gpredict.oz9aec.net/
 
    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, visit http://www.fsf.org/
*/
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#ifdef HAVE_CONFIG_H
#include <build-config.h>
#endif
#include "compat.h"
#include "sat-log.h"
#include "sat-cfg.h"
#include "gpredict-utils.h"
#include "first-time.h"

/* private function prototypes */
static void     first_time_check_step_01(guint * error);
static void     first_time_check_step_02(guint * error);
static void     first_time_check_step_03(guint * error);
static void     first_time_check_step_04(guint * error);
static void     first_time_check_step_05(guint * error);
static void     first_time_check_step_06(guint * error);
static void     first_time_check_step_07(guint * error);
static void     first_time_check_step_08(guint * error);

/**
 * Perform first time checks.
 *
 * This function is called by the main function very early during program
 * startup. It's purpose is to check the user configuration to see whether
 * this is the first time gpredict is executed. If it is, a new default
 * configuration is set up so that the user has some sort of setup to get
 * started with.
 *
 * Check logic:
 *
 * 0. USER_CONF_DIR already exists because sat_log_init() initializes it.
 *
 * 1. Check for USER_CONF_DIR/gpredict.cfg - if not found, check if there is a
 *    gpredict.cfg in the old configuration directory and copy it to the new location.
 * 2. Check for the existence of at least one .qth file in USER_CONF_DIR
 *    If no such file found, check if there are any in the pre-1.1 configuration.
 *    If still none, copy PACKAGE_DATA_DIR/data/sample.qth to this
 *    directory.
 * 3. Check for the existence of USER_CONF_DIR/modules directory and create
 *    it if it does not exist. Moreover, if this is a new installation, check
 *    for .mod files in pre-1.1 directory (use get_old_conf_dir()). If no .mod
 *    files are available copy PACKAGE_DATA_DIR/data/Amateur.mod to
 *    USER_CONF_DIR/modules/
 * 4. Check for the existence of USER_CONF_DIR/satdata directory and create it if
 *    it does not exist.
 * 5. Check if there are any .sat files in USER_CONF_DIR/satdata/ - if not extract
 *    PACKAGE_DATA_DIR/data/satdata/satellites.dat to .sat files.
 *    Do the same with .cat files.
 * 6. Check for the existence of USER_CONF_DIR/satdata/cache directory. This
 *    directory is used to store temporary TLE files when updating from
 *    network.
 * 7. Check for the existence of USER_CONF_DIR/hwconf directory. This
 *    directory contains radio and rotator configurations (.rig and .rot files).
 *    If the directory is newly created, check if we have any existing configuration
 *    in the pre-1.1 configuration directory (use get_old_conf_dir()).
 * 8. Check for the existence of USER_CONF_DIR/trsp directory. This
 *    directory contains transponder data for satellites.
 *
 * Send both error, warning and verbose debug messages to sat-log during this
 * process.
 *
 * The function returns 0 if everything seems to be ready or 1 if an error occured
 * during on of the steps above. In case of error, the only safe thing is to exit
 * imediately.
 *
 * FIXME: Should only have one parameterized function for checking directories.
 */
guint first_time_check_run()
{
    guint           error = 0;

    first_time_check_step_01(&error);
    first_time_check_step_02(&error);
    first_time_check_step_03(&error);
    first_time_check_step_04(&error);
    first_time_check_step_05(&error);
    first_time_check_step_06(&error);
    first_time_check_step_07(&error);
    first_time_check_step_08(&error);

    return error;
}

/**
 * Execute step 1 of the first time checks.
 *
 * 1. Check for USER_CONF_DIR/gpredict.cfg - if not found, check if there is a
 *    gpredict.cfg in the old configuration directory and copy it to the new location.
 *
 */
static void first_time_check_step_01(guint * error)
{
    gchar          *newdir, *olddir;
    gchar          *source, *target;

    /* FIXME */
    (void)error;                /* avoid unused parameter compiler warning */

    newdir = get_user_conf_dir();
    target = g_strconcat(newdir, G_DIR_SEPARATOR_S, "gpredict.cfg", NULL);
    g_free(newdir);

    if (g_file_test(target, G_FILE_TEST_EXISTS))
    {
        /* already have config file => return */
        g_free(target);

        return;
    }

    /* check if we have old configuration */
    olddir = get_old_conf_dir();
    source = g_strconcat(olddir, G_DIR_SEPARATOR_S, "gpredict.cfg", NULL);
    g_free(olddir);

    if (g_file_test(source, G_FILE_TEST_EXISTS))
    {
        /* copy old config file to new location */
        gpredict_file_copy(source, target);

    }

    g_free(source);
    g_free(target);
}

/**
 * Execute step 2 of the first time checks.
 *
 * 2. Check for the existence of at least one .qth file in USER_CONF_DIR
 *    If no such file found, check if there are any in the pre-1.1 configuration.
 *    If still none, copy PACKAGE_DATA_DIR/data/sample.qth to this
 *    directory.
 *
 */
static void first_time_check_step_02(guint * error)
{
    GDir           *dir;
    gchar          *dirname;
    gchar          *filename;
    const gchar    *datafile;
    gchar          *target;
    gboolean        foundqth = FALSE;

    dirname = get_user_conf_dir();
    dir = g_dir_open(dirname, 0, NULL);

    /* directory does not exist, something went wrong in step 1 */
    if (!dir)
    {
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s: Could not open %s."), __func__, dirname);

        /* no reason to continue */
        *error |= FTC_ERROR_STEP_02;
    }
    else
    {
        /* read files, if any; count number of .qth files */
        while ((datafile = g_dir_read_name(dir)))
        {

            /* note: filename is not a newly allocated gchar *,
               so we must not free it
             */

            if (g_str_has_suffix(datafile, ".qth"))
                foundqth = TRUE;
        }

        g_dir_close(dir);

        if (foundqth)
            sat_log_log(SAT_LOG_LEVEL_DEBUG,
                        _("%s: Found at least one .qth file."), __func__);
        else
        {
            /* try to see if there are any .qth file in pre-1.1 configuration */
            gchar          *olddir = get_old_conf_dir();

            dir = g_dir_open(olddir, 0, NULL);

            if (dir)
            {
                /* read files, if any; count number of .qth files */
                while ((datafile = g_dir_read_name(dir)))
                {

                    /* note: filename is not a newly allocated gchar *,
                       so we must not free it
                     */
                    if (g_str_has_suffix(datafile, ".qth"))
                    {

                        gchar          *source =
                            g_strconcat(olddir, G_DIR_SEPARATOR_S, datafile,
                                        NULL);

                        /* copy .qth file to USER_CONF_DIR */
                        target =
                            g_strconcat(dirname, G_DIR_SEPARATOR_S, datafile,
                                        NULL);
                        if (!gpredict_file_copy(source, target))
                        {
                            /* success */
                            foundqth = TRUE;
                        }
                        g_free(target);
                        g_free(source);
                    }

                }
                g_dir_close(dir);
            }
            else if (!foundqth)
            {
                /* try to copy sample.qth */
                filename = data_file_name("sample.qth");
                target =
                    g_strconcat(dirname, G_DIR_SEPARATOR_S, "sample.qth",
                                NULL);

                if (gpredict_file_copy(filename, target))
                {
                    sat_log_log(SAT_LOG_LEVEL_ERROR,
                                _("%s: Failed to copy sample.qth"), __func__);

                    *error |= FTC_ERROR_STEP_02;
                }
                else
                {
                    sat_log_log(SAT_LOG_LEVEL_DEBUG,
                                _("%s: Copied sample.qth to %s/"),
                                __func__, dirname);
                }
                g_free(target);
                g_free(filename);
            }
            g_free(olddir);
        }
    }
    g_free(dirname);
}

/**
 * Execute step 3 of the first time checks.
 *
 * 3. Check for the existence of USER_CONF_DIR/modules directory and create
 *    it if it does not exist. Moreover, if this is a new installation, check
 *    for .mod files in pre-1.1 directory (use get_old_conf_dir()). If no .mod
 *    files are available copy PACKAGE_DATA_DIR/data/Amateur.mod to
 *    USER_CONF_DIR/modules/
 *
 */
static void first_time_check_step_03(guint * error)
{
    GDir           *dir;
    gchar          *confdir, *olddir, *buff;
    int             status;
    gchar          *target;
    gchar          *filename;
    const gchar    *datafile;
    gboolean        foundmod = FALSE;


    confdir = get_modules_dir();

    if (g_file_test(confdir, G_FILE_TEST_IS_DIR))
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
    }
    else
    {
        /* try to create directory */
        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                    _("%s: Check failed. Creating %s"), __func__, confdir);

        status = g_mkdir_with_parents(confdir, 0755);

        if (status)
        {
            /* set error flag */
            *error |= FTC_ERROR_STEP_03;

            sat_log_log(SAT_LOG_LEVEL_ERROR,
                        _("%s: Failed to create %s"), __func__, confdir);
        }
        else
        {
            sat_log_log(SAT_LOG_LEVEL_DEBUG,
                        _("%s: Created %s."), __func__, confdir);

            /* try to see if there are any .mod file in pre-1.1 configuration */
            buff = get_old_conf_dir();
            olddir = g_strconcat(buff, G_DIR_SEPARATOR_S, "modules", NULL);
            dir = g_dir_open(olddir, 0, NULL);

            g_free(buff);

            if (dir)
            {
                /* read files, if any; count number of .qth files */
                while ((datafile = g_dir_read_name(dir)))
                {

                    /* note: filename is not a newly allocated gchar *,
                       so we must not free it
                     */
                    if (g_str_has_suffix(datafile, ".mod"))
                    {
                        gchar          *source =
                            g_strconcat(olddir, G_DIR_SEPARATOR_S, datafile,
                                        NULL);

                        /* copy .qth file to USER_CONF_DIR */
                        target =
                            g_strconcat(confdir, G_DIR_SEPARATOR_S, datafile,
                                        NULL);
                        if (!gpredict_file_copy(source, target))
                        {
                            /* success */
                            foundmod = TRUE;
                        }
                        g_free(target);
                        g_free(source);
                    }

                }
                g_dir_close(dir);
            }
            else if (!foundmod)
            {
                /* copy Amateur.mod to this directory */
                filename = data_file_name("Amateur.mod");
                target =
                    g_strconcat(confdir, G_DIR_SEPARATOR_S, "Amateur.mod",
                                NULL);

                if (gpredict_file_copy(filename, target))
                {
                    sat_log_log(SAT_LOG_LEVEL_ERROR,
                                _("%s: Failed to copy Amateur.mod"), __func__);

                    *error |= FTC_ERROR_STEP_02;
                }
                else
                {
                    sat_log_log(SAT_LOG_LEVEL_DEBUG,
                                _("%s: Copied amateur.mod to %s/"),
                                __func__, dir);
                }
                g_free(target);
                g_free(filename);
            }
            g_free(olddir);
        }
    }
    g_free(confdir);
}

/**
 * Execute step 4 of the first time checks.
 *
 * 4. Check for the existence of USER_CONF_DIR/satdata directory and create it if
 *    it does not exist.
 *
 */
static void first_time_check_step_04(guint * error)
{
    gchar          *dir;
    int             status;

    dir = get_satdata_dir();

    if (g_file_test(dir, G_FILE_TEST_IS_DIR))
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
    }
    else
    {
        /* try to create directory */
        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                    _("%s: Check failed. Creating %s"), __func__, dir);

        status = g_mkdir_with_parents(dir, 0755);

        if (status)
        {
            /* set error flag */
            *error |= FTC_ERROR_STEP_04;

            sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Failed to create %s"),
                        __func__, dir);
        }
        else
        {
            sat_log_log(SAT_LOG_LEVEL_DEBUG,
                        _("%s: Created %s."), __func__, dir);
        }
    }
    g_free(dir);
}

/* create .sat files from a satellites.dat file */
static void create_sat_files(guint * error)
{
    gchar          *satfilename, *targetfilename;
    gchar          *datadir;
    gchar         **satellites;
    GKeyFile       *satfile, *target;
    gsize           num;
    GError         *err = NULL;
    guint           i;
    guint           newsats = 0;
    gchar          *name, *nickname, *website, *tle1, *tle2, *cfgver;

    sat_log_log(SAT_LOG_LEVEL_INFO,
                _("Copying satellite data to user config"));

    /* open datellites.dat and load into memory */
    datadir = get_data_dir();
    satfilename = g_strconcat(datadir, G_DIR_SEPARATOR_S, "satdata",
                              G_DIR_SEPARATOR_S, "satellites.dat", NULL);

    satfile = g_key_file_new();
    if (!g_key_file_load_from_file
        (satfile, satfilename, G_KEY_FILE_KEEP_COMMENTS, &err))
    {
        /* an error occurred */
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s: Failed to load data from %s (%s)"),
                    __func__, satfilename, err->message);

        g_clear_error(&err);
        *error |= FTC_ERROR_STEP_05;
    }
    else
    {
        satellites = g_key_file_get_groups(satfile, &num);
        sat_log_log(SAT_LOG_LEVEL_INFO,
                    _("%s: Found %d satellites in %s"),
                    __func__, num, satfilename);

        for (i = 0; i < num; i++)
        {
            /* first, check if this satellite already has a .sat file */
            targetfilename = sat_file_name_from_catnum_s(satellites[i]);
            if (g_file_test(targetfilename, G_FILE_TEST_EXISTS))
            {
                sat_log_log(SAT_LOG_LEVEL_DEBUG,
                            _("%s: %s.sat already exists. Skipped."),
                            __func__, satellites[i]);
            }
            else
            {
                /* read data for this satellite */
                cfgver =
                    g_key_file_get_string(satfile, satellites[i], "VERSION",
                                          NULL);
                name =
                    g_key_file_get_string(satfile, satellites[i], "NAME",
                                          NULL);
                nickname =
                    g_key_file_get_string(satfile, satellites[i], "NICKNAME",
                                          NULL);
                website =
                    g_key_file_get_string(satfile, satellites[i], "WEBSITE",
                                          NULL);
                tle1 =
                    g_key_file_get_string(satfile, satellites[i], "TLE1",
                                          NULL);
                tle2 =
                    g_key_file_get_string(satfile, satellites[i], "TLE2",
                                          NULL);

                /* create output .sat file */
                target = g_key_file_new();
                g_key_file_set_string(target, "Satellite", "VERSION", cfgver);
                g_key_file_set_string(target, "Satellite", "NAME", name);
                g_key_file_set_string(target, "Satellite", "NICKNAME",
                                      nickname);
                if (website != NULL)
                {
                    g_key_file_set_string(target, "Satellite", "WEBSITE",
                                          website);
                    g_free(website);
                }
                g_key_file_set_string(target, "Satellite", "TLE1", tle1);
                g_key_file_set_string(target, "Satellite", "TLE2", tle2);

                if (gpredict_save_key_file(target, targetfilename))
                {
                    *error |= FTC_ERROR_STEP_05;
                }
                else
                {
                    newsats++;
                }

                g_key_file_free(target);

                g_free(cfgver);
                g_free(name);
                g_free(nickname);
                g_free(tle1);
                g_free(tle2);
            }
            g_free(targetfilename);
        }
        g_strfreev(satellites);
        sat_log_log(SAT_LOG_LEVEL_INFO,
                    _("%s: Written %d new satellite to user config"),
                    __func__, newsats);
    }
    g_key_file_free(satfile);
    g_free(satfilename);
    g_free(datadir);
}

/* create .cat files in user conf directory */
static void create_cat_files(guint * error)
{
    gchar          *datadir;
    GError         *err = NULL;
    GDir           *srcdir;
    gchar          *srcdirname;
    const gchar    *filename;

    sat_log_log(SAT_LOG_LEVEL_INFO,
                _("Copying satellite categories to user config"));

    /* .cat files: if .cat file does not exist, copy it, otherwise skip */
    datadir = get_data_dir();
    srcdirname = g_strconcat(datadir, G_DIR_SEPARATOR_S, "satdata", NULL);
    srcdir = g_dir_open(srcdirname, 0, &err);

    /* directory does not exist, something went wrong in step 4 */
    if (!srcdir)
    {
        sat_log_log(SAT_LOG_LEVEL_ERROR,
                    _("%s: Could not open %s (%s)."),
                    __func__, srcdirname, err->message);

        /* no reason to continue */
        g_clear_error(&err);
        *error |= FTC_ERROR_STEP_05;
    }
    else
    {
        /* get each .cat file and check if they already exist in user conf */
        /* read files one by one, if any; count number of .tle files */
        while ((filename = g_dir_read_name(srcdir)))
        {
            /* note: filename is not a newly allocated gchar *,
               so we must not free it
             */
            if (g_str_has_suffix(filename, ".cat"))
            {

                /* check whether .cat file exisits in user conf */
                gchar          *catfilename = sat_file_name(filename);

                if (!g_file_test(catfilename, G_FILE_TEST_EXISTS))
                {
                    /* copy file to target dir */
                    gchar          *source =
                        g_strconcat(srcdirname, G_DIR_SEPARATOR_S, filename,
                                    NULL);
                    if (gpredict_file_copy(source, catfilename))
                    {
                        sat_log_log(SAT_LOG_LEVEL_ERROR,
                                    _("%s: Failed to copy %s"),
                                    __func__, filename);
                    }
                    else
                    {
                        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                                    _("%s: Successfully copied %s"),
                                    __func__, filename);
                    }
                    g_free(source);
                }
                g_free(catfilename);
            }
        }
        g_dir_close(srcdir);
    }
    g_free(srcdirname);
    g_free(datadir);
}

/**
 * Execute step 5 of the first time checks.
 *
 * 5. Check if there are any .sat files in USER_CONF_DIR/satdata/ - if not extract
 *    PACKAGE_DATA_DIR/data/satdata/satellites.dat to .sat files.
 *    Do the same with .cat files.
 *
 */
static void first_time_check_step_05(guint * error)
{
    gchar          *datadir_str;
    GDir           *datadir;
    const gchar    *filename;
    gboolean        have_sat = FALSE;
    gboolean        have_cat = FALSE;

    /* check if there already is a .sat and .cat in ~/.config/... */
    datadir_str = get_satdata_dir();
    datadir = g_dir_open(datadir_str, 0, NULL);
    while ((filename = g_dir_read_name(datadir)))
    {
        /* note: filename is not newly allocated */
        if (g_str_has_suffix(filename, ".sat"))
            have_sat = TRUE;
        if (g_str_has_suffix(filename, ".cat"))
            have_cat = TRUE;
    }
    g_free(datadir_str);
    g_dir_close(datadir);

    if (!have_sat)
        create_sat_files(error);

    if (!have_cat)
        create_cat_files(error);
}

/**
 * Execute step 6 of the first time checks.
 *
 * 6. Check for the existence of USER_CONF_DIR/satdata/cache directory. This
 *    directory is used to store temporary TLE files when updating from
 *    network.
 *
 */
static void first_time_check_step_06(guint * error)
{
    gchar          *buff, *dir;
    int             status;

    buff = get_satdata_dir();
    dir = g_strconcat(buff, G_DIR_SEPARATOR_S, "cache", NULL);
    g_free(buff);

    if (g_file_test(dir, G_FILE_TEST_IS_DIR))
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
    }
    else
    {
        /* try to create directory */
        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                    _("%s: Check failed. Creating %s"), __func__, dir);

        status = g_mkdir_with_parents(dir, 0755);

        if (status)
        {
            /* set error flag */
            *error |= FTC_ERROR_STEP_06;

            sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Failed to create %s"),
                        __func__, dir);
        }
        else
        {
            sat_log_log(SAT_LOG_LEVEL_DEBUG,
                        _("%s: Created %s."), __func__, dir);
        }
    }
    g_free(dir);
}

/**
 * Execute step 7 of the first time checks.
 *
 * 7. Check for the existence of USER_CONF_DIR/hwconf directory. This
 *    directory contains radio and rotator configurations (.rig and .rot files).
 *    If the directory is newly created, check if we have any existing configuration
 *    in the pre-1.1 configuration directory (use get_old_conf_dir()).
 *
 */
static void first_time_check_step_07(guint * error)
{
    GDir           *dir;
    gchar          *confdir, *olddir, *buff;
    int             status;
    gchar          *target;
    const gchar    *datafile;

    confdir = get_hwconf_dir();

    if (g_file_test(confdir, G_FILE_TEST_IS_DIR))
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
    }
    else
    {
        /* try to create directory */
        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                    _("%s: Check failed. Creating %s"), __func__, confdir);

        status = g_mkdir_with_parents(confdir, 0755);

        if (status)
        {
            /* set error flag */
            *error |= FTC_ERROR_STEP_03;
            sat_log_log(SAT_LOG_LEVEL_ERROR,
                        _("%s: Failed to create %s"), __func__, confdir);
        }
        else
        {
            sat_log_log(SAT_LOG_LEVEL_DEBUG,
                        _("%s: Created %s."), __func__, confdir);

            /* try to see if there are any .rig or .rot file in pre-1.1 configuration */
            buff = get_old_conf_dir();
            olddir = g_strconcat(buff, G_DIR_SEPARATOR_S, "hwconf", NULL);

            dir = g_dir_open(olddir, 0, NULL);

            g_free(buff);

            if (dir)
            {
                /* read files, if any; count number of .qth files */
                while ((datafile = g_dir_read_name(dir)))
                {
                    gchar          *source =
                        g_strconcat(olddir, G_DIR_SEPARATOR_S, datafile, NULL);

                    /* note: filename is not a newly allocated gchar *,
                       so we must not free it
                     */

                    /* copy file to USER_CONF_DIR */
                    target = g_strconcat(confdir, G_DIR_SEPARATOR_S,
                                    datafile, NULL);
                    gpredict_file_copy(source, target);
                    g_free(target);
                    g_free(source);
                }
                g_dir_close(dir);
            }
            g_free(olddir);
        }
    }
    g_free(confdir);

}

/**
 * Execute step 8 of the first time checks.
 *
 * 8. Check for the existence of USER_CONF_DIR/trsp directory. This
 *    directory contains transponder data for satellites.
 *
 */
static void first_time_check_step_08(guint * error)
{
    gchar          *dir;
    int             status;

    dir = get_trsp_dir();

    if (g_file_test(dir, G_FILE_TEST_IS_DIR))
    {
        sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
    }
    else
    {
        /* try to create directory */
        sat_log_log(SAT_LOG_LEVEL_DEBUG,
                    _("%s: Check failed. Creating %s"), __func__, dir);

        status = g_mkdir_with_parents(dir, 0755);

        if (status)
        {
            /* set error flag */
            *error |= FTC_ERROR_STEP_08;
            sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Failed to create %s"),
                        __func__, dir);
        }
        else
        {
            sat_log_log(SAT_LOG_LEVEL_DEBUG,
                        _("%s: Created %s."), __func__, dir);
        }
    }

    g_free(dir);
}