From: Alexandru C. <cs...@us...> - 2005-10-22 22:30:47
|
Update of /cvsroot/groundstation/gpredict2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30587 Modified Files: first-time.c Log Message: Implemented all functions but will have to rewrite / clean up most of it. For example, the directory checking functions have the same code but use different dirnames and code, which checks for .qth and .tle files is also very similar. Index: first-time.c =================================================================== RCS file: /cvsroot/groundstation/gpredict2/src/first-time.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** first-time.c 22 Oct 2005 15:55:39 -0000 1.1 --- first-time.c 22 Oct 2005 22:30:37 -0000 1.2 *************** *** 35,41 **** --- 35,45 ---- #include "sat-log.h" #include "sat-cfg.h" + #include "gpredict-utils.h" #include "first-time.h" + /**** FIXME: clean up / rewrite: check_dir, checkfile and driver */ + + /* private function prototypes */ static void first_time_check_step_01 (guint *error); *************** *** 121,125 **** g_free (msg); ! status = g_mkdir (dir, 755); if (status) { --- 125,129 ---- g_free (msg); ! status = g_mkdir (dir, 0755); if (status) { *************** *** 149,153 **** * 2. Check for the existence of at least one .qth file in $HOME/.gpredict2/ * If no such file found, copy PACKAGE_DATA_DIR/data/sample.qth to this ! * directory.\ * */ --- 153,157 ---- * 2. Check for the existence of at least one .qth file in $HOME/.gpredict2/ * If no such file found, copy PACKAGE_DATA_DIR/data/sample.qth to this ! * directory. * */ *************** *** 155,158 **** --- 159,236 ---- first_time_check_step_02 (guint *error) { + GDir *dir; + gchar *dirname; + gchar *filename; + gchar *target; + gchar *msg; + gboolean foundqth = FALSE; + + + dirname = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, + ".gpredict2", NULL); + + dir = g_dir_open (dirname, 0, NULL); + + /* directory does not exist, something went wrong in step 1 */ + if (!dir) { + msg = g_strdup_printf (_("%s: Could not open %s."), + __FUNCTION__, dirname); + sat_log_log (SAT_LOG_LEVEL_ERROR, msg); + g_free (msg); + + /* no reason to continue */ + *error |= FTC_ERROR_STEP_02; + } + else { + /* read files, if any; count number of .qth files */ + /**** FIXME: There is a compile waing here */ + while ((filename = g_dir_read_name (dir))) { + + /* note: filename is not a newly allocated gchar *, + so we must not free it + */ + + if (g_strrstr (filename, ".qth")) { + foundqth = TRUE; + } + + } + + g_dir_close (dir); + + if (foundqth) { + msg = g_strdup_printf (_("%s: Found at least one .qth file."), + __FUNCTION__); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + else { + /* 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)) { + msg = g_strdup_printf (_("%s: Failed to copy sample.qth"), + __FUNCTION__); + sat_log_log (SAT_LOG_LEVEL_ERROR, msg); + g_free (msg); + + *error |= FTC_ERROR_STEP_02; + } + else { + msg = g_strdup_printf (_("%s: Copied sample.qth to %s/"), + __FUNCTION__, dirname); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + + g_free (target); + g_free (filename); + + } + } + + g_free (dirname); } *************** *** 160,167 **** --- 238,290 ---- /** \brief Execute step 3 of the first time checks. + * + * 3. Check for the existence of $HOME/.gpredict2/modules directory and create + * it if it does not exist. + * */ static void first_time_check_step_03 (guint *error) { + gchar *msg; + gchar *dir; + int status; + + dir = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, + ".gpredict2", G_DIR_SEPARATOR_S, + "modules", NULL); + + if (g_file_test (dir, G_FILE_TEST_IS_DIR)) { + msg = g_strdup_printf (_("%s: Check successful."), __FUNCTION__); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + else { + /* try to create directory */ + msg = g_strdup_printf (_("%s: Check failed. Creating %s"), + __FUNCTION__, + dir); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + + status = g_mkdir (dir, 0755); + + if (status) { + /* set error flag */ + *error |= FTC_ERROR_STEP_03; + + msg = g_strdup_printf (_("%s: Failed to create %s"), + __FUNCTION__, dir); + sat_log_log (SAT_LOG_LEVEL_ERROR, msg); + g_free (msg); + } + else { + msg = g_strdup_printf (_("%s: Created %s."), + __FUNCTION__, dir); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + } + + g_free (dir); } *************** *** 169,176 **** --- 292,344 ---- /** \brief Execute step 4 of the first time checks. + * + * 4. Check for the existence of $HOME/.gpredict2/tle directory and create it if + * it does not exist. + * */ static void first_time_check_step_04 (guint *error) { + gchar *msg; + gchar *dir; + int status; + + dir = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, + ".gpredict2", G_DIR_SEPARATOR_S, + "tle", NULL); + + if (g_file_test (dir, G_FILE_TEST_IS_DIR)) { + msg = g_strdup_printf (_("%s: Check successful."), __FUNCTION__); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + else { + /* try to create directory */ + msg = g_strdup_printf (_("%s: Check failed. Creating %s"), + __FUNCTION__, + dir); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + + status = g_mkdir (dir, 0755); + + if (status) { + /* set error flag */ + *error |= FTC_ERROR_STEP_04; + + msg = g_strdup_printf (_("%s: Failed to create %s"), + __FUNCTION__, dir); + sat_log_log (SAT_LOG_LEVEL_ERROR, msg); + g_free (msg); + } + else { + msg = g_strdup_printf (_("%s: Created %s."), + __FUNCTION__, dir); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + } + + g_free (dir); } *************** *** 178,185 **** --- 346,457 ---- /** \brief Execute step 5 of the first time checks. + * + * 5. Check for the existence of at least one .tle file in the above mentioned + * directory. If no such file found, copy PACKAGE_DATA_DIR/data/xxx.tle to this + * directory. + * */ static void first_time_check_step_05 (guint *error) { + GDir *dir; + gchar *dirname; + gchar *datadir; + gchar *filename; + gchar *target; + gchar *msg; + gchar *tlefile; + gboolean foundtle = FALSE; + + + dirname = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, + ".gpredict2", G_DIR_SEPARATOR_S, + "tle", NULL); + + dir = g_dir_open (dirname, 0, NULL); + + /* directory does not exist, something went wrong in step 1 */ + if (!dir) { + msg = g_strdup_printf (_("%s: Could not open %s."), + __FUNCTION__, dirname); + sat_log_log (SAT_LOG_LEVEL_ERROR, msg); + g_free (msg); + + /* no reason to continue */ + *error |= FTC_ERROR_STEP_05; + } + else { + /* read files, if any; count number of .tle files */ + /**** FIXME: There is a compile waing here */ + while ((filename = g_dir_read_name (dir))) { + + /* note: filename is not a newly allocated gchar *, + so we must not free it + */ + + if (g_strrstr (filename, ".tle")) { + foundtle = TRUE; + } + + } + + g_dir_close (dir); + + if (foundtle) { + msg = g_strdup_printf (_("%s: Found at least one .tle file."), + __FUNCTION__); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + else { + + /* try to copy each tle file from instalation dir */ + datadir = get_data_dir (); + dir = g_dir_open (datadir, 0, NULL); + + g_print ("====> %s\n", datadir); + + /**** FIXME: There is a compile waing here */ + while ((filename = g_dir_read_name (dir))) { + + /* note: filename is not a newly allocated gchar *, + so we must not free it + */ + + if (g_strrstr (filename, ".tle")) { + + tlefile = data_file_name (filename); + + target = g_strconcat (dirname, + G_DIR_SEPARATOR_S, + filename, + NULL); + + if (gpredict_file_copy (tlefile, target)) { + msg = g_strdup_printf (_("%s: Failed to copy %s"), + __FUNCTION__, filename); + sat_log_log (SAT_LOG_LEVEL_ERROR, msg); + g_free (msg); + + *error |= FTC_ERROR_STEP_05; + } + else { + msg = g_strdup_printf (_("%s: Successfully copied %s"), + __FUNCTION__, filename); + sat_log_log (SAT_LOG_LEVEL_DEBUG, msg); + g_free (msg); + } + g_free (tlefile); + g_free (target); + } + + } + g_free (datadir); + g_dir_close (dir); + } + + } + g_free (dirname); + } |