forked from ercanersoy/FDTUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·1220 lines (988 loc) · 31.3 KB
/
main.cpp
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
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* main.cpp - Main source file
* Written by Ercan Ersoy and Mark Olesen.
*/
#include "main.h"
// Common Functions
// Exit window manager function
void exit_window_manager(menuitem *, void *)
{
// Close window manager
wm_deinit();
// Release current directory string on memory
free(current_directory);
// Release clipboard item path name string on memory
free(clipboard_item_name);
// Release clipboard item path string on memory
free(clipboard_item_path);
}
// Command run function
void command_run(char const* command)
{
// Mouse release on memory
mouse_deinit();
// Clear screen
system("CLS");
// Run command
system(command);
// Mouse initalization
mouse_init();
// Mouse show
mouse_show();
// Hide cursor
cursor_hide();
// Draw window manager
wm_draw(NULL);
}
// Directory view function
void directory_view(menuitem *, void *)
{
// Element pointer variable
struct dirent *element;
// Directory pointer variable
DIR *directory = opendir(getcwd(current_directory, MAX_NAME_LENGTH + 1));
// Element status variable
struct stat element_status;
// Listbox item of element variable
char listbox_item_of_element[MAX_NAME_LENGTH + 8] = { 0 };
// Current drive letter variable
unsigned int current_drive_letter;
// Drive letter count information variable
unsigned int drive_letter_count;
// Drive letter information variable
unsigned int drive_letter;
// Previous drive letter information variable
unsigned int previous_drive_letter = 0;
// Drive variable
unsigned char *drive = (unsigned char *)malloc(3);
// Clear the directories and files listbox
directories_and_files->remove_all();
// Set text of current directory label
current_directory_label->set_text((unsigned char *)current_directory);
while(element = readdir(directory)) // If element is exists
{
if(!strcmp(element->d_name, ".") || (!strcmp(element->d_name, "..") && (strlen(current_directory) == 3))) // If item names not "." or ".." and currnet directory is upper directory
{
// Continue while loop
continue;
}
if((element->d_attr & _A_ARCH) && !show_archive_item) // If archive item not showing condition is true
{
// Continue while loop
continue;
}
if((element->d_attr & _A_HIDDEN) && !show_hidden_item) // If hidden item not showing condition is true
{
// Continue while loop
continue;
}
if((element->d_attr & _A_RDONLY) && !show_read_only_item) // If read only item not showing condition is true
{
// Continue while loop
continue;
}
if((element->d_attr & _A_SYSTEM) && !show_system_item) // If system item not showing condition is true
{
// Continue while loop
continue;
}
stat(element->d_name, &element_status);
if(S_ISDIR(element_status.st_mode)) // If item is directory
{
strcat(listbox_item_of_element, "<DIR> ");
// Add item on the directories listbox
directories_and_files->add(reinterpret_cast<unsigned char const*>(strcat(listbox_item_of_element, element->d_name)));
}
else // If item is file
{
strcat(listbox_item_of_element, "<FILE> ");
// Add item on the files listbox
directories_and_files->add(reinterpret_cast<unsigned char const*>(strcat(listbox_item_of_element, element->d_name)));
}
listbox_item_of_element[0] = '\0';
}
closedir(directory);
// Set selected item variable
selected_item = 0;
// Clear the drivers listbox
drivers->remove_all();
// Get current drive letter
current_drive_letter = (int)current_directory[0] - 64;
// Get drive letter count
_dos_setdrive(NULL, &drive_letter_count);
// All drive letters been tested
for(int i = 1; i <= drive_letter_count; i++)
{
// Drive letter test
_dos_setdrive(i, &drive_letter_count);
//If drive letter is exists
_dos_getdrive(&drive_letter);
if(!drive_letter || drive_letter == previous_drive_letter) // If drive letter is null or drive letter is not changed
{
// Continue loop
continue;
}
// Drive letter calculation and assignment
*drive = (unsigned char)(64 + i);
// Assignment double dot
*(drive + 1) = ':';
// Assignment null
*(drive + 2) = '\0';
// Add drive to drivers listbox
drivers->add(drive);
// Set previous drive letter
previous_drive_letter = i;
}
// Free drive string
free(drive);
// Set current drive letter
_dos_setdrive(current_drive_letter, &drive_letter_count);
// Draw window manager
wm_draw(NULL);
}
// Upper directory control function
void upper_directory_control_for_go_menu_item(void)
{
if(strlen(current_directory) == 3) // If directory exists
{
// Up directory menu disabled
go_menu[2].m_flags |= MENUITEM_DISABLED;
}
else // If not directory exists
{
// Up directory menu enabled
go_menu[2].m_flags = !(go_menu[2].m_flags ^ MENUITEM_DISABLED);
}
}
// Get item name function
char *get_item_name(char* item_name, int selected)
{
int i; // Counter variable
// Copy selected listbox item
item_name = strcpy(item_name, (char *)directories_and_files->get_item(selected));
// Shift listbox item for item name
for(i = 0; i < MAX_NAME_LENGTH; i++)
{
// Shifting
item_name[i] = item_name[i + 7];
}
// Clear last characters
for(i = MAX_NAME_LENGTH - 1; i < MAX_NAME_LENGTH + 8; i++)
{
// Clearing
item_name[i] = '\0';
}
// Return item name
return item_name;
}
// Item attributes viewing function
void item_attributes_viewing(void)
{
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Selected item attributes variable
unsigned int selected_item_attributes;
// Get selected item attributes
_dos_getfileattr(reinterpret_cast<char const*>(get_item_name(item_name, directories_and_files->get_selected_first())), &selected_item_attributes);
if(selected_item_attributes & _A_ARCH) // If item is archive item
{
// Set item attributes as archive
item_attributes[0] = 'A';
// Set "Archive" menu item
edit_menu[5].m_flags |= MENUITEM_VALUE;
}
else // If item isn't archive item
{
// Set item attributes as not archive
item_attributes[0] = '-';
// Clear "Archive" menu item
edit_menu[5].m_flags &= edit_menu[5].m_flags ^ MENUITEM_VALUE;
}
if(selected_item_attributes & _A_HIDDEN) // If item is hidden item
{
// Set item attributes as hidden
item_attributes[1] = 'H';
// Set "Hidden" menu item
edit_menu[6].m_flags |= MENUITEM_VALUE;
}
else // If item isn't hidden item
{
// Set item attributes as not hidden
item_attributes[1] = '-';
// Clear "Hidden" menu item
edit_menu[6].m_flags &= edit_menu[6].m_flags ^ MENUITEM_VALUE;
}
if(selected_item_attributes & _A_RDONLY) // If item is read only item
{
// Set item attributes as read only
item_attributes[2] = 'R';
// Set "Read Only" menu item
edit_menu[7].m_flags |= MENUITEM_VALUE;
}
else // If item isn't read only item
{
// Set item attributes as not read only
item_attributes[2] = '-';
// Clear "Read Only" menu item
edit_menu[7].m_flags &= edit_menu[7].m_flags ^ MENUITEM_VALUE;
}
if(selected_item_attributes & _A_SYSTEM) // If item is system item
{
// Set item attributes as system
item_attributes[3] = 'S';
// Set "System" menu item
edit_menu[8].m_flags |= MENUITEM_VALUE;
}
else // If item isn't system item
{
// Set item attributes as not system
item_attributes[3] = '-';
// Clear "System" menu item
edit_menu[8].m_flags &= edit_menu[8].m_flags ^ MENUITEM_VALUE;
}
// Set item attributes label text
item_attributes_view->set_text(item_attributes);
// Free item name variable
free(item_name);
}
// Select directory or file function
void select_directory_or_file(listbox const *, void *)
{
if(selected_item == directories_and_files->get_selected_first()) // If selected item is clicked
{
// Open item
item_open(NULL, NULL);
// Refresh directory
directory_view(NULL, NULL);
// Exit function
return;
}
// Item attribute viewing function
item_attributes_viewing();
// Set selected item
selected_item = directories_and_files->get_selected_first();
// Draw window manager
wm_draw(NULL);
}
// Change current drive function
void change_current_drive(listbox const *, void *)
{
// Drive variable
char *drive = (char *)malloc(4);
// Drive letter information variable
unsigned int drive_letter_information = 0;
// Drive letter count information variable
unsigned int drive_letter_count = 0;
// Get item from drivers listbox
strcpy(drive, (char *)drivers->get_item(drivers->get_selected_first()));
// Calculate drive
drive_letter_information = *drive - 64;
// Change current drive
_dos_setdrive(drive_letter_information, &drive_letter_count);
// Get drive letter information
_dos_getdrive(&drive_letter_information);
if(!drive_letter_information) // If drive letter information is null
{
// Free drive information from memory
free(drive);
// Exit function
return;
}
// Change current directory
change_current_directory(strcat(drive, "\\"), 0);
// Free drive information from memory
free(drive);
}
// Change current directory function
void change_current_directory(char *directory, unsigned char status)
{
// Previous drive letter variable
char previous_drive_letter;
// Drive letter count variable
unsigned int drive_letter_count = 0;
if(status == 0) // If status is adding new history item
{
if(directory != 0) // If directory pointer is not null
{
// Change Directory
chdir(directory);
}
if(history_index < HISTORY_LENGTH - 1) // If history index is less than history length minus 1
{
// History index increase
history_index++;
// History save
strcpy(history_path_names[history_index], getcwd(current_directory, MAX_PATH_LENGTH + 1));
for(int i = history_index + 1; i < HISTORY_LENGTH - 1; i++) // History path names clear loop
{
// History path names clear
history_path_names[i][0] = '\0';
}
}
else // If history index is equals history length - 1
{
for(int i = 0; i < HISTORY_LENGTH - 1; i++)
{
// History shifting
strcpy(history_path_names[i], history_path_names[i + 1]);
}
// History save
strcpy(history_path_names[history_index], getcwd(current_directory, MAX_PATH_LENGTH + 1));
}
}
else if(status == 1) // If status is changing previous history item
{
// Get previous drive letter
previous_drive_letter = history_path_names[history_index][0];
// Decrase History
history_index--;
if(history_path_names[history_index][0] != previous_drive_letter) // If equals currnet drive letter and previous drive letter
{
// Change current drive
_dos_setdrive(history_path_names[history_index][0] - 64, &drive_letter_count);
}
// Change Directory
chdir(history_path_names[history_index]);
}
else if(status == 2) // If status is changing previous history item
{
// Get previous drive letter
previous_drive_letter = history_path_names[history_index][0];
// Increase History
history_index++;
if(history_path_names[history_index][0] != previous_drive_letter) // If equals currnet drive letter and previous drive letter
{
// Change current drive
_dos_setdrive(history_path_names[history_index][0] - 64, &drive_letter_count);
}
// Change Directory
chdir(history_path_names[history_index]);
}
// Upper directory control
upper_directory_control_for_go_menu_item();
if(history_index == 0) // If history index equals 0
{
// Back menu item disabled
go_menu[0].m_flags |= MENUITEM_DISABLED;
}
else
{
// Back menu item enabled
go_menu[0].m_flags = !(go_menu[0].m_flags ^ MENUITEM_DISABLED);
}
if((history_index == HISTORY_LENGTH - 1) || history_path_names[history_index + 1][0] == '\0') // If history index equals history length minus 1 or next history item equals 0
{
// Foward menu item disabled
go_menu[1].m_flags |= MENUITEM_DISABLED;
}
else
{
// Foward menu item enabled
go_menu[1].m_flags = !(go_menu[1].m_flags ^ MENUITEM_DISABLED);
}
// Refresh directory
directory_view(NULL, NULL);
}
// Copy file function
void copy_file(char *source_file, char *target_file)
{
// Source pointer variable
FILE *source;
// Target pointer variable
FILE *target;
// Character buffer variable
char buffer = 0;
// Source file open
source = fopen(source_file, "rb");
// Target file open
target = fopen(target_file, "wb");
while((buffer = fgetc(source)) != 255 && !feof(source)) // While read source file to buffer as one character
{
// Write buffer target
fputc(buffer, target);
}
// Close source file
fclose(source);
// Close target file
fclose(target);
}
// Copy directory function
void copy_directory(char *source_directory, char *target_directory)
{
// Directory element pointer variable
DIR *element;
// Source item properties string pointer variable
struct dirent *source_item_properties;
// Source item name string pointer variable
char *source_item_name = (char *)malloc(MAX_NAME_LENGTH + 1);
// Item path string pointer variable
char *source_item_path = (char *)malloc(MAX_PATH_LENGTH + 1);
// Target item path string pointer variable
char *target_item_path = (char *)malloc(MAX_PATH_LENGTH + 1);
// Status variable
struct stat status;
// Make target directory
mkdir(target_directory);
// Open source directory
element = opendir(source_directory);
// Get source item properties
source_item_properties = readdir(element);
// Get source item name
source_item_name = source_item_properties->d_name;
while(source_item_name[0] != 1) // While if item name is exists
{
if(strcmp(source_item_name, ".") && strcmp(source_item_name, "..") && (strlen(source_item_path) + strlen(target_item_path) <= (MAX_PATH_LENGTH + 1) * 2)) // If item provide item condition
{
// Make source directory path
strcpy(source_item_path, source_directory);
strcat(source_item_path, "\\");
strcat(source_item_path, source_item_name);
// Make target directory path
strcpy(target_item_path, target_directory);
strcat(target_item_path, "\\");
strcat(target_item_path, source_item_name);
// Get source item status
stat(source_item_path, &status);
if(S_ISDIR(status.st_mode)) // If source item is directory
{
// Copy directory
copy_directory(source_item_path, target_item_path);
}
else // If source item is file
{
// Copy file
copy_file(source_item_path, target_item_path);
}
}
// Get source item properties
source_item_properties = readdir(element);
// Get source item name
source_item_name = source_item_properties->d_name;
// Clean source item path
*source_item_path = NULL;
// Clean target item path
*target_item_path = NULL;
}
// Close directory
closedir(element);
// If source item name string
free(source_item_name);
// If source item path string
free(source_item_path);
// Free target item path string
free(target_item_path);
}
// Remove item function
char remove_item(char *removing_item_path)
{
// Directory element pointer variable
DIR *element;
// Item properties pointer variable
struct dirent *item_properties;
// Item name string pointer variable
char *item_name = (char *)malloc(MAX_NAME_LENGTH + 1);
// Item path string pointer variable
char *item_path = (char *)malloc(MAX_PATH_LENGTH + 1);
// Open directory
element = opendir(removing_item_path);
// Get item properties
item_properties = readdir(element);
// Get item name
item_name = item_properties->d_name;
while(item_name[0] != 1) // While if item name is exists
{
if(strcmp(item_name, ".") && strcmp(item_name, "..") && (strlen(item_path) + strlen(item_path) <= (MAX_PATH_LENGTH + 1) * 2)) // If item provide item condition
{
// Make item path
strcpy(item_path, removing_item_path);
strcat(item_path, "\\");
strcat(item_path, item_name);
if(remove(item_path)) // If remove item as file
{
// Remove item as directory
remove_item(item_path);
}
}
// Get item porperties
item_properties = readdir(element);
// Get item name
item_name = item_properties->d_name;
// Clean item path string
*item_path = NULL;
}
// Close directory
closedir(element);
// Clean item name string
free(item_name);
// Clean item path string
free(item_path);
// Remove directory and return status
return rmdir(removing_item_path);
}
// History back function
void history_back(menuitem *, void *)
{
// Change current directory to back history item
change_current_directory(NULL, 1);
}
// History foward function
void history_foward(menuitem *, void *)
{
// Change current directory to foward history item
change_current_directory(NULL, 2);
}
// Change to upper directory function
void change_to_upper_directory(menuitem *, void *)
{
// Change current directory to upper directory
change_current_directory("..", 0);
}
// Bar Menu Functions
// Show file manager function
void show_file_manager(menuitem *, void *)
{
if(!file_manager->get_visible()) // If file manager visible
{
// File manager set to visible
file_manager->set_visible();
// Refresh directory
directory_view(NULL, NULL);
// Draw file manager
wm_draw(file_manager);
}
}
// Show file manager function
void show_run(menuitem *, void *)
{
// Run command
command_run((char *)popup_input(reinterpret_cast<unsigned char const*>(kittengets(12, 0, "Run")), reinterpret_cast<unsigned char const*>(kittengets(12, 1, "Command to Run:")), reinterpret_cast<unsigned char const*>("")));
}
// Run application EDIT function
void run_application_edit(menuitem *, void *)
{
// Run EDIT
command_run("EDIT");
}
// Run application EDLIN function
void run_application_edlin(menuitem *, void *)
{
// Run EDLIN
command_run("EDLIN");
}
// Quit function
void quit(menuitem *, void *)
{
// Exit window manager
exit_window_manager(NULL, NULL);
if(kitten_status != -1) // If Kitten library is open
{
// Close Kitten library
kittenclose();
}
// Exit FreeDOS TUI Shell
exit(EXIT_SUCCESS);
}
// Reboot function
void reboot(menuitem *, void *)
{
// Exit window manager
exit_window_manager(NULL, NULL);
// Reboot computer via FDAPM
system("FDAPM WARMBOOT");
return;
}
// Poweroff function
void poweroff(menuitem *, void *)
{
// Exit window manager
exit_window_manager(NULL, NULL);
// Poweroff computer via FDAPM
system("FDAPM POWEROFF");
}
// File Manager Menu Functions
// Item open function
void item_open(menuitem *, void *)
{
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Status variable
struct stat status;
// Copy listbox item
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get item status
stat(item_name, &status);
if(S_ISDIR(status.st_mode)) // If item is dir
{
// Change directory
change_current_directory(item_name, 0);
}
else // If item is file
{
// Run executable file
command_run(item_name);
}
free(item_name);
}
// New directory function
void new_directory(menuitem *, void *)
{
// Make new directory of specified name
mkdir((char *)popup_input(reinterpret_cast<unsigned char const*>(kittengets(9, 0, "New Directory")), reinterpret_cast<unsigned char const*>(kittengets(9, 1, "Directory Name:")), reinterpret_cast<unsigned char const*>("")));
// Refresh directories
directory_view(NULL, NULL);
}
// Exit file manager function
void file_manager_exit(menuitem *, void *)
{
// Hide file manager window
file_manager->set_hidden();
}
// Cut function
void cut_item(menuitem *, void *)
{
// Item name variable
char *item_name = (char *)calloc(MAX_PATH_LENGTH + 8, 1);
// Copy listbox item
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get selected item
strcat(clipboard_item_name, item_name);
// Set clipboard item path
strcat(clipboard_item_path, current_directory);
strcat(clipboard_item_path, "\\");
strcat(clipboard_item_path, clipboard_item_name);
// Set clipboard status to cut
clipboard_status = 2;
free(item_name);
}
// Copy function
void copy_item(menuitem *, void *)
{
// Item name variable
char *item_name = (char *)calloc(MAX_PATH_LENGTH + 8, 1);
// Copy listbox item
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get selected item
strcat(clipboard_item_name, item_name);
// Set clipboard item path
strcat(clipboard_item_path, current_directory);
strcat(clipboard_item_path, "\\");
strcat(clipboard_item_path, clipboard_item_name);
// Set clipboard status to copy
clipboard_status = 1;
free(item_name);
}
// Paste Function
void paste_item(menuitem *, void *)
{
// Target path variable
char *target_path = current_directory;
// Status variable
struct stat status;
// Make clipboard item name
strcat(target_path, "\\");
strcat(target_path, clipboard_item_name);
if(clipboard_status == 1) // If copy
{
// Get clipboard source item status
stat(clipboard_item_path, &status);
if(S_ISDIR(status.st_mode)) // If item is dir
{
// Copy directory
copy_directory(clipboard_item_path, target_path);
}
else // If item is file
{
// Copy file
copy_file(clipboard_item_path, target_path);
}
}
else if(clipboard_status == 2) // If cut
{
// Move file
rename(clipboard_item_path, target_path);
}
// Clean clipboard
clipboard_status = 0;
*clipboard_item_name = '\0';
*clipboard_item_path = '\0';
// Refresh directories
directory_view(NULL, NULL);
}
// Rename function
void rename_item(menuitem *, void *)
{
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Copy listbox item
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
rename((char *)item_name, (char *)popup_input(reinterpret_cast<unsigned char const*>(kittengets(10, 0, "Rename")), reinterpret_cast<unsigned char const*>(kittengets(10, 1, "New Name:")), reinterpret_cast<unsigned char const*>("")));
// Refresh directories
directory_view(NULL, NULL);
free(item_name);
}
// Change archive attribute function
void change_archive_attribute(menuitem *menu_item, void *)
{
// Attribute variable
unsigned int attribute;
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Get item name
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get item attribute
_dos_getfileattr(item_name, &attribute);
if(menu_item->m_flags & MENUITEM_VALUE) // If checked
{
// Add archive file attribute
_dos_setfileattr(item_name, attribute | _A_ARCH);
}
else // If not checked
{
// Remove archive file attribute
_dos_setfileattr(item_name, !(attribute ^ _A_ARCH));
}
free(item_name);
// Refresh directories
directory_view(NULL, NULL);
}
// Change hidden attribute function
void change_hidden_attribute(menuitem *menu_item, void *)
{
// Attribute variable
unsigned int attribute;
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Get item name
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get item attribute
_dos_getfileattr(item_name, &attribute);
if(menu_item->m_flags & MENUITEM_VALUE) // If checked
{
// Add hidden file attribute
_dos_setfileattr(item_name, attribute | _A_HIDDEN);
}
else // If not checked
{
// Remove hidden file attribute
_dos_setfileattr(item_name, !(attribute ^ _A_HIDDEN));
}
free(item_name);
// Refresh directories
directory_view(NULL, NULL);
}
// Change read only attribute function
void change_read_only_attribute(menuitem *menu_item, void *)
{
// Attribute variable
unsigned int attribute;
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Get item name
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get item attribute
_dos_getfileattr(item_name, &attribute);
if(menu_item->m_flags & MENUITEM_VALUE) // If checked
{
// Add read only file attribute
_dos_setfileattr(item_name, attribute | _A_RDONLY);
}
else // If not checked
{
// Remove read only file attribute
_dos_setfileattr(item_name, !(attribute ^ _A_RDONLY));
}
free(item_name);
// Refresh directories
directory_view(NULL, NULL);
}
// Change system attribute function
void change_system_attribute(menuitem *menu_item, void *)
{
// Attribute variable
unsigned int attribute;
// Item name variable
char *item_name = (char *)calloc(MAX_NAME_LENGTH + 8, 1);
// Get item name
item_name = get_item_name(item_name, directories_and_files->get_selected_first());
// Get item attribute
_dos_getfileattr(item_name, &attribute);
if(menu_item->m_flags & MENUITEM_VALUE) // If checked
{
// Add system file attribute
_dos_setfileattr(item_name, attribute | _A_SYSTEM);
}
else // If not checked
{
// Remove system file attribute
_dos_setfileattr(item_name, !(attribute ^ _A_SYSTEM));