/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace dnSpy.Contracts.Hex.Files {
///
/// Creates and removes s from a
///
public abstract class HexBufferFileService {
///
/// Constructor
///
protected HexBufferFileService() { }
///
/// Gets the buffer
///
public abstract HexBuffer Buffer { get; }
///
/// Gets all files
///
public abstract IEnumerable Files { get; }
///
/// Creates a file. Overlapping files isn't supported.
///
/// Span of file
/// Name
/// Filename if possible, otherwise any name
/// Tags, see eg.
///
public HexBufferFile CreateFile(HexSpan span, string name, string filename, string[] tags) =>
CreateFiles(new BufferFileOptions(span, name, filename, tags)).Single();
///
/// Creates files. Overlapping files isn't supported.
///
/// File options
///
public abstract HexBufferFile[] CreateFiles(params BufferFileOptions[] options);
///
/// Removes all files
///
public void RemoveAllFiles() => RemoveFiles(HexSpan.FullSpan);
///
/// Removes all files overlapping with
///
/// Span
public abstract void RemoveFiles(HexSpan span);
///
/// Removes a file
///
/// File to remove
public abstract void RemoveFile(HexBufferFile file);
///
/// Removes files
///
/// Files to remove
public abstract void RemoveFiles(IEnumerable files);
///
/// Raised after files are added
///
public abstract event EventHandler? BufferFilesAdded;
///
/// Raised after files are removed
///
public abstract event EventHandler? BufferFilesRemoved;
///
/// Finds a file
///
/// Position
/// true to check nested files
///
public abstract HexBufferFile? GetFile(HexPosition position, bool checkNestedFiles);
///
/// Gets a and structure at or null if
/// there's no structure
///
/// Position
///
public FileAndStructure? GetFileAndStructure(HexPosition position) {
// Don't get the inner-most file since if it doesn't contain any structures,
// nothing will be returned.
var file = GetFile(position, checkNestedFiles: false);
return file?.GetFileAndStructure(position, checkNestedFiles: true);
}
}
///
/// File and structure
///
public readonly struct FileAndStructure {
///
/// Gets the file
///
public HexBufferFile File { get; }
///
/// Gets the structure
///
public ComplexData Structure { get; }
///
/// Constructor
///
/// File
/// Structure
public FileAndStructure(HexBufferFile file, ComplexData structure) {
File = file ?? throw new ArgumentNullException(nameof(file));
Structure = structure ?? throw new ArgumentNullException(nameof(structure));
}
}
}