Example #1
0
        Dictionary <string, string> WalkDirectoryTree(System.IO.DirectoryInfo root)
        {
            System.IO.FileInfo[] files = null;
            var fileMap = new Dictionary <string, string>();

            try
            {
                files = root.GetFiles("*.*");
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                txtList.Text += e.Message + "\n";
                return(fileMap);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                txtList.Text += e.Message + "\r\n";
                return(fileMap);
            }

            if (files != null)
            {
                var count = 0;
                progressBar.Maximum = files.Length;

                foreach (System.IO.FileInfo fi in files)
                {
                    count++;
                    if (fi.Name.Contains(".ini"))
                    { //Skip INI files
                        continue;
                    }
                    if (fi.Name == System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
                    { //Skip self EXE
                        continue;
                    }

                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    var md5 = UtilityLibrary.GetMD5(fi.FullName);
                    txtList.Text     += fi.Name + ": " + md5 + "\r\n";
                    progressBar.Value = count;
                    fileMap[fi.Name]  = md5;
                    txtList.Refresh();
                    updateTaskbarProgress();
                    Application.DoEvents();
                }
                //One final update of data
                progressBar.Value = count;
                txtList.Refresh();
                updateTaskbarProgress();
                Application.DoEvents();
            }
            return(fileMap);
        }
Example #2
0
        //Pass the working directory (or later, you can pass another directory) and it returns a hash if the file is found
        public static string GetEverquestExecutableHash(string path)
        {
            var di    = new System.IO.DirectoryInfo(path);
            var files = di.GetFiles("eqgame.exe");

            if (files == null || files.Length == 0)
            {
                return("");
            }
            return(UtilityLibrary.GetMD5(files[0].FullName));
        }
Example #3
0
        private void StartPatch()
        {
            Process[] pname = Process.GetProcessesByName("eqgame");
            if (pname.Length != 0)
            {
                MessageBox.Show("Everquest is running, please close it.");
                return;
            }

            if (isPatching)
            {
                return;
            }
            isPatching    = true;
            btnCheck.Text = "Cancel";

            txtList.Text = "Patching...";

            using (var input = File.OpenText("filelist.yml"))
            {
                var deserializerBuilder = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());

                var deserializer = deserializerBuilder.Build();

                filelist = deserializer.Deserialize <FileList>(input);
            }

            foreach (var entry in filelist.downloads)
            {
                Application.DoEvents();
                var path = entry.name.Replace("/", "\\");
                //See if file exists.
                if (!File.Exists(path) || isPatchForce)
                {
                    //Console.WriteLine("Downloading: "+ entry.name);
                    filesToDownload.Add(entry);
                    if (entry.size < 1)
                    {
                        totalBytes += 1;
                    }
                    else
                    {
                        totalBytes += entry.size;
                    }
                }
                else
                {
                    var md5 = UtilityLibrary.GetMD5(path);

                    if (md5.ToUpper() != entry.md5.ToUpper())
                    {
                        Console.WriteLine(entry.name + ": " + md5 + " vs " + entry.md5);
                        filesToDownload.Add(entry);
                        if (entry.size < 1)
                        {
                            totalBytes += 1;
                        }
                        else
                        {
                            totalBytes += entry.size;
                        }
                    }
                }
                Application.DoEvents();
                if (!isPatching)
                {
                    LogEvent("Patching cancelled.");
                    return;
                }
            }

            if (filelist.deletes != null && filelist.deletes.Count > 0)
            {
                foreach (var entry in filelist.deletes)
                {
                    if (File.Exists(entry.name))
                    {
                        LogEvent("Deleting " + entry.name + "...");
                        File.Delete(entry.name);
                    }
                    Application.DoEvents();
                    if (!isPatching)
                    {
                        LogEvent("Patching cancelled.");
                        return;
                    }
                }
            }

            if (filesToDownload.Count == 0)
            {
                LogEvent("Up to date with patch " + filelist.version + ".");
                progressBar.Maximum = progressBar.Value = 1;
                IniLibrary.instance.LastPatchedVersion = filelist.version;
                IniLibrary.Save();
                btnCheck.BackColor = SystemColors.Control;
                btnCheck.Text      = "Force Full Download";
                labelPerc.Text     = "Done";
                isPatching         = false;
                isDone             = true;
                isPatchForce       = false;
                return;
            }

            LogEvent("Downloading " + totalBytes + " bytes for " + filesToDownload.Count + " files...");
            curBytes = 0;

            if (!isAsync)
            {
                //progressBar.Maximum = totalBytes;
                progressBar.Maximum = 100;
                progressBar.Value   = 0;
                foreach (var entry in filesToDownload)
                {
                    //progressBar.Value = (curBytes > totalBytes) ? totalBytes : curBytes;
                    progressBar.Value = (curBytes > totalBytes) ? 100 : (int)((100d / totalBytes) * (curBytes));;
                    string url = filelist.downloadprefix + entry.name.Replace("\\", "/");
                    DownloadFile(url, entry.name);
                    curBytes += entry.size;
                    Application.DoEvents();
                    if (!isPatching)
                    {
                        LogEvent("Patching cancelled.");
                        return;
                    }
                }
                progressBar.Value = progressBar.Maximum;
                LogEvent("Complete! Press Play to begin.");
                IniLibrary.instance.LastPatchedVersion = filelist.version;
                IniLibrary.Save();
                btnCheck.BackColor = SystemColors.Control;
                btnCheck.Text      = "Force Full Download";
                labelPerc.Text     = "Done";
                isPatching         = false;
                isDone             = true;
                isPatchForce       = false;
            }
            else
            {
                progressBar.Maximum = 100;
                progressBar.Value   = 0;
                string path;

                foreach (var entry in filesToDownload)
                {
                    isAsyncDone = false;
                    path        = entry.name.Replace("/", "\\");
                    string url = filelist.downloadprefix + path;

                    LogEvent(path + "...");

                    DownloadFileUrl(url, entry.name);

                    while (!isAsyncDone)
                    {
                        Application.DoEvents();
                        if (isCancelled || isError)
                        {
                            return;
                        }
                    }
                }

                //progressBar.Value = progressBar.Maximum;
                LogEvent("Complete! Press Play to begin.");
                IniLibrary.instance.LastPatchedVersion = filelist.version;
                IniLibrary.Save();
                btnCheck.BackColor = SystemColors.Control;
                btnCheck.Text      = "Force Full Download";
                labelPerc.Text     = "Done";
                isPatching         = false;
                isDone             = true;
                isPatchForce       = false;
            }
        }
Example #4
0
        private void StartPatch()
        {
            if (isPatching)
            {
                return;
            }
            isPatching    = true;
            btnCheck.Text = "Cancel";

            txtList.Text = "Patching...";
            FileList filelist;

            using (var input = File.OpenText("filelist.yml"))
            {
                var deserializerBuilder = new DeserializerBuilder().WithNamingConvention(new CamelCaseNamingConvention());

                var deserializer = deserializerBuilder.Build();

                filelist = deserializer.Deserialize <FileList>(input);
            }
            int totalBytes = 0;
            List <FileEntry> filesToDownload = new List <FileEntry>();

            foreach (var entry in filelist.downloads)
            {
                Application.DoEvents();
                var path = entry.name.Replace("/", "\\");
                //See if file exists.
                if (!File.Exists(path))
                {
                    //Console.WriteLine("Downloading: "+ entry.name);
                    filesToDownload.Add(entry);
                    if (entry.size < 1)
                    {
                        totalBytes += 1;
                    }
                    else
                    {
                        totalBytes += entry.size;
                    }
                }
                else
                {
                    var md5 = UtilityLibrary.GetMD5(path);

                    if (md5.ToUpper() != entry.md5.ToUpper())
                    {
                        Console.WriteLine(entry.name + ": " + md5 + " vs " + entry.md5);
                        filesToDownload.Add(entry);
                        if (entry.size < 1)
                        {
                            totalBytes += 1;
                        }
                        else
                        {
                            totalBytes += entry.size;
                        }
                    }
                }
                Application.DoEvents();
                if (!isPatching)
                {
                    LogEvent("Patching cancelled.");
                    return;
                }
            }

            if (filelist.deletes != null && filelist.deletes.Count > 0)
            {
                foreach (var entry in filelist.deletes)
                {
                    if (File.Exists(entry.name))
                    {
                        LogEvent("Deleting " + entry.name + "...");
                        File.Delete(entry.name);
                    }
                    Application.DoEvents();
                    if (!isPatching)
                    {
                        LogEvent("Patching cancelled.");
                        return;
                    }
                }
            }

            if (filesToDownload.Count == 0)
            {
                LogEvent("Up to date with patch " + filelist.version + ".");
                progressBar.Maximum = progressBar.Value = 1;
                IniLibrary.instance.LastPatchedVersion = filelist.version;
                IniLibrary.Save();
                btnCheck.BackColor = SystemColors.Control;
                btnCheck.Text      = "Patch";
                return;
            }

            LogEvent("Downloading " + totalBytes + " bytes for " + filesToDownload.Count + " files...");
            int curBytes = 0;

            progressBar.Maximum = totalBytes;
            progressBar.Value   = 0;
            foreach (var entry in filesToDownload)
            {
                progressBar.Value = (curBytes > totalBytes) ? totalBytes : curBytes;
                string url = filelist.downloadprefix + entry.name.Replace("\\", "/");
                DownloadFile(url, entry.name);
                curBytes += entry.size;
                Application.DoEvents();
                if (!isPatching)
                {
                    LogEvent("Patching cancelled.");
                    return;
                }
            }
            progressBar.Value = progressBar.Maximum;
            LogEvent("Complete! Press Play to begin.");
            IniLibrary.instance.LastPatchedVersion = filelist.version;
            IniLibrary.Save();
            btnCheck.BackColor = SystemColors.Control;
            btnCheck.Text      = "Patch";
        }