Example #1
0
        private void AuthenticateVersion()
        {
            var ver       = GetScmpBlob <Shared.Scmp.Version>();
            var verNumber = Shared.Scmp.ScmpExtension.ToInt32(ver);

            var appVer       = new Version(Application.ProductVersion);
            var appVerNumber = appVer.ToInt32();

            var minVerNumber = m_minVersion.ToInt32();

            // Allow a range of versions
            if ((verNumber >= minVerNumber) && (verNumber <= appVerNumber))
            {
                // Send success message
                SendScmp(new Shared.Scmp.Success(SledPluginId));
            }
            else
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(
                        Localization.SledRemoteTargetErrorVersionMismatch,
                        appVer.Major, appVer.Minor,
                        m_minVersion.Major, m_minVersion.Minor,
                        ver.Major, ver.Minor));

                // Send failure message
                SendScmp(new Shared.Scmp.Failure(SledPluginId));
            }
        }
Example #2
0
        private void UpdateRemoteTargetComboBox()
        {
            try
            {
                // Add all targets to combo box
                m_remoteTargetComboBox.Items.Clear();
                foreach (var target in m_lstTargets)
                {
                    m_remoteTargetComboBox.Items.Add(target);
                }

                // Select the proper target
                var selTarget = SelectedTarget;
                if (selTarget != null)
                {
                    m_remoteTargetComboBox.SelectedItem = selTarget;
                }
                else if (m_remoteTargetComboBox.Items.Count > 0)
                {
                    m_remoteTargetComboBox.SelectedItem = m_remoteTargetComboBox.Items[0];
                }
                else
                {
                    m_remoteTargetComboBox.Text = string.Empty;
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledRemoteTargetErrorUpdatingComboBox, ex.Message));
            }
        }
Example #3
0
        /// <summary>
        /// Reads a DomObject from the given stream
        /// </summary>
        /// <param name="stream">Stream to read</param>
        /// <returns>Dom tree that was read</returns>
        public override DomObject Read(Stream stream)
        {
            // Read project settings
            DomObject rootProjDomObject = ReadInternal(stream);

            // Try and read temporary settings file
            DomObject rootTempDomObject = null;

            try
            {
                // Path to project file
                string szAbsProjPath = ((FileStream)stream).Name;
                // Path to hidden project temporary settings file
                string szAbsTempPath = Path.ChangeExtension(szAbsProjPath, m_extTmp);

                // Read from disk if file exists
                if (File.Exists(szAbsTempPath))
                {
                    using (FileStream file = new FileStream(szAbsTempPath, FileMode.Open, FileAccess.Read))
                    {
                        rootTempDomObject = ReadInternal(file);
                    }
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(SledMessageType.Error, SledUtil.TransSub(Localization.SledSharedLoadTempSettingsFileError, new string[] { ex.Message }));
            }

            // Combine project file with temporary settings file
            Combine(rootProjDomObject, rootTempDomObject);

            return(rootProjDomObject);
        }
        void IInitializable.Initialize()
        {
            if (IsInitialized)
            {
                return;
            }

            var networkPlugins = SledServiceInstance.GetAll <ISledNetworkPlugin>();

            m_lstPlugins.Clear();

            using (new SledOutDevice.BreakBlock())
            {
                foreach (var netPlugin in networkPlugins)
                {
                    // Add plugin to list
                    m_lstPlugins.Add(netPlugin);

                    // Report the plugin was found
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        SledUtil.TransSub(Localization.SledNetworkPluginLoaded, netPlugin.Protocol, netPlugin.Name));
                }
            }

            try
            {
                Initialized.Raise(this, EventArgs.Empty);
            }
            finally
            {
                IsInitialized = true;
            }
        }
Example #5
0
        private void EditorKeyPress(object sender, KeyPressEventArgs e)
        {
            if (!m_editor.ReadOnly)
            {
                return;
            }

            if ((s_debugService.Get != null) && s_debugService.Get.IsDebugging)
            {
                MessageBox.Show(
                    s_mainForm.Get,
                    Localization.SledCannotMakeChanges,
                    Localization.SledEditorLocked,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            else
            {
                // Quick hack for a feature Zindagi requested
                if (CanGetSourceControlToCheckOut(this))
                {
                    return;
                }

                // Otherwise show normal GUI
                var res =
                    MessageBox.Show(
                        s_mainForm.Get,
                        string.Format(
                            "{0}{1}{1}{2}",
                            Localization.SledFileReadOnly,
                            Environment.NewLine,
                            Localization.SledAttemptChangeFilePermissions),
                        Localization.SledFileReadOnly,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Error);

                if (res == DialogResult.Yes)
                {
                    try
                    {
                        File.SetAttributes(Uri.LocalPath, FileAttributes.Normal);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            s_mainForm.Get,
                            string.Format(
                                "{0}{1}{1}{2}",
                                Localization.SledFailChangePermissions,
                                Environment.NewLine,
                                SledUtil.TransSub(Localization.SledErrorWas, ex.Message)),
                            Localization.SledFileReadOnlyError,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #6
0
 /// <summary>
 /// Fill in contents for displaying on a GUI
 /// </summary>
 /// <param name="item"></param>
 /// <param name="info">structure to hold display information</param>
 public void GetInfo(object item, ItemInfo info)
 {
     info.Label       = Address;
     info.Checked     = Checked;
     info.Properties  = new[] { Name };
     info.IsLeaf      = false;
     info.Description = SledUtil.TransSub(Localization.SledLuaLuaState, Address);
     info.ImageIndex  = info.GetImageIndex(Atf.Resources.DataImage);
 }
Example #7
0
        /// <summary>
        /// Go to a specific word on a line in a file
        /// </summary>
        /// <param name="sd">document</param>
        /// <param name="szWord">word to find</param>
        /// <param name="iLine">line in document</param>
        /// <param name="iOccurence">if the word occurs multiple times on a line then this represents which occurence</param>
        /// <param name="bUseCsi">whether to use a "current statement indicator" or not</param>
        public void GotoLineWord(ISledDocument sd, string szWord, int iLine, int iOccurence, bool bUseCsi)
        {
            if (sd == null)
            {
                return;
            }

            // Bring this files tab to the front
            m_controlHostService.Show(sd.Control);

            try
            {
                if (iOccurence < 0)
                {
                    // Selecting whole line
                    sd.Editor.SelectLine(iLine);
                }
                else
                {
                    // Selecting part of line

                    // Try and select the word "name" on the line
                    var szLine = sd.Editor.GetLineText(iLine);

                    var iBeg = -1;
                    for (var i = 0; i < iOccurence; i++)
                    {
                        iBeg = szLine.IndexOf(szWord, iBeg + 1);
                    }

                    var iEnd = iBeg + szWord.Length - 1;

                    // Select
                    sd.Editor.SelectLine(iLine, iBeg, iEnd);
                }

                // Scroll to line
                sd.Editor.CurrentLineNumber = iLine;

                if (bUseCsi)
                {
                    sd.Editor.CurrentStatement(iLine, true);
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(
                        Localization.SledGotoLineError1,
                        iLine, Path.GetFileName(sd.Uri.LocalPath), ex.Message));
            }

            // Now force focus to actually see the cursor on the newly selected line
            sd.Control.Focus();
        }
Example #8
0
        private void NetPluginReadyEvent(ISledTarget target)
        {
            // Fake event

            SledOutDevice.OutLine(
                SledMessageType.Info,
                SledUtil.TransSub(Localization.SledTargetReady, target));

            // Fire event
            Ready.Raise(this, new SledDebugServiceEventArgs(target));
        }
Example #9
0
        /// <summary>
        /// Load a TTY filter file
        /// </summary>
        /// <param name="szAbsPath"></param>
        private void TryLoadTtyFilterFile(string szAbsPath)
        {
            try
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(szAbsPath);

                if (xmlDoc.DocumentElement == null)
                {
                    return;
                }

                var nodes = xmlDoc.DocumentElement.SelectNodes("TTYFilter");
                if ((nodes == null) || (nodes.Count == 0))
                {
                    MessageBox.Show(
                        this,
                        SledUtil.TransSub(Localization.SledTTYFilterNoNodesFoundInFile, szAbsPath),
                        Localization.SledTTYFilterFileError,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);

                    return;
                }

                foreach (XmlElement elem in nodes)
                {
                    var filter = new SledTtyFilter(
                        elem.GetAttribute("filter"),
                        ((int.Parse(elem.GetAttribute("result")) == 1) ? SledTtyFilterResult.Show : SledTtyFilterResult.Ignore),
                        Color.FromArgb(
                            int.Parse(elem.GetAttribute("txtColorR")),
                            int.Parse(elem.GetAttribute("txtColorG")),
                            int.Parse(elem.GetAttribute("txtColorB"))
                            ),
                        Color.FromArgb(
                            int.Parse(elem.GetAttribute("bgColorR")),
                            int.Parse(elem.GetAttribute("bgColorG")),
                            int.Parse(elem.GetAttribute("bgColorB"))
                            ));

                    TryAddTtyFilter(filter);
                }
            }
            catch
            {
                MessageBox.Show(
                    this,
                    SledUtil.TransSub(Localization.SledTTYFilterErrorLoadingFile, szAbsPath),
                    Localization.SledTTYFilterFileError,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
Example #10
0
        /// <summary>
        /// Validate the condition string has some text in it
        /// </summary>
        /// <param name="sender">object that fired the event</param>
        /// <param name="e">event arguments</param>
        private void BtnOkClick(object sender, EventArgs e)
        {
            // Need to make sure if a condition is being saved then it must be valid
            var bSyntaxCheckCondition = (ConditionEnabled || !string.IsNullOrEmpty(Condition));

            if (!bSyntaxCheckCondition)
            {
                return;
            }

            if (string.IsNullOrEmpty(Condition))
            {
                MessageBox.Show(
                    this,
                    Localization.SledBreakpointConditionErrorNoCondition,
                    Localization.SledBreakpointConditionError,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                // Make user enter valid stuff
                DialogResult = DialogResult.None;
            }
            else
            {
                // Check syntax
                if (m_plugin != null)
                {
                    // Wrap the condition in a function like how it would be when running in libluaplugin
                    var szCondFunc = string.Format("function libluaplugin_condfunc(){0}    return ({1}){0}end", Environment.NewLine, Condition);

                    // Format actual syntax checker to use
                    var szSyntaxCheckFunc =
                        string.Format("function libluaplugin_condfunc()\nreturn ({0})\nend", Condition);

                    var syntaxCheckerService = SledServiceInstance.Get <ISledSyntaxCheckerService>();

                    // Force a syntax check of the string
                    var errors = syntaxCheckerService.CheckString(m_plugin, szSyntaxCheckFunc);
                    if (errors.Any())
                    {
                        // Show error
                        MessageBox.Show(
                            this,
                            SledUtil.TransSub(
                                Localization.SledBreakpointConditionErrorVarArg,
                                Environment.NewLine, szCondFunc, errors.ElementAt(0).Error),
                            Localization.SledBreakpointConditionSyntaxError);

                        // Make user fix error
                        DialogResult = DialogResult.None;
                    }
                }
            }
        }
Example #11
0
        /// <summary>
        /// Open the project file and make sure the namespace is correct
        /// </summary>
        /// <param name="szAbsPath"></param>
        public static void CleanupProjectFileNamespace(string szAbsPath)
        {
            if (!File.Exists(szAbsPath))
            {
                return;
            }

            if (SledUtil.IsFileReadOnly(szAbsPath))
            {
                return;
            }

            try
            {
                Encoding encoding;
                string   szFileContents;

                using (Stream stream = new FileStream(szAbsPath, FileMode.Open, FileAccess.Read))
                {
                    using (var reader = new StreamReader(stream, true))
                    {
                        // Store encoding & read contents
                        encoding       = reader.CurrentEncoding;
                        szFileContents = reader.ReadToEnd();
                    }
                }

                if (!string.IsNullOrEmpty(szFileContents))
                {
                    const string szOldXmlNs = "xmlns=\"lua\"";
                    const string szNewXmlNs = "xmlns=\"sled\"";

                    if (szFileContents.Contains(szOldXmlNs))
                    {
                        szFileContents = szFileContents.Replace(szOldXmlNs, szNewXmlNs);

                        using (Stream stream = new FileStream(szAbsPath, FileMode.Create, FileAccess.Write))
                        {
                            using (var writer = new StreamWriter(stream, encoding))
                            {
                                writer.Write(szFileContents);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledProjectFilesErrorVerifyingNamespace, ex.Message, szAbsPath));
            }
        }
Example #12
0
        protected override void ShowHelpAbout()
        {
            try
            {
                var assem   = Assembly.GetAssembly(typeof(SledAboutService));
                var version = assem.GetName().Version.ToString();

                var title =
                    SledUtil.TransSub(Resources.Resource.HelpAboutTitleWithVersion, version);

                using (Image image = m_mainForm.Icon.ToBitmap())
                {
                    {
                        //
                        // WWS version
                        //

                        using (var richTextBox = new RichTextBox())
                        {
                            richTextBox.BorderStyle = BorderStyle.None;
                            richTextBox.ReadOnly    = true;

                            using (var strm = assem.GetManifestResourceStream(Resources.Resource.HelpAboutAssemblyPath))
                            {
                                if (strm != null)
                                {
                                    richTextBox.LoadFile(strm, RichTextBoxStreamType.RichText);
                                }

                                using (var dialog =
                                           new AboutDialog(
                                               title,
                                               ApplicationUrl,
                                               richTextBox,
                                               image,
                                               null,
                                               true))
                                {
                                    dialog.ShowDialog(m_mainForm);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledHelpAboutErrorException, ex.Message));
            }
        }
Example #13
0
        private void NetPluginConnectingEvent(ISledTarget target)
        {
            // Fake event

            m_curTarget = target;

            SledOutDevice.OutLine(
                SledMessageType.Info,
                SledUtil.TransSub(Localization.SledTargetConnectionNegotiating, target));

            // Fire event
            Connecting.Raise(this, new SledDebugServiceEventArgs(target));
        }
Example #14
0
        private void Connect(ISledTarget target)
        {
            CurrentlyHitBp = null;
            m_lastDebugCmd = DebugCommand.Default;

            try
            {
                Freeze();

                if (target == null)
                {
                    throw new NullReferenceException("Target is null!");
                }

                if (target.Plugin == null)
                {
                    throw new NullReferenceException("No network plugin found or specified!");
                }

                // Grab network plugin from target
                m_netPlugin = target.Plugin;

                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    SledUtil.TransSub(Localization.SledTargetConnectingTo, target));

                SetEndianness(Endian.Unknown);
                IsConnecting = true;
                m_recvBuf.Reset();

                CreateScmpLoggingFile();

                // Subscribe to events
                m_netPlugin.ConnectedEvent          += NetPluginConnectedEvent;
                m_netPlugin.DisconnectedEvent       += NetPluginDisconnectedEvent;
                m_netPlugin.DataReadyEvent          += NetPluginDataReadyEvent;
                m_netPlugin.UnHandledExceptionEvent += NetPluginUnHandledExceptionEvent;

                // Fire event
                DebugConnect.Raise(this, new SledDebugServiceEventArgs(target));

                // Try and connect
                m_netPlugin.Connect(target);
            }
            catch (Exception ex)
            {
                NetPluginUnHandledExceptionEvent(m_netPlugin, ex);
            }
        }
Example #15
0
        public void TransSub()
        {
            const string inputString1 = "%s0 %s1 %s2 %s3 %s4 %s5 %s6 %s7 %s8 %s9";
            const string inputString2 = "%s0 %s1 %s1 %s4";

            var trans1 = SledUtil.TransSub(inputString1, "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine");
            var trans2 = SledUtil.TransSub(inputString2, "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine");

            const string result1 = "zero one two three four five six seven eight nine";
            const string result2 = "zero one one four";

            Assert.AreEqual(0, string.Compare(trans1, result1));
            Assert.AreEqual(0, string.Compare(trans2, result2));
            Assert.That(string.Compare(trans1, trans2) != 0);
        }
Example #16
0
        private void NetPluginDisconnectedEvent(object sender, ISledTarget target)
        {
            try
            {
                m_recvBuf.Reset();

                SetEndianness(Endian.Unknown);

                IsConnected              = false;
                IsDebugging              = false;
                IsConnecting             = false;
                m_bAuthenticated         = false;
                IsUpdateInProgress       = false;
                CurrentlyHitBp           = null;
                IsCurrentlyHitBpActualBp = false;

                Disconnected.Raise(this, new SledDebugServiceEventArgs(target));

                // Update status text
                m_connectStatus.Text = Localization.SledDisconnected;

                if (target != null)
                {
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        SledUtil.TransSub(Localization.SledTargetDisconnectedFrom, target));
                }

                m_curTarget = null;

                // Unsubscribe from events & release resources
                m_netPlugin.ConnectedEvent          -= NetPluginConnectedEvent;
                m_netPlugin.DisconnectedEvent       -= NetPluginDisconnectedEvent;
                m_netPlugin.DataReadyEvent          -= NetPluginDataReadyEvent;
                m_netPlugin.UnHandledExceptionEvent -= NetPluginUnHandledExceptionEvent;
                m_netPlugin.Dispose();
                m_netPlugin = null;
            }
            finally
            {
                Thaw();
            }
        }
Example #17
0
        /// <summary>
        /// Try and save the TTY filter list to a file
        /// </summary>
        /// <param name="szAbsPath"></param>
        private void TrySaveTtyFilterFile(string szAbsPath)
        {
            // Generate Xml document to contain TTY filter list
            var xmlDoc = new XmlDocument();

            xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes"));
            var root = xmlDoc.CreateElement("TTYFilters");

            xmlDoc.AppendChild(root);

            foreach (var filter in m_lstTtyFilters)
            {
                var elem = xmlDoc.CreateElement("TTYFilter");
                elem.SetAttribute("filter", filter.Filter);
                elem.SetAttribute("txtColorR", filter.TextColor.R.ToString());
                elem.SetAttribute("txtColorG", filter.TextColor.G.ToString());
                elem.SetAttribute("txtColorB", filter.TextColor.B.ToString());
                elem.SetAttribute("bgColorR", filter.BackgroundColor.R.ToString());
                elem.SetAttribute("bgColorG", filter.BackgroundColor.G.ToString());
                elem.SetAttribute("bgColorB", filter.BackgroundColor.B.ToString());
                elem.SetAttribute("result", (filter.Result == SledTtyFilterResult.Show) ? "1" : "0");
                root.AppendChild(elem);
            }

            try
            {
                // Try to write to disk
                var xmlWriter = new XmlTextWriter(szAbsPath, Encoding.UTF8);
                xmlDoc.WriteTo(xmlWriter);
                xmlWriter.Close();
            }
            catch
            {
                MessageBox.Show(
                    this,
                    SledUtil.TransSub(Localization.SledTTYFilterErrorWritingFile, szAbsPath),
                    Localization.SledTTYFilterFileError,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
        }
        void IInitializable.Initialize()
        {
            var languagePlugins =
                SledServiceInstance.GetAll <ISledLanguagePlugin>();

            m_dictPlugins.Clear();

            using (new SledOutDevice.BreakBlock())
            {
                foreach (var langPlugin in languagePlugins)
                {
                    // Add plugin to list
                    m_dictPlugins.Add(langPlugin.LanguageId, langPlugin);

                    // Report the plugin was found
                    SledOutDevice.OutLine(
                        SledMessageType.Info,
                        SledUtil.TransSub(Localization.SledLanguagePluginLoaded, langPlugin.LanguageName, langPlugin.LanguageDescription));
                }
            }
        }
        private void DebugServiceDataReady(object sender, SledDebugServiceEventArgs e)
        {
            var typeCode = (Scmp.LuaTypeCodes)e.Scmp.TypeCode;

            switch (typeCode)
            {
            case Scmp.LuaTypeCodes.LuaLimits:
            {
                var scmp = m_debugService.GetScmpBlob <Scmp.LuaLimits>();

                m_iMaxBreakpoints = scmp.MaxBreakpoints;

                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    SledUtil.TransSub(
                        "[%s0] Maximum breakpoints set to %s1 on the target.",
                        m_luaLanguagePlugin.LanguageName, m_iMaxBreakpoints));
            }
            break;
            }
        }
        /// <summary>
        /// Try and remove the read only attribute from a file
        /// </summary>
        /// <param name="sd">Document to remove read only attribute from</param>
        /// <returns>True if read only attribute was removed false if it wasn't</returns>
        public bool TryRemoveReadOnlyAttribute(ISledDocument sd)
        {
            var bResult   = false;
            var bValidDoc = IsValidDocument(sd);

            try
            {
                if (bValidDoc)
                {
                    Disable(sd);
                }

                File.SetAttributes(sd.Uri.LocalPath, FileAttributes.Normal);

                // Successful
                bResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    m_mainForm,
                    string.Format(
                        "{0}{1}{1}{2}",
                        Localization.SledFailChangePermissions,
                        Environment.NewLine,
                        SledUtil.TransSub(Localization.SledExceptionWas, ex.Message)),
                    Localization.SledFileReadOnlyError,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            finally
            {
                if (bValidDoc)
                {
                    Enable(sd);
                }
            }

            return(bResult);
        }
Example #21
0
        private void NetPluginConnectedEvent(object sender, ISledTarget target)
        {
            if (!m_bAuthenticated)
            {
                NetPluginConnectingEvent(target);
            }
            else
            {
                IsConnecting = false;
                IsConnected  = true;
                IsDebugging  = true;

                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    SledUtil.TransSub(Localization.SledTargetConnectionEstablishedTo, target));

                // Update status text
                m_connectStatus.Text = Localization.SledConnected + ": " + target;

                // Fire event
                Connected.Raise(this, new SledDebugServiceEventArgs(target));
            }
        }
Example #22
0
        private void DebugServiceDataReady(object sender, SledDebugServiceEventArgs e)
        {
            if (e.Scmp.TypeCode != (UInt16)TypeCodes.ScriptCache)
            {
                return;
            }

            var scriptCache = m_debugService.GetScmpBlob <ScriptCache>();

            var szAbsFilePath = SledUtil.GetAbsolutePath(scriptCache.RelScriptPath, m_projectService.AssetDirectory);

            if (!File.Exists(szAbsFilePath))
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledRemoteTargetErrorScriptCacheFileNotExist, scriptCache.RelScriptPath, szAbsFilePath));
            }
            else
            {
                SledProjectFilesFileType file;
                m_projectService.AddFile(szAbsFilePath, out file);
            }
        }
        /// <summary>
        /// Determines whether breakpoint can be added
        /// </summary>
        /// <param name="sd">Document (if any - might be null)</param>
        /// <param name="lineNumber">Line number of breakpoint</param>
        /// <param name="lineText">Text on line of breakpoint</param>
        /// <param name="numLanguagePluginBreakpoints">The current number of breakpoints that belong to the language plugin</param>
        /// <returns></returns>
        public bool CanAdd(ISledDocument sd, int lineNumber, string lineText, int numLanguagePluginBreakpoints)
        {
            // Allow all breakpoints to be added if disconnected
            if (m_debugService.IsDisconnected)
            {
                return(true);
            }

            // Figure out if we can add the breakpoint & show message if not
            var bCanAdd = ((numLanguagePluginBreakpoints + 1) <= m_iMaxBreakpoints);

            if (!bCanAdd)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    SledUtil.TransSub(
                        "[%s0] Breakpoint cannot be added due to target setting " +
                        "(will be over max allowed breakpoints: %s1).",
                        m_luaLanguagePlugin.LanguageName, m_iMaxBreakpoints));
            }

            return(bCanAdd);
        }
Example #24
0
        /// <summary>
        /// Writes the DomObject to the given stream
        /// </summary>
        /// <param name="stream">Stream to write to</param>
        /// <param name="rootDomObject">Dom tree to write</param>
        public override void Write(Stream stream, DomObject rootDomObject)
        {
            // Write project settings
            WriteInternal(stream, rootDomObject, false);

            // Create stream to write the temporary settings file or if we can't then do nothing
            try
            {
                // Path to project file
                string szAbsProjPath = ((FileStream)stream).Name;
                // Path to hidden project temporary settings file
                string szAbsTempPath = Path.ChangeExtension(szAbsProjPath, m_extTmp);

                // Make it writeable if it already exists
                if (File.Exists(szAbsTempPath))
                {
                    File.SetAttributes(szAbsTempPath, FileAttributes.Normal);
                }

                // Write to disk
                using (FileStream file = new FileStream(szAbsTempPath, FileMode.Create, FileAccess.Write))
                {
                    WriteInternal(file, rootDomObject, true);
                }

                // Make hidden
                if (File.Exists(szAbsTempPath))
                {
                    File.SetAttributes(szAbsTempPath, FileAttributes.Hidden);
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(SledMessageType.Error, SledUtil.TransSub(Localization.SledSharedSaveTempSettingsFileError, new string[] { ex.Message }));
            }
        }
Example #25
0
 private static void NotifyBreakpointHitting(Shared.Scmp.BreakpointBegin bp)
 {
     SledOutDevice.OutLine(
         SledMessageType.Info,
         SledUtil.TransSub(Resources.Resource.BreakpointStopped, bp.RelFilePath, bp.Line));
 }
Example #26
0
        /// <summary>
        /// Write collection to disk
        /// </summary>
        /// <param name="root">Root DomNode</param>
        /// <param name="uri">URI for project settings file</param>
        /// <param name="bWriteTempSettings">Whether to write project temporary settings file (.sus)</param>
        public void Write(DomNode root, Uri uri, bool bWriteTempSettings)
        {
            try
            {
                // Write project settings
                using (var file = new FileStream(uri.LocalPath, FileMode.Create, FileAccess.Write))
                {
                    WriteInternal(root, file);
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "Encountered an error when " +
                    "saving project file! {0}",
                    ex.Message);
            }

            if (!bWriteTempSettings)
            {
                return;
            }

            try
            {
                m_bWritingUserSettings = true;

                // Path to project file
                var szAbsProjPath = uri.LocalPath;
                // Path to hidden project temporary settings file
                var szAbsTempPath = Path.ChangeExtension(szAbsProjPath, ".sus");

                // Make it writable if it exists already
                if (File.Exists(szAbsTempPath))
                {
                    File.SetAttributes(szAbsTempPath, FileAttributes.Normal);
                }

                // Write project temporary settings file
                using (var file = new FileStream(szAbsTempPath, FileMode.Create, FileAccess.Write))
                {
                    WriteInternal(root, file);
                }

                // Make it hidden
                if (File.Exists(szAbsTempPath))
                {
                    File.SetAttributes(szAbsTempPath, FileAttributes.Hidden);
                }
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledSharedSaveTempSettingsFileError, ex.Message));
            }
            finally
            {
                m_bWritingUserSettings = false;
            }
        }
Example #27
0
        /// <summary>
        /// Go to a specific variable instance in a file
        /// </summary>
        /// <param name="var">variable to go to</param>
        public void GotoVariable(ISledVarBaseType var)
        {
            if (var == null)
            {
                return;
            }

            if (var.Locations.Count <= 0)
            {
                return;
            }

            if (var.Locations.Count == 1)
            {
                // Go to this specific one
                GotoLineWord(
                    var.Locations[0].File,
                    var.Name,
                    var.Locations[0].Line,
                    var.Locations[0].Occurence,
                    false);
            }
            else
            {
                var dictLocations =
                    new Dictionary <string, List <SledVarLocationType> >(StringComparer.CurrentCultureIgnoreCase);

                // Go through all locations grouping by file
                foreach (var loc in var.Locations)
                {
                    List <SledVarLocationType> lstLocs;
                    if (dictLocations.TryGetValue(loc.File, out lstLocs))
                    {
                        // Add to existing key
                        lstLocs.Add(loc);
                    }
                    else
                    {
                        // Create new key/value pair
                        lstLocs =
                            new List <SledVarLocationType> {
                            loc
                        };

                        dictLocations.Add(loc.File, lstLocs);
                    }
                }

                if (dictLocations.Count <= 0)
                {
                    return;
                }

                // Create variable goto form
                var form = new SledVarGotoForm();

                // Create one syntax editor for all the iterations
                using (var sec = TextEditorFactory.CreateSyntaxHighlightingEditor())
                {
                    // Go through each file pulling out locations
                    foreach (var kv in dictLocations)
                    {
                        StreamReader reader = null;

                        try
                        {
                            // Open the file
                            reader = new StreamReader(kv.Key, true);
                            if (reader != StreamReader.Null)
                            {
                                // Read entire file contents into SyntaxEditor
                                sec.Text = reader.ReadToEnd();

                                // Go through populating form
                                foreach (var loc in kv.Value)
                                {
                                    try
                                    {
                                        // Add location to the form
                                        form.AddLocation(loc, sec.GetLineText(loc.Line).Trim());
                                    }
                                    catch (Exception ex2)
                                    {
                                        SledOutDevice.OutLine(
                                            SledMessageType.Info,
                                            SledUtil.TransSub(Localization.SledGotoVariableError1, loc.Line, kv.Key, ex2.Message));
                                    }
                                }
                            }
                        }
                        catch (Exception ex1)
                        {
                            SledOutDevice.OutLine(
                                SledMessageType.Info,
                                SledUtil.TransSub(Localization.SledGotoVariableError2, kv.Key, ex1.Message));
                        }
                        finally
                        {
                            // Close up reader if everything went well
                            if ((reader != null) && (reader != StreamReader.Null))
                            {
                                reader.Close();
                                reader.Dispose();
                            }
                        }
                    }
                }

                if (form.ShowDialog(m_mainForm) == DialogResult.OK)
                {
                    // Go to this one
                    GotoLineWord(
                        form.SelectedLocation.File,
                        var.Name,
                        form.SelectedLocation.Line,
                        form.SelectedLocation.Occurence,
                        false);
                }

                form.Dispose();
            }
        }
Example #28
0
        /// <summary>
        /// Open the project file and remove any duplicates
        /// </summary>
        /// <param name="szAbsPath"></param>
        public static void CleanupProjectFileDuplicates(string szAbsPath)
        {
            if (!File.Exists(szAbsPath))
            {
                return;
            }

            if (SledUtil.IsFileReadOnly(szAbsPath))
            {
                return;
            }

            try
            {
                var schemaLoader = SledServiceInstance.TryGet <SledSharedSchemaLoader>();
                if (schemaLoader == null)
                {
                    return;
                }

                var uri    = new Uri(szAbsPath);
                var reader = new SledSpfReader(schemaLoader);

                var root = reader.Read(uri, false);
                if (root == null)
                {
                    return;
                }

                var lstProjFiles = new List <SledProjectFilesFileType>();

                // Gather up all project files in the project
                SledDomUtil.GatherAllAs(root, lstProjFiles);

                if (lstProjFiles.Count <= 1)
                {
                    return;
                }

                var uniquePaths   = new Dictionary <string, SledProjectFilesFileType>(StringComparer.CurrentCultureIgnoreCase);
                var lstDuplicates = new List <SledProjectFilesFileType>();

                foreach (var projFile in lstProjFiles)
                {
                    if (uniquePaths.ContainsKey(projFile.Path))
                    {
                        lstDuplicates.Add(projFile);
                    }
                    else
                    {
                        uniquePaths.Add(projFile.Path, projFile);
                    }
                }

                if (lstDuplicates.Count <= 0)
                {
                    return;
                }

                foreach (var projFile in lstDuplicates)
                {
                    projFile.DomNode.RemoveFromParent();
                }

                var writer = new SledSpfWriter(schemaLoader.TypeCollection);

                // Write changes back to disk
                writer.Write(root, uri, false);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledProjectFilesErrorRemovingDuplicates, ex.Message, szAbsPath));
            }
        }
Example #29
0
        private void Compile(SledLuaCompileConfigurationType configType)
        {
            if (configType == null)
            {
                return;
            }

            // Gather files owned by the Lua plugin
            IList <SledProjectFilesFileType> lstFiles =
                new List <SledProjectFilesFileType>(
                    m_projectFileGathererService.Get.GetFilesOwnedByPlugin(
                        m_luaLanguagePlugin));

            // No files so nothing to compile
            if (lstFiles.Count <= 0)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    Localization.SledLuaCompilerErrorNoPluginOwnedFiles);

                return;
            }

            IList <SledProjectFilesFileType> lstNoCompileFiles =
                new List <SledProjectFilesFileType>();

            // Gather any files aren't supposed to be compiled
            foreach (var file in lstFiles)
            {
                var bCompileFile = false;

                foreach (SledLuaCompileAttributeType attr in file.Attributes)
                {
                    if (!attr.Is <SledLuaCompileAttributeType>())
                    {
                        continue;
                    }

                    var luaAttr =
                        attr.As <SledLuaCompileAttributeType>();

                    bCompileFile = luaAttr.Compile;
                }

                // Don't compile the file
                if (!bCompileFile)
                {
                    lstNoCompileFiles.Add(file);
                }
            }

            // Remove any files that aren't supposed to be compiled
            foreach (var file in lstNoCompileFiles)
            {
                lstFiles.Remove(file);
            }

            // No files so nothing to compile
            if (lstFiles.Count <= 0)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Info,
                    Localization.SledLuaCompilerErrorNoFiles);

                return;
            }

            ILuaCompiler compiler = null;

            try
            {
                // Create compiler based on platform
                compiler = SledLuaCompilerServiceFactory.Create();

                // Set up configuration
                var config =
                    new LuaCompilerConfig(
                        configType.LittleEndian
                            ? LuaCompilerConfig.Endian.Little
                            : LuaCompilerConfig.Endian.Big,
                        configType.SizeOfInt,
                        configType.SizeOfSizeT,
                        configType.SizeOfLuaNumber,
                        configType.StripDebugInfo);

                // Compile each file individually
                foreach (var file in lstFiles)
                {
                    try
                    {
                        //
                        // Fix up path to respect users' configType settings
                        //

                        // Fix up extension
                        var dumpPath = Path.ChangeExtension(file.AbsolutePath, configType.OutputExtension);

                        // Grab new file name w/ updated extension
                        var newName = Path.GetFileName(dumpPath);
                        if (string.IsNullOrEmpty(newName))
                        {
                            throw new InvalidOperationException("new filename null or empty");
                        }

                        // Fix up output directory
                        if (configType.PreserveRelativePathInfo)
                        {
                            // Get relative path hierarchy
                            var dirHierarchy = Path.GetDirectoryName(file.Path);
                            dumpPath = string.Format("{0}{1}{2}{1}{3}", configType.OutputPath, Path.DirectorySeparatorChar, dirHierarchy, newName);
                        }
                        else
                        {
                            // Just take output path + new name (which includes new extension)
                            dumpPath = string.Format("{0}{1}{2}", configType.OutputPath, Path.DirectorySeparatorChar, newName);
                        }

                        dumpPath = Path.GetFullPath(dumpPath);

                        if (m_bVerbose)
                        {
                            SledOutDevice.OutLine(
                                SledMessageType.Info,
                                "[Lua compiler] Compiling {0} to {1}",
                                file.AbsolutePath, dumpPath);
                        }

                        // Make sure directory exists before trying to place compiled script there
                        var newDir = Path.GetDirectoryName(dumpPath);
                        if (string.IsNullOrEmpty(newDir))
                        {
                            throw new InvalidOperationException("new directory null or empty");
                        }

                        if (!Directory.Exists(newDir))
                        {
                            var bDirExists = false;
                            var message    = string.Empty;

                            try
                            {
                                Directory.CreateDirectory(newDir);
                                bDirExists = true;
                            }
                            catch (UnauthorizedAccessException ex)  { message = ex.Message; }
                            catch (ArgumentNullException ex)        { message = ex.Message; }
                            catch (ArgumentException ex)            { message = ex.Message; }
                            catch (PathTooLongException ex)         { message = ex.Message; }
                            catch (DirectoryNotFoundException ex)   { message = ex.Message; }
                            catch (NotSupportedException ex)        { message = ex.Message; }
                            catch (IOException ex)                  { message = ex.Message; }

                            // Show message if directory couldn't be created
                            if (!bDirExists)
                            {
                                // Can't compile script to user supplied destination directory
                                // because the directory doesn't exist and can't be created!
                                SledOutDevice.OutLine(
                                    SledMessageType.Error,
                                    SledUtil.TransSub(Localization.SledLuaCompilerErrorCantCreateDir, message));

                                // Skip this file...
                                continue;
                            }
                        }

                        // Try and compile file
                        var succeeded = compiler.Compile(new Uri(file.AbsolutePath), new Uri(dumpPath), config);
                        SledOutDevice.OutLine(
                            SledMessageType.Info,
                            succeeded
                                ? SledUtil.TransSub(Localization.SledLuaCompilerErrorSuccess, file.Name)
                                : SledUtil.TransSub(Localization.SledLuaCompilerErrorFailed, file.Name, compiler.Error));
                    }
                    catch (Exception ex2)
                    {
                        SledOutDevice.OutLine(
                            SledMessageType.Error,
                            SledUtil.TransSub(Localization.SledLuaCompilerErrorExceptionCompilingFile, file.Name, ex2.Message));
                    }
                }
            }
            catch (Exception ex1)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    SledUtil.TransSub(Localization.SledLuaCompilerErrorExceptionInLuaCompiler, ex1.Message));
            }
            finally
            {
                if (compiler != null)
                {
                    compiler.Dispose();
                }
            }
        }
Example #30
0
 private static void NotifyBreakpointContinue(Shared.Scmp.BreakpointContinue bp)
 {
     SledOutDevice.OutLine(
         SledMessageType.Info,
         SledUtil.TransSub(Resources.Resource.BreakpointContinue, bp.RelFilePath, bp.Line));
 }