public void TestSettingsValidationForFile()
        {
            var outFile = new LogWriterSettings
            {
                OutputToString = false,
                Structure      = LogWriterSettings.FormatStructure.SingleFile
            };

            ShouldThrow(outFile with {
                FileOrFolderOutPath = ""
            });
            ShouldThrow(outFile with {
                FileOrFolderOutPath = PretendNoExists()
            });
            ShouldNotThrow(outFile with {
                FileOrFolderOutPath = PretendExists()
            });

            outFile = outFile with
            {
                Structure = LogWriterSettings.FormatStructure.OneBankPerFile
            };

            ShouldThrow(outFile with {
                FileOrFolderOutPath = ""
            });
            ShouldThrow(outFile with {
                FileOrFolderOutPath = PretendNoExists()
            });
            ShouldThrow(outFile with {
                FileOrFolderOutPath = PretendExists()
            });
        }
            /// <summary>
            ///     Loads the logging settings from the specified XML element.
            /// </summary>
            /// <param name="element">The XML element to load from.</param>
            /// <param name="helper">The XML configuration helper being used.</param>
            internal void LoadFromXmlElement(XElement element, ConfigurationFileHelper helper)
            {
                if (element == null)
                {
                    return;
                }

                StartupLogLevels = helper.ReadLogLevelsAttributeOrDefault(
                    element,
                    "startupLevels",
                    new LogType[] { LogType.Info, LogType.Warning, LogType.Error, LogType.Fatal }
                    );

                //Load writers
                var logWritersElement = helper.GetRequiredElement(element, "logWriters");

                helper.ReadElementCollectionTo(
                    logWritersElement,
                    "logWriter",
                    e => {
                    LogWriterSettings s = new LogWriterSettings();
                    s.LoadFromXmlElement(e, helper);
                    return(s);
                },
                    LogWriters
                    );
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="LogConfigurationFile"/> class.
        /// </summary>
        public LogConfigurationFile()
        {
            mGlobalSettings = new Dictionary <string, string>();
            ApplicationName = Process.GetCurrentProcess().ProcessName;
            var writer = LogWriterConfiguration.Default;

            writer.IsDefault = true;             // ensures that the log writer configuration is removed, if some other is added
            LogWriterSettings.Add(writer);
        }
示例#4
0
 /// <summary>
 /// Generate a sample of assembly output with the given settings
 /// </summary>
 /// <param name="baseSettings">Existing settings to base this generation on</param>
 /// <returns>Output of assembly generation as text</returns>
 /// <remarks>
 /// This is handy for UI and other areas where you want to quickly demo what the effect
 /// will be of various setting changes. We'll use a built-in sample ROM as our data source.
 /// </remarks>
 public static LogCreatorOutput.OutputResult GetSampleAssemblyOutput(LogWriterSettings baseSettings)
 {
     var sampleRomData = SampleRomData.CreateSampleData();
     var lc            = new LogCreator
     {
         Settings = baseSettings with
         {
             Structure           = LogWriterSettings.FormatStructure.SingleFile,
             FileOrFolderOutPath = "",
             OutputToString      = true,
             RomSizeOverride     = sampleRomData.OriginalRomSizeBeforePadding,
         },
示例#5
0
    public bool WriteAssemblyOutputIfSettingsValid(LogWriterSettings settingsToUseAndSave)
    {
        if (settingsToUseAndSave == null || !settingsToUseAndSave.IsValid(fs))
        {
            return(false);
        }

        UpdateExportSettings(settingsToUseAndSave);
        WriteAssemblyOutput();

        return(true);
    }
示例#6
0
        private void WriteAssemblyOutput(LogWriterSettings settings, bool showProgressBarUpdates = false)
        {
            var lc = new LogCreator()
            {
                Settings = settings,
                Data     = Project.Data,
            };

            LogCreator.OutputResult result = null;
            DoLongRunningTask(delegate { result = lc.CreateLog(); }, "Exporting assembly source code...");

            ProjectView.OnExportFinished(result);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="LogConfigurationFile"/> by copying another instance.
 /// </summary>
 /// <param name="other">Log configuration file to copy.</param>
 public LogConfigurationFile(LogConfigurationFile other)
 {
     if (other == null)
     {
         throw new ArgumentNullException(nameof(other));
     }
     mGlobalSettings = new Dictionary <string, string>(other.mGlobalSettings);
     ApplicationName = other.ApplicationName;
     LogWriterSettings.AddRange(other.LogWriterSettings);             // log writer settings are immutable, so no copy needed
     foreach (var kvp in other.ProcessingPipelineStageSettings)
     {
         ProcessingPipelineStageSettings.Add(kvp.Key, new Dictionary <string, string>(kvp.Value));
     }
 }
        private static void Run(LogWriterSettings settings, bool shouldThrow)
        {
            var validateShould = new LogWriterSettingsTestValidator()
                                 .Invoking(x => x.ValidateAndThrow(settings)).Should();

            if (shouldThrow)
            {
                validateShould.Throw <ValidationException>();
            }
            else
            {
                validateShould.NotThrow();
            }
        }
示例#9
0
        public static LogCreator.OutputResult ExportAssembly(Data inputRom)
        {
            var settings = new LogWriterSettings();

            settings.SetDefaults();
            settings.OutputToString = true;
            settings.Structure      = LogCreator.FormatStructure.SingleFile;

            return(new LogCreator()
            {
                Data = inputRom,
                Settings = settings,
            }.CreateLog());
        }
示例#10
0
 static void Main()
 {
     Program.Log = new LogFile(LogWriterSettings.Default());
     LogHelper.Add(Program.Log);
     LogHelper.Write(LogWriterLevel.MANDATORY, LogWriterIO.START, "██╗      █████╗ ███████╗██╗   ██╗     ██████╗ ████████╗ █████╗ ██╗  ██╗██╗   ██╗ | Product Lazy Otaku");
     LogHelper.Write(LogWriterLevel.MANDATORY, LogWriterIO.EMPTY, "██║     ██╔══██╗╚══███╔╝╚██╗ ██╔╝    ██╔═══██╗╚══██╔══╝██╔══██╗██║ ██╔╝██║   ██║ | Version 1.0.0.0");
     LogHelper.Write(LogWriterLevel.MANDATORY, LogWriterIO.EMPTY, "██║     ███████║  ███╔╝  ╚████╔╝     ██║   ██║   ██║   ███████║█████╔╝ ██║   ██║ | Author  Anderson Breder");
     LogHelper.Write(LogWriterLevel.MANDATORY, LogWriterIO.EMPTY, "██║     ██╔══██║ ███╔╝    ╚██╔╝      ██║   ██║   ██║   ██╔══██║██╔═██╗ ██║   ██║ | UUID    ff5bae169281478e8de1687fdf319d82");
     LogHelper.Write(LogWriterLevel.MANDATORY, LogWriterIO.EMPTY, "███████╗██║  ██║███████╗   ██║       ╚██████╔╝   ██║   ██║  ██║██║  ██╗╚██████╔╝ | Repo    github.com/andbreder/LazyOtaku");
     LogHelper.Write(LogWriterLevel.MANDATORY, LogWriterIO.CLOSE, "╚══════╝╚═╝  ╚═╝╚══════╝   ╚═╝        ╚═════╝    ╚═╝   ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝  | All rights reserved © 2021");
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new Views.frmMain());
 }
示例#11
0
        public ExportDisassembly(Project project)
        {
            this.project = project;
            settings     = project.LogWriterSettings; // copy

            if (settings.Validate() != "")
            {
                settings.SetDefaults();
            }

            InitializeComponent();
            UpdateUiFromProjectSettings();
            RegenerateSampleOutput();
        }
        private static void TestDirect()
        {
            var outFile = new LogWriterSettings
            {
                OutputToString = false,
                Structure      = LogWriterSettings.FormatStructure.SingleFile
            };

            var validationFailures = new LogWriterSettingsTestValidator().Validate(outFile with {
                FileOrFolderOutPath = ""
            });

            validationFailures.IsValid.Should()
            .BeFalse("should have failed the check", validationFailures.ToString());
        }
示例#13
0
    public void UpdateExportSettings(LogWriterSettings selectedSettings)
    {
        if (Project == null)
        {
            return;
        }

        var projectHadUnsavedChanges = Project.Session?.UnsavedChanges ?? false;
        var exportSettingsChanged    = !Project.LogWriterSettings.Equals(selectedSettings);

        Project.LogWriterSettings = selectedSettings;

        if (Project.Session != null && exportSettingsChanged && !projectHadUnsavedChanges)
        {
            Project.Session.UnsavedChanges = true;
        }
    }
 private static void ShouldNotThrow(LogWriterSettings settings) => Run(settings, false);
 private static void ShouldThrow(LogWriterSettings settings) => Run(settings, true);
示例#16
0
        public void UpdateExportSettings(LogWriterSettings selectedSettings)
        {
            // TODO: ref readonly or similar here, to save us an extra copy of the struct?

            Project.LogWriterSettings = selectedSettings;
        }
示例#17
0
        public void TestAFewLines()
        {
            var expectedRaw =
                //          label:       instructions                         ;PC    |rawbytes|ia
                "                        lorom                                ;      |        |      ;  \r\n" +
                "                                                             ;      |        |      ;  \r\n" +
                "                                                             ;      |        |      ;  \r\n" +
                "                        ORG $808000                          ;      |        |      ;  \r\n" +
                "                                                             ;      |        |      ;  \r\n" +
                "           CODE_808000: LDA.W Test_Data,X                    ;808000|BD5B80  |80805B;  \r\n" +
                "                        STA.W $0100,X                        ;808003|9D0001  |800100;  \r\n" +
                "           Test22:      DEX                                  ;808006|CA      |      ;  \r\n" +
                "                        BPL CODE_808000                      ;808007|10F7    |808000;  \r\n" +
                "                                                             ;      |        |      ;  \r\n" +
                "                        Test_Data = $80805B                  ;      |        |      ;  \r\n";

            var expectedOut = ParseAll(expectedRaw);

            var inputData = new Data
            {
                Labels = new ObservableDictionary <int, Label>
                {
                    { 0x808000 + 0x06, new Label {
                          Name = "Test22"
                      } },
                    { 0x808000 + 0x5B, new Label {
                          Name = "Test_Data", Comment = "Pretty cool huh?"
                      } },
                    // the CODE_XXXXXX labels are autogenerated
                },
                RomMapMode = RomMapMode.LoRom,
                RomSpeed   = RomSpeed.FastRom,
                RomBytes   =
                {
                    // --------------------------
                    // highlighting a particular section here
                    // we will use this for unit tests as well.

                    // CODE_808000: LDA.W Test_Data,X
                    new RomByte {
                        Rom = 0xBD, TypeFlag = Data.FlagType.Opcode, MFlag = true, Point = Data.InOutPoint.InPoint, DataBank = 0x80, DirectPage = 0x2100
                    },
                    new RomByte {
                        Rom = 0x5B, TypeFlag = Data.FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100
                    },                                                                                                // Test_Data
                    new RomByte {
                        Rom = 0x80, TypeFlag = Data.FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100
                    },                                                                                                // Test_Data

                    // STA.W $0100,X
                    new RomByte {
                        Rom = 0x9D, TypeFlag = Data.FlagType.Opcode, MFlag = true, DataBank = 0x80, DirectPage = 0x2100
                    },
                    new RomByte {
                        Rom = 0x00, TypeFlag = Data.FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100
                    },
                    new RomByte {
                        Rom = 0x01, TypeFlag = Data.FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100
                    },

                    // DEX
                    new RomByte {
                        Rom = 0xCA, TypeFlag = Data.FlagType.Opcode, MFlag = true, DataBank = 0x80, DirectPage = 0x2100
                    },

                    // BPL CODE_808000
                    new RomByte {
                        Rom = 0x10, TypeFlag = Data.FlagType.Opcode, MFlag = true, Point = Data.InOutPoint.OutPoint, DataBank = 0x80, DirectPage = 0x2100
                    },
                    new RomByte {
                        Rom = 0xF7, TypeFlag = Data.FlagType.Operand, DataBank = 0x80, DirectPage = 0x2100
                    },

                    // ------------------------------------
                }
            };

            var settings = new LogWriterSettings();

            settings.SetDefaults();
            settings.OutputToString = true;
            settings.Structure      = LogCreator.FormatStructure.SingleFile;

            var lc = new LogCreator()
            {
                Data     = inputData,
                Settings = settings,
            };

            var result = lc.CreateLog();

            Assert.True(result.LogCreator != null);
            Assert.True(result.OutputStr != null);
            Assert.True(result.ErrorCount == 0);

            var actualOut = ParseAll(result.OutputStr);

            Assert.Equal(expectedOut.Count, actualOut.Count);

            for (var i = 0; i < expectedOut.Count; ++i)
            {
                Assert.Equal(expectedOut[i], actualOut[i]);
            }

            Assert.True(expectedOut.SequenceEqual(actualOut));
        }
示例#18
0
        public static string?Validate(this LogWriterSettings @this)
        {
            var results = new LogWriterSettingsValidator().Validate(@this);

            return(!results.IsValid ? results.ToString() : null);
        }
示例#19
0
 public static LogWriterSettings GetDefaultsIfInvalid(this LogWriterSettings @this) =>
 @this.IsValid() ? @this : new LogWriterSettings();
示例#20
0
 public static bool IsValid(this LogWriterSettings @this) =>
 @this.Validate() != null;