Пример #1
0
        public void GetAbsolutePath()
        {
            var basePaths = new[] { @"C:\usr\local\cell", @"C:\usr\local\cell\" };

            const string relPath1 = @"..\..\some\folder\file.txt";
            const string relPath2 = @"some\folder\file.txt";

            var absPath1 = SledUtil.GetAbsolutePath(relPath1, basePaths[0]);
            var absPath2 = SledUtil.GetAbsolutePath(relPath1, basePaths[1]);
            var absPath3 = SledUtil.GetAbsolutePath(relPath1, basePaths[0]);
            var absPath4 = SledUtil.GetAbsolutePath(relPath1, basePaths[1]);

            const string absPath5 = @"C:\usr\some\folder\file.txt";
            const string absPath6 = @"C:\usr\local\cell\some\folder\file.txt";

            Assert.That(
                (string.Compare(absPath1, absPath5) == 0) &&
                (string.Compare(absPath2, absPath5) == 0) &&
                (string.Compare(absPath3, absPath5) == 0) &&
                (string.Compare(absPath4, absPath5) == 0));

            absPath1 = SledUtil.GetAbsolutePath(relPath2, basePaths[0]);
            absPath2 = SledUtil.GetAbsolutePath(relPath2, basePaths[1]);
            absPath3 = SledUtil.GetAbsolutePath(relPath2, basePaths[0]);
            absPath4 = SledUtil.GetAbsolutePath(relPath2, basePaths[1]);

            Assert.That(
                (string.Compare(absPath1, absPath6) == 0) &&
                (string.Compare(absPath2, absPath6) == 0) &&
                (string.Compare(absPath3, absPath6) == 0) &&
                (string.Compare(absPath4, absPath6) == 0));
        }
Пример #2
0
        private void FuncCallsEditorMouseDoubleClick(object sender, MouseEventArgs e)
        {
            var editor = sender.As <SledLuaProfileFuncCallsEditor>();

            if (editor == null)
            {
                return;
            }

            if (editor.LastHit == null)
            {
                return;
            }

            var pi = editor.LastHit.As <SledProfileInfoType>();

            if (pi == null)
            {
                return;
            }

            var szAbsPath =
                SledUtil.GetAbsolutePath(
                    pi.File,
                    m_projectService.Get.AssetDirectory);

            if (!File.Exists(szAbsPath))
            {
                return;
            }

            m_gotoService.Get.GotoLine(szAbsPath, pi.Line, false);
        }
Пример #3
0
        private void DebugServiceBreakpointHit(object sender, SledDebugServiceBreakpointEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Breakpoint.File))
            {
                // TODO: open a faux document saying something about unknown file?
                return;
            }

            // Get absolute path to file
            var szAbsPath = SledUtil.GetAbsolutePath(e.Breakpoint.File, m_projectService.AssetDirectory);

            if (!string.IsNullOrEmpty(szAbsPath) && File.Exists(szAbsPath))
            {
                ISledDocument sd;
                var           uri = new Uri(szAbsPath);

                // If already open jump to line otherwise open the file
                if (m_documentService.IsOpen(uri, out sd))
                {
                    m_gotoService.Get.GotoLine(sd, m_curBreakpoint.Line, true);
                }
                else
                {
                    m_documentService.Open(uri, out sd);
                }
            }

            MarkProjectDocsReadOnly(false);
        }
Пример #4
0
        private void DebugServiceBreakpointHitting(object sender, SledDebugServiceBreakpointEventArgs e)
        {
            m_curBreakpoint = e.Breakpoint.Clone() as SledNetworkBreakpoint;

            if (m_curBreakpoint.IsUnknownFile())
            {
                return;
            }

            // Get absolute path to file
            var szAbsPath = SledUtil.GetAbsolutePath(e.Breakpoint.File, m_projectService.AssetDirectory);

            if (string.IsNullOrEmpty(szAbsPath) || !File.Exists(szAbsPath))
            {
                return;
            }

            // Check if file is in the project
            var projFile = m_projectFileFinderService.Get.Find(szAbsPath);

            // Try and add file to project
            if (projFile == null)
            {
                m_projectService.AddFile(szAbsPath, out projFile);
            }
        }
Пример #5
0
        private void SetupFile(SledProjectFilesFileType file)
        {
            // Assign language plugin (if any)
            file.LanguagePlugin = m_languagePluginService.Get.GetPluginForExtension(Path.GetExtension(file.Path));

            var project = file.Project ?? m_projectService.Get.ActiveProject;

            // Set Uri
            var absPath = SledUtil.GetAbsolutePath(file.Path, project.AssetDirectory);

            file.Uri = new Uri(absPath);
        }
Пример #6
0
        private void DebugServiceDebugCurrentStatement(object sender, EventArgs e)
        {
            if (m_curBreakpoint == null)
            {
                return;
            }

            var szAbsPath = SledUtil.GetAbsolutePath(m_curBreakpoint.File, m_projectService.AssetDirectory);

            if (string.IsNullOrEmpty(szAbsPath))
            {
                return;
            }

            m_gotoService.Get.GotoLine(szAbsPath, m_curBreakpoint.Line, true);
        }
Пример #7
0
        private void UpdatePaths(bool option1)
        {
            m_lstFiles.Items.Clear();
            m_lstFiles.BeginUpdate();

            foreach (var file in m_files)
            {
                string pathNew;

                if (option1)
                {
                    var absPath =
                        SledUtil.GetAbsolutePath(file.Path, m_assetDirOld);

                    pathNew =
                        SledUtil.GetRelativePath(absPath, m_assetDirNew);
                }
                else
                {
                    var absPath =
                        m_assetDirNew + file.Path;

                    pathNew =
                        SledUtil.GetRelativePath(absPath, m_assetDirNew);
                }

                var lstItem =
                    new ListViewItem(
                        new[] { file.Name, file.Path, pathNew });

                m_lstFiles.Items.Add(lstItem);
            }

            m_lstFiles.EndUpdate();

            foreach (ColumnHeader hdr in m_lstFiles.Columns)
            {
                hdr.Width = -1;
            }
        }
Пример #8
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);
            }
        }
Пример #9
0
        private void CallStackEditorMouseDoubleClick(object sender, MouseEventArgs e)
        {
            var editor = sender.As <SledLuaCallStackEditor>();

            if (editor == null)
            {
                return;
            }

            var obj = editor.GetItemAt(e.Location);

            if (obj == null)
            {
                return;
            }

            if (!obj.Is <SledCallStackType>())
            {
                return;
            }

            var cs = obj.As <SledCallStackType>();

            var szAbsPath =
                SledUtil.GetAbsolutePath(
                    cs.File,
                    m_projectService.AssetDirectory);

            if (!File.Exists(szAbsPath))
            {
                return;
            }

            // Jump to line
            m_gotoService.GotoLine(szAbsPath, cs.CurrentLine, false);
        }
Пример #10
0
        /// <summary>
        /// Try and obtain project information from a project file on disk
        /// </summary>
        /// <param name="absPath"></param>
        /// <param name="name"></param>
        /// <param name="projectDir"></param>
        /// <param name="assetDir"></param>
        /// <param name="guid"></param>
        /// <param name="files"></param>
        /// <returns></returns>
        public static bool TryGetProjectDetails(
            string absPath,
            out string name,
            out string projectDir,
            out string assetDir,
            out Guid guid,
            out List <string> files)
        {
            name       = null;
            projectDir = null;
            assetDir   = null;
            guid       = Guid.Empty;
            files      = null;

            try
            {
                // ATF 3's DOM makes this so much easier now!

                var schemaLoader =
                    SledServiceInstance.TryGet <SledSharedSchemaLoader>();

                if (schemaLoader == null)
                {
                    return(false);
                }

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

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

                var project =
                    root.As <SledProjectFilesType>();

                project.Uri = uri;

                // Pull out project details
                name       = project.Name;
                guid       = project.Guid;
                assetDir   = project.AssetDirectory;
                projectDir = Path.GetDirectoryName(absPath);

                var lstProjFiles =
                    new List <SledProjectFilesFileType>();

                SledDomUtil.GatherAllAs(root, lstProjFiles);

                var assetDirTemp = assetDir;
                files =
                    (from projFile in lstProjFiles
                     let absFilePath =
                         SledUtil.GetAbsolutePath(
                             projFile.Path,
                             assetDirTemp)
                         select absFilePath).ToList();

                return(true);
            }
            catch (Exception ex)
            {
                SledOutDevice.OutLine(
                    SledMessageType.Error,
                    "Exception encountered obtaining project " +
                    "details. Project file: \"{0}\". Exception: {1}",
                    absPath, ex.Message);

                return(false);
            }
        }