-
Notifications
You must be signed in to change notification settings - Fork 1
/
Poster.cs
198 lines (169 loc) · 7.06 KB
/
Poster.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
using AltoHttp;
using HtmlAgilityPack;
using System;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using Telerik.Windows.Documents.Fixed.Model;
using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace LoginPage
{
public partial class Poster : UserControl
{
private int id = 0;
private string description = " Description of course";
private string courselink = string.Empty;
HttpDownloader httpDownloader;
string file_name = "";
string temp3;
EducoRights t;
EducoRights j;
dec_file decryption;
DatabaseConnection db;
[DllImport("user32.dll")]
public static extern uint SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity);
public Poster()
{
InitializeComponent();
}
public int Id
{
get { return id; }
set { id = value; }
}
public string Description
{
get { return description; }
set { description = value; }
}
public string Coursename
{
get { return coursename.Text; }
set { coursename.Text = value; }
}
public string Coursedescreption
{
get { return coursedescreption.Text; }
set { coursedescreption.Text = value; }
}
public Image Courseimage
{
get { return photo.Image; }
set { photo.Image = value; }
}
public string CourseLink
{
get { return courselink; }
set { courselink = value; }
}
public string progressthemename
{
get { return progressBar.ThemeName; }
set { progressBar.ThemeName = value; }
}
public static Poster ActiveForm { get; internal set; }
private void Poster_Load(object sender, EventArgs e)
{
//Check if the course is exsited in the device or not
if (Directory.Exists(Directory.GetCurrentDirectory() + "\\" + Coursename))
{
if (File.Exists(Directory.GetCurrentDirectory() + "\\" + Coursename + ".zip"))
File.Delete(Directory.GetCurrentDirectory() + "\\" + Coursename + ".zip");
btndownload.Visible = false;
progressBar.Visible = false;
}
}
private void btndownload_Click(object sender, EventArgs e)
{
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument document = web.Load(courselink);
var tags = document.DocumentNode.SelectNodes("//div[@class='download_link']//a[@class='input popsok']").First().Attributes["href"].Value;
if (!(File.Exists(Directory.GetCurrentDirectory() + "\\" + Coursename + ".zip")))
{
httpDownloader = new HttpDownloader(tags, Directory.GetCurrentDirectory() + "\\" + Coursename + ".zip");
httpDownloader.DownloadCompleted += HttpDownloader_DownloadCompleted;
httpDownloader.ProgressChanged += HttpDownloader_ProgressChanged;
httpDownloader.Start();
}
else
File.Delete(Directory.GetCurrentDirectory() + "\\" + file_name); //To delete ZIP file after extraction
}
private void HttpDownloader_ProgressChanged(object sender, AltoHttp.ProgressChangedEventArgs e)
{
progressBar.Value1 = (int)e.Progress;
}
private void HttpDownloader_DownloadCompleted(object sender, EventArgs e)
{
this.Invoke((MethodInvoker)delegate
{
progressBar.Text = "100 %";
if (Directory.Exists(Directory.GetCurrentDirectory() + "\\" + Coursename))
Directory.Delete(Directory.GetCurrentDirectory() + "\\" + Coursename);
else
System.IO.Compression.ZipFile.ExtractToDirectory(Directory.GetCurrentDirectory() + "\\" + Coursename + ".zip", Directory.GetCurrentDirectory() + "\\" + Coursename);
btndownload.Visible = false;
progressBar.Visible = false;
});
}
private void startcourse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
t = new EducoRights();
t = (EducoRights)EducoRights.ActiveForm;
t.change_width(true);
t.Clear_list_item();
t.ProcessCompleted += t_ProcessCompleted; // register with an event
// t.StartProcess();
string root = Directory.GetCurrentDirectory() + "\\" + Coursename;
// Get a list of all subdirectories
var files = from file in
Directory.EnumerateFiles(root)
select file;
foreach (var file in files)
{
temp3 = string.Empty;
int i = file.Length - 1;
while (file[i] != '\\')
{
temp3 = file[i] + temp3;
i--;
}
t.creat_item(temp3);
}
}
public void t_ProcessCompleted(object sender, string SELECTED_ITEM)
{
string ext = string.Empty;
var stream=new MemoryStream();
j = new EducoRights();
j = (EducoRights)EducoRights.ActiveForm;
//Write what you want to do after selecting an item from Listbox1
var I = new Poster();
byte[] SelectedFile = File.ReadAllBytes(Directory.GetCurrentDirectory() + "\\" + Coursename + "\\" + SELECTED_ITEM);
I.decryption = dec_file.GetInstance();
I.db = DatabaseConnection.GetInstance();
string TDES = I.db.execute_scalar_query("SELECT `TripleDES_Password` FROM `courses` WHERE `Course_Name` = '" + Coursename + "' ;");
string AES = I.db.execute_scalar_query("SELECT `AES_Password` FROM `courses` WHERE `Course_Name` = '" + Coursename + "' ;");
SelectedFile = I.decryption.decrypt_TDES(TDES, SelectedFile);
SelectedFile = I.decryption.decrypt_AES(AES, SelectedFile);
stream = new MemoryStream(SelectedFile);
ext = Path.GetExtension(Directory.GetCurrentDirectory() + "\\" + Coursename + "\\" + SELECTED_ITEM);
if (ext == ".pdf")
{
PdfFormatProvider provider = new PdfFormatProvider();
provider.ImportSettings = PdfImportSettings.ReadOnDemand;
RadFixedDocument doc = provider.Import(stream);
j.view_doc(stream);
}
else if (ext == ".mp4")
{
File.WriteAllBytes(Directory.GetCurrentDirectory() + "\\" + Coursename + SELECTED_ITEM, SelectedFile);
j.set_path(Directory.GetCurrentDirectory() + "\\" + Coursename + SELECTED_ITEM);
}
}
}
}