Start to implement underlying Open Packaging Convention file formats
This commit is contained in:
parent
019f9a88d4
commit
3140766480
@ -10,5 +10,7 @@ namespace UniversalEditor.ObjectModels.FileSystem
|
||||
File.FileCollection Files { get; }
|
||||
Folder.FolderCollection Folders { get; }
|
||||
string GetNewFolderName();
|
||||
|
||||
File AddFile(string name, byte[] fileData = null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.DataFormats.FileSystem.ZIP.Internal
|
||||
{
|
||||
internal struct ZIPCentralDirectoryFooter
|
||||
{
|
||||
public uint unknown1;
|
||||
public ushort unknown2;
|
||||
public ushort unknown3;
|
||||
public uint centralDirectoryLength;
|
||||
public uint centralDirectoryOffset;
|
||||
public ushort unknown4;
|
||||
}
|
||||
}
|
||||
@ -208,6 +208,7 @@
|
||||
<Compile Include="DataFormats\FileSystem\ZipTV\BlakHole\BHDataFormat.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\ZipTV\BlakHole\BHEncryptDecrypt.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\ZipTV\BlakHole\BHEncryptionMethod.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\ZIP\Internal\ZIPCentralDirectoryFooter.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\ZIP\ZIPCreationPlatform.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\ZIP\ZIPDataFormat.cs" />
|
||||
<Compile Include="DataFormats\FileSystem\ZIP\ZIPGeneralPurposeFlags.cs" />
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.DataFormats.Markup.XML;
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
using UniversalEditor.ObjectModels.Package.ContentTypes;
|
||||
|
||||
namespace UniversalEditor.DataFormats.Package.ContentTypes
|
||||
{
|
||||
public class OPCContentTypesDataFormat : XMLDataFormat
|
||||
{
|
||||
protected override void BeforeLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.BeforeLoadInternal(objectModels);
|
||||
objectModels.Push(new MarkupObjectModel());
|
||||
}
|
||||
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.AfterLoadInternal(objectModels);
|
||||
|
||||
MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel);
|
||||
ContentTypesObjectModel types = (objectModels.Pop() as ContentTypesObjectModel);
|
||||
|
||||
MarkupTagElement tagTypes = (mom.Elements["Types"] as MarkupTagElement);
|
||||
foreach (MarkupElement elType in tagTypes.Elements)
|
||||
{
|
||||
MarkupTagElement tagType = (elType as MarkupTagElement);
|
||||
if (elType == null) continue;
|
||||
|
||||
ContentType type = new ContentType();
|
||||
MarkupAttribute attExtension = tagType.Attributes["Extension"];
|
||||
if (attExtension != null) type.Extension = attExtension.Value;
|
||||
|
||||
MarkupAttribute attContentType = tagType.Attributes["ContentType"];
|
||||
if (attContentType != null) type.Value = attContentType.Value;
|
||||
|
||||
switch (elType.FullName)
|
||||
{
|
||||
case "Default":
|
||||
{
|
||||
types.ContentTypes.Add(type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.Accessors;
|
||||
|
||||
using UniversalEditor.ObjectModels.FileSystem;
|
||||
using UniversalEditor.DataFormats.FileSystem.ZIP;
|
||||
|
||||
using UniversalEditor.ObjectModels.Package;
|
||||
using UniversalEditor.ObjectModels.Package.Relationships;
|
||||
|
||||
using UniversalEditor.DataFormats.Package.Relationships;
|
||||
using UniversalEditor.ObjectModels.Package.ContentTypes;
|
||||
using UniversalEditor.DataFormats.Package.ContentTypes;
|
||||
|
||||
namespace UniversalEditor.DataFormats.Package.OpenPackagingConvention
|
||||
{
|
||||
public class OPCDataFormat : ZIPDataFormat
|
||||
{
|
||||
protected override void BeforeLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.BeforeLoadInternal(objectModels);
|
||||
objectModels.Push(new FileSystemObjectModel());
|
||||
}
|
||||
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.AfterLoadInternal(objectModels);
|
||||
|
||||
FileSystemObjectModel fsom = (objectModels.Pop() as FileSystemObjectModel);
|
||||
PackageObjectModel package = (objectModels.Pop() as PackageObjectModel);
|
||||
|
||||
Folder _rels = fsom.Folders["_rels"];
|
||||
if (_rels != null)
|
||||
{
|
||||
foreach (File file in _rels.Files)
|
||||
{
|
||||
string relatedFileName = null;
|
||||
if (file.Name.EndsWith(".rels") && file.Name != ".rels")
|
||||
{
|
||||
relatedFileName = file.Name.Substring(0, file.Name.Length - ".rels".Length);
|
||||
}
|
||||
|
||||
|
||||
byte[] data = file.GetData();
|
||||
|
||||
OPCRelationshipsDataFormat df = new OPCRelationshipsDataFormat();
|
||||
RelationshipsObjectModel rels = new RelationshipsObjectModel();
|
||||
Document.Load(rels, df, new MemoryAccessor(data));
|
||||
|
||||
if (relatedFileName != null)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Relationship rel in rels.Relationships)
|
||||
{
|
||||
package.Relationships.Add(rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File _Content_Types = fsom.Files["[Content_Types].xml"];
|
||||
{
|
||||
byte[] data = _Content_Types.GetData();
|
||||
|
||||
OPCContentTypesDataFormat df = new OPCContentTypesDataFormat();
|
||||
ContentTypesObjectModel contentTypes = new ContentTypesObjectModel();
|
||||
Document.Load(contentTypes, df, new MemoryAccessor(data));
|
||||
|
||||
foreach (ContentType type in contentTypes.ContentTypes)
|
||||
{
|
||||
package.ContentTypes.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
objectModels.Push(package);
|
||||
}
|
||||
|
||||
protected override void BeforeSaveInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.BeforeSaveInternal(objectModels);
|
||||
|
||||
PackageObjectModel package = (objectModels.Pop() as PackageObjectModel);
|
||||
FileSystemObjectModel fsom = new FileSystemObjectModel();
|
||||
|
||||
#region _rels
|
||||
{
|
||||
Folder fldr = new Folder();
|
||||
fldr.Name = "_rels";
|
||||
|
||||
File _rels = new File();
|
||||
_rels.Name = ".rels";
|
||||
|
||||
fldr.Files.Add(_rels);
|
||||
|
||||
fsom.Folders.Add(fldr);
|
||||
}
|
||||
#endregion
|
||||
#region Documents
|
||||
{
|
||||
Folder fldr = new Folder();
|
||||
fldr.Name = "Documents";
|
||||
fsom.Folders.Add(fldr);
|
||||
}
|
||||
#endregion
|
||||
#region Metadata
|
||||
{
|
||||
Folder fldr = new Folder();
|
||||
fldr.Name = "Metadata";
|
||||
fsom.Folders.Add(fldr);
|
||||
}
|
||||
#endregion
|
||||
#region [Content_Types].xml
|
||||
{
|
||||
File file = new File();
|
||||
file.Name = "[Content_Types].xml";
|
||||
fsom.Files.Add(file);
|
||||
}
|
||||
#endregion
|
||||
#region FixedDocumentSequence.fdseq
|
||||
{
|
||||
File file = new File();
|
||||
file.Name = "FixedDocumentSequence.fdseq";
|
||||
fsom.Files.Add(file);
|
||||
}
|
||||
#endregion
|
||||
|
||||
objectModels.Push(fsom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using UniversalEditor.DataFormats.Markup.XML;
|
||||
using UniversalEditor.ObjectModels.Markup;
|
||||
using UniversalEditor.ObjectModels.Package.Relationships;
|
||||
|
||||
namespace UniversalEditor.DataFormats.Package.Relationships
|
||||
{
|
||||
public class OPCRelationshipsDataFormat : XMLDataFormat
|
||||
{
|
||||
protected override void BeforeLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.BeforeLoadInternal(objectModels);
|
||||
objectModels.Push(new MarkupObjectModel());
|
||||
}
|
||||
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels)
|
||||
{
|
||||
base.AfterLoadInternal(objectModels);
|
||||
|
||||
MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel);
|
||||
RelationshipsObjectModel rels = (objectModels.Pop() as RelationshipsObjectModel);
|
||||
|
||||
MarkupTagElement tagRelationships = (mom.Elements["Relationships"] as MarkupTagElement);
|
||||
foreach (MarkupElement elRelationship in tagRelationships.Elements)
|
||||
{
|
||||
MarkupTagElement tagRelationship = (elRelationship as MarkupTagElement);
|
||||
if (tagRelationship == null) continue;
|
||||
if (tagRelationship.FullName != "Relationship") continue;
|
||||
|
||||
Relationship rel = new Relationship();
|
||||
|
||||
MarkupAttribute attTarget = tagRelationship.Attributes["Target"];
|
||||
if (attTarget != null) rel.Target = attTarget.Value;
|
||||
|
||||
MarkupAttribute attID = tagRelationship.Attributes["Id"];
|
||||
if (attID != null) rel.ID = attID.Value;
|
||||
|
||||
MarkupAttribute attType = tagRelationship.Attributes["Type"];
|
||||
if (attType != null) rel.Schema = attType.Value;
|
||||
|
||||
rels.Relationships.Add(rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,14 +20,15 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using System;
|
||||
using UniversalEditor.DataFormats.FileSystem.ZIP;
|
||||
using UniversalEditor.ObjectModels.FileSystem;
|
||||
|
||||
using UniversalEditor.DataFormats.Package.OpenPackagingConvention;
|
||||
|
||||
using UniversalEditor.ObjectModels.Package;
|
||||
using UniversalEditor.ObjectModels.Text.Formatted;
|
||||
|
||||
namespace UniversalEditor.DataFormats.Text.Formatted.XPS
|
||||
{
|
||||
public class XPSDataFormat : ZIPDataFormat
|
||||
public class XPSDataFormat : OPCDataFormat
|
||||
{
|
||||
private static DataFormatReference _dfr = null;
|
||||
protected override DataFormatReference MakeReferenceInternal()
|
||||
@ -42,57 +43,25 @@ namespace UniversalEditor.DataFormats.Text.Formatted.XPS
|
||||
|
||||
protected override void BeforeLoadInternal(System.Collections.Generic.Stack<ObjectModel> objectModels)
|
||||
{
|
||||
objectModels.Push(new FileSystemObjectModel());
|
||||
objectModels.Push(new PackageObjectModel());
|
||||
base.BeforeLoadInternal(objectModels);
|
||||
}
|
||||
protected override void AfterLoadInternal(System.Collections.Generic.Stack<ObjectModel> objectModels)
|
||||
{
|
||||
FileSystemObjectModel fsom = (objectModels.Pop() as FileSystemObjectModel);
|
||||
base.AfterLoadInternal(objectModels);
|
||||
|
||||
PackageObjectModel package = (objectModels.Pop() as PackageObjectModel);
|
||||
FormattedTextObjectModel text = (objectModels.Pop() as FormattedTextObjectModel);
|
||||
|
||||
}
|
||||
|
||||
protected override void BeforeSaveInternal(System.Collections.Generic.Stack<ObjectModel> objectModels)
|
||||
{
|
||||
FormattedTextObjectModel text = (objectModels.Pop() as FormattedTextObjectModel);
|
||||
|
||||
PackageObjectModel package = new PackageObjectModel();
|
||||
|
||||
FileSystemObjectModel fsom = new FileSystemObjectModel();
|
||||
|
||||
#region _rels
|
||||
{
|
||||
Folder fldr = new Folder();
|
||||
fldr.Name = "_rels";
|
||||
fsom.Folders.Add(fldr);
|
||||
}
|
||||
#endregion
|
||||
#region Documents
|
||||
{
|
||||
Folder fldr = new Folder();
|
||||
fldr.Name = "Documents";
|
||||
fsom.Folders.Add(fldr);
|
||||
}
|
||||
#endregion
|
||||
#region Metadata
|
||||
{
|
||||
Folder fldr = new Folder();
|
||||
fldr.Name = "Metadata";
|
||||
fsom.Folders.Add(fldr);
|
||||
}
|
||||
#endregion
|
||||
#region [Content_Types].xml
|
||||
{
|
||||
File file = new File();
|
||||
file.Name = "[Content_Types].xml";
|
||||
fsom.Files.Add(file);
|
||||
}
|
||||
#endregion
|
||||
#region FixedDocumentSequence.fdseq
|
||||
{
|
||||
File file = new File();
|
||||
file.Name = "FixedDocumentSequence.fdseq";
|
||||
fsom.Files.Add(file);
|
||||
}
|
||||
#endregion
|
||||
|
||||
objectModels.Push(fsom);
|
||||
objectModels.Push(package);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.Package.ContentTypes
|
||||
{
|
||||
public class ContentType : ICloneable
|
||||
{
|
||||
public class ContentTypeCollection
|
||||
: System.Collections.ObjectModel.Collection<ContentType>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private string mvarExtension = String.Empty;
|
||||
public string Extension { get { return mvarExtension; } set { mvarExtension = value; } }
|
||||
|
||||
private string mvarValue = String.Empty;
|
||||
public string Value { get { return mvarValue; } set { mvarValue = value; } }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("*.");
|
||||
sb.Append(mvarExtension);
|
||||
sb.Append("; ");
|
||||
sb.Append(mvarValue);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
ContentType clone = new ContentType();
|
||||
clone.Value = (mvarValue.Clone() as string);
|
||||
clone.Extension = (mvarExtension.Clone() as string);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.Package.ContentTypes
|
||||
{
|
||||
public class ContentTypesObjectModel : ObjectModel
|
||||
{
|
||||
private ContentType.ContentTypeCollection mvarContentTypes = new ContentType.ContentTypeCollection();
|
||||
public ContentType.ContentTypeCollection ContentTypes { get { return mvarContentTypes; } }
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
mvarContentTypes.Clear();
|
||||
}
|
||||
|
||||
public override void CopyTo(ObjectModel where)
|
||||
{
|
||||
ContentTypesObjectModel clone = (where as ContentTypesObjectModel);
|
||||
if (clone == null) throw new ObjectModelNotSupportedException();
|
||||
|
||||
foreach (ContentType item in mvarContentTypes)
|
||||
{
|
||||
clone.ContentTypes.Add(item.Clone() as ContentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UniversalEditor.ObjectModels.Package.ContentTypes;
|
||||
using UniversalEditor.ObjectModels.Package.Relationships;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.Package
|
||||
{
|
||||
public class PackageObjectModel : ObjectModel
|
||||
{
|
||||
|
||||
private ContentType.ContentTypeCollection mvarContentTypes = new ContentType.ContentTypeCollection();
|
||||
public ContentType.ContentTypeCollection ContentTypes { get { return mvarContentTypes; } }
|
||||
|
||||
private Relationship.RelationshipCollection mvarRelationships = new Relationship.RelationshipCollection();
|
||||
public Relationship.RelationshipCollection Relationships { get { return mvarRelationships; } }
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
mvarContentTypes.Clear();
|
||||
mvarRelationships.Clear();
|
||||
}
|
||||
|
||||
public override void CopyTo(ObjectModel where)
|
||||
{
|
||||
PackageObjectModel clone = (where as PackageObjectModel);
|
||||
if (clone == null) throw new ObjectModelNotSupportedException();
|
||||
|
||||
foreach (ContentType item in mvarContentTypes)
|
||||
{
|
||||
clone.ContentTypes.Add(item.Clone() as ContentType);
|
||||
}
|
||||
foreach (Relationship item in mvarRelationships)
|
||||
{
|
||||
clone.Relationships.Add(item.Clone() as Relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.Package.Relationships
|
||||
{
|
||||
public class Relationship : ICloneable
|
||||
{
|
||||
public class RelationshipCollection
|
||||
: System.Collections.ObjectModel.Collection<Relationship>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private string mvarID = String.Empty;
|
||||
public string ID { get { return mvarID; } set { mvarID = value; } }
|
||||
|
||||
private string mvarSchema = String.Empty;
|
||||
public string Schema { get { return mvarSchema; } set { mvarSchema = value; } }
|
||||
|
||||
private string mvarTarget = String.Empty;
|
||||
public string Target { get { return mvarTarget; } set { mvarTarget = value; } }
|
||||
|
||||
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
Relationship clone = new Relationship();
|
||||
clone.ID = (mvarID.Clone() as string);
|
||||
clone.Schema = (mvarSchema.Clone() as string);
|
||||
clone.Target = (mvarTarget.Clone() as string);
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.Package.Relationships
|
||||
{
|
||||
public class RelationshipsObjectModel : ObjectModel
|
||||
{
|
||||
private Relationship.RelationshipCollection mvarRelationships = new Relationship.RelationshipCollection();
|
||||
public Relationship.RelationshipCollection Relationships { get { return mvarRelationships; } }
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
mvarRelationships.Clear();
|
||||
}
|
||||
|
||||
public override void CopyTo(ObjectModel where)
|
||||
{
|
||||
RelationshipsObjectModel clone = (where as RelationshipsObjectModel);
|
||||
foreach (Relationship item in mvarRelationships)
|
||||
{
|
||||
clone.Relationships.Add(item.Clone() as Relationship);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -77,6 +77,9 @@
|
||||
<Compile Include="DataFormats\Help\Compiled\WinHelp\Internal\TopicLinkDisplay31Opcode.cs" />
|
||||
<Compile Include="DataFormats\Help\Compiled\WinHelp\Internal\TopicLinkRecordType.cs" />
|
||||
<Compile Include="DataFormats\Help\TableOfContents\V3\H1TDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Package\ContentTypes\OPCContentTypesDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Package\OpenPackagingConvention\OPCDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Package\Relationships\OPCRelationshipsDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Shortcut\Microsoft\LNKDataFlags.cs" />
|
||||
<Compile Include="DataFormats\Shortcut\Microsoft\LNKDataFormat.cs" />
|
||||
<Compile Include="DataFormats\Shortcut\Microsoft\LNKFileAttributeFlags.cs" />
|
||||
@ -84,6 +87,11 @@
|
||||
<Compile Include="DataFormats\Shortcut\Microsoft\LNKLocationFlags.cs" />
|
||||
<Compile Include="DataFormats\Shortcut\Microsoft\LNKWindowState.cs" />
|
||||
<Compile Include="ObjectModels\Help\Compiled\CompiledHelpObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\Package\ContentTypes\ContentType.cs" />
|
||||
<Compile Include="ObjectModels\Package\ContentTypes\ContentTypesObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\Package\PackageObjectModel.cs" />
|
||||
<Compile Include="ObjectModels\Package\Relationships\Relationship.cs" />
|
||||
<Compile Include="ObjectModels\Package\Relationships\RelationshipsObjectModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="DataFormats\Text\Formatted\XPS\XPSDataFormat.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user