private void OnUpdateContent(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest())
            {
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to update the rupee content files?", "Update Rupees", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            try {
                ContentReplacer.Replace();
                ContentReplacer.SaveXmlConfiguration();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Rupee content files successfully updated!", "Rupees Updated");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while updating rupee content files! Would you like to see the error?", "Patch Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
        }
        private void OnRestoreAndPatch(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result;

            if (!ValidPathTest())
            {
                return;
            }
            if (!File.Exists(Patcher.BackupPath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Error, "Could not find Terraria backup!", "Missing Backup");
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to restore Terraria from its backup and then patch it?", "Patch & Restore Terraria", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            if (File.Exists(Patcher.ExePath) && IL.GetAssemblyVersion(Patcher.BackupPath) < IL.GetAssemblyVersion(Patcher.ExePath))
            {
                result = TriggerMessageBox.Show(this, MessageIcon.Warning, "The backed up Terraria executable is an older game version. Are you sure you want to restore it?", "Older Version", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            if (!CheckSupportedVersion(Patcher.BackupPath))
            {
                return;
            }
            try {
                Patcher.Restore(false);
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while restoring Terraria! Would you like to see the error?", "Restore Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
                return;
            }
            try {
                Patcher.Patch();
                ContentReplacer.Replace();
                ContentReplacer.SaveXmlConfiguration();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully restored and patched!", "Terraria Repatched");
            }
            catch (AlreadyPatchedException) {
                TriggerMessageBox.Show(this, MessageIcon.Error, "The backup executable has already been patched by Rupee Replacer!", "Already Patched");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while patching Terraria! Would you like to see the error?", "Patch Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
            }
        }
Exemple #3
0
        public void ReplaceTest()
        {
            ContentReplacer target = new ContentReplacer(); // TODO: Initialize to an appropriate value

            byte[] source   = null;                         // TODO: Initialize to an appropriate value
            byte[] expected = null;                         // TODO: Initialize to an appropriate value
            byte[] actual;
            actual = target.Replace(source);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemple #4
0
        private byte[] PrepareContent(string filename)
        {
            // Prepare content parameters and their values
            // Parameters are <ProductName>, <StockCode> & <Barcode>
            // see afterParameterizing.LBL contents
            IContentParameters param = new ContentParameters();

            param.Add("<ProductName>", "My Sample Products");
            param.Add("<StockCode>", "PC-01");
            param.Add("<Barcode>", "8693332221117");

            // Read payload file
            IFileContentReader reader = new FileContentReader(filename);

            byte[] payload = reader.ReadAllAsByte();

            // Do the replacing
            IContentReplacer replacer = new ContentReplacer(param, Encoding.UTF8);

            return(replacer.Replace(payload));
        }
        //--------------------------------
        #region Patching

        private void OnPatch(object sender = null, RoutedEventArgs e = null)
        {
            MessageBoxResult result;

            if (!ValidPathTest())
            {
                return;
            }
            if (!File.Exists(Patcher.ExePath))
            {
                TriggerMessageBox.Show(this, MessageIcon.Error, "Could not find Terraria executable!", "Missing Exe");
                return;
            }
            result = TriggerMessageBox.Show(this, MessageIcon.Question, "Are you sure you want to patch the current Terraria executable?", "Patch Terraria", MessageBoxButton.YesNo);
            if (result == MessageBoxResult.No)
            {
                return;
            }
            if (!CheckSupportedVersion(Patcher.ExePath))
            {
                return;
            }
            try {
                Patcher.Patch();
                ContentReplacer.Replace();
                ContentReplacer.SaveXmlConfiguration();
                TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully patched!", "Terraria Patched");
            }
            catch (AlreadyPatchedException) {
                TriggerMessageBox.Show(this, MessageIcon.Error, "This executable has already been patched by Rupee Replacer! Use Restore & Patch instead.", "Already Patched");
            }
            catch (Exception ex) {
                result = TriggerMessageBox.Show(this, MessageIcon.Error, "An error occurred while patching Terraria! Would you like to see the error?", "Patch Error", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    ErrorMessageBox.Show(ex, true);
                }
            }
        }