示例#1
0
        public LibraryDataDiff(LSLLibraryDataProvider left, LSLLibraryDataProvider right, IEnumerable <LSLLibrarySubsetDescription> subsetDescriptions)
        {
            Left  = left;
            Right = right;


            var lslLibrarySubsetDescriptions = subsetDescriptions as LSLLibrarySubsetDescription[] ?? subsetDescriptions.ToArray();

            var activeSubsets = lslLibrarySubsetDescriptions.Select(x => x.Subset).ToList();

            NotInLeft  = new LSLXmlLibraryDataProvider(activeSubsets);
            NotInRight = new LSLXmlLibraryDataProvider(activeSubsets);

            NotInLeft.AddSubsetDescriptions(lslLibrarySubsetDescriptions);
            NotInRight.AddSubsetDescriptions(lslLibrarySubsetDescriptions);
        }
示例#2
0
        private static void Run(TextWriter logFile)
        {
            Log.LogWriters.Add(Console.Out);

            if (logFile != null)
            {
                Log.LogWriters.Add(logFile);
            }


            var openSimBinPath = OpenOpenSimBinPath();


            var firestormScriptLibraries = OpenFirestormScriptLibrarys();


            IDocumentationProvider docProvider = null;


            foreach (var lib in firestormScriptLibraries)
            {
                var p = new FirestormDocumentationScraper(lib);
                if (docProvider == null)
                {
                    docProvider = p;
                }
                else
                {
                    docProvider = new CompoundDocumentationScraper(docProvider, p);
                }
            }


            var llsdKeywordsFile = OpenKeywordsFile();


            if (docProvider == null)
            {
                docProvider = new LLSDDocumentationScraper(llsdKeywordsFile);
            }
            else
            {
                docProvider = new CompoundDocumentationScraper(docProvider, new LLSDDocumentationScraper(llsdKeywordsFile));
            }


            var llsdData = new LLSDLibraryData(llsdKeywordsFile, new[] { "lsl" });



            var openSimLibraryReflectedTypeData = new OpenSimLibraryReflectedTypeData(openSimBinPath);

            var openSimData = new OpenSimDirectLibraryData(openSimLibraryReflectedTypeData);


            openSimData.IncludeScriptConstantContainerClass(openSimLibraryReflectedTypeData.ScriptBaseClass, new[] { "os-lsl" });
            openSimData.IncludeFunctionContainingInterface("ICM_Api", new[] { "os-country" });
            openSimData.IncludeFunctionContainingInterface("ILS_Api", new[] { "os-lightshare" });
            openSimData.IncludeFunctionContainingInterface("ILSL_Api", new[] { "os-lsl" });
            openSimData.IncludeFunctionContainingInterface("IOSSL_Api", new[] { "ossl" });
            openSimData.IncludeFunctionContainingInterface("IMOD_Api", new[] { "os-mod-api" });
            openSimData.IncludeAttributedModuleClass("ExtendedPhysics", new[] { "os-bullet-physics" });
            openSimData.IncludeAttributedModuleClass("JsonStoreScriptModule", new[] { "os-json-store" });

            //no longer has a script invocation attribute, so its there but wont be detected.
            //stuff like this is why the scraper program is so ugly and I don't spend to much time improving it.
            //openSimData.IncludeAttributedModuleClass("TempAttachmentsModule", new[] { "os-attach-temp" });



            var openSim = new LibraryDataSet(openSimData);

            //meh
            openSim.FunctionSet.Add(new LSLLibraryFunctionSignature(LSLType.Integer, "llAttachToAvatarTemp",
                                                                    new[] { new LSLParameterSignature(LSLType.Integer, "attachmentPoint", false) }));


            var activeLibrarySubsets = SubsetDescriptions.Select(x => x.Subset).ToList();


            var provider = new LSLXmlLibraryDataProvider(activeLibrarySubsets);

            provider.AddSubsetDescriptions(SubsetDescriptions);



            var wikiData = new SecondlifeWikiLibraryData(new[] { "lsl" });


            foreach (var func in wikiData.LSLFunctions())
            {
                Log.WriteLineWithHeader("[NOTICE, LSL WIKI FUNCTION ADDED]:",
                                        "The function {0}; was found on the LSL Wiki that was in not in the current set of functions, adding it.",
                                        func.SignatureString);


                IReadOnlyGenericArray <LSLLibraryFunctionSignature> overloads;
                if (openSim.OverloadsHashMap.TryGetValue(func.Name, out overloads))
                {
                    if (overloads.Any(x => x.SignatureEquivalent(func)))
                    {
                        func.Subsets.Add("os-lsl");
                    }
                }

                func.DocumentationString = docProvider.DocumentFunction(func);
                provider.DefineFunction(func);
            }


            foreach (var con in openSim.LSLFunctions())
            {
                var x = provider.GetLibraryFunctionSignatures(con.Name);

                if (x != null && x.Any(y => y.SignatureEquivalent(con)))
                {
                    continue;
                }

                con.DocumentationString = docProvider.DocumentFunction(con);


                provider.DefineFunction(con);
            }

            //the wiki is just wrong, the constant values are wrong there to much for comfort.
            foreach (var con in llsdData.LSLConstants())
            {
                if (openSim.LSLConstantExist(con.Name))
                {
                    var consant = openSim.LSLConstant(con.Name);

                    if (consant.Type == con.Type && consant.ValueString == con.ValueString)
                    {
                        con.Subsets.Add("os-lsl");
                    }
                }

                Log.WriteLineWithHeader("[NOTICE, LSL WIKI CONSTANT ADDED]:",
                                        "The constant {0}; was found on the LSL Wiki that was not in the current set of constants, adding it.",
                                        con.SignatureString);

                con.DocumentationString = docProvider.DocumentConstant(con);
                provider.DefineConstant(con);
            }


            foreach (var con in openSim.LSLConstants())
            {
                var consant = provider.GetLibraryConstantSignature(con.Name);
                if (consant != null)
                {
                    if (consant.Type == con.Type && consant.ValueString == con.ValueString)
                    {
                        continue;
                    }
                }

                con.DocumentationString = docProvider.DocumentConstant(con);
                provider.DefineConstant(con);
            }



            foreach (var ev in wikiData.LSLEvents())
            {
                Log.WriteLineWithHeader("[NOTICE, LSL WIKI EVENT ADDED]:",
                                        "The event {0}; was found on the LSL Wiki that was not in the current set of events, adding it.",
                                        ev.SignatureString);


                if (openSimLibraryReflectedTypeData.EventNames.Contains(ev.Name))
                {
                    ev.Subsets.AddSubsets("os-lsl");
                }


                ev.DocumentationString = docProvider.DocumentEvent(ev);
                provider.DefineEventHandler(ev);
            }


            foreach (var c in llsdData.LSLFunctions())
            {
                if (provider.LibraryFunctionExist(c.Name))
                {
                    continue;
                }

                if (openSim.LSLFunctionExist(c.Name))
                {
                    var overloads = openSim.LSLFunctionOverloads(c.Name).Where(x => x.ParameterCount == c.ParameterCount).ToList();

                    if (overloads.Any())
                    {
                        var osFunc = overloads.First();

                        c.Subsets.AddSubsets(osFunc.Subsets);
                        c.ModInvoke = osFunc.ModInvoke;
                    }
                }

                provider.DefineFunction(c);
            }


            foreach (var c in llsdData.LSLEvents())
            {
                if (provider.EventHandlerExist(c.Name))
                {
                    continue;
                }

                if (openSimLibraryReflectedTypeData.EventNames.Contains(c.Name))
                {
                    c.Subsets.AddSubsets("os-lsl");
                }

                provider.DefineEventHandler(c);
            }



            foreach (var c in openSim.LSLConstants().Where(x => !provider.LibraryConstantExist(x.Name)))
            {
                Log.WriteLineWithHeader("[NOTICE, OPENSIM CONSTANT ADDED]:",
                                        "The constant {0}; was found in the OpenSim binaries but was not in the current set of constants, adding it to the current set of data.",
                                        c.SignatureString);

                c.DocumentationString = docProvider.DocumentConstant(c);
                provider.DefineConstant(c);
            }



            MessageBox.Show("Select a place to save the generated LibLSLCC library data.",
                            "Select Library Data Save Path", MessageBoxButtons.OK, MessageBoxIcon.Information);

retrySave:



            var libraryDataWritterSettings = new XmlWriterSettings
            {
                Indent      = true,
                Encoding    = Encoding.Unicode,
                CloseOutput = true
            };


            var saveGeneratedLibraryDataDialog = new SaveFileDialog
            {
                CreatePrompt    = true,
                Filter          = "Library Data (*.xml) | *.xml",
                OverwritePrompt = true,
                Title           = "Select a place to save the library data",
                FileName        = "LibLSLCC_LibraryData.xml"
            };

            string libraryDataOutputFilePath = null;

            if (saveGeneratedLibraryDataDialog.ShowDialog() != DialogResult.OK || string.IsNullOrWhiteSpace(saveGeneratedLibraryDataDialog.FileName))
            {
                var dialogResult =
                    MessageBox.Show(
                        "Are you sure you wish to discard the generated library data? you did not select a file to save it in.",
                        "Discard Data?", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);

                if (dialogResult == DialogResult.No)
                {
                    goto retrySave;
                }
            }
            else
            {
                libraryDataOutputFilePath = saveGeneratedLibraryDataDialog.FileName;

                using (var file = XmlWriter.Create(saveGeneratedLibraryDataDialog.OpenFile(), libraryDataWritterSettings))
                {
                    provider.WriteXml(file, true);
                }
            }



            var runDiffDialogResult =
                MessageBox.Show(
                    "Would you like to DIFF the generated data with another set of LibLSLCC Library Data? (The data you just generated will be the 'Left' file).",
                    "Run Library Data DIFF", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (runDiffDialogResult == DialogResult.No)
            {
                return;
            }



            MessageBox.Show("Select a LibLSLCC Library Data XML File to be on the Right side of the DIFF.", "Select the 'Right' Library File",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);



retrySelectRightDiffOutput:

            var selectRightDialog = new OpenFileDialog
            {
                Filter          = "LibLSLCC Library Data (*.xml) | *.xml",
                CheckFileExists = true,
                Title           = "Select a LibLSLCC Library data file"
            };



            if (selectRightDialog.ShowDialog() != DialogResult.OK || string.IsNullOrWhiteSpace(selectRightDialog.FileName))
            {
                var dialogResult =
                    MessageBox.Show(
                        "You must select a LibLSLCC Library data file to be on the right side of the DIFF, " +
                        "click Retry to select again or Cancel to exit the program.",
                        "File Required", MessageBoxButtons.RetryCancel, MessageBoxIcon.Stop);

                if (dialogResult == DialogResult.Retry)
                {
                    goto retrySelectRightDiffOutput;
                }

                return;
            }


            var rightDiffLibraryDataProvider = new LSLXmlLibraryDataProvider(activeLibrarySubsets);

            rightDiffLibraryDataProvider.AddSubsetDescriptions(SubsetDescriptions);


            using (var file = XmlReader.Create(selectRightDialog.OpenFile(),
                                               new XmlReaderSettings {
                CloseInput = true
            }))
            {
                rightDiffLibraryDataProvider.FillFromXml(file);
            }

            var diff = new LibraryDataDiff(provider, rightDiffLibraryDataProvider, SubsetDescriptions);

            diff.Diff();


            var saveNotRightButInLeft =
                MessageBox.Show(
                    "Would you like to save a library data file representing what was in the generated data, but not in the Right DIFF File?",
                    "Save Added Library Element Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (saveNotRightButInLeft == DialogResult.Yes)
            {
retryNotInRightSave:

                var saveFileLibraryData = new SaveFileDialog
                {
                    CreatePrompt    = true,
                    Filter          = "LibLSLCC Library Data (*.xml) | *.xml",
                    OverwritePrompt = true,
                    Title           = "Select a place to save the added library elements data.",
                    FileName        = "GeneratedDataNotIn_" + selectRightDialog.SafeFileName
                };

                if (libraryDataOutputFilePath != null)
                {
                    saveFileLibraryData.FileName =
                        "DataIn_"
                        + Path.GetFileNameWithoutExtension(libraryDataOutputFilePath) +
                        "_ButNotIn_"
                        + selectRightDialog.SafeFileName;
                }
                else
                {
                    saveFileLibraryData.FileName =
                        "DataIn_GeneratedData_ButNotIn_" + selectRightDialog.SafeFileName;
                }


                if (saveFileLibraryData.ShowDialog() != DialogResult.OK || string.IsNullOrWhiteSpace(saveFileLibraryData.FileName))
                {
                    var dialogResult =
                        MessageBox.Show(
                            "Are you sure you wish to discard the DIFF file representing elements added to the generated library data? " +
                            "you did not select a file to save it in.",
                            "Discard Data?", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);

                    if (dialogResult == DialogResult.No)
                    {
                        goto retryNotInRightSave;
                    }
                }
                else
                {
                    using (var file = XmlWriter.Create(saveFileLibraryData.OpenFile(), libraryDataWritterSettings))
                    {
                        diff.NotInRight.WriteXml(file, true);
                    }
                }
            }



            var saveNotLeftButInRight =
                MessageBox.Show(
                    "Would you like to save a library data file representing what was in the Right DIFF file, but not in the generated library data?",
                    "Save Removed Library Element Data", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (saveNotLeftButInRight == DialogResult.Yes)
            {
retryNotInLeftSave:

                var saveFileLibraryData = new SaveFileDialog
                {
                    CreatePrompt    = true,
                    Filter          = "LibLSLCC Library Data (*.xml) | *.xml",
                    OverwritePrompt = true,
                    Title           = "Select a place to save the removed library elements data."
                };

                if (libraryDataOutputFilePath != null)
                {
                    saveFileLibraryData.FileName =
                        "DataIn_"
                        + Path.GetFileNameWithoutExtension(selectRightDialog.SafeFileName) +
                        "_ButNotIn_"
                        + Path.GetFileNameWithoutExtension(libraryDataOutputFilePath) + ".xml";
                }
                else
                {
                    saveFileLibraryData.FileName =
                        "DataIn_"
                        + Path.GetFileNameWithoutExtension(selectRightDialog.FileName) +
                        "_ButNotIn_GeneratedData" + ".xml";
                }

                if (saveFileLibraryData.ShowDialog() != DialogResult.OK || string.IsNullOrWhiteSpace(saveFileLibraryData.FileName))
                {
                    var dialogResult =
                        MessageBox.Show(
                            "Are you sure you wish to discard the DIFF file representing elements removed from the generated library data? " +
                            "you did not select a file to save it in.",
                            "Discard Data?", MessageBoxButtons.YesNo, MessageBoxIcon.Stop);

                    if (dialogResult == DialogResult.No)
                    {
                        goto retryNotInLeftSave;
                    }
                }
                else
                {
                    using (var file = XmlWriter.Create(saveFileLibraryData.OpenFile(), libraryDataWritterSettings))
                    {
                        diff.NotInLeft.WriteXml(file, true);
                    }
                }
            }
        }
示例#3
0
        private void Initialize(bool newInstance, string[] args)
        {
            ShowEndOfLine = AppSettings.Settings.ShowEndOfLine;
            ShowSpaces    = AppSettings.Settings.ShowSpaces;
            ShowTabs      = AppSettings.Settings.ShowTabs;


            var entryAssembly = Assembly.GetEntryAssembly();

            Title = "LSLCCEditor v" + entryAssembly.GetName().Version;


            var assembly = entryAssembly.Location;

            var appDirectory = Path.GetDirectoryName(assembly);


            _libraryDataProvider = new LSLXmlLibraryDataProvider(new[] { "lsl" });


            try
            {
                _libraryDataProvider.FillFromXmlDirectory(Path.Combine(appDirectory, "library_data"));
            }
            catch (LSLLibraryDataXmlSyntaxException err)
            {
                MessageBox.Show(this,
                                "There is a syntax error in one of your XML library data files and the application must close."
                                + LSLFormatTools.CreateNewLinesString(2) + err.Message,
                                "Library Data Syntax Error", MessageBoxButton.OK, MessageBoxImage.Error);

                Application.Current.Shutdown();
            }


            _codeValidatorStrategies = new LSLCodeValidatorStrategies
            {
                ExpressionValidator       = new LSLDefaultExpressionValidator(),
                StringLiteralPreProcessor = new LSLDefaultStringPreProcessor(),
                SyntaxErrorListener       = new WindowSyntaxErrorListener(this),
                SyntaxWarningListener     = new WindowSyntaxWarningListener(this),
                LibraryDataProvider       = _libraryDataProvider
            };


            foreach (var dataMenuItem in _libraryDataProvider.SubsetDescriptions.Select(subset => new MenuItem
            {
                StaysOpenOnClick = true,
                IsCheckable = true,
                Header = subset.Value.FriendlyName,
                Tag = subset.Value.Subset,
                ToolTip = new ToolTip {
                    Content = new TextBlock {
                        Text = subset.Value.Description
                    }
                }
            }))
            {
                dataMenuItem.Checked   += DataMenuItemOnChecked;
                dataMenuItem.Unchecked += DataMenuItemOnUnChecked;
                TabLibraryDataMenu.Items.Add(dataMenuItem);
            }


            FindDialogManager = new FindReplaceMgr
            {
                OwnerWindow        = this,
                InterfaceConverter = new IEditorConverter(),
                ShowSearchIn       = false
            };

            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    var tab = CreateEditorTab();
                    if (tab.OpenFileInteractive(arg))
                    {
                        EditorTabs.Add(tab);
                    }
                }
            }
            else
            {
                EditorTabs.Add(CreateEditorTab());
            }

            if (!newInstance)
            {
                StartOpenTabPipeServer();
            }


            _selectingStartupTabDuringWindowLoad = true;

            TabControl.SelectedIndex = 0;

            var initialTab = (EditorTab)TabControl.SelectedItem;

            initialTab.IsSelected = true;

            SetLibraryMenuFromTab(initialTab);


            FindDialogManager.CurrentEditor = initialTab.Content.EditControl.Editor;


            initialTab.Content.EditControl.Editor.TextChanged += Editor_OnTextChanged;

            EditRedoMenuItem.IsEnabled = initialTab.Content.EditControl.Editor.CanRedo;
            EditUndoMenuItem.IsEnabled = initialTab.Content.EditControl.Editor.CanUndo;


            _selectingStartupTabDuringWindowLoad = false;
        }