forked from aakashchandhoke/SpiderUnleashed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperFunctions.cs
More file actions
80 lines (64 loc) · 2.54 KB
/
HelperFunctions.cs
File metadata and controls
80 lines (64 loc) · 2.54 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Threading.Tasks;
using System.IO;
namespace SpiderUnleashed {
public static class HelperFunctions {
public static WebProxy CreateWebProxy(string server, int port, string username, string password) {
WebProxy webProxy = null;
if (server != null) {
string temp = server + ":" + port;
webProxy = new WebProxy(temp, true);
if (username != null && password != null) {
webProxy.Credentials = new NetworkCredential(username, password);
}
}
return webProxy;
}
public static List<string> GetAllFilesFromFolder(string root, bool searchSubfolders) {
Queue<string> folders = new Queue<string>();
List<string> files = new List<string>();
folders.Enqueue(root);
while (folders.Count != 0) {
string currentFolder = folders.Dequeue();
try {
string[] filesInCurrent = System.IO.Directory.GetFiles(currentFolder, "*.*", System.IO.SearchOption.TopDirectoryOnly);
files.AddRange(filesInCurrent);
}
catch {
// Do Nothing
}
try {
if (searchSubfolders) {
string[] foldersInCurrent = System.IO.Directory.GetDirectories(currentFolder, "*.*", System.IO.SearchOption.TopDirectoryOnly);
foreach (string _current in foldersInCurrent) {
folders.Enqueue(_current);
}
}
}
catch {
// Do Nothing
}
}
return files;
}
public static string GetDesktopPath() {
return (Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
}
public static WebProxy GetProxyFromFile(string FilePath) {
WebProxy webProxy = null;
if (File.Exists(FilePath)) {
string[] contents = File.ReadAllLines(FilePath);
string pAddress = contents[0];
int pPort = int.Parse(contents[1]);
string pUser = contents[2];
string pPass = contents[3];
webProxy = CreateWebProxy(pAddress, pPort, pUser, pPass);
}
return webProxy;
}
}
}