This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
157 lines (142 loc) · 5.9 KB
/
Copy pathProgram.cs
File metadata and controls
157 lines (142 loc) · 5.9 KB
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
using FTP_console.Config;
using FTP_console.Debug;
using FTP_console.Menus;
using FTP_console.Misc;
using Newtonsoft.Json;
public class FTPConsole
{
/// <summary>
/// This method handles the first boot of the software and taking in a parameter if its started
/// from the console
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
{
//detect if we have any args at startup and init in the way we need
if (args.Length == 0)
{
init();
}
else
{
init(args[0]);
}
}
/// <summary>
/// this method starts checking that required files exist and also detects if we are in debug mode
/// or any other argument passed via the cmd
/// </summary>
/// <param name="arg_1"></param>
public static void init(string arg_1)
{
if (arg_1 == "-d")
{
Console.WriteLine("you seem to have started the program witha debug flag are you sure you want to run in debug mode? [Y/N]");
var confirmation = Console.ReadLine();
confirmation.ToLower();
if (confirmation.Equals("y", StringComparison.OrdinalIgnoreCase))
{
Debug_and_test debug = new Debug_and_test();
debug.debug_1();
}
}
}
/// <summary>
/// init method but without any args passed in
/// </summary>
public static void init()
{
ColorConsole color = new ColorConsole();
while (true)
{
try
{
Config_Json config_to_serialize = new Config_Json();
//check files for settings
if (!File.Exists(@"./Config/Settings_Config.json"))
{
if (!Directory.Exists(@"./Config"))
{
Directory.CreateDirectory(@"./Config");
}
using (StreamWriter file = File.CreateText(@"./Config/Settings_Config.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Formatting = Formatting.Indented;
serializer.Serialize(file, config_to_serialize);
}
}
//we read after creatign or if its already tehre good enough to set the colors immediately
Config_Json config = JsonConvert.DeserializeObject<Config_Json>(File.ReadAllText(@"./Config/Settings_Config.json"));
color.SetColor(config.color);
if (config.verbose)
{
Console.WriteLine("Loading Settings config files");
}
//check files for config
if (!File.Exists(@"./Config/FTP_Config.json"))
{
if (!Directory.Exists(@"./Config"))
{
Directory.CreateDirectory(@"./Config");
}
FTP_Json ftp_config = new FTP_Json
{
host = "localhost",
logon_type = null,
password = "",
port = 21,
username = "anonymous"
};
if (config.verbose)
{
Console.WriteLine("Loading FTP config files");
}
using (StreamWriter file = File.CreateText(@"./Config/FTP_Config.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Formatting = Formatting.Indented;
serializer.Serialize(file, ftp_config);
color.PrintColor("!!!IF THIS IS THE FIRST TIME YOU START UP THIS APPLICATION GO INTO THE CONFIG FOLDER AND WRITE YOUR FTP LOGIN DETAILS INTO THE JSON FILE!!! \n If you see this message even if the file was created and was modified leave an issue on the Github page!", ConsoleColor.Yellow);
//MessageBox.Show("!!!IF THIS IS THE FIRST TIME YOU START UP THIS APPLICATION GO INTO THE CONFIG FOLDER AND WRITE YOUR FTP LOGIN DETAILS INTO THE JSON FILE!!! \n If you see this message even if the file was created and was modified leave an issue on the Github page!", "Caution!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
//main menu startup
int op = 0;
string line;
Console.WriteLine("Select which operation you would like to use");
Console.WriteLine("[0] Quit program");
Console.WriteLine("[1] Upload");
Console.WriteLine("[2] Download");
line = Console.ReadLine();
if (line == "")
{
op = Int32.MaxValue;
}
else op = Convert.ToInt32(line);
switch (op)
{
case 2:
DownloadMenu downloadMenu = new DownloadMenu();
downloadMenu.download_menu_UI(config.verbose);
break;
case 1:
UploadMenu uploadMenu = new UploadMenu();
uploadMenu.upload_menu_UI(config.verbose);
break;
case 0:
Console.WriteLine("Quitting...");
return;
break;
default:
break;
}
}
catch (Exception e)
{
color.PrintColor(e.Message, ConsoleColor.Red);
//MessageBox.Show(e.Message, e.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}