1 /*
2     Gpredict: Real-time satellite tracking and orbit prediction program
3 
4     Copyright (C)  2001-2017  Alexandru Csete, OZ9AEC.
5 
6     Comments, questions and bugreports should be submitted via
7     http://sourceforge.net/projects/gpredict/
8     More details can be found at the project home page:
9 
10             http://gpredict.oz9aec.net/
11 
12     This program is free software; you can redistribute it and/or modify
13     it under the terms of the GNU General Public License as published by
14     the Free Software Foundation; either version 2 of the License, or
15     (at your option) any later version.
16 
17     This program is distributed in the hope that it will be useful,
18     but WITHOUT ANY WARRANTY; without even the implied warranty of
19     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20     GNU General Public License for more details.
21 
22     You should have received a copy of the GNU General Public License
23     along with this program; if not, visit http://www.fsf.org/
24 */
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <glib/gstdio.h>
28 #ifdef HAVE_CONFIG_H
29 #include <build-config.h>
30 #endif
31 #include "compat.h"
32 #include "sat-log.h"
33 #include "sat-cfg.h"
34 #include "gpredict-utils.h"
35 #include "first-time.h"
36 
37 /* private function prototypes */
38 static void     first_time_check_step_01(guint * error);
39 static void     first_time_check_step_02(guint * error);
40 static void     first_time_check_step_03(guint * error);
41 static void     first_time_check_step_04(guint * error);
42 static void     first_time_check_step_05(guint * error);
43 static void     first_time_check_step_06(guint * error);
44 static void     first_time_check_step_07(guint * error);
45 static void     first_time_check_step_08(guint * error);
46 
47 /**
48  * Perform first time checks.
49  *
50  * This function is called by the main function very early during program
51  * startup. It's purpose is to check the user configuration to see whether
52  * this is the first time gpredict is executed. If it is, a new default
53  * configuration is set up so that the user has some sort of setup to get
54  * started with.
55  *
56  * Check logic:
57  *
58  * 0. USER_CONF_DIR already exists because sat_log_init() initializes it.
59  *
60  * 1. Check for USER_CONF_DIR/gpredict.cfg - if not found, check if there is a
61  *    gpredict.cfg in the old configuration directory and copy it to the new location.
62  * 2. Check for the existence of at least one .qth file in USER_CONF_DIR
63  *    If no such file found, check if there are any in the pre-1.1 configuration.
64  *    If still none, copy PACKAGE_DATA_DIR/data/sample.qth to this
65  *    directory.
66  * 3. Check for the existence of USER_CONF_DIR/modules directory and create
67  *    it if it does not exist. Moreover, if this is a new installation, check
68  *    for .mod files in pre-1.1 directory (use get_old_conf_dir()). If no .mod
69  *    files are available copy PACKAGE_DATA_DIR/data/Amateur.mod to
70  *    USER_CONF_DIR/modules/
71  * 4. Check for the existence of USER_CONF_DIR/satdata directory and create it if
72  *    it does not exist.
73  * 5. Check if there are any .sat files in USER_CONF_DIR/satdata/ - if not extract
74  *    PACKAGE_DATA_DIR/data/satdata/satellites.dat to .sat files.
75  *    Do the same with .cat files.
76  * 6. Check for the existence of USER_CONF_DIR/satdata/cache directory. This
77  *    directory is used to store temporary TLE files when updating from
78  *    network.
79  * 7. Check for the existence of USER_CONF_DIR/hwconf directory. This
80  *    directory contains radio and rotator configurations (.rig and .rot files).
81  *    If the directory is newly created, check if we have any existing configuration
82  *    in the pre-1.1 configuration directory (use get_old_conf_dir()).
83  * 8. Check for the existence of USER_CONF_DIR/trsp directory. This
84  *    directory contains transponder data for satellites.
85  *
86  * Send both error, warning and verbose debug messages to sat-log during this
87  * process.
88  *
89  * The function returns 0 if everything seems to be ready or 1 if an error occured
90  * during on of the steps above. In case of error, the only safe thing is to exit
91  * imediately.
92  *
93  * FIXME: Should only have one parameterized function for checking directories.
94  */
first_time_check_run()95 guint first_time_check_run()
96 {
97     guint           error = 0;
98 
99     first_time_check_step_01(&error);
100     first_time_check_step_02(&error);
101     first_time_check_step_03(&error);
102     first_time_check_step_04(&error);
103     first_time_check_step_05(&error);
104     first_time_check_step_06(&error);
105     first_time_check_step_07(&error);
106     first_time_check_step_08(&error);
107 
108     return error;
109 }
110 
111 /**
112  * Execute step 1 of the first time checks.
113  *
114  * 1. Check for USER_CONF_DIR/gpredict.cfg - if not found, check if there is a
115  *    gpredict.cfg in the old configuration directory and copy it to the new location.
116  *
117  */
first_time_check_step_01(guint * error)118 static void first_time_check_step_01(guint * error)
119 {
120     gchar          *newdir, *olddir;
121     gchar          *source, *target;
122 
123     /* FIXME */
124     (void)error;                /* avoid unused parameter compiler warning */
125 
126     newdir = get_user_conf_dir();
127     target = g_strconcat(newdir, G_DIR_SEPARATOR_S, "gpredict.cfg", NULL);
128     g_free(newdir);
129 
130     if (g_file_test(target, G_FILE_TEST_EXISTS))
131     {
132         /* already have config file => return */
133         g_free(target);
134 
135         return;
136     }
137 
138     /* check if we have old configuration */
139     olddir = get_old_conf_dir();
140     source = g_strconcat(olddir, G_DIR_SEPARATOR_S, "gpredict.cfg", NULL);
141     g_free(olddir);
142 
143     if (g_file_test(source, G_FILE_TEST_EXISTS))
144     {
145         /* copy old config file to new location */
146         gpredict_file_copy(source, target);
147 
148     }
149 
150     g_free(source);
151     g_free(target);
152 }
153 
154 /**
155  * Execute step 2 of the first time checks.
156  *
157  * 2. Check for the existence of at least one .qth file in USER_CONF_DIR
158  *    If no such file found, check if there are any in the pre-1.1 configuration.
159  *    If still none, copy PACKAGE_DATA_DIR/data/sample.qth to this
160  *    directory.
161  *
162  */
first_time_check_step_02(guint * error)163 static void first_time_check_step_02(guint * error)
164 {
165     GDir           *dir;
166     gchar          *dirname;
167     gchar          *filename;
168     const gchar    *datafile;
169     gchar          *target;
170     gboolean        foundqth = FALSE;
171 
172     dirname = get_user_conf_dir();
173     dir = g_dir_open(dirname, 0, NULL);
174 
175     /* directory does not exist, something went wrong in step 1 */
176     if (!dir)
177     {
178         sat_log_log(SAT_LOG_LEVEL_ERROR,
179                     _("%s: Could not open %s."), __func__, dirname);
180 
181         /* no reason to continue */
182         *error |= FTC_ERROR_STEP_02;
183     }
184     else
185     {
186         /* read files, if any; count number of .qth files */
187         while ((datafile = g_dir_read_name(dir)))
188         {
189 
190             /* note: filename is not a newly allocated gchar *,
191                so we must not free it
192              */
193 
194             if (g_str_has_suffix(datafile, ".qth"))
195                 foundqth = TRUE;
196         }
197 
198         g_dir_close(dir);
199 
200         if (foundqth)
201             sat_log_log(SAT_LOG_LEVEL_DEBUG,
202                         _("%s: Found at least one .qth file."), __func__);
203         else
204         {
205             /* try to see if there are any .qth file in pre-1.1 configuration */
206             gchar          *olddir = get_old_conf_dir();
207 
208             dir = g_dir_open(olddir, 0, NULL);
209 
210             if (dir)
211             {
212                 /* read files, if any; count number of .qth files */
213                 while ((datafile = g_dir_read_name(dir)))
214                 {
215 
216                     /* note: filename is not a newly allocated gchar *,
217                        so we must not free it
218                      */
219                     if (g_str_has_suffix(datafile, ".qth"))
220                     {
221 
222                         gchar          *source =
223                             g_strconcat(olddir, G_DIR_SEPARATOR_S, datafile,
224                                         NULL);
225 
226                         /* copy .qth file to USER_CONF_DIR */
227                         target =
228                             g_strconcat(dirname, G_DIR_SEPARATOR_S, datafile,
229                                         NULL);
230                         if (!gpredict_file_copy(source, target))
231                         {
232                             /* success */
233                             foundqth = TRUE;
234                         }
235                         g_free(target);
236                         g_free(source);
237                     }
238 
239                 }
240                 g_dir_close(dir);
241             }
242             else if (!foundqth)
243             {
244                 /* try to copy sample.qth */
245                 filename = data_file_name("sample.qth");
246                 target =
247                     g_strconcat(dirname, G_DIR_SEPARATOR_S, "sample.qth",
248                                 NULL);
249 
250                 if (gpredict_file_copy(filename, target))
251                 {
252                     sat_log_log(SAT_LOG_LEVEL_ERROR,
253                                 _("%s: Failed to copy sample.qth"), __func__);
254 
255                     *error |= FTC_ERROR_STEP_02;
256                 }
257                 else
258                 {
259                     sat_log_log(SAT_LOG_LEVEL_DEBUG,
260                                 _("%s: Copied sample.qth to %s/"),
261                                 __func__, dirname);
262                 }
263                 g_free(target);
264                 g_free(filename);
265             }
266             g_free(olddir);
267         }
268     }
269     g_free(dirname);
270 }
271 
272 /**
273  * Execute step 3 of the first time checks.
274  *
275  * 3. Check for the existence of USER_CONF_DIR/modules directory and create
276  *    it if it does not exist. Moreover, if this is a new installation, check
277  *    for .mod files in pre-1.1 directory (use get_old_conf_dir()). If no .mod
278  *    files are available copy PACKAGE_DATA_DIR/data/Amateur.mod to
279  *    USER_CONF_DIR/modules/
280  *
281  */
first_time_check_step_03(guint * error)282 static void first_time_check_step_03(guint * error)
283 {
284     GDir           *dir;
285     gchar          *confdir, *olddir, *buff;
286     int             status;
287     gchar          *target;
288     gchar          *filename;
289     const gchar    *datafile;
290     gboolean        foundmod = FALSE;
291 
292 
293     confdir = get_modules_dir();
294 
295     if (g_file_test(confdir, G_FILE_TEST_IS_DIR))
296     {
297         sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
298     }
299     else
300     {
301         /* try to create directory */
302         sat_log_log(SAT_LOG_LEVEL_DEBUG,
303                     _("%s: Check failed. Creating %s"), __func__, confdir);
304 
305         status = g_mkdir_with_parents(confdir, 0755);
306 
307         if (status)
308         {
309             /* set error flag */
310             *error |= FTC_ERROR_STEP_03;
311 
312             sat_log_log(SAT_LOG_LEVEL_ERROR,
313                         _("%s: Failed to create %s"), __func__, confdir);
314         }
315         else
316         {
317             sat_log_log(SAT_LOG_LEVEL_DEBUG,
318                         _("%s: Created %s."), __func__, confdir);
319 
320             /* try to see if there are any .mod file in pre-1.1 configuration */
321             buff = get_old_conf_dir();
322             olddir = g_strconcat(buff, G_DIR_SEPARATOR_S, "modules", NULL);
323             dir = g_dir_open(olddir, 0, NULL);
324 
325             g_free(buff);
326 
327             if (dir)
328             {
329                 /* read files, if any; count number of .qth files */
330                 while ((datafile = g_dir_read_name(dir)))
331                 {
332 
333                     /* note: filename is not a newly allocated gchar *,
334                        so we must not free it
335                      */
336                     if (g_str_has_suffix(datafile, ".mod"))
337                     {
338                         gchar          *source =
339                             g_strconcat(olddir, G_DIR_SEPARATOR_S, datafile,
340                                         NULL);
341 
342                         /* copy .qth file to USER_CONF_DIR */
343                         target =
344                             g_strconcat(confdir, G_DIR_SEPARATOR_S, datafile,
345                                         NULL);
346                         if (!gpredict_file_copy(source, target))
347                         {
348                             /* success */
349                             foundmod = TRUE;
350                         }
351                         g_free(target);
352                         g_free(source);
353                     }
354 
355                 }
356                 g_dir_close(dir);
357             }
358             else if (!foundmod)
359             {
360                 /* copy Amateur.mod to this directory */
361                 filename = data_file_name("Amateur.mod");
362                 target =
363                     g_strconcat(confdir, G_DIR_SEPARATOR_S, "Amateur.mod",
364                                 NULL);
365 
366                 if (gpredict_file_copy(filename, target))
367                 {
368                     sat_log_log(SAT_LOG_LEVEL_ERROR,
369                                 _("%s: Failed to copy Amateur.mod"), __func__);
370 
371                     *error |= FTC_ERROR_STEP_02;
372                 }
373                 else
374                 {
375                     sat_log_log(SAT_LOG_LEVEL_DEBUG,
376                                 _("%s: Copied amateur.mod to %s/"),
377                                 __func__, dir);
378                 }
379                 g_free(target);
380                 g_free(filename);
381             }
382             g_free(olddir);
383         }
384     }
385     g_free(confdir);
386 }
387 
388 /**
389  * Execute step 4 of the first time checks.
390  *
391  * 4. Check for the existence of USER_CONF_DIR/satdata directory and create it if
392  *    it does not exist.
393  *
394  */
first_time_check_step_04(guint * error)395 static void first_time_check_step_04(guint * error)
396 {
397     gchar          *dir;
398     int             status;
399 
400     dir = get_satdata_dir();
401 
402     if (g_file_test(dir, G_FILE_TEST_IS_DIR))
403     {
404         sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
405     }
406     else
407     {
408         /* try to create directory */
409         sat_log_log(SAT_LOG_LEVEL_DEBUG,
410                     _("%s: Check failed. Creating %s"), __func__, dir);
411 
412         status = g_mkdir_with_parents(dir, 0755);
413 
414         if (status)
415         {
416             /* set error flag */
417             *error |= FTC_ERROR_STEP_04;
418 
419             sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Failed to create %s"),
420                         __func__, dir);
421         }
422         else
423         {
424             sat_log_log(SAT_LOG_LEVEL_DEBUG,
425                         _("%s: Created %s."), __func__, dir);
426         }
427     }
428     g_free(dir);
429 }
430 
431 /* create .sat files from a satellites.dat file */
create_sat_files(guint * error)432 static void create_sat_files(guint * error)
433 {
434     gchar          *satfilename, *targetfilename;
435     gchar          *datadir;
436     gchar         **satellites;
437     GKeyFile       *satfile, *target;
438     gsize           num;
439     GError         *err = NULL;
440     guint           i;
441     guint           newsats = 0;
442     gchar          *name, *nickname, *website, *tle1, *tle2, *cfgver;
443 
444     sat_log_log(SAT_LOG_LEVEL_INFO,
445                 _("Copying satellite data to user config"));
446 
447     /* open datellites.dat and load into memory */
448     datadir = get_data_dir();
449     satfilename = g_strconcat(datadir, G_DIR_SEPARATOR_S, "satdata",
450                               G_DIR_SEPARATOR_S, "satellites.dat", NULL);
451 
452     satfile = g_key_file_new();
453     if (!g_key_file_load_from_file
454         (satfile, satfilename, G_KEY_FILE_KEEP_COMMENTS, &err))
455     {
456         /* an error occurred */
457         sat_log_log(SAT_LOG_LEVEL_ERROR,
458                     _("%s: Failed to load data from %s (%s)"),
459                     __func__, satfilename, err->message);
460 
461         g_clear_error(&err);
462         *error |= FTC_ERROR_STEP_05;
463     }
464     else
465     {
466         satellites = g_key_file_get_groups(satfile, &num);
467         sat_log_log(SAT_LOG_LEVEL_INFO,
468                     _("%s: Found %d satellites in %s"),
469                     __func__, num, satfilename);
470 
471         for (i = 0; i < num; i++)
472         {
473             /* first, check if this satellite already has a .sat file */
474             targetfilename = sat_file_name_from_catnum_s(satellites[i]);
475             if (g_file_test(targetfilename, G_FILE_TEST_EXISTS))
476             {
477                 sat_log_log(SAT_LOG_LEVEL_DEBUG,
478                             _("%s: %s.sat already exists. Skipped."),
479                             __func__, satellites[i]);
480             }
481             else
482             {
483                 /* read data for this satellite */
484                 cfgver =
485                     g_key_file_get_string(satfile, satellites[i], "VERSION",
486                                           NULL);
487                 name =
488                     g_key_file_get_string(satfile, satellites[i], "NAME",
489                                           NULL);
490                 nickname =
491                     g_key_file_get_string(satfile, satellites[i], "NICKNAME",
492                                           NULL);
493                 website =
494                     g_key_file_get_string(satfile, satellites[i], "WEBSITE",
495                                           NULL);
496                 tle1 =
497                     g_key_file_get_string(satfile, satellites[i], "TLE1",
498                                           NULL);
499                 tle2 =
500                     g_key_file_get_string(satfile, satellites[i], "TLE2",
501                                           NULL);
502 
503                 /* create output .sat file */
504                 target = g_key_file_new();
505                 g_key_file_set_string(target, "Satellite", "VERSION", cfgver);
506                 g_key_file_set_string(target, "Satellite", "NAME", name);
507                 g_key_file_set_string(target, "Satellite", "NICKNAME",
508                                       nickname);
509                 if (website != NULL)
510                 {
511                     g_key_file_set_string(target, "Satellite", "WEBSITE",
512                                           website);
513                     g_free(website);
514                 }
515                 g_key_file_set_string(target, "Satellite", "TLE1", tle1);
516                 g_key_file_set_string(target, "Satellite", "TLE2", tle2);
517 
518                 if (gpredict_save_key_file(target, targetfilename))
519                 {
520                     *error |= FTC_ERROR_STEP_05;
521                 }
522                 else
523                 {
524                     newsats++;
525                 }
526 
527                 g_key_file_free(target);
528 
529                 g_free(cfgver);
530                 g_free(name);
531                 g_free(nickname);
532                 g_free(tle1);
533                 g_free(tle2);
534             }
535             g_free(targetfilename);
536         }
537         g_strfreev(satellites);
538         sat_log_log(SAT_LOG_LEVEL_INFO,
539                     _("%s: Written %d new satellite to user config"),
540                     __func__, newsats);
541     }
542     g_key_file_free(satfile);
543     g_free(satfilename);
544     g_free(datadir);
545 }
546 
547 /* create .cat files in user conf directory */
create_cat_files(guint * error)548 static void create_cat_files(guint * error)
549 {
550     gchar          *datadir;
551     GError         *err = NULL;
552     GDir           *srcdir;
553     gchar          *srcdirname;
554     const gchar    *filename;
555 
556     sat_log_log(SAT_LOG_LEVEL_INFO,
557                 _("Copying satellite categories to user config"));
558 
559     /* .cat files: if .cat file does not exist, copy it, otherwise skip */
560     datadir = get_data_dir();
561     srcdirname = g_strconcat(datadir, G_DIR_SEPARATOR_S, "satdata", NULL);
562     srcdir = g_dir_open(srcdirname, 0, &err);
563 
564     /* directory does not exist, something went wrong in step 4 */
565     if (!srcdir)
566     {
567         sat_log_log(SAT_LOG_LEVEL_ERROR,
568                     _("%s: Could not open %s (%s)."),
569                     __func__, srcdirname, err->message);
570 
571         /* no reason to continue */
572         g_clear_error(&err);
573         *error |= FTC_ERROR_STEP_05;
574     }
575     else
576     {
577         /* get each .cat file and check if they already exist in user conf */
578         /* read files one by one, if any; count number of .tle files */
579         while ((filename = g_dir_read_name(srcdir)))
580         {
581             /* note: filename is not a newly allocated gchar *,
582                so we must not free it
583              */
584             if (g_str_has_suffix(filename, ".cat"))
585             {
586 
587                 /* check whether .cat file exisits in user conf */
588                 gchar          *catfilename = sat_file_name(filename);
589 
590                 if (!g_file_test(catfilename, G_FILE_TEST_EXISTS))
591                 {
592                     /* copy file to target dir */
593                     gchar          *source =
594                         g_strconcat(srcdirname, G_DIR_SEPARATOR_S, filename,
595                                     NULL);
596                     if (gpredict_file_copy(source, catfilename))
597                     {
598                         sat_log_log(SAT_LOG_LEVEL_ERROR,
599                                     _("%s: Failed to copy %s"),
600                                     __func__, filename);
601                     }
602                     else
603                     {
604                         sat_log_log(SAT_LOG_LEVEL_DEBUG,
605                                     _("%s: Successfully copied %s"),
606                                     __func__, filename);
607                     }
608                     g_free(source);
609                 }
610                 g_free(catfilename);
611             }
612         }
613         g_dir_close(srcdir);
614     }
615     g_free(srcdirname);
616     g_free(datadir);
617 }
618 
619 /**
620  * Execute step 5 of the first time checks.
621  *
622  * 5. Check if there are any .sat files in USER_CONF_DIR/satdata/ - if not extract
623  *    PACKAGE_DATA_DIR/data/satdata/satellites.dat to .sat files.
624  *    Do the same with .cat files.
625  *
626  */
first_time_check_step_05(guint * error)627 static void first_time_check_step_05(guint * error)
628 {
629     gchar          *datadir_str;
630     GDir           *datadir;
631     const gchar    *filename;
632     gboolean        have_sat = FALSE;
633     gboolean        have_cat = FALSE;
634 
635     /* check if there already is a .sat and .cat in ~/.config/... */
636     datadir_str = get_satdata_dir();
637     datadir = g_dir_open(datadir_str, 0, NULL);
638     while ((filename = g_dir_read_name(datadir)))
639     {
640         /* note: filename is not newly allocated */
641         if (g_str_has_suffix(filename, ".sat"))
642             have_sat = TRUE;
643         if (g_str_has_suffix(filename, ".cat"))
644             have_cat = TRUE;
645     }
646     g_free(datadir_str);
647     g_dir_close(datadir);
648 
649     if (!have_sat)
650         create_sat_files(error);
651 
652     if (!have_cat)
653         create_cat_files(error);
654 }
655 
656 /**
657  * Execute step 6 of the first time checks.
658  *
659  * 6. Check for the existence of USER_CONF_DIR/satdata/cache directory. This
660  *    directory is used to store temporary TLE files when updating from
661  *    network.
662  *
663  */
first_time_check_step_06(guint * error)664 static void first_time_check_step_06(guint * error)
665 {
666     gchar          *buff, *dir;
667     int             status;
668 
669     buff = get_satdata_dir();
670     dir = g_strconcat(buff, G_DIR_SEPARATOR_S, "cache", NULL);
671     g_free(buff);
672 
673     if (g_file_test(dir, G_FILE_TEST_IS_DIR))
674     {
675         sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
676     }
677     else
678     {
679         /* try to create directory */
680         sat_log_log(SAT_LOG_LEVEL_DEBUG,
681                     _("%s: Check failed. Creating %s"), __func__, dir);
682 
683         status = g_mkdir_with_parents(dir, 0755);
684 
685         if (status)
686         {
687             /* set error flag */
688             *error |= FTC_ERROR_STEP_06;
689 
690             sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Failed to create %s"),
691                         __func__, dir);
692         }
693         else
694         {
695             sat_log_log(SAT_LOG_LEVEL_DEBUG,
696                         _("%s: Created %s."), __func__, dir);
697         }
698     }
699     g_free(dir);
700 }
701 
702 /**
703  * Execute step 7 of the first time checks.
704  *
705  * 7. Check for the existence of USER_CONF_DIR/hwconf directory. This
706  *    directory contains radio and rotator configurations (.rig and .rot files).
707  *    If the directory is newly created, check if we have any existing configuration
708  *    in the pre-1.1 configuration directory (use get_old_conf_dir()).
709  *
710  */
first_time_check_step_07(guint * error)711 static void first_time_check_step_07(guint * error)
712 {
713     GDir           *dir;
714     gchar          *confdir, *olddir, *buff;
715     int             status;
716     gchar          *target;
717     const gchar    *datafile;
718 
719     confdir = get_hwconf_dir();
720 
721     if (g_file_test(confdir, G_FILE_TEST_IS_DIR))
722     {
723         sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
724     }
725     else
726     {
727         /* try to create directory */
728         sat_log_log(SAT_LOG_LEVEL_DEBUG,
729                     _("%s: Check failed. Creating %s"), __func__, confdir);
730 
731         status = g_mkdir_with_parents(confdir, 0755);
732 
733         if (status)
734         {
735             /* set error flag */
736             *error |= FTC_ERROR_STEP_03;
737             sat_log_log(SAT_LOG_LEVEL_ERROR,
738                         _("%s: Failed to create %s"), __func__, confdir);
739         }
740         else
741         {
742             sat_log_log(SAT_LOG_LEVEL_DEBUG,
743                         _("%s: Created %s."), __func__, confdir);
744 
745             /* try to see if there are any .rig or .rot file in pre-1.1 configuration */
746             buff = get_old_conf_dir();
747             olddir = g_strconcat(buff, G_DIR_SEPARATOR_S, "hwconf", NULL);
748 
749             dir = g_dir_open(olddir, 0, NULL);
750 
751             g_free(buff);
752 
753             if (dir)
754             {
755                 /* read files, if any; count number of .qth files */
756                 while ((datafile = g_dir_read_name(dir)))
757                 {
758                     gchar          *source =
759                         g_strconcat(olddir, G_DIR_SEPARATOR_S, datafile, NULL);
760 
761                     /* note: filename is not a newly allocated gchar *,
762                        so we must not free it
763                      */
764 
765                     /* copy file to USER_CONF_DIR */
766                     target = g_strconcat(confdir, G_DIR_SEPARATOR_S,
767                                     datafile, NULL);
768                     gpredict_file_copy(source, target);
769                     g_free(target);
770                     g_free(source);
771                 }
772                 g_dir_close(dir);
773             }
774             g_free(olddir);
775         }
776     }
777     g_free(confdir);
778 
779 }
780 
781 /**
782  * Execute step 8 of the first time checks.
783  *
784  * 8. Check for the existence of USER_CONF_DIR/trsp directory. This
785  *    directory contains transponder data for satellites.
786  *
787  */
first_time_check_step_08(guint * error)788 static void first_time_check_step_08(guint * error)
789 {
790     gchar          *dir;
791     int             status;
792 
793     dir = get_trsp_dir();
794 
795     if (g_file_test(dir, G_FILE_TEST_IS_DIR))
796     {
797         sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: Check successful."), __func__);
798     }
799     else
800     {
801         /* try to create directory */
802         sat_log_log(SAT_LOG_LEVEL_DEBUG,
803                     _("%s: Check failed. Creating %s"), __func__, dir);
804 
805         status = g_mkdir_with_parents(dir, 0755);
806 
807         if (status)
808         {
809             /* set error flag */
810             *error |= FTC_ERROR_STEP_08;
811             sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Failed to create %s"),
812                         __func__, dir);
813         }
814         else
815         {
816             sat_log_log(SAT_LOG_LEVEL_DEBUG,
817                         _("%s: Created %s."), __func__, dir);
818         }
819     }
820 
821     g_free(dir);
822 }
823