-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
1687 lines (1629 loc) · 75.2 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Media;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Backup_Service_Console_Edition_1._0
{
class Program
{
static void Main(string[] args)
{
welcome_message();
Stopwatch total_timer = new Stopwatch();
total_timer.Start();
string file_name = DateTime.Now.ToString("backup_MM-dd-yyy");
file_name += ".zip";
string file_to_backup = @"C:\Backup Service Console Edition 1.0\Service files\backup_path.txt";
string dir_to_zip = @"C:\Backup Service Console Edition 1.0\Service files\temp_backup_files\to_zip";
string dir_to_upload_copy = @"C:\Backup Service Console Edition 1.0\Service files\temp_backup_files\to_upload_copy";
string dir_zip_zipfun = "C:\\\"Backup Service Console Edition 1.0\"\\\"Service files\"\\temp_backup_files\\to_zip"; //zip function doesn't allows spaces in address, so the folder with a "space name" you have to add the quotations marks "".
string dir_up_copy_zip_fun = "C:\\\"Backup Service Console Edition 1.0\"\\\"Service files\"\\temp_backup_files\\to_upload_copy"; //zip function doesn't allows spaces in address, so the folder with a "space name" you have to add the quotations marks "".
string file_server_info = @"C:\Backup Service Console Edition 1.0\Service files\server_info.txt";
string file_del_days = @"C:\Backup Service Console Edition 1.0\Service files\del_days.txt";
string file_to_upload_path = dir_to_upload_copy + @"\" + file_name;
string file_csv_history = @"C:\Backup Service Console Edition 1.0\Service files\Backup Service 1.0 History.csv";
string file_csv_copy = @"C:\Backup Service Console Edition 1.0\Service files\csv_copy_path.txt";
string file_device_on_off = @"C:\Backup Service Console Edition 1.0\Service files\device_backup_on_off.txt";
string file_ftp_on_off = @"C:\Backup Service Console Edition 1.0\Service files\ftp_backup_on_off.txt";
string file_mount = @"C:\Backup Service Console Edition 1.0\Service files\mount_unmount_files\mount_admin.bat";
string file_unmount = @"C:\Backup Service Console Edition 1.0\Service files\mount_unmount_files\unmount_admin.bat";
string file_device_dest_path = @"C:\Backup Service Console Edition 1.0\Service files\device_dest_path.txt";
bool autopilot = autopilot_check(file_to_backup, file_server_info, file_del_days, file_device_on_off, file_ftp_on_off, file_mount, file_unmount, file_device_dest_path);
if (autopilot)
settings_change(file_to_backup, file_csv_copy, file_del_days, file_server_info, file_device_on_off, file_ftp_on_off, file_mount, file_unmount, file_device_dest_path);
folder_cleaner(dir_to_upload_copy);
folder_cleaner(dir_to_zip);
List<string> dir_address = new List<string>(File.ReadAllLines(file_to_backup));
Stopwatch copy_timer = new Stopwatch();
copy_timer.Start();
copy_fun(dir_address, dir_to_zip);
copy_timer.Stop();
Stopwatch zip_timer = new Stopwatch();
zip_timer.Start();
zip_fun(dir_zip_zipfun, dir_up_copy_zip_fun, file_name);
zip_timer.Stop();
folder_cleaner(dir_to_zip);
if (File.ReadAllText(file_device_on_off) == "1")
{
string device_dest = File.ReadAllText(file_device_dest_path);
mount_device(file_mount);
int days;
string days_read = File.ReadAllText(file_del_days);
if (int.TryParse(days_read, out days))
{
if (days > 0)
{
del_old_file_device(file_device_dest_path, days);
}
}
File.Copy(dir_to_upload_copy + @"\" + file_name, device_dest + @"\" + file_name, true);
unmount_device(file_unmount);
}
Stopwatch upload_timer = new Stopwatch();
if (File.ReadAllText(file_ftp_on_off) == "1")
{
int days;
string days_read = File.ReadAllText(file_del_days);
if (int.TryParse(days_read, out days))
{
if (days > 0)
{
del_old_file_ftp(file_server_info, days);
}
}
upload_timer.Start();
ftp_upload(file_server_info, file_to_upload_path);
upload_timer.Stop();
}
string upload_size= folder_dimension(dir_to_upload_copy);
folder_cleaner(dir_to_upload_copy);
folder_cleaner(dir_to_zip);
total_timer.Stop();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("\n\n");
line_printer();
TimeSpan copy_t = TimeSpan.FromMinutes(copy_timer.Elapsed.TotalMinutes);
TimeSpan zip_t = TimeSpan.FromMinutes(zip_timer.Elapsed.TotalMinutes);
TimeSpan upload_t = TimeSpan.FromMinutes(upload_timer.Elapsed.TotalMinutes);
TimeSpan total_t = TimeSpan.FromMinutes(total_timer.Elapsed.TotalMinutes);
Console.WriteLine("\"COPY\" Elapsed time= {0:D2}H : {1:D2}M : {2:D2}s : {3:D3}ms", copy_t.Hours, copy_t.Minutes, copy_t.Seconds, copy_t.Milliseconds);
Console.WriteLine("\"ZIP\" Elapsed time= {0:D2}H : {1:D2}M : {2:D2}s : {3:D3}ms", zip_t.Hours, zip_t.Minutes, zip_t.Seconds, zip_t.Milliseconds);
Console.WriteLine("\"UPLOAD\" Elapsed time= {0:D2}H : {1:D2}M : {2:D2}s : {3:D3}ms", upload_t.Hours, upload_t.Minutes, upload_t.Seconds, upload_t.Milliseconds);
Console.WriteLine("\"TOTAL\" Elapsed time= {0:D2}H : {1:D2}M : {2:D2}s : {3:D3}ms", total_t.Hours, total_t.Minutes, total_t.Seconds, total_t.Milliseconds);
line_printer();
Console.ResetColor();
CSV_update(file_csv_history, file_name, file_device_on_off, file_ftp_on_off, upload_t, total_t, copy_t, upload_size, file_csv_copy);
goodbye_message();
Console.Write("Enter to exit ");
Console.ReadLine();
}
private static void welcome_message()
{
Console.ForegroundColor = ConsoleColor.Yellow;
int width = Console.WindowWidth;
for (int line = 0; line < 2; line++)
{
for (int asterisk = 0; asterisk < width; asterisk++)
{
Console.Write("*");
}
}
string welcome = "Welcome to Backup Service Console Edition 1.0";
for (int wel = 0; wel < (width - welcome.Length) / 2; wel++)
{
Console.Write("*");
}
Console.Write(welcome);
for (int wel = 0; wel < (width - welcome.Length) / 2; wel++)
{
Console.Write("*");
}
for (int line = 0; line < 2; line++)
{
for (int asterisk = 0; asterisk < width; asterisk++)
{
Console.Write("*");
}
}
Console.ResetColor();
Console.WriteLine("\n");
}
private static void goodbye_message()
{
Console.WriteLine("\n");
Console.ForegroundColor = ConsoleColor.Cyan;
int width = Console.WindowWidth;
for (int line = 0; line < 2; line++)
{
for (int asterisk = 0; asterisk < width; asterisk++)
{
Console.Write("*");
}
}
string uploaded = "Goodbye";
for (int wel = 0; wel < (width - uploaded.Length) / 2; wel++)
{
Console.Write("*");
}
Console.Write(uploaded);
for (int wel = 0; wel < (width - uploaded.Length) / 2; wel++)
{
Console.Write("*");
}
for (int line = 0; line < 2; line++)
{
for (int asterisk = 0; asterisk < width; asterisk++)
{
Console.Write("*");
}
}
Console.ResetColor();
Console.WriteLine("\n");
}
private static void line_printer()
{
int width = Console.WindowWidth;
for (int line = 0; line < width; line++)
{
Console.Write("-");
}
}
private static bool autopilot_check(string file_to_backup, string file_server_info, string file_del_days, string file_device_on_off, string file_ftp_on_off, string file_mount, string file_unmount, string file_device_dest_path)
{
//valuate to enter a TimeOut
settings_check(file_to_backup, file_server_info, file_del_days, file_device_on_off, file_ftp_on_off, file_mount, file_unmount, file_device_dest_path); //valuate to return a bool value
Console.Write("If you want to change or check settings, press Enter within 10 secs ");
bool autopilot = Timeout.ReadLine(10000);
if (autopilot)
{
Console.ForegroundColor = ConsoleColor.Red;
new SoundPlayer(@"C:\Backup Service Console Edition 1.0\Service files\sounds\Autopilot Disconnect sound.wav").Play();
Console.WriteLine("\n\t\"AUTOPILOT\" DISCONNECT\n");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\n\t\"AUTOPILOT\" ON\n");
Console.ResetColor();
}
return autopilot;
}
private static void autopilot_deactivate_error_warning()
{
Console.ForegroundColor = ConsoleColor.Red;
new SoundPlayer(@"C:\Backup Service Console Edition 1.0\Service files\sounds\Autopilot Disconnect sound.wav").Play();
Console.WriteLine("\n\t\"AUTOPILOT\" DISCONNECT\n");
Console.ResetColor();
}
private static void settings_change(string file_to_backup, string file_csv_copy, string file_del_days, string file_server_info, string file_device_on_off, string file_ftp_on_off, string file_mount, string file_unmount, string file_device_dest_path)
{
bool exit_check = false;
while (!exit_check)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\nSettings control panel\n");
Console.ResetColor();
Console.Write("To check or change ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write("\"GENERAL\" ");
Console.ResetColor();
Console.Write("settings press ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write("\"G\" ");
Console.ResetColor();
Console.Write(", ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("\"F\" ");
Console.ResetColor();
Console.Write("for ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("\"FTP\" ");
Console.ResetColor();
Console.Write(", ");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write("\"D\" ");
Console.ResetColor();
Console.Write("for ");
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write("\"DEVICES\"");
Console.ResetColor();
Console.Write(", ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("\"E\" ");
Console.ResetColor();
Console.Write("to ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("EXIT");
Console.ResetColor();
Console.Write(": ");
string ans = Console.ReadLine();
if (ans.ToLower() == "g")
{
string gen_ans;
do
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\n\nGeneral Settings panel");
Console.ResetColor();
Console.Write("\nBackup Type (");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"B\"");
Console.ResetColor();
Console.WriteLine(")");
Console.Write("\tBackup Device: ");
if (File.ReadAllText(file_device_on_off) == "1")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("ON");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("OFF");
Console.ResetColor();
}
Console.Write("\tFTP Backup: ");
if (File.ReadAllText(file_ftp_on_off) == "1")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("ON");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("OFF");
Console.ResetColor();
}
Console.Write("\nFolders to Backup (");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"F\"");
Console.ResetColor();
Console.WriteLine(")");
Console.Write("\tFolder set: ");
if (new FileInfo(file_to_backup).Length <= 2)
{
Console.WriteLine("No folder set!");
}
else
{
List<string> to_print_list = new List<string>(File.ReadAllLines(file_to_backup));
Console.WriteLine();
foreach (string line in to_print_list)
{
Console.WriteLine("\t" + line);
}
}
Console.WriteLine();
Console.Write("Backup History copy destination (");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"C\"");
Console.ResetColor();
Console.WriteLine(" to change destination or for more info)");
Console.Write("\tFolder set: ");
if (new FileInfo(file_csv_copy).Length <= 2)
{
Console.WriteLine("No folder set!");
}
else
{
Console.WriteLine(File.ReadAllText(file_csv_copy));
}
Console.Write("\nDays limit (");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"D\"");
Console.ResetColor();
Console.WriteLine(" to change days or for more info)");
Console.Write("\tDays set: ");
if (new FileInfo(file_del_days).Length == 0)
{
Console.Write("No Days set!");
}
else
{
Console.WriteLine(File.ReadAllText(file_del_days));
}
Console.WriteLine("\n");
Console.Write("Choose setting to change, otherwise Press \"E\" to Exit: ");
gen_ans = Console.ReadLine().ToLower();
if (gen_ans.ToLower() == "f")
{
Console.Beep();
change_file_backup(file_to_backup);
}
if (gen_ans.ToLower() == "c")
{
Console.Beep();
change_file_csv_copy(file_csv_copy);
}
if (gen_ans.ToLower() == "d")
{
Console.Beep();
change_days_limit(file_del_days);
}
if (gen_ans.ToLower() == "b")
{
Console.Beep();
change_bakcup_type(file_device_on_off, file_ftp_on_off);
}
if (new FileInfo(file_to_backup).Length <= 2)
{
change_file_backup(file_to_backup);
}
}
while (gen_ans != "e");
}
if (ans.ToLower() == "f")
{
change_server_info(file_server_info, file_ftp_on_off);
}
if (ans.ToLower() == "d")
{
string dev_ans="";
while (dev_ans != "e")
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\n\nDevice Settings panel");
Console.ResetColor();
Console.Write("\nMount/Unmount settings (");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"M\"");
Console.ResetColor();
Console.WriteLine(")");
StreamReader file = new StreamReader(file_mount);
file.ReadLine();
string device_letter = file.ReadLine();
string volume = file.ReadLine();
volume = volume.Replace("set volume=", "");
device_letter = device_letter.Replace("set drive=", "");
file.Close();
Console.WriteLine("\tMount:");
Console.WriteLine("\t\tDriver Letter Mount: " + device_letter);
Console.WriteLine("\t\tVolume Name: " + volume);
Console.WriteLine("\tUnmount:");
StreamReader file_un_check = new StreamReader(file_unmount);
file_un_check.ReadLine();
string device_letter_unmount_check = file_un_check.ReadLine();
device_letter_unmount_check = device_letter_unmount_check.Replace("set drive=", "");
file_un_check.Close();
Console.WriteLine("\t\tDriver Letter Unmount: " + device_letter_unmount_check);
Console.Write("\nDestination Setting (");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"D\"");
Console.ResetColor();
Console.WriteLine(")");
string dest = File.ReadAllText(file_device_dest_path);
Console.Write("\tDestination Folder: ");
if (dest.Length < 3)
{
Console.WriteLine("\tNo folder set");
}
else
{
Console.WriteLine(dest);
}
Console.WriteLine();
Console.Write("Choose setting to change, otherwise Press \"E\" to Exit: ");
dev_ans = Console.ReadLine();
if (dev_ans.ToLower() == "m")
{
change_mount_unmount(file_mount, file_unmount);
}
if (dev_ans.ToLower() == "d")
{
change_destination_device(file_device_dest_path, file_device_on_off);
}
}
//change_mount_unmount(file_mount, file_unmount);
}
if (ans.ToLower() == "e")
{
exit_check = true;
}
}
}
private static void change_file_backup(string file_to_backup)
{
Console.WriteLine();
line_printer();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Backup Settings");
Console.ResetColor();
List<string> dir_address = new List<string>(File.ReadAllLines(file_to_backup));
Console.Write("\tFolder set: ");
if (new FileInfo(file_to_backup).Length <= 2)
{
Console.WriteLine("No folder set!");
}
else
{
Console.WriteLine();
foreach (string line in dir_address)
{
Console.WriteLine("\t" + line);
}
}
Console.WriteLine();
string change_input;
if (new FileInfo(file_to_backup).Length <= 2)
{
while (new FileInfo(file_to_backup).Length <= 2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\a\nWARNING: No folder to backup, this will cause a fatal error\n");
Console.ResetColor();
do
{
Console.Write("Press \"A\" to Add folder, \"D\" to Del folder, \"C\" to erase file, \"E\" to stop: ");
change_input = Console.ReadLine().ToLower();
if (change_input.ToLower() == "a")
{
Console.Write("Enter folder path: ");
dir_address.Add(Console.ReadLine());
}
if (change_input.ToLower() == "d")
{
Console.Write("Enter folder path: ");
dir_address.Remove(Console.ReadLine());
}
if (change_input.ToLower() == "c")
{
dir_address.Clear();
Console.WriteLine("File Successfully erased");
}
}
while (change_input != "e");
File.WriteAllLines(file_to_backup, dir_address);
}
}
else
{
do
{
Console.Write("Press \"A\" to Add folder, \"D\" to Del folder, \"C\" to erase file, \"E\" to stop: ");
change_input = Console.ReadLine().ToLower();
if (change_input.ToLower() == "a")
{
Console.Write("Enter folder path: ");
dir_address.Add(Console.ReadLine());
}
if (change_input.ToLower() == "d")
{
Console.Write("Enter folder path: ");
dir_address.Remove(Console.ReadLine());
}
if (change_input.ToLower() == "c")
{
dir_address.Clear();
Console.WriteLine("File Successfully erased");
}
}
while (change_input != "e");
File.WriteAllLines(file_to_backup, dir_address);
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Folders to backup");
Console.ResetColor();
List<string> to_print_list = new List<string>(File.ReadAllLines(file_to_backup));
Console.Write("\tFolder set: ");
Console.WriteLine();
foreach (string line in to_print_list)
{
Console.WriteLine("\t" + line);
}
line_printer();
}
private static void change_file_csv_copy(string file_csv_copy)
{
Console.WriteLine("\n");
line_printer();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Backup History settings");
Console.ResetColor();
Console.WriteLine("\nIf you enter a folder path, the program will copy the updated Backup History in that folder. It could be useful if you want to remotely check it by a Cloud Service. Whatever is your decision, the program will update the Backup History in his default folder.");
Console.Write("\nFolder set: ");
if(new FileInfo(file_csv_copy).Length <= 2)
{
Console.Write("No folder set!");
}
else
{
Console.WriteLine(File.ReadAllText(file_csv_copy));
}
Console.WriteLine();
Console.Write("\nTo change copy path ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"C\"");
Console.ResetColor();
Console.Write(", to erase file");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write(" Press \"E\"");
Console.ResetColor();
Console.Write(", otherwise ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press ENTER ");
Console.ResetColor();
Console.Write(": ");
string check = Console.ReadLine();
if (check.ToLower() == "c")
{
Console.Write("\nEnter folder path: ");
File.WriteAllText(file_csv_copy, Console.ReadLine());
Console.Write("\nFolder set: ");
Console.WriteLine(File.ReadAllText(file_csv_copy));
}
if (check.ToLower() == "e")
{
File.WriteAllText(file_csv_copy, "");
Console.WriteLine("File Successfully erased");
}
line_printer();
}
private static void change_days_limit(string file_del_days)
{
Console.Beep();
Console.WriteLine();
line_printer();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Days limit Settings");
Console.ResetColor();
Console.Write("\tDays set: ");
if (new FileInfo(file_del_days).Length == 0)
{
Console.Write("No Days set!");
}
else
{
Console.WriteLine(File.ReadAllText(file_del_days));
}
Console.WriteLine("\n");
Console.WriteLine("This setting helps you to keep memory free, the files older than X days will be deleted.\nNote: the limit works for Devices and Server settings.\nThe input must be an integer.\n");
Console.Write("To change Days limit ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"C\"");
Console.ResetColor();
Console.Write(", to erase limit press ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"E\"");
Console.ResetColor();
Console.Write(", otherwise ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("press ENTER");
Console.ResetColor();
Console.Write(": ");
string check = Console.ReadLine();
if (check.ToLower() == "c")
{
bool check_out = false;
string input;
int limit;
while (!check_out)
{
Console.Write("\aEnter limit: ");
input = Console.ReadLine();
if (int.TryParse(input, out limit))
{
File.WriteAllText(file_del_days, input);
check_out = true;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ERROR: input must be an integer");
Console.ResetColor();
}
}
}
if (check.ToLower() == "e")
{
File.WriteAllText(file_del_days, "");
}
Console.Write("\nDays set: ");
if (new FileInfo(file_del_days).Length == 0)
{
Console.Write("No Days set!");
}
else
{
Console.WriteLine(File.ReadAllText(file_del_days));
}
Console.WriteLine();
line_printer();
Console.WriteLine();
}
private static void change_server_info(string file_server_info, string file_ftp_on_off)
{
//bool enable: TRUE: If server info are required, FALSE: if FTP upload is deactivated
string enable_check = File.ReadAllText(file_ftp_on_off);
bool enable;
if (enable_check == "1")
{
enable = true;
}
else
{
enable = false;
}
Console.Beep();
Console.WriteLine();
line_printer();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Server Settings");
Console.ResetColor();
StreamReader file = new StreamReader(file_server_info);
string ftp_address = file.ReadLine();
string user = file.ReadLine();
string pass = file.ReadLine();
string dest_path = file.ReadLine();
file.Close();
if (ftp_address== null)
{
Console.WriteLine("Address: No Address Set");
}
else
{
Console.WriteLine("Address: {0}", ftp_address);
}
if (user == null)
{
Console.WriteLine("User: No User Set");
}
else
{
Console.WriteLine("User: {0}", user);
}
if (pass == null)
{
Console.WriteLine("Password: No Password Set");
}
else
{
Console.Write("Password: ");
for (int count = 0; count < pass.Length; count++)
{
Console.Write("*");
}
}
Console.WriteLine();
if (dest_path == null)
{
Console.WriteLine("Server Destination folder: No Folder Set");
}
else
{
Console.WriteLine("Server Destination folder: {0}", dest_path);
}
Console.WriteLine();
if (enable)
{
while (ftp_address == null || ftp_address.Length<=2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\aERROR: No Address Set");
Console.ResetColor();
Console.Write("Enter FTP Address: ");
ftp_address = Console.ReadLine();
}
while (user == null || user.Length<=2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\aERROR: No User Set");
Console.ResetColor();
Console.Write("Enter User: ");
user = Console.ReadLine();
}
while (pass == null || pass.Length<=2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\aERROR: No Password Set");
Console.ResetColor();
Console.Write("Enter Password: ");
pass = Console.ReadLine();
}
while (dest_path == null || dest_path.Length<=2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\aERROR: No Destination path Set");
Console.ResetColor();
Console.Write("Enter Destination path: ");
dest_path = Console.ReadLine();
}
}
bool exit_check = false;
bool erase = false;
while (!exit_check)
{
Console.Write("To change FTP Address ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"A\"");
Console.ResetColor();
Console.Write(", User ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"U\"");
Console.ResetColor();
Console.Write(", Password ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"P\"");
Console.ResetColor();
Console.Write(", Destination path ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"D\"");
Console.ResetColor();
Console.Write(", for Help ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"H\"");
Console.ResetColor();
Console.Write(", to erase settings ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"C\"");
Console.ResetColor();
Console.Write(", to Exit ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"E\"");
Console.ResetColor();
Console.Write(": ");
string ans = Console.ReadLine();
if (ans.ToLower() == "h")
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Server settings example:");
Console.WriteLine("Address: ftp://www.example.com");
Console.WriteLine("User: 123456@server.com");
Console.WriteLine("Password: qwerty12");
Console.WriteLine("Folder: /www.example.com/destination_folder \n");
Console.WriteLine("This infos were provided by your hosting, you can find them on your account, or contact the provider.");
Console.ResetColor();
Console.WriteLine();
}
if (ans.ToLower() == "a")
{
Console.Write("Enter Address: ");
ftp_address = Console.ReadLine();
erase = false;
}
if (ans.ToLower() == "u")
{
Console.Write("Enter User: ");
user = Console.ReadLine();
erase = false;
}
if (ans.ToLower() == "p")
{
Console.Write("Enter Password: ");
pass = Console.ReadLine();
erase = false;
}
if (ans.ToLower() == "d")
{
Console.Write("Enter Destination path: ");
dest_path = Console.ReadLine();
erase = false;
}
if (ans.ToLower() == "c")
{
erase = true;
ftp_address = "";
user = "";
pass = "";
dest_path = "";
File.WriteAllText(file_server_info, "");
Console.Beep();
Console.WriteLine("Settings successfully erased");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\aWARNING: if FTP backup is enabled and there are some empty settings, the program will stop.\n");
Console.ResetColor();
}
if (ans.ToLower() == "e")
{
exit_check = true;
}
}
if (!erase)
{
StreamWriter file_write = new StreamWriter(file_server_info);
file_write.WriteLine(ftp_address);
file_write.WriteLine(user);
file_write.WriteLine(pass);
file_write.WriteLine(dest_path);
file_write.Close();
}
Console.WriteLine();
}
private static void change_bakcup_type(string file_device_on_off, string file_ftp_on_off)
{
Console.WriteLine();
line_printer();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Backup Type Settings");
Console.ResetColor();
string device = File.ReadAllText(file_device_on_off);
string ftp = File.ReadAllText(file_ftp_on_off);
Console.Write("\tBackup Device: ");
if (device == "1")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("ON");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("OFF");
Console.ResetColor();
}
Console.Write("\tFTP Backup: ");
if (ftp=="1")
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("ON");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("OFF");
Console.ResetColor();
}
bool exit_check = false;
string ans;
while (!exit_check)
{
Console.Write("\nTo Activate/Deactivate Backup Device ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"D\"");
Console.ResetColor();
Console.Write(", to Activate/Deactivate Backup FTP ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"F\"");
Console.ResetColor();
Console.Write(", to Exit ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"E\"");
Console.ResetColor();
Console.Write(": ");
ans = Console.ReadLine();
if (ans.ToLower() == "d")
{
Console.Write("\nDevice Backup: To Activate ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"A\"");
Console.ResetColor();
Console.Write(", to Deactivate ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"D\"");
Console.ResetColor();
Console.Write(": ");
string ans_d = Console.ReadLine();
if (ans_d.ToLower() == "a")
{
File.WriteAllText(file_device_on_off, "1");
Console.Beep();
Console.WriteLine("\tBackup Device successfully Activated.");
}
if (ans_d.ToLower() == "d")
{
File.WriteAllText(file_device_on_off, "0");
Console.Beep();
Console.WriteLine("\tBackup Device successfully Deactivated.");
}
}
if (ans.ToLower() == "f")
{
Console.Write("\nFTP Backup: To Activate ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"A\"");
Console.ResetColor();
Console.Write(", to Deactivate ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("Press \"D\"");
Console.ResetColor();
Console.Write(": ");
string ans_d = Console.ReadLine();
if (ans_d.ToLower() == "a")
{
File.WriteAllText(file_ftp_on_off, "1");
Console.Beep();
Console.WriteLine("\tFTP Backup successfully Activated.");
}
if (ans_d.ToLower() == "d")
{
File.WriteAllText(file_ftp_on_off, "0");
Console.Beep();
Console.WriteLine("\tFTP Backup successfully Deactivated.");
}
}
if (ans.ToLower() == "e")
{
exit_check = true;
}
}
line_printer();
}
private static void change_mount_unmount(string file_mount, string file_unmount)
{
bool exit_check = false;
Console.WriteLine();
line_printer();
while (!exit_check)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Device Backup Settings");
Console.ResetColor();
Console.WriteLine("\nMount settings:");
StreamReader file = new StreamReader(file_mount);
file.ReadLine();
string device_letter = file.ReadLine();
string volume = file.ReadLine();
volume = volume.Replace("set volume=", "");
device_letter = device_letter.Replace("set drive=", "");
file.Close();
Console.WriteLine("\tDriver Letter Mount: " + device_letter);
Console.WriteLine("\tVolume Name: " + volume);
Console.WriteLine("\nUnmount settings:");
StreamReader file_un_check = new StreamReader(file_unmount);