Jump to content
  • 0
OverLord

Thor Patcher and Auto-Updater

Question

Well ... I saw the Thor Patcher does not receive more updates and Windows 8.1 it is considered virus and unless it is started as "Administrator" he can not open the executable of the game when you click "Start". So, I was wondering if anyone would have the Thor source code to provide for the community update or someone could pass me some study material on how to unpack one GRF, add or remove files on it and compacting again. For I am thinking of creating a new auto-updater in C # if we can not solutions for Thor. :thx:

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Heya,

 

If you're going to do a patcher via C#, then you can download GRF Editor's sources over here : http://www.mediafire.com/download/7z6hkdag4ayj8rs

 

Add a reference to the dlls found in the "Output Libraries" folder to your project and you can use the following code to get you started :

 

using System;using System.Diagnostics;using System.IO;using System.Windows.Forms;using GRF.Core;using GRF.FileFormats.RgzFormat;using GRF.FileFormats.ThorFormat;using GRF.IO;using Utilities.Extension;namespace TestPatcher {    public partial class Form1 : Form {        public Form1() {            InitializeComponent();            Patch();        }        public void Patch() {            var patchesPath = @"C:Patches";            var patcherExeName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);            var roDirectory = Directory.GetCurrentDirectory();            var serverGrfName = @"server.grf";            var temporaryGrfName = @"temp.grf";            using (var output = new GrfHolder(temporaryGrfName, GrfLoadOptions.New)) {                foreach (var patchFile in Directory.GetFiles(patchesPath)) {                    if (patchFile.IsExtension(".grf", ".gpf")) {                        using (var grf = new GrfHolder(patchFile)) {                            output.QuickMerge(grf);                        }                    }                    else if (patchFile.IsExtension(".rgz")) {                        using (var rgz = new Rgz(patchFile)) {                            if (rgz.Table.ContainsFile(patcherExeName)) {                                // Updating on this executable, do something...!                                throw new NotImplementedException();                            }                            foreach (var entry in rgz.Table) {                                entry.ExtractFromRelative(roDirectory);                            }                        }                    }                    else if (patchFile.IsExtension(".thor")) {                        using (var thor = new Thor(patchFile)) {                            if (thor.Header.UseGrfMerging) {                                string targetGrf = thor.Header.UseDefaultTargetGrf ? serverGrfName : thor.Header.TargetGrf;                                if (string.IsNullOrEmpty(targetGrf))                                    throw new Exception("THOR extraction failed : no target GRF identified.");                                if (String.Compare(serverGrfName, targetGrf, StringComparison.OrdinalIgnoreCase) == 0) {                                    output.QuickMerge(thor.ToGrfHolderQuick());                                }                                else {                                    using (var grf = new GrfHolder(targetGrf, GrfLoadOptions.OpenOrNew)) {                                        grf.QuickMerge(thor.ToGrfHolderQuick());                                    }                                }                            }                            else {                                if (thor.Table.ContainsFile(patcherExeName)) {                                    // Updating on this executable, do something...!                                    throw new NotImplementedException();                                }                                foreach (var entry in thor.Table) {                                    entry.ExtractFromRelative(roDirectory);                                }                            }                        }                    }                }                using (var serverGrf = new GrfHolder(serverGrfName, GrfLoadOptions.OpenOrNew)) {                    serverGrf.QuickMerge(output);                }            }            GrfPath.Delete(temporaryGrfName);        }    }}

 

Obviously this is not optimized and errors are not handled at all, but it yields good results nonetheless. I would definitely not recommend you to start from scratch to make a patcher.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.