Exemplo n.º 1
0
        private void Button4_Click(object sender, EventArgs e)
        {
            //DeployPatches();
            var JetLocation = Path.Combine(Config.GAME_PATH, "Assets", "data.jet");
            var jv          = Config.GAME_JETVERSION;
            var backupName  = "org" + jv.ShortHand() + ".jet";
            var backupPath  = Path.Combine(Config.JETB_PATH, backupName);

            IncrementProgress();
            if (File.Exists(backupPath))
            {
                File.Delete(JetLocation);
                File.Copy(backupPath, JetLocation);
                IncrementProgress();
            }
            else
            {
                PatchDeployer.BackupDataJet(JetLocation, jv, Config.JETB_PATH, "org");
                IncrementProgress();
            }

            IncrementProgress();
            new Task(() =>
            {
                var r = PatchDeployer.PatchJet(JetLocation, jv, EnabledMods);

                if (r)
                {
                    BeginInvoke(new MethodInvoker(() => {
                        IncrementProgress(30);
                        MessageBox.Show("Finished Patching v" + jv.ShortHand() + "\nInstalled " + EnabledMods.Count.ToString() + " mods");
                    }));
                }
                else
                {
                    BeginInvoke(new MethodInvoker(() => {
                        IncrementProgress(30);
                        MessageBox.Show("There was an error patching.");
                    }));
                }
            }).Start();
        }
Exemplo n.º 2
0
        private void Button7_Click(object sender, EventArgs e)
        {
            string filePath = "";
            string mName    = "";
            string authr    = "";
            string fName    = "";

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter           = "Data.jet Files (*.jet)|*.jet";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    //Get the path of specified file
                    return;
                }
                filePath = openFileDialog.FileName;
            }

            while (mName == "")
            {
                mName = ShowDialog("Mod Name", "Input the name for the mod");
            }
            while (authr == "")
            {
                authr = ShowDialog("Author", "Input Author Name");
            }
            while (fName == "")
            {
                fName = ShowDialog("File Name", "Input the name for the mod to be saved as");
            }

            new Task(() =>
            {
                var modzip = PatchDeployer.ExtractJet(filePath, Config.GAME_JETVERSION, Path.Combine(Config.JETE_PATH, "modded", fName));

                IncrementProgress();
                var JetLocation = Path.Combine(Config.GAME_PATH, "Assets", "data.jet");
                IncrementProgress();
                var normZip = PatchDeployer.ExtractJet(JetLocation, Config.GAME_JETVERSION, Config.JETB_PATH);
                IncrementProgress();

                var modInfo            = new DirectoryInfo(modzip);
                JArray patchCollection = new JArray();
                foreach (FileInfo file in modInfo.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var m    = string.Join("\n", File.ReadAllLines(file.FullName));
                    string o = "";
                    try
                    {
                        o = string.Join("\n", File.ReadAllLines(file.FullName.Replace(modInfo.FullName, normZip)));
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(file.Name + " is a new file, and thus cannot be processed at this time");
                        continue;
                    }

                    if (m == o)
                    {
                        continue;
                    }
                    JObject thisPatch = new JObject();
                    var relativePath  = file.FullName.Split(new string[] { @"Assets\JSON\" }, StringSplitOptions.None).Last();
                    thisPatch.Add("file", relativePath);

                    JObject patches = new JObject();

                    //There is a difference.
                    try
                    {
                        JObject modded = JObject.Parse(m);
                        JObject defjsn = JObject.Parse(o);

                        var diffs = GetDifferences(modded, defjsn);
                        if (diffs.Count > 0)
                        {
                            foreach (JValue diff in diffs)
                            {
                                patches.Add(diff.Path, diff);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("There was a parsing error in " + file.Name);
                        continue;
                    }

                    thisPatch.Add("patch", patches);
                    patchCollection.Add(thisPatch);
                }

                var mod        = new JObject();
                mod["title"]   = mName;
                mod["author"]  = authr;
                mod["pool"]    = true;
                mod["patches"] = patchCollection;
                //Loop all the files over and compare, saving all JToken and File Pathes that concern us.
                IncrementProgress();
                File.WriteAllText(Path.Combine(Config.MODS_PATH, fName + ".btdbmod"), mod.ToString());
                IncrementProgress(50);
            }).Start();


            //Ask for a jet
            //Extract it
            //Take game clean copy, and extract
            //Compare EVERY file
            //Generate patches from
            //Ask user about Name/Author
            //Save mod into mod directory with filesafe name
        }