Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

C# Updater - SHA256 based


Joyce
 Share

Recommended Posts

It's another updater, this one compares hashes of files and decides whether or not to download the update that way though. Enjoy! I threw this together during today's breaks at work, don't expect it to magically catch all errors, it basically catches none and may crash if you do something wrong. I haven't written a full piece of documentation for it, probably never will. But if you need help with getting it to run just ask.

> Usage
> Preparing an Update
>
> 1. Open the Hash Calculator.
> 2. Select your Game Client folder (including the latest update, minus the patcher!)
> 3. Hit Go! and wait for it to finish.
> 4. Copy **output.xml** from the Hash Calculator folder to the folder you selected earlier and rename **output.xml** to **Checksums.xml**
> 5. Upload the entire folder you selected earlier to the location you pointed your updater to.
>
> Getting an Update
>
> 1. Make sure you have completed the previous steps, and configured your Patcher (see: https://github.com/Azurebeats/YAGP#configuration).
> 2. Run your patcher and sit back!

You can find the download and source over here: https://github.com/Azurebeats/YAGP
Link to comment
Share on other sites

@'artix5455':

> I don't get how this works, I am clueless XDDDD

Which part exactly do you not understand? 

@'Growlith1223':

> Looks good, joyce, nice job on making it! i'll try and see if i can spot any errors

There might be a couple! I've tested it a few times and it came out pretty well though. :) It can take a while to compare/download updates on very large clients though which -can- be a little annoying since it will do this every time it starts. (Of course you could edit it in such a way to only do this when a new version has been uploaded!)
Link to comment
Share on other sites

  • 1 month later...
Thanks Joyce, we're using this for our game. I prefer C# over PureBasic, the one we had was in VB6 then we went to PureBasic and now finally to C#. SHA256 is probably way better than our old method, which was using a CRC.PHP file in the webhost that anyone could run. It was pretty unsafe if people were aware of it, they could abuse it.
Link to comment
Share on other sites

  • 2 weeks later...
@'Helladen':

> Thanks Joyce, we're using this for our game. I prefer C# over PureBasic, the one we had was in VB6 then we went to PureBasic and now finally to C#. SHA256 is probably way better than our old method, which was using a CRC.PHP file in the webhost that anyone could run. It was pretty unsafe if people were aware of it, they could abuse it.

Oh neat! Never thought I'd see someone use it for something besides a small project! And seeing how you came from a similar system you should already be aware that it takes a little time to compare local files to remote hashes. :) I'll be sure to see what you make of it when the game comes out!

@'Dialectics':

> When will you people learn not to publicly expose fields, especially when they are collections.

@'jcsnider':

> Whenever Visual Studio refuses to compile due to publicly exposed fields :D

As far as I am aware I barely expose anything in this project, although I did miss a private on my Dictionary.
Link to comment
Share on other sites

We are actually going to change SHA-256 to CRC-32\. It is a better algorithm for this type of behavior. SHA-256 is better for security though. I plan to make it look really pretty, and I may end up open-source and pushing it to your source-code branch or making a new one based on it. I will of course put you in the credits. I was planning to make the type of hashing optional - but have a CRC.php included for those who prefer to use a webserver over a .EXE. It isn't that I can't code, I just don't like to reinvent the wheel. A lot of time is wasted by people trying to reinvent the wheel instead of working together to make great projects.
Link to comment
Share on other sites

Haha, that'd work. But wouldn't picking up something lighter (in regards to SHA) like MD5 work just as well (which .net already has a class for, much like SHA256) rather than using php files? More of a personal preference though, I do quite like keeping things together.

I agree lots of time is lost with folks creating different things that all end up doing the same thing though. Rooting for one guy's project for an engine right now, but seeing how he didn't want to tie it to any existing site or project I don't feel comfortable just throwing links around.. I do nudge him on Skype from time to time about his ideas though. Seems like an interesting project.
Link to comment
Share on other sites

  • 3 weeks later...
Yeah we refactored your updater a lot. Robin actually contributed massively to it as well. I think we're going to keep it closed-source, but I do thank you for the work. It helped get me into C#. I was on the fence for a long time messing around with the Authentication Server we had, but this really helped get me in for good. It looks almost entirely like a different program now, but it was a good spot to start off. I hate writing anything from scratch, I like a base to work with and to refactor it. We switched it from YAML to WinForms simply due to WinForms being a better choice for this type of software in our opinion.

The reason to use CRC-32 is simply due to what we used in the past. We use what has worked for us. :P
Link to comment
Share on other sites

@'Joyce':

> I saw, I may or may not have decompiled it. ;) And if Robin cursed at it tell him I'm sorry. :P
>
> Fair enough on the CRC32! Everyone has their own preferences regarding these things.

How did you decompile? :O I never released it to the public, maybe you downloaded it from the FTP directly. Robin doesn't mind much, he hates doing the grunt work.
Link to comment
Share on other sites

@'Helladen':

> How did you decompile?

Programs written with the .NET framework are (practically) fully decompilable to C#/VB.NET/CIL itself/IronPython/etc.

http://www.telerik.com/products/decompiler.aspx
http://www.jetbrains.com/decompiler/
http://www.red-gate.com/products/reflector/
http://wiki.sharpdevelop.net/ilspy.ashx
Link to comment
Share on other sites

I grabbed the executable and decompiled it. :P And yeah, it's rather simple to decompile any .Net application. Generally it takes very little work to get it to compile again unless whoever wrote it used some obscure assemblies. I tend to use ILSpy when I look at how someone wrote something, it's never a perfect representation of how the code was written by the original author but it works well enough to see the general structure of an application and what it does.

http://ilspy.net/

And woo, I don't have to worry about Robin bashing down my door for being a complete fuckup just yet!
Link to comment
Share on other sites

  • 1 year later...
I do not know if someone uses this updater but I've a problem.

I followed the steps and it shows me this error message :

![](http://image.noelshack.com/fichiers/2016/51/1482177602-capture.png)

I looked at the source level but I do not master the C # so I do not find the problem

The part of the code where the error message appears:

```
private void CompareFiles(Object sender, DoWorkEventArgs e) {
var files = e.Argument as XElement;
var total = files.Elements().Count();
var current = 0;
this.ThreadSafe(() => { TotalProgress.Maximum = total; });
try {
foreach (var file in files.Elements()) {
var dir = AppDomain.CurrentDomain.BaseDirectory + "\\";
var name = file.Attribute("name").Value;
var rhash = file.Attribute("hash").Value;
var download = false;
this.ThreadSafe(() => { ContentLabel.Content = String.Format("Checking {0}...", name); });
if (!File.Exists(dir + name)) {
download = true;
} else {
using (var f = File.OpenRead(dir + name)) {
var lhash = f.ToSha256();
if (!String.Equals(lhash, rhash)) download = true;
}
}

if (download) {
this.ThreadSafe(() => { ContentLabel.Content = String.Format("Downloading {0}...", name); });
if (!Directory.Exists(System.IO.Path.GetDirectoryName(dir + name))) Directory.CreateDirectory(System.IO.Path.GetDirectoryName(dir + name));
if (File.Exists(dir + name)) File.Delete(dir + name);
using (var client = new WebClient()) {
try {
client.DownloadFile(Options["RemoteDirectory"] + name, dir + name);
} catch { ReportError(String.Format("An error has occured while attempting to download '{0}'", name)); return; }
}
}

current++;
this.ThreadSafe(() => { TotalProgress.Value = current; });
}
} catch { ReportError("A fatal error has occured while attempting to process the updates."); return; }
}
```
Someone can help me ?
Link to comment
Share on other sites

@'Escanor':

> I do not know if someone uses this updater but I've a problem.
>
> I followed the steps and it shows me this error message :
>
> ![](http://image.noelshack.com/fichiers/2016/51/1482177602-capture.png)
>
> I looked at the source level but I do not master the C # so I do not find the problem
>
> The part of the code where the error message appears:
>
> ```
> private void CompareFiles(Object sender, DoWorkEventArgs e) {
>            var files   = e.Argument as XElement;
>            var total   = files.Elements().Count();
>            var current = 0;
>            this.ThreadSafe(() => { TotalProgress.Maximum = total; });
>            try {
>                foreach (var file in files.Elements()) {
>                    var dir = AppDomain.CurrentDomain.BaseDirectory + "\\";
>                    var name = file.Attribute("name").Value;
>                    var rhash = file.Attribute("hash").Value;
>                    var download = false;
>                    this.ThreadSafe(() => { ContentLabel.Content = String.Format("Checking {0}...", name); });
>                    if (!File.Exists(dir + name)) {
>                        download = true;
>                    } else {
>                        using (var f = File.OpenRead(dir + name)) {
>                            var lhash = f.ToSha256();
>                            if (!String.Equals(lhash, rhash)) download = true;
>                        }
>                    }
>
>                    if (download) {
>                        this.ThreadSafe(() => { ContentLabel.Content = String.Format("Downloading {0}...", name); });
>                        if (!Directory.Exists(System.IO.Path.GetDirectoryName(dir + name))) Directory.CreateDirectory(System.IO.Path.GetDirectoryName(dir + name));
>                        if (File.Exists(dir + name)) File.Delete(dir + name);
>                        using (var client = new WebClient()) {
>                            try {
>                                client.DownloadFile(Options["RemoteDirectory"] + name, dir + name);
>                            } catch { ReportError(String.Format("An error has occured while attempting to download '{0}'", name)); return; }
>                        }
>                    }
>
>                    current++;
>                    this.ThreadSafe(() => { TotalProgress.Value = current; });
>                }
>            } catch { ReportError("A fatal error has occured while attempting to process the updates."); return; }
>        }
> ```
> Someone can help me ?

Change this line of the source:
```
} catch { ReportError("A fatal error has occured while attempting to process the updates."); return; }

```
to

```
} catch (Exception e) { ReportError("A fatal error has occured while attempting to process the updates.\r\n" + e.ToString()); return; }

```

recompile, run it again, and post the error here
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...