mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Split into smaller projects, now uses plugins.
This commit is contained in:
		@@ -1,11 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents
 | 
			
		||||
{
 | 
			
		||||
    public class AutoRegisterAttribute : Attribute
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,13 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.DocumentEditorFeatures
 | 
			
		||||
{
 | 
			
		||||
    public interface ICustomDocumentTitleProvider
 | 
			
		||||
    {
 | 
			
		||||
        string Title { get; }
 | 
			
		||||
        event EventHandler TitleChanged;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,16 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.DocumentEditorFeatures
 | 
			
		||||
{
 | 
			
		||||
    interface ISelectionPropertiesProvider
 | 
			
		||||
    {
 | 
			
		||||
        string SelectionName { get; }
 | 
			
		||||
        IEnumerable<Property> SelectionProperties { get; }
 | 
			
		||||
 | 
			
		||||
        event EventHandler SelectionChanged;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.DocumentEditorFeatures
 | 
			
		||||
{
 | 
			
		||||
    public interface IToolboxProvider
 | 
			
		||||
    {
 | 
			
		||||
        bool SupportsToolboxDrop { get; }
 | 
			
		||||
        IEnumerable<string> ToolboxItems { get; }
 | 
			
		||||
 | 
			
		||||
        event EventHandler ToolboxItemsChanged;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.DocumentEditorFeatures
 | 
			
		||||
{
 | 
			
		||||
    public interface IUndoSupport
 | 
			
		||||
    {
 | 
			
		||||
        // TODO
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
namespace RainmeterStudio.Documents
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Represents a document template
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public abstract class DocumentTemplate
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the document template name
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string Name { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets the default extension of this template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public string DefaultExtension { get; private set; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the document template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="name">Name of template</param>
 | 
			
		||||
        /// <param name="defaultExtension">Default extension</param>
 | 
			
		||||
        public DocumentTemplate(string name, string defaultExtension)
 | 
			
		||||
        {
 | 
			
		||||
            Name = name;
 | 
			
		||||
            DefaultExtension = defaultExtension;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Creates a document using this template
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <returns></returns>
 | 
			
		||||
        public abstract IDocument CreateDocument();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents
 | 
			
		||||
{
 | 
			
		||||
    public interface IDocumentEditor
 | 
			
		||||
    {
 | 
			
		||||
        IDocument AttachedDocument { get; }
 | 
			
		||||
        UIElement EditorUI { get; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents
 | 
			
		||||
{
 | 
			
		||||
    public interface IDocumentEditorFactory
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Creates a new editor object
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="document">Document to be edited by the editor</param>
 | 
			
		||||
        /// <returns>A new document editor</returns>
 | 
			
		||||
        IDocumentEditor CreateEditor(IDocument document);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Tests if this editor can edit this document type
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="type">Document type</param>
 | 
			
		||||
        /// <returns>True if the editor can edit the document type</returns>
 | 
			
		||||
        bool CanEdit(Type type);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,39 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents
 | 
			
		||||
{
 | 
			
		||||
    public interface IDocumentStorage
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Reads a document from file
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path">Path to file</param>
 | 
			
		||||
        /// <returns>Read document</returns>
 | 
			
		||||
        IDocument Read(string path);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Writes a document to a file
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path">Path to file</param>
 | 
			
		||||
        /// <param name="document">Document to write</param>
 | 
			
		||||
        void Write(string path, IDocument document);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Tests if the file can be read by this storage
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="path">Path to file</param>
 | 
			
		||||
        /// <returns>True if file can be read</returns>
 | 
			
		||||
        bool CanRead(string path);
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Tests if the document can be written by this storage
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="documentType">Document type</param>
 | 
			
		||||
        /// <returns>True if the document can be written</returns>
 | 
			
		||||
        bool CanWrite(Type documentType);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,12 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Ini
 | 
			
		||||
{
 | 
			
		||||
    /*public class IniDocument : IDocument
 | 
			
		||||
    {
 | 
			
		||||
    }*/
 | 
			
		||||
}
 | 
			
		||||
@@ -1,31 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Ini
 | 
			
		||||
{
 | 
			
		||||
    /*public class IniSkinDesigner : IDocumentEditor
 | 
			
		||||
    {
 | 
			
		||||
        public override IDocument Document
 | 
			
		||||
        {
 | 
			
		||||
            get { throw new NotImplementedException(); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override string Title
 | 
			
		||||
        {
 | 
			
		||||
            get { throw new NotImplementedException(); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override System.Windows.UIElement EditorUI
 | 
			
		||||
        {
 | 
			
		||||
            get { throw new NotImplementedException(); }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override EventHandler SelectionChanged
 | 
			
		||||
        {
 | 
			
		||||
            get { throw new NotImplementedException(); }
 | 
			
		||||
        }
 | 
			
		||||
    }*/
 | 
			
		||||
}
 | 
			
		||||
@@ -1,11 +0,0 @@
 | 
			
		||||
<UserControl x:Class="RainmeterStudio.Documents.Ini.IniSkinDesignerControl"
 | 
			
		||||
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 | 
			
		||||
             mc:Ignorable="d" 
 | 
			
		||||
             d:DesignHeight="300" d:DesignWidth="300">
 | 
			
		||||
    <Grid>
 | 
			
		||||
            
 | 
			
		||||
    </Grid>
 | 
			
		||||
</UserControl>
 | 
			
		||||
@@ -1,27 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Controls;
 | 
			
		||||
using System.Windows.Data;
 | 
			
		||||
using System.Windows.Documents;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Navigation;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Ini
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for IniSkinDesignerControl.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class IniSkinDesignerControl : UserControl
 | 
			
		||||
    {
 | 
			
		||||
        public IniSkinDesignerControl()
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,14 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Ini
 | 
			
		||||
{
 | 
			
		||||
    /*public class IniSkinDesignerFactory : IDocumentEditorFactory
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
    }*/
 | 
			
		||||
}
 | 
			
		||||
@@ -1,73 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
using System.ComponentModel;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Text
 | 
			
		||||
{
 | 
			
		||||
    public class TextDocument : IDocument
 | 
			
		||||
    {
 | 
			
		||||
        private Reference _reference;
 | 
			
		||||
        private bool _isDirty;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the text associated with this document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public List<string> Lines
 | 
			
		||||
        {
 | 
			
		||||
            get; private set;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets or sets the reference of this document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public Reference Reference
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _reference;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _reference = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("Reference"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a property indicating if this file was modified and not saved
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public bool IsDirty
 | 
			
		||||
        {
 | 
			
		||||
            get
 | 
			
		||||
            {
 | 
			
		||||
                return _isDirty;
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                _isDirty = value;
 | 
			
		||||
 | 
			
		||||
                if (PropertyChanged != null)
 | 
			
		||||
                    PropertyChanged(this, new PropertyChangedEventArgs("IsDirty"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Triggered when the value of a property changes
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public event PropertyChangedEventHandler PropertyChanged;
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Initializes the text document
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public TextDocument()
 | 
			
		||||
        {
 | 
			
		||||
            Lines = new List<string>();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,25 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Text
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// A blank text document template
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    [AutoRegister]
 | 
			
		||||
    public class TextDocumentTemplate : DocumentTemplate
 | 
			
		||||
    {
 | 
			
		||||
        public TextDocumentTemplate()
 | 
			
		||||
            : base("TextDocument", "txt")
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override IDocument CreateDocument()
 | 
			
		||||
        {
 | 
			
		||||
            return new TextDocument();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,31 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Text
 | 
			
		||||
{
 | 
			
		||||
    public class TextEditor : IDocumentEditor
 | 
			
		||||
    {
 | 
			
		||||
        private TextDocument _document;
 | 
			
		||||
        private TextEditorControl _control;
 | 
			
		||||
 | 
			
		||||
        public TextEditor(TextDocument document)
 | 
			
		||||
        {
 | 
			
		||||
            _document = document;
 | 
			
		||||
            _control = new TextEditorControl(document);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IDocument AttachedDocument
 | 
			
		||||
        {
 | 
			
		||||
            get { return _document; }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public System.Windows.UIElement EditorUI
 | 
			
		||||
        {
 | 
			
		||||
            get { return _control; }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,11 +0,0 @@
 | 
			
		||||
<UserControl x:Class="RainmeterStudio.Documents.Text.TextEditorControl"
 | 
			
		||||
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
			
		||||
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
			
		||||
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 | 
			
		||||
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 | 
			
		||||
             mc:Ignorable="d" 
 | 
			
		||||
             d:DesignHeight="300" d:DesignWidth="300">
 | 
			
		||||
    <Grid>
 | 
			
		||||
        <TextBox Name="text" AcceptsReturn="True" />
 | 
			
		||||
    </Grid>
 | 
			
		||||
</UserControl>
 | 
			
		||||
@@ -1,32 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Windows;
 | 
			
		||||
using System.Windows.Controls;
 | 
			
		||||
using System.Windows.Data;
 | 
			
		||||
using System.Windows.Documents;
 | 
			
		||||
using System.Windows.Input;
 | 
			
		||||
using System.Windows.Media;
 | 
			
		||||
using System.Windows.Media.Imaging;
 | 
			
		||||
using System.Windows.Navigation;
 | 
			
		||||
using System.Windows.Shapes;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Text
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Interaction logic for TextEditorControl.xaml
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public partial class TextEditorControl : UserControl
 | 
			
		||||
    {
 | 
			
		||||
        private TextDocument _document;
 | 
			
		||||
 | 
			
		||||
        public TextEditorControl(TextDocument document)
 | 
			
		||||
        {
 | 
			
		||||
            InitializeComponent();
 | 
			
		||||
 | 
			
		||||
            _document = document;
 | 
			
		||||
            text.Text = document.Lines.Aggregate((a, b) => a + "\n" + b);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,24 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using RainmeterStudio.Business;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Text
 | 
			
		||||
{
 | 
			
		||||
    [AutoRegister]
 | 
			
		||||
    public class TextEditorFactory : IDocumentEditorFactory
 | 
			
		||||
    {
 | 
			
		||||
        public IDocumentEditor CreateEditor(IDocument document)
 | 
			
		||||
        {
 | 
			
		||||
            return new TextEditor((TextDocument)document);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool CanEdit(Type type)
 | 
			
		||||
        {
 | 
			
		||||
            return type.Equals(typeof(TextDocument));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,71 +0,0 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using RainmeterStudio.Model;
 | 
			
		||||
 | 
			
		||||
namespace RainmeterStudio.Documents.Text
 | 
			
		||||
{
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Storage for text files
 | 
			
		||||
    /// </summary>    
 | 
			
		||||
    [AutoRegister]
 | 
			
		||||
    public class TextStorage : IDocumentStorage
 | 
			
		||||
    {
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        IDocument IDocumentStorage.Read(string path)
 | 
			
		||||
        {
 | 
			
		||||
            TextDocument document = new TextDocument();
 | 
			
		||||
            document.Reference.Path = path;
 | 
			
		||||
            document.Reference.Name = Path.GetFileName(path);
 | 
			
		||||
            document.Lines.AddRange(File.ReadAllLines(path));
 | 
			
		||||
 | 
			
		||||
            return document;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        public void Write(string path, IDocument document)
 | 
			
		||||
        {
 | 
			
		||||
            TextDocument textDocument = document as TextDocument;
 | 
			
		||||
 | 
			
		||||
            if (textDocument == null)
 | 
			
		||||
                throw new ArgumentException("Provided document is not supported by this storage.");
 | 
			
		||||
 | 
			
		||||
            File.WriteAllLines(path, textDocument.Lines);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <inheritdoc />
 | 
			
		||||
        public bool CanRead(string path)
 | 
			
		||||
        {
 | 
			
		||||
            // Open the file
 | 
			
		||||
            FileStream file = File.OpenRead(path);
 | 
			
		||||
 | 
			
		||||
            // Read a small chunk (1kb should be enough)
 | 
			
		||||
            byte[] buffer = new byte[1024];
 | 
			
		||||
            int read = file.Read(buffer, 0, buffer.Length);
 | 
			
		||||
 | 
			
		||||
            // Close file
 | 
			
		||||
            file.Close();
 | 
			
		||||
 | 
			
		||||
            // Find 4 consecutive zero bytes
 | 
			
		||||
            int cnt = 0;
 | 
			
		||||
            for (int i = 0; i < read; i++)
 | 
			
		||||
            {
 | 
			
		||||
                // Count zero bytes
 | 
			
		||||
                if (buffer[i] == 0)
 | 
			
		||||
                    ++cnt;
 | 
			
		||||
                else cnt = 0;
 | 
			
		||||
 | 
			
		||||
                // Found > 4? Most likely binary file
 | 
			
		||||
                if (cnt >= 4)
 | 
			
		||||
                    return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Not found, probably text file
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public bool CanWrite(Type documentType)
 | 
			
		||||
        {
 | 
			
		||||
            return documentType.Equals(typeof(TextDocument));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user