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;
            }
        }
Пример #2
0
        public void ContentReplacerConstructorTest1()
        {
            IContentParameters contentParameters = null; // TODO: Initialize to an appropriate value
            ContentReplacer    target            = new ContentReplacer(contentParameters);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Пример #3
0
        public void TestReplace()
        {
            var parser   = new TocParser();
            var replacer = new ContentReplacer();

            var toc = parser.MakeToc(content);

            var expected = @"Table of Content
 * [1. Introduction](#1-introduction)
 * [2. Configuration](#2-configuration)
   * [2.1 Stacked configuration principle](#21-stacked-configuration-principle)
   * [2.2 Simple changes](#22-simple-changes)";

            Create.Assert2().PrintIsSame(expected, toc);


            var newVersion = @"""
""Automatic `Asser.AreEqual()` and automatic `ToString()`.""
Like a JSON serializer on drugs


Table of Content
 * [1. Introduction](#1-introduction)
 * [2. Configuration](#2-configuration)
   * [2.1 Stacked configuration principle](#21-stacked-configuration-principle)
   * [2.2 Simple changes](#22-simple-changes)


# 1. Introduction

this is the intro
and so forth


# 2. Configuration

 StatePrinter is configurable. The configuration can be broken down to three parts each of which represents .

* `IFieldHarvester` deals with how/which fields are harvested from types. E.g. only public fields are printed.
Finally, culture specific printing of dates and numbers are supported.


## 2.1 Stacked configuration principle

The Stateprinter has a configuration object that for the e use. This is due to the FILO tems in the reverse order they lues.

```C#
public static Configuration GetStandardConfiguration()

## 2.2 Simple changes

The `Configuration` class should be rather self-documenting. 
var cfg = Confi""";

            Create.Assert().PrintIsSame(newVersion, replacer.TryReplaceToc(content, toc));

            // parsing the result again must yield the same result
            Assert.AreEqual(newVersion, replacer.TryReplaceToc(newVersion, parser.MakeToc(newVersion)));
        }
        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);
                }
            }
        }
Пример #5
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.");
        }
Пример #6
0
        /// <summary>
        /// 產生PDF報表
        /// </summary>
        /// <param name="set"></param>
        public static void PrintBill(/*BillSet set*/)
        {
            using PDFDoc pdfdoc = new PDFDoc();
            //pdftron.PDF.Convert.OfficeToPDF(pdfdoc, $"{ReportTemplate.TemplatePath}{ReportTemplate.BillTemplate}.docx", null);
            Page            page     = pdfdoc.GetPage(1);
            ContentReplacer replacer = new ContentReplacer();

            //SetData();
            //foreach (string key in Dic.Keys) replacer.AddString(key, Dic[key]);
            replacer.Process(page);
            //pdfdoc.Save($"{ReportTemplate.TemplateOutputPath}{ReportTemplate.ReceiptTemplate}{ReportTemplate.Resx}.pdf", SDFDoc.SaveOptions.e_linearized);
        }
Пример #7
0
        public void ExportPdf()
        {
            using PDFDoc pdfdoc = new PDFDoc();
            Convert.OfficeToPDF(pdfdoc, $"{ReportTemplate.TemplatePath}{ReportTemplate.ReceiptTemplate}.docx", null);
            Page            pg       = pdfdoc.GetPage(1);
            ContentReplacer replacer = new ContentReplacer();

            SetData();
            foreach (string key in Dic.Keys)
            {
                replacer.AddString(key, Dic[key]);
            }
            replacer.Process(pg);
            pdfdoc.Save($"{ReportTemplate.TemplateOutputPath}{ReportTemplate.ReceiptTemplate}{ReportTemplate.Resx}.pdf", SDFDoc.SaveOptions.e_linearized);
        }
Пример #8
0
        void Handle(string path)
        {
            var content = File.ReadAllText(path);

            var toc        = new TocParser().MakeToc(content);
            var newContent = new ContentReplacer().TryReplaceToc(content, toc);

            if (newContent != null && content != newContent)
            {
                Console.Write("    ... Updating");
                File.WriteAllText(path, newContent, Encoding.UTF8);
            }

            Console.WriteLine("");
        }
Пример #9
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);
                }
            }
        }
Пример #11
0
        public void ContentReplacerConstructorTest2()
        {
            ContentReplacer target = new ContentReplacer();

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
Пример #12
0
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Relative path to the folder containing test files.
            string input_path  = "../../TestFiles/";
            string output_path = "../../TestFiles/Output/";


            // The following example illustrates how to replace an image in a certain region,
            // and how to change template text.
            try
            {
                using (PDFDoc doc = new PDFDoc(input_path + "BusinessCardTemplate.pdf"))
                    using (ContentReplacer replacer = new ContentReplacer())
                    {
                        doc.InitSecurityHandler();

                        // first, replace the image on the first page
                        Page  page = doc.GetPage(1);
                        Image img  = Image.Create(doc, input_path + "peppers.jpg");
                        replacer.AddImage(page.GetMediaBox(), img.GetSDFObj());
                        // next, replace the text place holders on the second page
                        replacer.AddString("NAME", "John Smith");
                        replacer.AddString("QUALIFICATIONS", "Philosophy Doctor");
                        replacer.AddString("JOB_TITLE", "Software Developer");
                        replacer.AddString("ADDRESS_LINE1", "#100 123 Software Rd");
                        replacer.AddString("ADDRESS_LINE2", "Vancouver, BC");
                        replacer.AddString("PHONE_OFFICE", "604-730-8989");
                        replacer.AddString("PHONE_MOBILE", "604-765-4321");
                        replacer.AddString("EMAIL", "*****@*****.**");
                        replacer.AddString("WEBSITE_URL", "http://www.pdftron.com");
                        // finally, apply
                        replacer.Process(page);

                        doc.Save(output_path + "BusinessCard.pdf", 0);
                        Console.WriteLine("Done. Result saved in BusinessCard.pdf");
                    }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }


            // The following example illustrates how to replace text in a given region
            try
            {
                using (PDFDoc doc = new PDFDoc(input_path + "newsletter.pdf"))
                    using (ContentReplacer replacer = new ContentReplacer())
                    {
                        doc.InitSecurityHandler();

                        Page   page             = doc.GetPage(1);
                        Rect   target_region    = page.GetMediaBox();
                        string replacement_text = "hello hello hello hello hello hello hello hello hello hello";
                        replacer.AddText(target_region, replacement_text);
                        replacer.Process(page);

                        doc.Save(output_path + "ContentReplaced.pdf", 0);
                        Console.WriteLine("Done. Result saved in ContentReplaced.pdf");
                    }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Done.");
        }
        private void OnRestore(object sender = null, RoutedEventArgs e = null)
        {
            MessageBoxResult result;
            bool             cleanup = false;

            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, "Would you like to restore the current Terraria executable to its backup and cleanup the required files or just restore the backup?", "Restore Terraria", MessageBoxButton.YesNoCancel, "Cleanup & Restore", "Restore Only");
            if (result == MessageBoxResult.Cancel)
            {
                return;
            }
            cleanup = result == MessageBoxResult.Yes;
            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;
                }
            }
            try {
                Patcher.Restore(cleanup);
                bool someMissing = ContentReplacer.Restore();
                // Clean up directory and remove config file
                if (cleanup)
                {
                    string configPath = Path.Combine(Patcher.ExeDirectory, CoinReplacer.ConfigName);
                    string logPath    = Path.Combine(Patcher.ExeDirectory, ErrorLogger.LogName);
                    if (File.Exists(configPath))
                    {
                        File.Delete(configPath);
                    }
                    if (File.Exists(logPath))
                    {
                        File.Delete(logPath);
                    }
                }
                if (someMissing)
                {
                    TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria executable restored but some backup content files were missing!", "Missing Content");
                }
                else
                {
                    TriggerMessageBox.Show(this, MessageIcon.Info, "Terraria successfully restored!", "Terraria Restored");
                }
            }
            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);
                }
            }
        }
        //=========== SETTINGS ===========
        #region Settings

        /**<summary>Loads the application settings.</summary>*/
        private void LoadSettings()
        {
            Patcher.ExePath = Settings.Default.ExePath;
            if (string.IsNullOrEmpty(Patcher.ExePath))
            {
                Patcher.ExePath = "";
                if (!string.IsNullOrEmpty(TerrariaLocator.TerrariaPath))
                {
                    Patcher.ExePath = TerrariaLocator.TerrariaPath;
                }
            }
            Patcher.IsTMod = Settings.Default.IsTMod;

            var rupeeColors = (RupeeColors[])Enum.GetValues(typeof(RupeeColors));

            foreach (RupeeColors color in rupeeColors)
            {
                if (Settings.Default.Copper == color.ToString())
                {
                    ContentReplacer.Copper = color;
                }
                if (Settings.Default.Silver == color.ToString())
                {
                    ContentReplacer.Silver = color;
                }
                if (Settings.Default.Gold == color.ToString())
                {
                    ContentReplacer.Gold = color;
                }
                if (Settings.Default.Platinum == color.ToString())
                {
                    ContentReplacer.Platinum = color;
                }

                AddComboBoxItem(comboBoxCopper, color);
                AddComboBoxItem(comboBoxSilver, color);
                AddComboBoxItem(comboBoxGold, color);
                AddComboBoxItem(comboBoxPlat, color);
            }

            ContentReplacer.CoinGun    = Settings.Default.CoinGun;
            ContentReplacer.LuckyCoin  = Settings.Default.LuckyCoin;
            ContentReplacer.CoinRing   = Settings.Default.CoinRing;
            ContentReplacer.CoinPortal = Settings.Default.CoinPortal;

            // Try and load Terraria's current rupee configuration
            ContentReplacer.LoadXmlConfiguration();

            // Setup controls
            textBoxExe.Text = Patcher.ExePath;

            if (Patcher.IsTMod)
            {
                radioButtonTMod.IsChecked = true;
            }
            else
            {
                radioButtonVanilla.IsChecked = true;
            }

            if (ContentReplacer.CoinPortal)
            {
                portalTimer.Start();
            }

            comboBoxCopper.SelectedIndex = (int)ContentReplacer.Copper;
            comboBoxSilver.SelectedIndex = (int)ContentReplacer.Silver;
            comboBoxGold.SelectedIndex   = (int)ContentReplacer.Gold;
            comboBoxPlat.SelectedIndex   = (int)ContentReplacer.Platinum;

            checkBoxRupeeGun.IsChecked    = ContentReplacer.CoinGun;
            checkBoxLuckyRupee.IsChecked  = ContentReplacer.LuckyCoin;
            checkBoxRupeeRing.IsChecked   = ContentReplacer.CoinRing;
            checkBoxRupeePortal.IsChecked = ContentReplacer.CoinPortal;

            imagePortal.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Resources/Content/Images/RupeePortal" + ContentReplacer.Gold.ToString() + ".png"));
        }