@@ -67,6 +67,10 @@ int main(void) {
6767 printf ("\n-----------------------------" );
6868 text_color (COLOR_WHITE );
6969
70+ chdir ("F:/dokumenty/vyhry2.txt" );
71+
72+ printf ("%s" ,getcwd (cwd , 1000 ));
73+
7074 while (action != 17 ) {
7175 if (strcmp (lastDir , "" ) == 0 ){
7276 printf ("\n\n\nLast opened directory: You do not have any opened directory.\n\nWhat do you want to do?\n\n\t1. Open directory\n\t2. Create directory\n\t3. Copy directory (coming soon)\n\t4. Delete directory\n\t5. Open file\n\t6. Create file\n\t7. Copy file\n\t" );
@@ -667,26 +671,21 @@ int main(void) {
667671
668672 if (command (file_url , lastDir ) != 0 )goto aborting_encrypting ; //Checks for commands
669673
674+ if (file_url [strlen (file_url )- 3 ] != 't' && file_url [strlen (file_url )- 2 ] != 'x' && file_url [strlen (file_url )- 1 ] != 't' ) {
675+ text_color (COLOR_RED );
676+ printf ("\nFile '%s' is not a text file.\n" ,file_url );
677+ text_color (COLOR_WHITE );
678+ } else {
679+
670680 char fileenstr [5000 ] = "" ;
671681 char enstr [5000 ] = "" ;
672- char fileenname [1000 ] = "" ;
673682
674683 strcpy (lastDirFile , lastDir );
675684 strcat (lastDirFile , file_url );
676685 strcpy (file_url , lastDirFile ); //Copies strings
677686
678687 file = fopen (file_url , "r" );
679688
680- /*
681- Trying to change file extension
682-
683- chdir(file_url); //Sets current working dir
684- //getcwd(cwd, 1000)
685-
686- strcpy(fileenname, getcwd(cwd, 1000));
687- strcat
688- */
689-
690689 if (file == NULL ) { //Error handler
691690 text_color (COLOR_RED );
692691 printf ("\nUnable to find file '%s'.\n" ,file_url );
@@ -709,6 +708,27 @@ int main(void) {
709708 text_color (COLOR_GREEN );
710709 printf ("\nFile '%s' has been encrypted." ,file_url );
711710 text_color (COLOR_WHITE );
711+
712+ char newFileEnName [1000 ] = "" ;
713+
714+ strcpy (newFileEnName , str_replace (file_url , get_filename_from_path (file_url ), "" ));
715+ strcat (newFileEnName , get_filename_from_path (file_remove_extension (file_url )));
716+ strcat (newFileEnName , ".encf" );
717+
718+ renameResult = rename (file_url , newFileEnName ); //Changing file name
719+
720+ if (renameResult == 0 ) {
721+ text_color (COLOR_GREEN );
722+ printf ("\nFile has been renamed to '%s'." ,get_filename_from_path (newFileEnName ));
723+ text_color (COLOR_WHITE );
724+ } else {
725+ text_color (COLOR_RED );
726+ printf ("\nFile has not been renamed to '%s'." ,get_filename_from_path (newFileEnName ));
727+ text_color (COLOR_WHITE );
728+ }
729+
730+ }
731+
712732 }
713733
714734 text_color (COLOR_YELLOW );
@@ -725,7 +745,13 @@ int main(void) {
725745 scanf ("%d" ,& file_url );
726746 gets (file_url );
727747
728- if (command (file_url , lastDir ) != 0 )goto aborting_decrypting ; //Checks for commands
748+ if (command (file_url , lastDir ) != 0 )goto aborting_decrypting ; //Checks for commands enc
749+
750+ if (file_url [strlen (file_url )- 4 ] != 'e' && file_url [strlen (file_url )- 3 ] != 'n' && file_url [strlen (file_url )- 2 ] != 'c' && file_url [strlen (file_url )- 1 ] != 'f' ) {
751+ text_color (COLOR_RED );
752+ printf ("\nFile '%s' is not encrypted.\n" ,file_url );
753+ text_color (COLOR_WHITE );
754+ } else {
729755
730756 char filedestr [5000 ] = "" ;
731757 char destr [5000 ] = "" ;
@@ -736,6 +762,8 @@ int main(void) {
736762
737763 file = fopen (file_url , "r" );
738764
765+
766+
739767 if (file == NULL ) { //Error handler
740768 text_color (COLOR_RED );
741769 printf ("\nUnable to find file '%s'.\n" ,file_url );
@@ -756,8 +784,29 @@ int main(void) {
756784 fclose (file );
757785
758786 text_color (COLOR_GREEN );
759- printf ("\nFile '%s' has been encrypted." ,file_url );
787+ printf ("\nFile '%s' has been decrypted." ,file_url );
788+ text_color (COLOR_WHITE );
789+
790+ char newFileEnName [1000 ] = "" ;
791+
792+ strcpy (newFileEnName , str_replace (file_url , get_filename_from_path (file_url ), "" ));
793+ strcat (newFileEnName , get_filename_from_path (file_remove_extension (file_url )));
794+ strcat (newFileEnName , ".txt" );
795+
796+ renameResult = rename (file_url , newFileEnName ); //Changing file name
797+
798+ if (renameResult == 0 ) {
799+ text_color (COLOR_GREEN );
800+ printf ("\nFile has been renamed to '%s'." ,get_filename_from_path (newFileEnName ));
801+ text_color (COLOR_WHITE );
802+ } else {
803+ text_color (COLOR_RED );
804+ printf ("\nFile has not been renamed to '%s'." ,get_filename_from_path (newFileEnName ));
760805 text_color (COLOR_WHITE );
806+ }
807+
808+ }
809+
761810 }
762811
763812 text_color (COLOR_YELLOW );
@@ -770,7 +819,7 @@ int main(void) {
770819 break ;
771820
772821 case 15 : //About
773- printf ("\n\n\nFile explorer 1.1.0 \nThis application is under APACHE LICENSE 2.0 - \"./LICENSE.md\"\nPetr Pavlik 2021 - BeXCool\n\nWeb: bexcool.eu\nEmail: bxc@post.cz" );
822+ printf ("\n\n\nFile explorer 1.1.1 \nThis application is under APACHE LICENSE 2.0 - \"./LICENSE.md\"\nPetr Pavlik 2021 - BeXCool\n\nWeb: bexcool.eu\nEmail: bxc@post.cz" );
774823 text_color (COLOR_YELLOW );
775824 printf ("\n\nPress any key to continue." );
776825 text_color (COLOR_WHITE );
0 commit comments