-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathUserInterface.cs
More file actions
345 lines (302 loc) · 13.8 KB
/
Copy pathUserInterface.cs
File metadata and controls
345 lines (302 loc) · 13.8 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
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
using Newtonsoft.Json;
namespace Stalkiana_Console
{
public class CookieConfig
{
public string ActiveCookie { get; set; } = string.Empty;
public Dictionary<string, string> Cookies { get; set; } = new Dictionary<string, string>();
}
public static class UserInterface
{
public static void displayStartingScreen()
{
Console.Clear();
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(@" _________ __ .__ __ .__
/ _____/_/ |_ _____ | | | | __|__|_____ ____ _____
\_____ \ \ __\\__ \ | | | |/ /| |\__ \ / \ \__ \
/ \ | | / __ \_| |__| < | | / __ \_| | \ / __ \_
/_______ / |__| (____ /|____/|__|_ \|__|(____ /|___| /(____ /
\/ \/ \/ \/ \/ \/ ");
Console.ResetColor();
}
public static string getUsername()
{
string username;
do
{
Console.Write("\nPlease input the username to target: ");
username = Console.ReadLine()!;
if (string.IsNullOrWhiteSpace(username))
{
Console.WriteLine("Username cannot be empty. Please enter a valid username.");
}
} while (string.IsNullOrWhiteSpace(username));
return username;
}
public static int getOption(ref string username)
{
int option;
string? input;
while (true)
{
Console.WriteLine();
if (string.IsNullOrEmpty(username))
{
Console.WriteLine("1- Set Target Username");
Console.WriteLine("2- Manage Cookies");
Console.WriteLine("3- List All Users");
Console.WriteLine("4- Exit\n");
Console.Write("Choose what you want to do: ");
input = Console.ReadLine();
if (input == "1")
{
username = getUsername();
Console.Clear();
displayStartingScreen();
continue;
}
else if (input == "2") return 7;
else if (input == "3") return 8;
else if (input == "4") return 10;
else
{
Console.Clear();
displayStartingScreen();
Console.WriteLine("\nPlease enter a valid option.");
}
}
else
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"--- Current Target: {username} ---");
Console.ResetColor();
Console.WriteLine("1- Download Profile Picture ");
Console.WriteLine("2- Get Followers/Following");
Console.WriteLine("3- Show Local History");
Console.WriteLine("4- Download Posts");
Console.WriteLine("5- Download Stories");
Console.WriteLine("6- Get User ID");
Console.WriteLine("7- Manage Cookies");
Console.WriteLine("8- List All Users");
Console.WriteLine("9- Open Folder");
Console.WriteLine("10- Change/Clear Target Username");
Console.WriteLine("11- Exit\n");
Console.Write("Choose what you want to do: ");
input = Console.ReadLine();
if (int.TryParse(input, out option) && option >= 1 && option <= 11)
{
if (option == 10)
{
username = string.Empty;
Console.Clear();
displayStartingScreen();
continue;
}
if (option == 11) return 10;
return option;
}
Console.Clear();
displayStartingScreen();
Console.WriteLine("\nPlease enter a valid option.");
}
}
}
public static string getCookieInput()
{
string cookie;
do
{
Console.Write("\nPlease input the full instagram cookie: ");
cookie = Console.ReadLine()!;
if (string.IsNullOrWhiteSpace(cookie))
{
Console.WriteLine("Cookie cannot be empty. Please enter a valid cookie.");
}
} while (string.IsNullOrWhiteSpace(cookie));
return cookie;
}
private static CookieConfig LoadConfig(string path)
{
if (File.Exists(path))
{
try
{
return JsonConvert.DeserializeObject<CookieConfig>(File.ReadAllText(path)) ?? new CookieConfig();
}
catch (Exception ex)
{
Console.Error.WriteLine($"Failed to load JSON config: {ex.Message}");
}
}
return new CookieConfig();
}
private static void SaveConfig(string path, CookieConfig config)
{
File.WriteAllText(path, JsonConvert.SerializeObject(config, Formatting.Indented));
}
public static string getCookie(string configFilePath)
{
var config = LoadConfig(configFilePath);
if (!string.IsNullOrEmpty(config.ActiveCookie) && config.Cookies.ContainsKey(config.ActiveCookie))
{
return config.Cookies[config.ActiveCookie];
}
Console.WriteLine("\nNo active cookie found. Please configure a cookie first.");
manageCookies(configFilePath);
config = LoadConfig(configFilePath);
if (!string.IsNullOrEmpty(config.ActiveCookie) && config.Cookies.ContainsKey(config.ActiveCookie))
{
return config.Cookies[config.ActiveCookie];
}
return getCookieInput();
}
public static void manageCookies(string configFilePath)
{
CookieConfig config = LoadConfig(configFilePath);
while (true)
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("=== Manage Cookies ===");
Console.ResetColor();
Console.WriteLine($"Active Cookie: {(string.IsNullOrEmpty(config.ActiveCookie) ? "None" : config.ActiveCookie)}\n");
Console.WriteLine("1. List all cookies");
Console.WriteLine("2. Add a new cookie");
Console.WriteLine("3. Update an existing cookie");
Console.WriteLine("4. Remove a cookie");
Console.WriteLine("5. Rename a cookie");
Console.WriteLine("6. Set active cookie");
Console.WriteLine("7. Back to main menu");
Console.Write("\nChoose an option: ");
string? choice = Console.ReadLine();
if (choice == "7") break;
Console.WriteLine();
switch (choice)
{
case "1":
if (config.Cookies.Count == 0)
{
Console.WriteLine("No cookies saved.");
}
else
{
foreach (var kvp in config.Cookies)
{
string activeMarker = (kvp.Key == config.ActiveCookie) ? " [ACTIVE]" : "";
Console.WriteLine($"- {kvp.Key}{activeMarker}");
}
}
break;
case "2":
Console.Write("Enter a name/alias for the new cookie: ");
string? addName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(addName)) break;
if (config.Cookies.ContainsKey(addName))
{
Console.WriteLine("A cookie with this name already exists.");
}
else
{
string newCookieStr = getCookieInput();
config.Cookies[addName] = newCookieStr;
if (string.IsNullOrEmpty(config.ActiveCookie) || config.Cookies.Count == 1)
{
config.ActiveCookie = addName;
}
SaveConfig(configFilePath, config);
Console.WriteLine($"\nCookie '{addName}' added successfully.");
}
break;
case "3":
Console.Write("Enter the name of the cookie to update: ");
string? updateName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(updateName)) break;
if (config.Cookies.ContainsKey(updateName))
{
string updatedCookieStr = getCookieInput();
config.Cookies[updateName] = updatedCookieStr;
SaveConfig(configFilePath, config);
Console.WriteLine($"\nCookie '{updateName}' updated successfully.");
}
else
{
Console.WriteLine("Cookie not found.");
}
break;
case "4":
Console.Write("Enter the name of the cookie to remove: ");
string? removeName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(removeName)) break;
if (config.Cookies.ContainsKey(removeName))
{
config.Cookies.Remove(removeName);
if (config.ActiveCookie == removeName)
{
config.ActiveCookie = config.Cookies.Keys.FirstOrDefault() ?? string.Empty;
}
SaveConfig(configFilePath, config);
Console.WriteLine($"\nCookie '{removeName}' removed successfully.");
}
else
{
Console.WriteLine("Cookie not found.");
}
break;
case "5":
Console.Write("Enter the current name of the cookie: ");
string? oldName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(oldName)) break;
if (config.Cookies.ContainsKey(oldName))
{
Console.Write("Enter the new name: ");
string? newName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(newName)) break;
if (config.Cookies.ContainsKey(newName))
{
Console.WriteLine("The new name already exists.");
}
else
{
string val = config.Cookies[oldName];
config.Cookies.Remove(oldName);
config.Cookies[newName] = val;
if (config.ActiveCookie == oldName)
{
config.ActiveCookie = newName;
}
SaveConfig(configFilePath, config);
Console.WriteLine($"\nCookie renamed from '{oldName}' to '{newName}'.");
}
}
else
{
Console.WriteLine("Cookie not found.");
}
break;
case "6":
Console.Write("Enter the name of the cookie to set as active: ");
string? activeName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(activeName)) break;
if (config.Cookies.ContainsKey(activeName))
{
config.ActiveCookie = activeName;
SaveConfig(configFilePath, config);
Console.WriteLine($"\n'{activeName}' is now the active cookie.");
}
else
{
Console.WriteLine("Cookie not found.");
}
break;
default:
Console.WriteLine("Invalid option. Please try again.");
break;
}
Console.WriteLine("\nPress Enter to continue...");
Console.ReadLine();
}
}
}
}