Beispiel #1
0
        public SledProjectFilesType CreateProject(Uri uri, string name, string assetDirectory, Guid guid, bool bNew)
        {
            SledProjectFilesType project;

            if (bNew)
            {
                var root =
                    new DomNode(
                        SledSchema.SledProjectFilesType.Type,
                        SledSchema.SledProjectFilesRootElement);

                project = root.As<SledProjectFilesType>();
                project.Uri = uri;
                project.Name = name;
                project.AssetDirectory = assetDirectory;
                project.Guid = guid;
                project.Dirty = true;
            }
            else
            {
                var reader = new SledSpfReader(SchemaLoader);
                var root = reader.Read(uri, true);

                project = root.As<SledProjectFilesType>();
                project.Uri = uri;
                project.Dirty = false;
            }

            return project;
        }
Beispiel #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));
            }
        }
Beispiel #3
0
        private static Guid GetExistingProjectGuid(Uri uri, XmlSchemaTypeLoader schemaLoader)
        {
            // No file so make up guid
            if (!File.Exists(uri.LocalPath))
                return SledUtil.MakeXmlSafeGuid();

            // Look for guid
            var retval = Guid.Empty;

            try
            {
                var reader = new SledSpfReader(schemaLoader);
                var root = reader.Read(uri, false);
                var project = root.As<SledProjectFilesType>();

                retval = project.Guid;
            }
            catch (Exception ex)
            {
                ex.ToString();
                retval = Guid.Empty;
            }
            finally
            {
                if (retval == Guid.Empty)
                    retval = SledUtil.MakeXmlSafeGuid();
            }

            return retval;
        }
Beispiel #4
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;
            }
        }