02-01-2012, 09:28
, me no leecher @OrangePL
hey guys,
This is my first tutorial about C#, i will explain easy thing, which allows you make things like - check on updates, or just download bar.
You need:
Usage:
That's just easy code which checks number, and downloads file.
When you updated your program, you should re-upload it to SAME address and edit your prog.rtf file - make first line number bigger, and make same number in new program version. ( ex: string CurrentVersion = "22"; and first line in prog.rtf must be 22 )
First of all you need to make good interface, like:
Now make file prog.rtf and add into file, upload to your ftp(ex: www.blablalba.com/files/prog/ )
that file must have 2 lines: first line - version, second line - link to file
Ex:
Now need to make main checking.....
1. Double click on your "Check" button. Code will looks like:
2. Now need to add "file checking" thing which reads txt file.
NOTE: Current version value must be bigger than number in .txt file! That's main thing...
That's reads your rtf file from ftp and checks if current version less than num in file.
That's checks on update by checking values...
Now i need to add downloading thing. That's checks SECOND line and downloads it.
4. Making moving bar.
Now add:
That's already called.
Result code:
hey guys,
This is my first tutorial about C#, i will explain easy thing, which allows you make things like - check on updates, or just download bar.
You need:
- Visual C#
- FTP or file hoster
Usage:
That's just easy code which checks number, and downloads file.
When you updated your program, you should re-upload it to SAME address and edit your prog.rtf file - make first line number bigger, and make same number in new program version. ( ex: string CurrentVersion = "22"; and first line in prog.rtf must be 22 )
First of all you need to make good interface, like:
Now make file prog.rtf and add into file, upload to your ftp(ex: www.blablalba.com/files/prog/ )
that file must have 2 lines: first line - version, second line - link to file
Ex:
Code:
22
www.blalblalba.com/files/prog/myprog.rar
Now need to make main checking.....
1. Double click on your "Check" button. Code will looks like:
Code:
private void checkForUpdatesButton_Click(object sender, EventArgs e)
{
}
NOTE: Current version value must be bigger than number in .txt file! That's main thing...
That's reads your rtf file from ftp and checks if current version less than num in file.
Code:
private void checkForUpdatesButton_Click(object sender, EventArgs e)
{
string CurrentVersion = "21"; // CURRENT VERSION MUST BE LESS OR SAME
WebRequest request = WebRequest.Create("http://blablabla.com/files/prog/prog.rtf");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string NewestVersion = reader.ReadLine();
string Link = reader.ReadLine();
if (NewestVersion != CurrentVersion)
{
// continue
}
else
{
MessageBox.Show("Can't find any update.",
"Update");
}
}
Now i need to add downloading thing. That's checks SECOND line and downloads it.
Code:
WebRequest request = WebRequest.Create("http://blablalba.com/files/prog/prog.rtf");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string NewestVersion = reader.ReadLine();
string Link = reader.ReadLine();
MessageBox.Show("A new version is available! Version: " + NewestVersion + "",
"Updating");
WebClient wc = new WebClient();
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadFileAsync(new Uri(Link), @Directory.GetCurrentDirectory() + "/myprogram.rar");
4. Making moving bar.
Now add:
Code:
public void wc_DownloadProgressChanged(Object sender, DownloadProgressChangedEventArgs e)
{
progressBar2.Value = e.ProgressPercentage;
}
Result code:
Code:
private void checkForUpdatesButton_Click(object sender, EventArgs e)
{
string CurrentVersion = "21"; // CURRENT VERSION MUST BE LESS OR SAME
WebRequest request = WebRequest.Create("http://blablabla.com/files/prog/prog.rtf");
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string NewestVersion = reader.ReadLine();
string Link = reader.ReadLine();
if (NewestVersion != CurrentVersion)
{
string Link = reader.ReadLine();
MessageBox.Show("A new version is available! Version: " + NewestVersion + "",
"Updating");
WebClient wc = new WebClient();
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadFileAsync(new Uri(Link), @Directory.GetCurrentDirectory() + "/myprogram.rar");
}
else
{
MessageBox.Show("Can't find any update.",
"Update");
}
}
public void wc_DownloadProgressChanged(Object sender, DownloadProgressChangedEventArgs e)
{
progressBar2.Value = e.ProgressPercentage;
}