I have just started programming in C# and I have a project I have been working on. first off i'm a video game programmer so I tend to not do visual things like C# so i'm a bit clueless and right now i'm trying to build a game launcher using C#. Now i think I got all the coding in place, but the problem is for some reason it wont check online files like it is suppose to so it wont check the version of the program i'm running, and then it wont download patch files either. Well i think the code might explain it better after looking at it.
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using System.Net;
namespace Divine_Shadows
{
public partial class DSL : Form
{
public DSL()
{
InitializeComponent();
}
public WebClient update = new WebClient();
public FastZip zip = new FastZip();
private void DSL_Load(object sender, EventArgs e)
{
decimal Version = 0.0m;
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.divineshadowsonline.com/game/version.txt");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding(1252));
string Online = "0.0";
Online = sr.ReadToEnd();
if (Version >= Convert.ToDecimal(Online))
{
File_Progress_Title.Text = "100%";
Total_Progress_Title.Text = "100%";
}
else
{
VersionOld.Visible = true;
}
}
update.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback);
update.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
Update_Status.Text = "Updating...";
while (update.IsBusy)
{
Application.DoEvents();
}
update.DownloadFileAsync(new Uri("http://www.divineshadowsonline.com/game/updates/patch.zip"), @"C:\patch.zip");
Any and all help to let me know what i'm doing wrong will be greatly appreciated. And if you need to see an image of the launcher program let me know so I can et a screenshot so you can get an better idea of what the code is suppose to do.
vcdebugger
October 8th, 2009, 12:41 AM
can you clearly break up your problem in to smaller ones ?
Also where are you creating the worker thread Update in your code ?
dog199200
October 8th, 2009, 12:49 AM
well to break it down the best I can. The progress bar Wont Work, the program isn't sending out to check the program version like it should, and the patching system ain't working. So basically anything that has to do with reaching out for internet files wont work.
Also i'm not sure what you mean by update thread. The main patching system is done with ICSharpCode SharpZip which is suppose to look for the zip file in my server, downloads it, and then extracts it, overriding the old files, but it ain't working at all. Then the Progress Bar is suppose to work alo0ng side the patching. Then the version this is what is the trigger. What its suppose to do is look for a file on my server (http://www.divineshadowsonline.com/game/version.txt) and then checks it with the file versions within the program and if the files are older, it then activates the patching tool to get the files. but none of it is working at all.
dog199200
October 8th, 2009, 04:41 PM
I've made a few adjustments to the code above so here is the updated code. Its still don't work, but its been formatted better this time.
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using System.Net;
using System.Text;
namespace Divine_Shadows
{
public partial class DSL : Form
{
public DSL()
{
InitializeComponent();
}
private void DSL_Load(object sender, System.EventArgs e)
{
WebClient update = new WebClient();
decimal Version = 0.1m;
decimal Online = 0.1m;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.divineshadowsonline.com/game/version.txt");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252));
Online = Convert.ToDecimal(sr.ReadToEnd());
where are the following things declared in your code ?
File_Progress_Title.Text = "100%";
Total_Progress_Title.Text = "100%";
VersionOld.Visible = false;
VersionNew.Visible = true;
that all are names assigned to labels, which are part of the design code. But I found out my problem was that the DSL_Load didn't get called in the design files, so I got that working, but here is the new code I have working:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using System.Net;
using System.Text;
namespace Divine_Shadows
{
public partial class DSL : Form
{
public DSL()
{
this.InitializeComponent();
}
public WebClient update = new WebClient();
public FastZip zip = new FastZip();
private void DSL_Load(object sender, EventArgs e)
{
decimal Version = 0.1m;
decimal Online = 0.1m;
string vernumber = "ver. 1.0";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.divineshadowsonline.com/game/version.txt");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252));
Online = Convert.ToDecimal(sr.ReadToEnd());
The problem is it finds the fine and downloads it to the right place, but it doesn't extract it. And since I got the main idea from another code, i'm not sure if i'm going things right, but here are the lines related to finding the file, downloading it and are suppose to extract the file.
but if the last one keep causing the error after the file fully downloads, so i'm sure its the problem.
vcdebugger
October 9th, 2009, 12:19 AM
so you mean to say private void DSL_Load(object sender, EventArgs e) was not getting called?
what did you change in your designer file to get it work ?
dog199200
October 9th, 2009, 12:34 AM
I just needed to add this:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DSL));
vcdebugger
October 9th, 2009, 12:37 AM
cheers! :)
dog199200
October 9th, 2009, 12:43 AM
yea but i still have a problem or two here and there, but at least its downloading the patch now, i just need to figure out why it wont extract the file to where I want it extracted to.... Then I need to figure out how to get one progress bar to track the files download and then have the other track the files extraction process....
vcdebugger
October 9th, 2009, 12:50 AM
If it is problem with Zipping/Unzipping then you need to check out with the code related to that.
For the progress Bar display you need to attach that control to one of the form and set the visible field to true.
dog199200
October 9th, 2009, 12:55 AM
well I got the bars in place, umm this might help some to give you an idea what i want done with the bars:
The top one will check the downloading progress and the other will tell the unzipping progress. I got the downloading process to work, but the part of the code that does the unzipping progress wont let me setup a progress bar in it without causing an error.
vcdebugger
October 9th, 2009, 01:21 AM
I got the downloading process to work, but the part of the code that does the unzipping progress wont let me setup a progress bar in it without causing an error.
show the source code you have tried and what specific error is it showing ?
dog199200
October 9th, 2009, 01:44 AM
well for the over all source code i'm using ICSharpCode.SharpZipLib.Zip as a reference which is a C# compiling core system. This is what is suppose to extract the files:
but I have no idea what to really use. When i found the code it looked like this:
zip.ExtractZip("", Application.StartupPath.ToString(), "");
so I assumed the first set fo "s is the file and the second is either the files location of the extraction location, but neither work, all I know is if you don't end the last one with a trailing slash it screws up the Application.Run(new DSL()); function under the Program file.
vcdebugger
October 9th, 2009, 01:52 AM
Is ICSharpCode.SharpZipLib.Zip is a library or dll ?
Do you have the source code for it ?
what is the return type of Zip.ExtractZip(....) function ?
Why dont you check the return type of it and see was the function successfull or not ?
If you have the source code then try to put break point and trace it through as to why this Zip function is failing
dog199200
October 9th, 2009, 02:03 AM
ICSharpCode.SharpZipLib.Zip is a .dll, its used as a reference to the main source. I have the dll compiled and set as a internal reference in the source, and still got the main source.
Going by what I think you mean, the return type is a strong, but i know it needs 3 arguments unless it gives me an error. And i'm still completely new at all this, I have no idea how to check the return type, the thing is though it seems to get to the point and then just stop most of the time, without giving an error or a reason for stopping.
Also I have looked at the coding examples they provided from the source on how to do the extraction setup, and they had like 7 arguments in it, all where just nulled out strings.
vcdebugger
October 9th, 2009, 02:17 AM
Is the dll written in VC++ or C# ?
If you have source of the Zip dll then why dont you pass the correct paramters by looking at the code ?
dog199200
October 9th, 2009, 02:22 AM
i'm going to say c# cause i had to open the files it was made out of in MS Visual C# and build the project in order to get the .dll, and I have everything they used is bs cause its all nulled out, it was just an example taht was never meant to work.
Edit: Ok I think I found something, this is what they have, i'm testing it right now:
string tempFilePath = GetTempFilePath();
Assert.IsNotNull(tempFilePath, "No permission to execute this test?");