Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fills in or modifies the given display info for the item</summary>
        /// <param name="item">Item</param>
        /// <param name="info">Display info to update</param>
        public void GetInfo(object item, ItemInfo info)
        {
            info.Label          = Name;
            info.IsLeaf         = (Functions.Count == 0);
            info.AllowLabelEdit = true;
            info.Description    = Name;
            info.Properties     = new[] { Path };

            var bFileExists = File.Exists(Uri.LocalPath);
            var bReadOnly   = SledUtil.IsFileReadOnly(Uri.LocalPath);

            // Mark files that don't exist
            if (!bFileExists)
            {
                info.FontStyle      = FontStyle.Strikeout;
                info.AllowLabelEdit = false;
            }

            // Don't allow renaming of read-only files
            if (bReadOnly)
            {
                info.AllowLabelEdit = false;
            }

            // Default
            var imageName =
                Atf.Resources.DocumentImage;

            // Try to grab other
            if ((DocumentClient != null) &&
                (DocumentClient.Info != null) &&
                !string.IsNullOrEmpty(DocumentClient.Info.OpenIconName))
            {
                imageName = DocumentClient.Info.OpenIconName;
            }

            // Set image
            info.ImageIndex = info.GetImageIndex(imageName);

            // Set source control status
            {
                if (s_sourceControlService == null)
                {
                    s_sourceControlService = SledServiceInstance.TryGet <ISledSourceControlService>();
                }

                if (s_sourceControlService == null)
                {
                    return;
                }

                if (!s_sourceControlService.CanUseSourceControl)
                {
                    return;
                }

                var sourceControlStatus = s_sourceControlService.GetStatus(this);
                switch (sourceControlStatus)
                {
                case SourceControlStatus.CheckedOut:
                    info.StateImageIndex = info.GetImageIndex(Atf.Resources.DocumentCheckOutImage);
                    break;

                default:
                    info.StateImageIndex = Atf.Controls.TreeListView.InvalidImageIndex;
                    break;
                }
            }
        }