00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "config.h"
00046 #include <stdio.h>
00047 #include "nav_utils.h"
00048
00049
00050
00051 #define SIZE_NAME_COPY 50
00052
00053
00054
00055
00056
00057
00059 U8 str_ram[MAX_FILE_LENGHT];
00060
00061
00068 #ifdef __GNUC__
00069 U8 goto_code_name(U8 *str, Bool b_case_sensitive, Bool b_create)
00070 #else
00071 U8 goto_code_name(U8 code *str, Bool b_case_sensitive, Bool b_create)
00072 #endif
00073 {
00074 str_code_to_str_ram( str, str_ram );
00075 return nav_setcwd( (FS_STRING)str_ram, b_case_sensitive, b_create);
00076 }
00077
00078
00085 #ifdef __GNUC__
00086 void str_code_to_str_ram(U8 string_code[],U8 str_ram[MAX_FILE_LENGHT])
00087 #else
00088 void str_code_to_str_ram(U8 code string_code[],U8 str_ram[MAX_FILE_LENGHT])
00089 #endif
00090 {
00091 U8 i;
00092 for(i=0;i<MAX_FILE_LENGHT;i++)
00093 #ifndef __GNUC__
00094 { str_ram[i]=string_code[i];}
00095 #else
00096 { str_ram[i]=pgm_read_byte_near((unsigned int)string_code+i); }
00097 #endif
00098 }
00099
00100
00103 #ifdef __GNUC__
00104 Bool copy_dir( U8 string_src[], U8 string_dst[], Bool b_print )
00105 #else
00106 Bool copy_dir( U8 code string_src[], U8 code string_dst[], Bool b_print )
00107 #endif
00108 {
00109 Fs_index sav_index;
00110 char s_name[SIZE_NAME_COPY];
00111 U8 u8_folder_level = 0;
00112
00113 if( b_print ) printf("\n\r");
00114
00115 sav_index = nav_getindex();
00116
00117
00118
00119 if( b_print ) printf("Select source directory\n\r");
00120 nav_select( FS_NAV_ID_COPY_SRC_DIR );
00121 if( !goto_code_name( string_src, FALSE, FALSE ) )
00122 goto copy_dir_error;
00123 nav_filelist_reset();
00124
00125 if( b_print ) printf("Select destination directory\n\r");
00126 nav_select( FS_NAV_ID_COPY_DST_DIR );
00127 if( !goto_code_name( string_dst, FALSE, TRUE ) )
00128 goto copy_dir_error;
00129 nav_filelist_reset();
00130
00131
00132
00133 while(1)
00134 {
00135
00136 while(1)
00137 {
00138
00139
00140 nav_select( FS_NAV_ID_COPY_SRC_DIR );
00141 if( nav_filelist_set( 0 , FS_FIND_NEXT ) )
00142 break;
00143
00144
00145 if( 0 == u8_folder_level )
00146 {
00147
00148
00149 goto copy_dir_finish;
00150 }
00151
00152 if( b_print ) printf("Go to parent\n\r");
00153
00154 u8_folder_level--;
00155 if( !nav_dir_gotoparent() )
00156 goto copy_dir_error;
00157
00158 nav_select( FS_NAV_ID_COPY_DST_DIR );
00159 if( !nav_dir_gotoparent() )
00160 goto copy_dir_error;
00161 }
00162
00163 if( nav_file_isdir())
00164 {
00165 if( b_print ) printf("Dir found - create dir: ");
00166
00167
00168 if( !nav_file_name( (FS_STRING)s_name, MAX_FILE_LENGHT, FS_NAME_GET, FALSE ))
00169 goto copy_dir_error;
00170
00171 if( !nav_dir_cd())
00172 goto copy_dir_error;
00173 u8_folder_level++;
00174
00175 nav_select( FS_NAV_ID_COPY_DST_DIR );
00176
00177 if( b_print ) printf((char*)s_name);
00178 if( b_print ) printf("\n\r");
00179 if( !nav_dir_make( (FS_STRING )s_name ))
00180 {
00181 if( FS_ERR_FILE_EXIST != fs_g_status )
00182 goto copy_dir_error;
00183
00184 }
00185
00186 if( !nav_dir_cd())
00187 {
00188 if( FS_ERR_NO_DIR == fs_g_status )
00189 {
00190
00191 }
00192 goto copy_dir_error;
00193 }
00194
00195 }
00196 else
00197 {
00198 if( b_print ) printf("File found - copy file: ");
00199
00200
00201 if( !nav_file_name( (FS_STRING)s_name, MAX_FILE_LENGHT, FS_NAME_GET, FALSE ))
00202 goto copy_dir_error;
00203 if( b_print ) printf((char*)s_name);
00204 if( b_print ) printf("\n\r");
00205 if( !nav_file_copy())
00206 goto copy_dir_error;
00207
00208
00209 nav_select( FS_NAV_ID_COPY_DST_DIR );
00210 while( !nav_file_paste_start( (FS_STRING)s_name ) )
00211 {
00212
00213 if( fs_g_status != FS_ERR_FILE_EXIST )
00214 goto copy_dir_error;
00215
00216 if( b_print ) printf("File exists then deletes this one.\n\r");
00217 if( !nav_file_del( TRUE ) )
00218 goto copy_dir_error;
00219
00220 }
00221
00222 {
00223 U8 status;
00224 do{
00225 status = nav_file_paste_state(FALSE);
00226 }while( COPY_BUSY == status );
00227
00228 if( COPY_FINISH != status )
00229 goto copy_dir_error;
00230 }
00231 }
00232 }
00233
00234 copy_dir_error:
00235
00236 nav_select( FS_NAV_ID_USHELL_CMD );
00237 nav_gotoindex(&sav_index);
00238 if( b_print ) printf("!!!copy fail\n\r");
00239 return FALSE;
00240
00241 copy_dir_finish:
00242
00243 nav_select( FS_NAV_ID_USHELL_CMD );
00244 nav_gotoindex(&sav_index);
00245 if( b_print ) printf("End of copy\n\r");
00246 return TRUE;
00247 }
00248
00249