Patcher for Rappelz Client

01/11/2017 17:39 .Nexitis#1
Hey, im learning C# right now.

im almost done and im working on the patcher.
For some reason i want to stick with the idea to compare local and online hash and update files where the hash doesn't match.
A friend suggested that it would be easier to compare byte size.

Does anyone know if that would work? For whatever reason my brain thinks that comparing hash is the only option.
01/15/2017 04:29 Maks19973#2
Use this to make MD5 Byte hash

public string GetMd5HashFromFile(string path)
{
byte[] hash = MD5.Create().ComputeHash(File.ReadAllBytes(path));
string sHash = BitConverter.ToString(hash).Replace("-",string.Empty);
return sHash.ToLower();
}
01/15/2017 19:58 SilentWisdom#3
No need to reinvent the wheel my friend, just check out my opensource git

[Only registered and activated users can see links. Click Here To Register...]

And to compare files for updating I use the following

Code:
protected void compareFiles()
        {
            guiInstance.UpdateStatus(0, "Checking client files...");
            GUI.Instance.UpdateProgressMaximum(0, FileList.Count);

            for (; currentIndex < FileList.Count; ++currentIndex)
            {
                guiInstance.UpdateProgressValue(0, currentIndex);

                Structures.IndexEntry file = FileList[currentIndex];
                bool download = false;

                guiInstance.UpdateStatus(1, string.Format("Checking file: {0}", file.FileName));

                if (file.IsLegacy)
                {
                    if (!File.Exists(resourceFolder + file.FileName) || (Hash.GetSHA512Hash(resourceFolder + file.FileName) != file.FileHash))
                    {
                        download = true;
                    }
                }
                else
                {
                    DataCore.Structures.IndexEntry fileEntry = Core.GetEntry(ref index, file.FileName);

                    if (fileEntry != null)
                    {
                        string fileHash = Core.GetFileSHA512(settings.GetString("clientdirectory"), Core.GetID(fileEntry.Name), fileEntry.Offset, fileEntry.Length, GetFileExtension(fileEntry.Name));

                        if (file.FileHash != fileHash)
                        {
                            guiInstance.UpdateStatus(1, string.Format("File: {0} is depreciated!", file.FileName));
                            download = true;
                        }
                    }
                }

                if (download)
                {
                    GUI.Instance.UpdateStatus(1, string.Format("Downloading {0}...", FileList[currentIndex].FileName));
                    doUpdate();
                }
            }
        }
The above snippet is from my public open source launcher system called "[Only registered and activated users can see links. Click Here To Register...]" which you are more than welcome to use or use as an example.