From fb3e6b8f61b855ebad301d6a47a0d5ebcf844d01 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Tue, 10 Jun 2014 15:59:38 -0400 Subject: [PATCH] Various fixes and updates --- .../Common/Reflection.cs | 28 +++++++++++++++++++ .../VisualStudioSolutionDataFormat.cs | 7 ++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CSharp/Plugins/UniversalEditor.Essential/Common/Reflection.cs b/CSharp/Plugins/UniversalEditor.Essential/Common/Reflection.cs index 49bb0e19..62d9872c 100644 --- a/CSharp/Plugins/UniversalEditor.Essential/Common/Reflection.cs +++ b/CSharp/Plugins/UniversalEditor.Essential/Common/Reflection.cs @@ -926,6 +926,33 @@ namespace UniversalEditor.Common public static T GetAvailableObjectModel(string FileName) where T : ObjectModel { ObjectModelReference[] omrs = GetAvailableObjectModels(FileName); + if (omrs.Length == 0) + { + // we failed to find an object model from the file name, so let's try and + // force the loading of the object model we're told to load in the first place + + Type type = typeof(T); + ObjectModel om = (ObjectModel)type.Assembly.CreateInstance(type.FullName); + ObjectModelReference omr = om.MakeReference(); + + DataFormatReference[] dfrs = GetAvailableDataFormats(om.MakeReference()); + + FileAccessor accessor = new FileAccessor(FileName); + foreach (DataFormatReference dfr in dfrs) + { + try + { + DataFormat df = dfr.Create(); + Document.Load(om, df, accessor); + } + catch + { + accessor.Close(); + continue; + } + } + return (T)om; + } foreach (ObjectModelReference omr in omrs) { if (omr.ObjectModelType == typeof(T)) @@ -1014,6 +1041,7 @@ namespace UniversalEditor.Common ObjectModelReference[] array = GetAvailableObjectModels(); DataFormatReference[] dfs = GetAvailableDataFormats(FileName); List list = new List(); + if (dfs.Length == 0) return list.ToArray(); foreach (ObjectModelReference om in array) { diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Microsoft.VisualStudio/DataFormats/Solution/Microsoft/VisualStudio/VisualStudioSolutionDataFormat.cs b/CSharp/Plugins/UniversalEditor.Plugins.Microsoft.VisualStudio/DataFormats/Solution/Microsoft/VisualStudio/VisualStudioSolutionDataFormat.cs index f45242dd..b911fe56 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.Microsoft.VisualStudio/DataFormats/Solution/Microsoft/VisualStudio/VisualStudioSolutionDataFormat.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.Microsoft.VisualStudio/DataFormats/Solution/Microsoft/VisualStudio/VisualStudioSolutionDataFormat.cs @@ -34,6 +34,8 @@ namespace UniversalEditor.DataFormats.Solution.Microsoft.VisualStudio if (sol == null) throw new ObjectModelNotSupportedException(); Reader reader = base.Accessor.Reader; + if (base.Accessor.Remaining < 3) throw new InvalidDataFormatException("File must be at least three bytes"); + byte[] signature1 = reader.ReadBytes(3); if (!signature1.Match(new byte[] { 0xEF, 0xBB, 0xBF })) { @@ -148,15 +150,12 @@ namespace UniversalEditor.DataFormats.Solution.Microsoft.VisualStudio } */ - SolutionObjectModel solproj = new SolutionObjectModel(); - solproj.Projects.Add(project); - if (!System.IO.Directory.Exists(projdir)) { System.IO.Directory.CreateDirectory(projdir); } - Document.Save(solproj, new VisualStudioProjectDataFormat(), new FileAccessor(projdir + "/" + project.Title + ".ueproj", true, true), true); + Document.Save(project, new VisualStudioProjectDataFormat(), new FileAccessor(projdir + "/" + project.Title + ".ueproj", true, true), true); } writer.WriteLine("Global");