Beginning major rewrite of the UniversalEditor infrastructure... it compiles, but further testing and fixing is still needed

This commit is contained in:
Michael Becker 2014-11-12 15:47:03 -05:00
parent 073033ac0b
commit 4e141e9d9a
15 changed files with 591 additions and 586 deletions

View File

@ -89,7 +89,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
if (mvarAccessor != null)
{
// show all dataformats for the current accessor
omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels((mvarAccessor as FileAccessor).FileName);
omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels(mvarAccessor);
}
else
{
@ -123,8 +123,17 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
{
if (mvarAccessor != null)
{
// show all dataformats for the current accessor
dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats((mvarAccessor as FileAccessor).FileName);
// TODO: This desperately needs to be fixed; GetAvailableDataFormats should take
// an accessor, not a file name, as parameter to be cross-accessor compatible!!!
if (mvarAccessor is FileAccessor)
{
// show all dataformats for the current accessor
dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(mvarAccessor);
}
else
{
dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats();
}
}
else if (mvarObjectModel != null)
{
@ -234,8 +243,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
{
if (mvarAccessor is FileAccessor)
{
string filename = (mvarAccessor as FileAccessor).FileName;
DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(filename);
DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(mvarAccessor);
if (mvarDataFormat == null)
{
@ -261,7 +269,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
else if (mvarAccessor is FileAccessor)
{
string filename = (mvarAccessor as FileAccessor).FileName;
ObjectModelReference[] omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels(filename);
ObjectModelReference[] omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels(mvarAccessor);
if (omrs.Length == 1)
{
mvarObjectModel = omrs[0].Create();
@ -272,10 +280,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
if (mvarAccessor != null)
{
if (mvarAccessor is FileAccessor)
{
txtAccessor.Text = "File: " + (mvarAccessor as FileAccessor).FileName;
}
txtAccessor.Text = mvarAccessor.ToString();
}
if (mvarDataFormat != null)
{

View File

@ -50,7 +50,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
SessionManager.Session session = (lv.SelectedItems[0].Data as SessionManager.Session);
Dictionary<MainWindow, string[]> filenames = new Dictionary<MainWindow, string[]>();
Dictionary<MainWindow, Document[]> filenames = new Dictionary<MainWindow, Document[]>();
foreach (SessionManager.Window window in session.Windows)
{
MainWindow wnd = new MainWindow();
@ -59,13 +59,13 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
wnd.Top = window.Top;
wnd.Width = window.Width;
wnd.Height = window.Height;
filenames.Add(wnd, window.FileNames.ToArray());
filenames.Add(wnd, window.Documents.ToArray());
wnd.Show();
Engine.CurrentEngine.Windows.Add(wnd);
}
foreach (KeyValuePair<MainWindow, string[]> fkvp in filenames)
foreach (KeyValuePair<MainWindow, Document[]> fkvp in filenames)
{
fkvp.Key.OpenFile(fkvp.Value);
}
@ -107,10 +107,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Dialogs
System.Collections.ObjectModel.ReadOnlyCollection<Document> documents = wnd.Documents;
foreach (Document doc in documents)
{
if (System.IO.File.Exists(doc.Title))
{
window.FileNames.Add(doc.Title);
}
window.Documents.Add(doc);
}
session.Windows.Add(window);
}

View File

@ -300,7 +300,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
private void tsmiBookmark_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = (sender as ToolStripMenuItem);
OpenFile(tsmi.ToolTipText);
OpenFile(tsmi.Tag as Document);
}
PropertyGridControl pgc = new PropertyGridControl();
@ -779,7 +779,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
Pages.EditorPage page = new Pages.EditorPage();
page.DocumentEdited += page_DocumentEdited;
page.FileName = "<untitled>";
page.Title = "<untitled>";
ObjectModel objm = template.ObjectModelReference.Create();
if (objm == null)
@ -839,44 +839,26 @@ namespace UniversalEditor.UserInterface.WindowsForms
dlg.Mode = DocumentPropertiesDialogMode.Open;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
OpenFile((dlg.Accessor as FileAccessor).FileName);
OpenFile(new Document(dlg.ObjectModel, dlg.DataFormat, dlg.Accessor));
}
// Display the Open File dialog
/*
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.AutoUpgradeEnabled = true;
ofd.Filter = "All Files (*.*)|*.*";
ofd.Multiselect = true;
Glue.Common.Methods.SendApplicationEvent(new Glue.ApplicationEventEventArgs(Glue.Common.Constants.EventNames.BeforeOpenFileDialog,
new KeyValuePair<string, object>("Filter", ofd.Filter),
new KeyValuePair<string, object>("FilterIndex", ofd.FilterIndex),
new KeyValuePair<string, object>("FileNames", ofd.FileNames)
));
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Glue.Common.Methods.SendApplicationEvent(new Glue.ApplicationEventEventArgs(Glue.Common.Constants.EventNames.AfterOpenFileDialog,
new KeyValuePair<string, object>("Filter", ofd.Filter),
new KeyValuePair<string, object>("FilterIndex", ofd.FilterIndex),
new KeyValuePair<string, object>("FileNames", ofd.FileNames)
));
OpenFile(ofd.FileNames);
}
}
*/
}
public void OpenFile(params string[] FileNames)
public void OpenFile(params string[] fileNames)
{
foreach (string FileName in FileNames)
Document[] documents = new Document[fileNames.Length];
for (int i = 0; i < documents.Length; i++)
{
OpenFile(FileName, false);
documents[i] = new Document(null, null, new FileAccessor(fileNames[i]));
}
OpenFile(documents);
}
public void OpenFile(params Document[] documents)
{
foreach (Document doc in documents)
{
OpenFile(doc, false);
}
}
public void OpenFile(string FileName, bool reuseTab)
public void OpenFile(Document document, bool reuseTab)
{
Pages.EditorPage page = new Pages.EditorPage();
if (reuseTab && dcc.SelectedWindow != null)
@ -884,11 +866,11 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
else
{
DockingWindow wnd = dcc.Windows.Add(System.IO.Path.GetFileName(FileName), page);
DockingWindow wnd = dcc.Windows.Add(document.Accessor.GetFileTitle(), page);
dcc.Areas[DockPosition.Center].Areas[DockPosition.Center].Windows.Add(wnd);
}
page.OpenFile(FileName);
page.OpenFile(document);
page.FileOpened += page_FileOpened;
}
@ -990,8 +972,9 @@ namespace UniversalEditor.UserInterface.WindowsForms
page.Description = FileName + "::/" + file.Name;
byte[] data = file.GetDataAsByteArray();
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(ms, file.Name);
MemoryAccessor ma = new MemoryAccessor(data);
DataFormatReference[] dfrs = UniversalEditor.Common.Reflection.GetAvailableDataFormats(ma);
foreach (DataFormatReference dfr in dfrs)
{
ObjectModelReference[] omrs = UniversalEditor.Common.Reflection.GetAvailableObjectModels(dfr);
@ -999,7 +982,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
DataFormat df = dfr.Create();
ObjectModel om = omrs[0].Create();
page.Document = new Document(om, df, new StreamAccessor(ms));
page.Document = new Document(om, df, ma);
// page.DocumentEdited += page_DocumentEdited;
page.Document.InputAccessor.Open();
page.Document.Load();
@ -1113,7 +1096,9 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
public void OpenProject(string FileName, bool combineObjects = false)
{
SolutionObjectModel solution = UniversalEditor.Common.Reflection.GetAvailableObjectModel<SolutionObjectModel>(FileName);
FileAccessor fa = new FileAccessor(FileName);
SolutionObjectModel solution = UniversalEditor.Common.Reflection.GetAvailableObjectModel<SolutionObjectModel>(fa);
if (combineObjects)
{
SolutionObjectModel oldsolution = CurrentSolution;
@ -1772,7 +1757,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
private void page_Navigate(object sender, UniversalEditor.UserInterface.WindowsForms.Controls.NavigateEventArgs e)
{
OpenFile(e.FileName, ((Control.ModifierKeys & Keys.Alt) != Keys.Alt));
// OpenFile(e.FileName, ((Control.ModifierKeys & Keys.Alt) != Keys.Alt));
}
#endregion
@ -1846,7 +1831,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
return;
}
OpenFile(tsmi.ToolTipText);
OpenFile(new Document(null, null, new FileAccessor(tsmi.ToolTipText)));
}
#endregion
@ -1998,7 +1983,12 @@ namespace UniversalEditor.UserInterface.WindowsForms
else if (e.Data.GetDataPresent("FileNameW"))
{
string[] filenames = (e.Data.GetData("FileNameW") as string[]);
OpenFile(filenames);
Document[] documents = new Document[filenames.Length];
for (int i = 0; i < documents.Length; i++)
{
documents[i] = new Document(null, null, new FileAccessor(filenames[i]));
}
OpenFile(documents);
}
else if (e.Data.GetDataPresent("Shell IDList Array"))
{
@ -2015,7 +2005,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
Guid guid = br.ReadGuid();
short terminator = br.ReadInt16();
OpenFile("shell://" + guid.ToString("B"));
// OpenFile(new Document(null, null, new ShellObjectAccessor(guid)));
}
}
@ -2023,7 +2013,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
{
if (e.KeyCode == Keys.Enter)
{
OpenFile(cboAddress.Text, !e.Alt);
OpenFile(new Document(null, null, new FileAccessor(cboAddress.Text)), !e.Alt);
e.Handled = true;
e.SuppressKeyPress = true;
}
@ -2044,7 +2034,14 @@ namespace UniversalEditor.UserInterface.WindowsForms
}
Pages.EditorPage editorPage = (dcc.SelectedWindow.Control as Pages.EditorPage);
cboAddress.Text = editorPage.FileName;
if (editorPage.Document != null && editorPage.Document.Accessor != null)
{
cboAddress.Text = editorPage.Document.Accessor.GetFileName();
}
else
{
cboAddress.Text = String.Empty;
}
if (mvarCurrentDocument != editorPage.Document)
{

View File

@ -190,12 +190,12 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
if (IsHandleCreated) Invoke(_NotifyOnFileOpened, sender, e);
}
public void OpenFile(string FileName)
public void OpenFile(Document document)
{
this.FileName = FileName;
this.Document = document;
System.Threading.Thread tOpenFile = new System.Threading.Thread(tOpenFile_ParameterizedThreadStart);
tOpenFile.Start(FileName);
System.Threading.Thread tOpenFile = new System.Threading.Thread(tOpenFile_ThreadStart);
tOpenFile.Start();
}
private void _ErrorMessageConfig(bool visible, string title)
@ -212,16 +212,9 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
if (message != null) errorMessage1.Details = message;
}
private void tOpenFile_ParameterizedThreadStart(object param)
private void tOpenFile_ThreadStart()
{
string Path = param.ToString();
string[] FileNameParts = Path.Split(new string[] { "::/" }, 2, StringSplitOptions.None);
string FileName = FileNameParts[0];
string SecondaryFileName = String.Empty;
if (FileNameParts.Length > 1) SecondaryFileName = FileNameParts[1];
DataFormatReference[] fmts = UniversalEditor.Common.Reflection.GetAvailableDataFormats(FileName);
DataFormatReference[] fmts = UniversalEditor.Common.Reflection.GetAvailableDataFormats(mvarDocument.Accessor);
#region When there is no available DataFormat
if (fmts.Length == 0)
{
@ -232,7 +225,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
else if (fmts.Length > 1)
{
// attempt to guess the data format for the object model
ObjectModelReference[] objms = UniversalEditor.Common.Reflection.GetAvailableObjectModels(FileName);
ObjectModelReference[] objms = UniversalEditor.Common.Reflection.GetAvailableObjectModels(mvarDocument.Accessor);
ObjectModel om1 = null;
DataFormat df1 = null;
bool found1 = false;
@ -250,7 +243,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
{
df = dfr.Create();
Document d = new UniversalEditor.Document(om, df, new FileAccessor(FileName));
Document d = new UniversalEditor.Document(om, df, mvarDocument.Accessor);
d.InputAccessor.Open();
try
{
@ -311,7 +304,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
}
else
{
Document = new Document(om1, df1, new FileAccessor(FileName));
Document = new Document(om1, df1, mvarDocument.Accessor);
if (IsHandleCreated) Invoke(new Action<bool, string>(_ErrorMessageConfig), false, null);
@ -344,36 +337,14 @@ namespace UniversalEditor.UserInterface.WindowsForms.Pages
ObjectModel objm = objms[0].Create();
DataFormat fmt = fmts[0].Create();
if (!String.IsNullOrEmpty(SecondaryFileName))
{
FileSystemObjectModel fsom = (objm as FileSystemObjectModel);
Document document = new UniversalEditor.Document(fsom, fmt, new FileAccessor(FileName));
if (!Engine.CurrentEngine.ShowCustomOptionDialog(ref fmt, CustomOptionDialogType.Import)) return;
object fso = fsom.FindObject(SecondaryFileName);
if (fso is UniversalEditor.ObjectModels.FileSystem.File)
{
UniversalEditor.ObjectModels.FileSystem.File file = (fso as UniversalEditor.ObjectModels.FileSystem.File);
// OpenFileInternal(file, FileName);
}
else if (fso is UniversalEditor.ObjectModels.FileSystem.Folder)
{
}
else
{
}
return;
}
else
{
if (!Engine.CurrentEngine.ShowCustomOptionDialog(ref fmt, CustomOptionDialogType.Import)) return;
Document document = new UniversalEditor.Document(objm, fmt, mvarDocument.Accessor);
document.InputAccessor.Open();
document.Load();
Document document = new UniversalEditor.Document(objm, fmt, new FileAccessor(FileName));
document.InputAccessor.Open();
document.Load();
Document = document;
NotifyOnFileOpened(this, EventArgs.Empty);
}
Document = document;
NotifyOnFileOpened(this, EventArgs.Empty);
}
catch (InvalidDataFormatException ex)
{

View File

@ -7,31 +7,44 @@ using System.Windows.Forms;
namespace UniversalEditor.UserInterface.WindowsForms.Pages
{
public partial class FilePage : Page
{
public FilePage()
{
InitializeComponent();
}
public partial class FilePage : Page
{
public FilePage()
{
InitializeComponent();
}
private string mvarFileName = String.Empty;
public string FileName
{
get { return mvarFileName; }
set
{
mvarFileName = value;
private Document mvarDocument = null;
public Document Document
{
get { return mvarDocument; }
set
{
OnDocumentChanging(EventArgs.Empty);
try
{
Title = System.IO.Path.GetFileName(mvarFileName);
}
catch
{
Title = mvarFileName;
}
Description = mvarFileName;
}
}
}
mvarDocument = value;
if (mvarDocument.Accessor != null)
{
try
{
Title = System.IO.Path.GetFileName(mvarDocument.Accessor.GetFileName());
}
catch
{
Title = mvarDocument.Accessor.GetFileName();
}
Description = mvarDocument.Accessor.GetFileName();
}
OnDocumentChanged(EventArgs.Empty);
}
}
protected virtual void OnDocumentChanging(EventArgs e)
{
}
protected virtual void OnDocumentChanged(EventArgs e)
{
}
}
}

View File

@ -397,13 +397,13 @@ namespace UniversalEditor.UserInterface.WindowsForms
dlg.ShowDialog();
}
protected override IHostApplicationWindow OpenWindowInternal(params string[] FileNames)
protected override IHostApplicationWindow OpenWindowInternal(params Document[] documents)
{
MainWindow mw = new MainWindow();
if (FileNames.Length > 0)
if (documents.Length > 0)
{
mw.OpenFile(FileNames);
mw.OpenFile(documents);
}
mw.Show();
return mw;

View File

@ -85,7 +85,6 @@ namespace UniversalEditor
{
get { return String.Empty; }
}
public virtual string GetFileTitle()
{
return String.Empty;

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalEditor.IO;
namespace UniversalEditor
{
@ -74,188 +75,52 @@ namespace UniversalEditor
}
public bool MatchesFile(string FileName)
{
System.IO.FileStream fs = null;
UniversalEditor.Accessors.FileAccessor fa = null;
if (System.IO.File.Exists(FileName))
{
fs = System.IO.File.Open(FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
fa = new UniversalEditor.Accessors.FileAccessor(FileName);
}
bool matches = MatchesFile(FileName, fs);
if (fs != null) fs.Close();
bool matches = MatchesFile(FileName, fa);
if (fa != null) fa.Close();
return matches;
}
public bool MatchesFile(string FileName, byte[] FileData)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(FileData);
UniversalEditor.Accessors.MemoryAccessor ms = new UniversalEditor.Accessors.MemoryAccessor(FileData);
return MatchesFile(FileName, ms);
}
public bool MatchesFile(string FileName, System.IO.Stream FileData)
public bool MatchesFile(string FileName, Accessor FileData)
{
if (FileName == null) return false;
if (System.IO.File.Exists(FileName)) FileName = System.IO.Path.GetFileName(FileName);
if (!FileData.IsOpen) throw new InvalidOperationException("Accessor must be open");
switch (mvarHintComparison)
{
case DataFormatHintComparison.Always:
{
return true;
}
{
return true;
}
case DataFormatHintComparison.None:
{
return false;
}
{
return false;
}
case DataFormatHintComparison.FilterOnly:
{
foreach (string filter in mvarFileNameFilters)
{
foreach (string filter in mvarFileNameFilters)
{
if (FileName.ToLower().Match(filter.ToLower())) return true;
}
return false;
if (FileName.ToLower().Match(filter.ToLower())) return true;
}
return false;
}
case DataFormatHintComparison.FilterThenMagic:
{
foreach (string filter in mvarFileNameFilters)
{
foreach (string filter in mvarFileNameFilters)
{
if (FileName.ToLower().Match(filter.ToLower())) return true;
}
if (FileData != null)
{
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
byte?[] bytes = mvarMagicBytes[i];
if ((FileData.Position + bytes.Length) <= FileData.Length)
{
bool ret = true;
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.Begin);
}
}
FileData.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
for (int j = 0; j < bytes.Length; j++)
{
if (bytes[j] == null) continue;
if (bytes[j] != cmp[j])
{
ret = false;
break;
}
}
if (ret) return true;
}
}
}
return false;
if (FileName.ToLower().Match(filter.ToLower())) return true;
}
case DataFormatHintComparison.MagicOnly:
{
if (FileData != null)
{
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
byte?[] bytes = mvarMagicBytes[i];
if ((FileData.Position + bytes.Length) <= FileData.Length)
{
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.Begin);
}
}
FileData.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
bool ret = true;
for (int j = 0; j < bytes.Length; j++)
{
if (bytes[j] == null) continue;
if (bytes[j] != cmp[j])
{
ret = false;
break;
}
}
if (ret) return true;
}
}
}
return false;
}
case DataFormatHintComparison.MagicThenFilter:
{
if (FileData != null)
{
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
byte?[] bytes = mvarMagicBytes[i];
if ((FileData.Position + bytes.Length) <= FileData.Length)
{
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.Begin);
}
}
FileData.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
bool ret = true;
for (int j = 0; j < bytes.Length; j++)
{
if (bytes[j] == null) continue;
if (bytes[j] != cmp[j])
{
ret = false;
break;
}
}
if (ret) return true;
}
}
}
foreach (string filter in mvarFileNameFilters)
{
if (FileName.ToLower().Match(filter.ToLower())) return true;
}
return false;
}
}
return false;
}
public bool MatchesFile(System.IO.Stream FileData)
{
switch (mvarHintComparison)
{
case DataFormatHintComparison.Always:
{
return true;
}
case DataFormatHintComparison.MagicOnly:
case DataFormatHintComparison.FilterThenMagic:
case DataFormatHintComparison.MagicThenFilter:
if (FileData != null)
{
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
@ -264,20 +129,19 @@ namespace UniversalEditor
{
bool ret = true;
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.End);
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], System.IO.SeekOrigin.Begin);
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.Begin);
}
}
FileData.Read(cmp, 0, cmp.Length);
FileData.Reader.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
for (int j = 0; j < bytes.Length; j++)
@ -292,12 +156,151 @@ namespace UniversalEditor
if (ret) return true;
}
}
return false;
}
case DataFormatHintComparison.None:
return false;
}
case DataFormatHintComparison.MagicOnly:
{
if (FileData != null)
{
return false;
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
byte?[] bytes = mvarMagicBytes[i];
if ((FileData.Position + bytes.Length) <= FileData.Length)
{
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.Begin);
}
}
FileData.Reader.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
bool ret = true;
for (int j = 0; j < bytes.Length; j++)
{
if (bytes[j] == null) continue;
if (bytes[j] != cmp[j])
{
ret = false;
break;
}
}
if (ret) return true;
}
}
}
return false;
}
case DataFormatHintComparison.MagicThenFilter:
{
if (FileData != null)
{
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
byte?[] bytes = mvarMagicBytes[i];
if ((FileData.Position + bytes.Length) <= FileData.Length)
{
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.Begin);
}
}
FileData.Reader.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
bool ret = true;
for (int j = 0; j < bytes.Length; j++)
{
if (bytes[j] == null) continue;
if (bytes[j] != cmp[j])
{
ret = false;
break;
}
}
if (ret) return true;
}
}
}
foreach (string filter in mvarFileNameFilters)
{
if (FileName.ToLower().Match(filter.ToLower())) return true;
}
return false;
}
}
return false;
}
public bool MatchesFile(Accessor FileData)
{
switch (mvarHintComparison)
{
case DataFormatHintComparison.Always:
{
return true;
}
case DataFormatHintComparison.MagicOnly:
case DataFormatHintComparison.FilterThenMagic:
case DataFormatHintComparison.MagicThenFilter:
{
for (int i = 0; i < mvarMagicBytes.Count; i++)
{
byte?[] bytes = mvarMagicBytes[i];
if ((FileData.Position + bytes.Length) <= FileData.Length)
{
bool ret = true;
byte[] cmp = new byte[bytes.Length];
long offset = FileData.Position;
if (i < mvarMagicByteOffsets.Length)
{
if (mvarMagicByteOffsets[i] < 0)
{
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.End);
}
else
{
FileData.Seek(mvarMagicByteOffsets[i], SeekOrigin.Begin);
}
}
FileData.Reader.Read(cmp, 0, cmp.Length);
FileData.Position = offset;
for (int j = 0; j < bytes.Length; j++)
{
if (bytes[j] == null) continue;
if (bytes[j] != cmp[j])
{
ret = false;
break;
}
}
if (ret) return true;
}
}
return false;
}
case DataFormatHintComparison.None:
{
return false;
}
}
return false;
}

View File

@ -398,14 +398,23 @@ namespace UniversalEditor.UserInterface
private IHostApplicationWindow mvarLastWindow = null;
public IHostApplicationWindow LastWindow { get { return mvarLastWindow; } set { mvarLastWindow = value; } }
public void OpenFile(params string[] FileNames)
public void OpenFile(params string[] fileNames)
{
Document[] documents = new Document[fileNames.Length];
for (int i = 0; i < fileNames.Length; i++)
{
documents[i] = new Document(null, null, new FileAccessor(fileNames[i]));
}
OpenFile(documents);
}
public void OpenFile(params Document[] documents)
{
if (LastWindow == null)
{
OpenWindow(FileNames);
OpenWindow(documents);
return;
}
LastWindow.OpenFile(FileNames);
LastWindow.OpenFile(documents);
}
/// <summary>
@ -413,18 +422,31 @@ namespace UniversalEditor.UserInterface
/// </summary>
/// <param name="FileNames">The file name(s) of the document(s) to load.</param>
/// <returns>An <see cref="IHostApplicationWindow"/> representing the window that was created.</returns>
protected abstract IHostApplicationWindow OpenWindowInternal(params string[] FileNames);
protected abstract IHostApplicationWindow OpenWindowInternal(params Document[] documents);
public abstract void ShowAboutDialog();
public abstract void ShowAboutDialog(DataFormatReference dfr);
public void OpenWindow()
{
OpenWindow(new Document[0]);
}
public void OpenWindow(params string[] fileNames)
{
Document[] documents = new Document[fileNames.Length];
for (int i = 0; i < fileNames.Length; i++)
{
documents[i] = new Document(null, null, new FileAccessor(fileNames[i]));
}
OpenWindow(documents);
}
/// <summary>
/// Opens a new window, optionally loading the specified documents.
/// </summary>
/// <param name="FileNames">The file name(s) of the document(s) to load.</param>
public void OpenWindow(params string[] FileNames)
public void OpenWindow(params Document[] documents)
{
IHostApplicationWindow window = OpenWindowInternal(FileNames);
IHostApplicationWindow window = OpenWindowInternal(documents);
window.WindowClosed += delegate(object sender, EventArgs e)
{
mvarWindows.Remove(window);
@ -439,12 +461,13 @@ namespace UniversalEditor.UserInterface
{
if (LastWindow != null)
{
string[] FileNames = new string[e.CommandLineArgs.Length - 1];
Document[] documents = new Document[e.CommandLineArgs.Length - 1];
for (int i = 1; i < e.CommandLineArgs.Length; i++)
{
FileNames[i - 1] = e.CommandLineArgs[i];
documents[i - 1] = new Document(null, null, new FileAccessor(e.CommandLineArgs[i]));
}
LastWindow.OpenFile(FileNames);
LastWindow.OpenFile(documents);
LastWindow.ActivateWindow();
}
}

View File

@ -13,7 +13,8 @@ namespace UniversalEditor.UserInterface
void NewProject(bool combineObjects = false);
void OpenFile();
void OpenFile(params string[] FileNames);
void OpenFile(params string[] fileNames);
void OpenFile(params Document[] documents);
void OpenProject(bool combineObjects = false);
void OpenProject(string FileName, bool combineObjects = false);

View File

@ -34,8 +34,8 @@ namespace UniversalEditor.UserInterface
private WindowState mvarWindowState = WindowState.Normal;
public WindowState WindowState { get { return mvarWindowState; } set { mvarWindowState = value; } }
private List<string> mvarFileNames = new List<string>();
public List<string> FileNames { get { return mvarFileNames; } }
private List<Document> mvarDocuments = new List<Document>();
public List<Document> Documents { get { return mvarDocuments; } }
}
public class Session
@ -130,10 +130,17 @@ namespace UniversalEditor.UserInterface
if (tagDocument == null) continue;
if (tagDocument.FullName != "Document") continue;
// TODO: Implement accessor agnosticism in Session Manager!!!
#if DEBUG
throw new NotImplementedException();
#endif
/*
MarkupAttribute attFileName = tagDocument.Attributes["FileName"];
if (attFileName == null) continue;
window.FileNames.Add(attFileName.Value);
window.Documents.Add(attFileName.Value);
*/
}
}
@ -185,15 +192,40 @@ namespace UniversalEditor.UserInterface
tagWindow.Attributes.Add("Width", window.Width.ToString());
tagWindow.Attributes.Add("Height", window.Height.ToString());
if (window.FileNames.Count > 0)
if (window.Documents.Count > 0)
{
MarkupTagElement tagDocuments = new MarkupTagElement();
tagDocuments.FullName = "Documents";
foreach (string fileName in window.FileNames)
foreach (Document document in window.Documents)
{
MarkupTagElement tagDocument = new MarkupTagElement();
tagDocument.FullName = "Document";
tagDocument.Attributes.Add("FileName", fileName);
#if DEBUG
throw new NotImplementedException("Implement accessor agnosticism in Session Manager");
#endif
// We need to store information about the ObjectModel and DataFormat
// if the document has not been saved yet.
if (document.ObjectModel != null)
{
MarkupTagElement tagObjectModel = new MarkupTagElement();
tagObjectModel.FullName = "ObjectModel";
ObjectModelReference omr = document.ObjectModel.MakeReference();
if (omr.ObjectModelTypeName != null)
{
tagObjectModel.Attributes.Add("TypeName", omr.ObjectModelTypeName);
}
if (omr.ObjectModelID != Guid.Empty)
{
tagObjectModel.Attributes.Add("ID", omr.ObjectModelID.ToString("B"));
}
tagDocument.Elements.Add(tagObjectModel);
}
// tagDocument.Attributes.Add("FileName", fileName);
tagDocuments.Elements.Add(tagDocument);
}
tagWindow.Elements.Add(tagDocuments);

View File

@ -935,17 +935,17 @@ namespace UniversalEditor.Common
if (mvarAvailableObjectModels == null) Initialize();
return mvarAvailableObjectModels;
}
public static ObjectModelReference[] GetAvailableObjectModels(string FileName)
{
return GetAvailableObjectModels(FileName, DataFormatCapabilities.All);
}
public static T GetAvailableObjectModel<T>(string FileName) where T : ObjectModel
public static T GetAvailableObjectModel<T>(string filename) where T : ObjectModel
{
ObjectModelReference[] omrs = GetAvailableObjectModels(FileName);
return GetAvailableObjectModel<T>(new FileAccessor(filename));
}
public static T GetAvailableObjectModel<T>(Accessor accessor) where T : ObjectModel
{
ObjectModelReference[] omrs = GetAvailableObjectModels(accessor);
if (omrs.Length == 0)
{
// we failed to find an object model from the file name, so let's try and
// we failed to find an object model from the accessor, 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);
@ -954,7 +954,6 @@ namespace UniversalEditor.Common
DataFormatReference[] dfrs = GetAvailableDataFormats(om.MakeReference());
FileAccessor accessor = new FileAccessor(FileName);
foreach (DataFormatReference dfr in dfrs)
{
try
@ -976,11 +975,11 @@ namespace UniversalEditor.Common
{
ObjectModel om = (T)omr.Create();
DataFormatReference[] dfrs = GetAvailableDataFormats(FileName, omr);
DataFormatReference[] dfrs = GetAvailableDataFormats(accessor, omr);
foreach (DataFormatReference dfr in dfrs)
{
DataFormat df = dfr.Create();
Document doc = new Document(om, df, new FileAccessor(FileName, false, false, false));
Document doc = new Document(om, df, accessor);
try
{
doc.InputAccessor.Open();
@ -1002,10 +1001,14 @@ namespace UniversalEditor.Common
}
return null;
}
public static bool GetAvailableObjectModel<T>(string FileName, ref T objectToFill) where T : ObjectModel
public static bool GetAvailableObjectModel<T>(string filename, ref T objectToFill) where T : ObjectModel
{
return GetAvailableObjectModel<T>(new FileAccessor(filename), ref objectToFill);
}
public static bool GetAvailableObjectModel<T>(Accessor accessor, ref T objectToFill) where T : ObjectModel
{
ObjectModel om = (T)objectToFill;
DataFormatReference[] dfrs = GetAvailableDataFormats(FileName);
DataFormatReference[] dfrs = GetAvailableDataFormats(accessor);
if (dfrs.Length == 0)
{
return false;
@ -1014,7 +1017,7 @@ namespace UniversalEditor.Common
for (int i = 0; i < dfrs.Length; i++)
{
DataFormat df = dfrs[i].Create();
Document doc = new Document(om, df, new FileAccessor(FileName, false, false, false));
Document doc = new Document(om, df, accessor);
try
{
doc.InputAccessor.Open();
@ -1053,10 +1056,10 @@ namespace UniversalEditor.Common
}
return list.ToArray();
}
public static ObjectModelReference[] GetAvailableObjectModels(string FileName, DataFormatCapabilities capabilities)
public static ObjectModelReference[] GetAvailableObjectModels(Accessor accessor, DataFormatCapabilities capabilities = DataFormatCapabilities.All)
{
ObjectModelReference[] array = GetAvailableObjectModels();
DataFormatReference[] dfs = GetAvailableDataFormats(FileName);
DataFormatReference[] dfs = GetAvailableDataFormats(accessor);
List<ObjectModelReference> list = new List<ObjectModelReference>();
if (dfs.Length == 0) return list.ToArray();
@ -1133,7 +1136,8 @@ namespace UniversalEditor.Common
if (mvarAvailableDataFormats == null) Initialize();
return mvarAvailableDataFormats;
}
public static DataFormatReference[] GetAvailableDataFormats(string FileName)
public static DataFormatReference[] GetAvailableDataFormats(string filename)
{
List<DataFormatReference> list = new List<DataFormatReference>();
DataFormatReference[] dfs = GetAvailableDataFormats();
@ -1141,7 +1145,25 @@ namespace UniversalEditor.Common
{
foreach (DataFormatFilter filter in df.Filters)
{
if (filter.MatchesFile(FileName))
if (filter.MatchesFile(filename))
{
list.Add(df);
break;
}
}
}
list.Sort(new Comparison<DataFormatReference>(_DataFormatReferenceComparer));
return list.ToArray();
}
public static DataFormatReference[] GetAvailableDataFormats(Accessor accessor)
{
List<DataFormatReference> list = new List<DataFormatReference>();
DataFormatReference[] dfs = GetAvailableDataFormats();
foreach (DataFormatReference df in dfs)
{
foreach (DataFormatFilter filter in df.Filters)
{
if (filter.MatchesFile(accessor.GetFileName(), accessor))
{
list.Add(df);
break;
@ -1152,23 +1174,6 @@ namespace UniversalEditor.Common
return list.ToArray();
}
public static DataFormatReference[] GetAvailableDataFormats(System.IO.Stream stream, string FileName = null)
{
List<DataFormatReference> list = new List<DataFormatReference>();
DataFormatReference[] dfs = GetAvailableDataFormats();
foreach (DataFormatReference df in dfs)
{
foreach (DataFormatFilter filter in df.Filters)
{
if (filter.MatchesFile(FileName, stream))
{
list.Add(df);
break;
}
}
}
return list.ToArray();
}
public static DataFormatReference[] GetAvailableDataFormats(ObjectModelReference objectModelReference)
{
List<DataFormatReference> list = new List<DataFormatReference>();
@ -1182,7 +1187,7 @@ namespace UniversalEditor.Common
}
return list.ToArray();
}
public static DataFormatReference[] GetAvailableDataFormats(string FileName, ObjectModelReference omr)
public static DataFormatReference[] GetAvailableDataFormats(Accessor accessor, ObjectModelReference omr)
{
List<DataFormatReference> list = new List<DataFormatReference>();
DataFormatReference[] dfs = GetAvailableDataFormats();
@ -1192,7 +1197,7 @@ namespace UniversalEditor.Common
{
foreach (DataFormatFilter filter in df.Filters)
{
if (filter.MatchesFile(FileName))
if (filter.MatchesFile(accessor))
{
list.Add(df);
break;
@ -1323,63 +1328,16 @@ namespace UniversalEditor.Common
return handlers.ToArray();
}
#endif
public static T GetAvailableObjectModel<T>(byte[] data) where T : ObjectModel
{
return GetAvailableObjectModel<T>(data, null);
}
public static T GetAvailableObjectModel<T>(byte[] data, string FileName) where T : ObjectModel
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
return GetAvailableObjectModel<T>(ms, FileName);
}
public static T GetAvailableObjectModel<T>(System.IO.Stream stream) where T : ObjectModel
public static ObjectModel GetAvailableObjectModel(byte[] data, string filename, string ObjectModelTypeName)
{
return GetAvailableObjectModel<T>(stream, null);
return GetAvailableObjectModel(new MemoryAccessor(data, filename), ObjectModelTypeName);
}
public static T GetAvailableObjectModel<T>(System.IO.Stream stream, string FileName) where T : ObjectModel
public static ObjectModel GetAvailableObjectModel(Accessor accessor, string ObjectModelTypeName)
{
long resetpos = stream.Position;
long resetpos = accessor.Position;
DataFormatReference[] dfrs = GetAvailableDataFormats(stream, FileName);
foreach (DataFormatReference dfr in dfrs)
{
ObjectModelReference[] omrs = GetAvailableObjectModels(dfr);
foreach (ObjectModelReference omr in omrs)
{
if (omr.ObjectModelType == typeof(T))
{
T om = (omr.Create() as T);
if (om == null) return null;
DataFormat df = dfr.Create();
try
{
Document.Load(om, df, new StreamAccessor(stream));
}
catch (InvalidDataFormatException)
{
stream.Position = resetpos;
break;
}
return om;
}
}
}
return null;
}
public static ObjectModel GetAvailableObjectModel(byte[] data, string FileName, string ObjectModelTypeName)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream(data);
return GetAvailableObjectModel(ms, FileName, ObjectModelTypeName);
}
public static ObjectModel GetAvailableObjectModel(System.IO.Stream stream, string FileName, string ObjectModelTypeName)
{
long resetpos = stream.Position;
DataFormatReference[] dfrs = GetAvailableDataFormats(stream, FileName);
DataFormatReference[] dfrs = GetAvailableDataFormats(accessor);
foreach (DataFormatReference dfr in dfrs)
{
ObjectModelReference[] omrs = GetAvailableObjectModels(dfr);
@ -1393,11 +1351,11 @@ namespace UniversalEditor.Common
DataFormat df = dfr.Create();
try
{
Document.Load(om, df, new StreamAccessor(stream));
Document.Load(om, df, accessor);
}
catch (InvalidDataFormatException)
{
stream.Position = resetpos;
accessor.Position = resetpos;
break;
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using UniversalEditor.Accessors;
namespace UniversalEditor.ObjectModels.FileSystem
{
@ -19,11 +20,11 @@ namespace UniversalEditor.ObjectModels.FileSystem
}
public override void Clear()
{
mvarFiles.Clear();
mvarFolders.Clear();
mvarID = Guid.Empty;
mvarTitle = String.Empty;
mvarPathSeparators = new string[] { System.IO.Path.DirectorySeparatorChar.ToString(), System.IO.Path.AltDirectorySeparatorChar.ToString() };
mvarFiles.Clear();
mvarFolders.Clear();
mvarID = Guid.Empty;
mvarTitle = String.Empty;
mvarPathSeparators = new string[] { System.IO.Path.DirectorySeparatorChar.ToString(), System.IO.Path.AltDirectorySeparatorChar.ToString() };
}
public override void CopyTo(ObjectModel where)
{
@ -31,12 +32,12 @@ namespace UniversalEditor.ObjectModels.FileSystem
clone.ID = mvarID;
for (int i = 0; i < mvarFiles.Count; i++)
{
File file = mvarFiles[i];
File file = mvarFiles[i];
clone.Files.Add(file.Clone() as File);
}
for (int i = 0; i < mvarFolders.Count; i++)
{
Folder folder = mvarFolders[i];
Folder folder = mvarFolders[i];
clone.Folders.Add(folder.Clone() as Folder);
}
}
@ -53,7 +54,8 @@ namespace UniversalEditor.ObjectModels.FileSystem
foreach (string fileName in fileNames)
{
FileSystemObjectModel fsom1 = UniversalEditor.Common.Reflection.GetAvailableObjectModel<FileSystemObjectModel>(fileName);
FileAccessor accessor = new FileAccessor(fileName);
FileSystemObjectModel fsom1 = UniversalEditor.Common.Reflection.GetAvailableObjectModel<FileSystemObjectModel>(accessor);
if (fsom1 == null) continue;
fsom1.CopyTo(fsom);
@ -83,8 +85,8 @@ namespace UniversalEditor.ObjectModels.FileSystem
/// </summary>
public string Title { get { return mvarTitle; } set { mvarTitle = value; } }
private string[] mvarPathSeparators = new string[] { System.IO.Path.DirectorySeparatorChar.ToString(), System.IO.Path.AltDirectorySeparatorChar.ToString() };
public string[] PathSeparators { get { return mvarPathSeparators; } set { mvarPathSeparators = value; } }
private string[] mvarPathSeparators = new string[] { System.IO.Path.DirectorySeparatorChar.ToString(), System.IO.Path.AltDirectorySeparatorChar.ToString() };
public string[] PathSeparators { get { return mvarPathSeparators; } set { mvarPathSeparators = value; } }
public bool ContainsFile(string path)
{
@ -120,137 +122,137 @@ namespace UniversalEditor.ObjectModels.FileSystem
return null;
}
public Folder FindFolder(string name)
{
string[] path = name.Split(new char[] { '/' });
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
parent = mvarFolders[path[i]];
}
else
{
parent = parent.Folders[path[i]];
}
}
public Folder FindFolder(string name)
{
string[] path = name.Split(new char[] { '/' });
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
parent = mvarFolders[path[i]];
}
else
{
parent = parent.Folders[path[i]];
}
}
if (parent == null)
{
return mvarFolders[path[path.Length - 1]];
}
else
{
return parent.Folders[path[path.Length - 1]];
}
}
if (parent == null)
{
return mvarFolders[path[path.Length - 1]];
}
else
{
return parent.Folders[path[path.Length - 1]];
}
}
public object FindObject(string name)
{
string[] path = name.Split(new char[] { '/' });
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
parent = mvarFolders[path[i]];
}
else
{
parent = parent.Folders[path[i]];
}
}
public object FindObject(string name)
{
string[] path = name.Split(new char[] { '/' });
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
parent = mvarFolders[path[i]];
}
else
{
parent = parent.Folders[path[i]];
}
}
if (parent == null)
{
File file = mvarFiles[path[path.Length - 1]];
Folder folder = mvarFolders[path[path.Length - 1]];
if (folder == null) return file;
return folder;
}
else
{
File file = parent.Files[path[path.Length - 1]];
Folder folder = parent.Folders[path[path.Length - 1]];
if (folder == null) return file;
return folder;
}
}
if (parent == null)
{
File file = mvarFiles[path[path.Length - 1]];
Folder folder = mvarFolders[path[path.Length - 1]];
if (folder == null) return file;
return folder;
}
else
{
File file = parent.Files[path[path.Length - 1]];
Folder folder = parent.Folders[path[path.Length - 1]];
if (folder == null) return file;
return folder;
}
}
public Folder AddFolder(string name)
{
string[] path = name.Split(mvarPathSeparators, StringSplitOptions.None);
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
parent = mvarFolders[path[i]];
}
else
{
parent = parent.Folders[path[i]];
}
if (parent == null) throw new System.IO.DirectoryNotFoundException();
}
if (parent == null)
{
return mvarFolders.Add(path[path.Length - 1]);
}
return parent.Folders.Add(path[path.Length - 1]);
}
public Folder AddFolder(string name)
{
string[] path = name.Split(mvarPathSeparators, StringSplitOptions.None);
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
parent = mvarFolders[path[i]];
}
else
{
parent = parent.Folders[path[i]];
}
if (parent == null) throw new System.IO.DirectoryNotFoundException();
}
if (parent == null)
{
return mvarFolders.Add(path[path.Length - 1]);
}
return parent.Folders.Add(path[path.Length - 1]);
}
public File AddFile(string name)
{
string[] path = name.Split(mvarPathSeparators, StringSplitOptions.None);
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
if (mvarFolders.Contains(path[i]))
{
parent = mvarFolders[path[i]];
}
else
{
parent = mvarFolders.Add(path[i]);
}
}
else
{
if (parent.Folders.Contains(path[i]))
{
parent = parent.Folders[path[i]];
}
else
{
parent = parent.Folders.Add(path[i]);
}
}
public File AddFile(string name)
{
string[] path = name.Split(mvarPathSeparators, StringSplitOptions.None);
Folder parent = null;
for (int i = 0; i < path.Length - 1; i++)
{
if (parent == null)
{
if (mvarFolders.Contains(path[i]))
{
parent = mvarFolders[path[i]];
}
else
{
parent = mvarFolders.Add(path[i]);
}
}
else
{
if (parent.Folders.Contains(path[i]))
{
parent = parent.Folders[path[i]];
}
else
{
parent = parent.Folders.Add(path[i]);
}
}
if (parent == null)
{
throw new System.IO.DirectoryNotFoundException();
}
}
if (parent == null)
{
throw new System.IO.DirectoryNotFoundException();
}
}
if (parent == null)
{
File file = new File();
file.Name = path[path.Length - 1];
mvarFiles.Add(file);
return file;
}
else
{
File file = new File();
file.Name = path[path.Length - 1];
parent.Files.Add(file);
return file;
}
}
if (parent == null)
{
File file = new File();
file.Name = path[path.Length - 1];
mvarFiles.Add(file);
return file;
}
else
{
File file = new File();
file.Name = path[path.Length - 1];
parent.Files.Add(file);
return file;
}
}
/// <summary>
/// Gets all files in all folders of the <see cref="FileSystemObjectModel" /> with file names that
@ -280,45 +282,45 @@ namespace UniversalEditor.ObjectModels.FileSystem
return files.ToArray();
}
/// <summary>
/// Gets all files in all folders of the <see cref="FileSystemObjectModel" />, and assigns the file names
/// separated by the default path separator.
/// </summary>
/// <returns></returns>
public File[] GetAllFiles(string pathSeparator = null)
{
if (pathSeparator == null) pathSeparator = "/";
/// <summary>
/// Gets all files in all folders of the <see cref="FileSystemObjectModel" />, and assigns the file names
/// separated by the default path separator.
/// </summary>
/// <returns></returns>
public File[] GetAllFiles(string pathSeparator = null)
{
if (pathSeparator == null) pathSeparator = "/";
List<File> files = new List<File>();
for (int i = 0; i < mvarFiles.Count; i++)
{
File file = mvarFiles[i];
files.Add(file);
}
for (int i = 0; i < mvarFolders.Count; i++ )
{
Folder folder = mvarFolders[i];
GetAllFilesRecursively(folder, ref files, folder.Name, pathSeparator);
}
return files.ToArray();
}
List<File> files = new List<File>();
for (int i = 0; i < mvarFiles.Count; i++)
{
File file = mvarFiles[i];
files.Add(file);
}
for (int i = 0; i < mvarFolders.Count; i++ )
{
Folder folder = mvarFolders[i];
GetAllFilesRecursively(folder, ref files, folder.Name, pathSeparator);
}
return files.ToArray();
}
private void GetAllFilesRecursively(Folder folder, ref List<File> files, string parentPath, string pathSeparator, string searchPattern = null)
{
for (int i = 0; i < folder.Files.Count; i++)
{
File file = folder.Files[i];
private void GetAllFilesRecursively(Folder folder, ref List<File> files, string parentPath, string pathSeparator, string searchPattern = null)
{
for (int i = 0; i < folder.Files.Count; i++)
{
File file = folder.Files[i];
if (searchPattern != null && !file.Name.Match(searchPattern)) continue;
File file2 = (file.Clone() as File);
file2.Name = parentPath + pathSeparator + file.Name;
files.Add(file2);
}
for (int i = 0; i < folder.Folders.Count; i++)
{
Folder folder1 = folder.Folders[i];
GetAllFilesRecursively(folder1, ref files, parentPath + pathSeparator + folder1.Name, pathSeparator, searchPattern);
}
}
File file2 = (file.Clone() as File);
file2.Name = parentPath + pathSeparator + file.Name;
files.Add(file2);
}
for (int i = 0; i < folder.Folders.Count; i++)
{
Folder folder1 = folder.Folders[i];
GetAllFilesRecursively(folder1, ref files, parentPath + pathSeparator + folder1.Name, pathSeparator, searchPattern);
}
}
}
}

View File

@ -133,14 +133,15 @@ namespace UniversalEditor.DataFormats.Multimedia.Audio.Synthesized.MusicXML
{
if (text == "synthesizer")
{
if (Accessor is FileAccessor)
{
FileAccessor file = (Accessor as FileAccessor);
if (file.FileName != null)
{
track.Synthesizer = Reflection.GetAvailableObjectModel<VoicebankObjectModel>(Path.MakeAbsolutePath(tag_elTagScorePartChild.Attributes["href"].Value, System.IO.Path.GetDirectoryName(file.FileName)));
}
}
if (Accessor is FileAccessor)
{
FileAccessor file = (Accessor as FileAccessor);
if (file.FileName != null)
{
string fileName = Path.MakeAbsolutePath(tag_elTagScorePartChild.Attributes["href"].Value, System.IO.Path.GetDirectoryName(file.FileName));
track.Synthesizer = Reflection.GetAvailableObjectModel<VoicebankObjectModel>(new FileAccessor(fileName));
}
}
}
}
}

View File

@ -30,16 +30,19 @@ namespace UniversalEditor.Accessors
{
get
{
if (mvarStream == null) throw new InvalidOperationException("Please open before looking");
return mvarStream.Length;
}
set
{
if (mvarStream == null) throw new InvalidOperationException("Please open before looking");
mvarStream.SetLength(value);
}
}
protected override long GetPosition()
{
if (mvarStream == null) throw new InvalidOperationException("Please open before looking");
return mvarStream.Position;
}