#region Disclaimer / License
// Copyright (C) 2011, Kenneth Skovhede
// http://www.hexad.dk, opensource@hexad.dk
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace Duplicati.Library.Main
{
//This file contains various classes that represents the
// various types of files that exist on a backend.
//
//The classes are primarily created from the FilenameStrategy class
///
/// Sort helper to keep the entries sorted by datetime and volumenumber
///
internal class Sorter
: IComparer,
IComparer,
IComparer,
IComparer,
IComparer,
IComparer
{
#region IComparer Members
public int Compare(BackupEntryBase x, BackupEntryBase y)
{
if (x.Time.Equals(y.Time))
{
if (x is PayloadEntryBase && y is PayloadEntryBase)
return ((PayloadEntryBase)x).Volumenumber.CompareTo(((PayloadEntryBase)y).Volumenumber);
else
return 0;
}
else
return x.Time.CompareTo(y.Time);
}
#endregion
public int Compare(ContentEntry x, ContentEntry y) { return Compare((BackupEntryBase)x, (BackupEntryBase)y); }
public int Compare(SignatureEntry x, SignatureEntry y) { return Compare((BackupEntryBase)x, (BackupEntryBase)y); }
public int Compare(PayloadEntryBase x, PayloadEntryBase y) { return Compare((BackupEntryBase)x, (BackupEntryBase)y); }
public int Compare(ManifestEntry x, ManifestEntry y) { return Compare((BackupEntryBase)x, (BackupEntryBase)y); }
public int Compare(Library.Interface.IFileEntry x, Library.Interface.IFileEntry y)
{
return string.Compare(x.Name, y.Name);
}
}
///
/// An abstract base class for all backup entries
///
public abstract class BackupEntryBase
{
protected string m_filename;
protected Duplicati.Library.Interface.IFileEntry m_fileentry;
protected DateTime m_time;
protected string m_timeString;
protected string m_encryption;
protected bool m_isFull;
protected bool m_isEncrypted;
protected string m_remoteHash;
protected long m_size = -1;
///
/// Gets the filename that represents this entry
///
public string Filename { get { return m_filename; } set { m_filename = value; } }
///
/// Gets the Fileentry that was parsed into this object
///
public Duplicati.Library.Interface.IFileEntry Fileentry { get { return m_fileentry; } }
///
/// Gets the backup time that this entry represents
///
public DateTime Time { get { return m_time; } }
///
/// Gets the string that was used to parse the date
///
public string TimeString { get { return m_timeString; } }
///
/// Gets the encryption mode used, or null if no encryption was applied
///
public string EncryptionMode { get { return m_encryption; } }
///
/// Gets a value indicating if this is a full backup entry
///
public bool IsFull { get { return m_isFull; } }
///
/// Gets or sets the hash of the remote file
///
public string RemoteHash { get { return m_remoteHash; } set { m_remoteHash = value; } }
///
/// Gets or sets a value indicating if the associated file has been encrypted
///
public bool IsEncrypted { get { return m_isEncrypted; } set { m_isEncrypted = value; } }
///
/// Gets or sets the size of the remote file
///
public long Filesize { get { return m_size; } set { m_size = value; } }
protected BackupEntryBase(string filename, Duplicati.Library.Interface.IFileEntry entry, DateTime time, bool isFull, string timeString, string encryption)
{
m_filename = filename;
m_fileentry = entry;
if (entry != null)
m_size = entry.Size;
m_time = time;
m_isFull = isFull;
m_timeString = timeString;
m_encryption = encryption;
}
}
///
/// A class that represents the delete transaction file
///
public class DeleteTransactionEntry : BackupEntryBase
{
public DeleteTransactionEntry(Duplicati.Library.Interface.IFileEntry entry, string encryption)
: base(entry.Name, entry, DateTime.Now, true, "", encryption)
{
}
public DeleteTransactionEntry(string encryption)
: base(null, null, DateTime.Now, true, "", encryption)
{
}
}
///
/// A class that represents the verification file
///
public class VerificationEntry : BackupEntryBase
{
public VerificationEntry(string filename, Duplicati.Library.Interface.IFileEntry entry, DateTime time, string timestring)
: base(filename, entry, time, true, timestring, null)
{
}
public VerificationEntry(DateTime time)
: base(null, null, time, true, null, null)
{
}
}
///
/// A class that represents a backup set
///
public class ManifestEntry : BackupEntryBase
{
protected List> m_volumes;
protected List m_incrementals;
protected ManifestEntry m_alternate;
protected ManifestEntry m_previous;
protected Manifestfile m_parsedManifest;
protected bool m_isPrimary;
protected VerificationEntry m_verification;
///
/// Gets a list of volumes that make up this backup
///
public List> Volumes { get { return m_volumes; } }
///
/// Gets a list of incrementals that belong to this entry
///
public List Incrementals { get { return m_incrementals; } }
///
/// Gets a value indicating if this manifest is the primary one
///
public bool IsPrimary { get { return m_isPrimary; } }
///
/// Gets or sets the alternate manifest file, if available
///
public ManifestEntry Alternate { get { return m_alternate; } set { m_alternate = value; } }
///
/// Gets or sets the previous manifest in the chain
///
public ManifestEntry Previous { get { return m_previous; } set { m_previous = value; } }
///
/// Gets the parsed manifest file for this entry
///
public Manifestfile ParsedManifest { get { return m_parsedManifest; } set { m_parsedManifest = value; } }
///
/// Gets or sets the verifcation file associated with the entry
///
public VerificationEntry Verification { get { return m_verification; } set { m_verification = value; } }
public ManifestEntry(string filename, Duplicati.Library.Interface.IFileEntry entry, DateTime time, bool isFull, string timeString, string encryption, bool primary)
: base(filename, entry, time, isFull, timeString, encryption)
{
m_volumes = new List>();
m_incrementals = new List();
m_isPrimary = primary;
}
public ManifestEntry(DateTime time, bool full, bool primary)
: base(null, null, time, full, null, null)
{
m_isPrimary = primary;
}
}
public abstract class PayloadEntryBase : BackupEntryBase
{
protected string m_compression;
protected int m_volumenumber;
///
/// Gets the volumenumber of the entry
///
public int Volumenumber { get { return m_volumenumber; } }
///
/// Gets the compression type applied to the file
///
public string Compression { get { return m_compression; } }
protected PayloadEntryBase(string filename, Duplicati.Library.Interface.IFileEntry entry, DateTime time, bool isFull, string timeString, string encryption, string compression, int volumenumber)
: base(filename, entry, time, isFull, timeString, encryption)
{
m_compression = compression;
m_volumenumber = volumenumber;
}
}
///
/// A class that represents a signature entry
///
public class SignatureEntry : PayloadEntryBase
{
public SignatureEntry(string filename, Duplicati.Library.Interface.IFileEntry entry, DateTime time, bool isFull, string timeString, string encryption, string compression, int volumenumber)
: base(filename, entry, time, isFull, timeString, encryption, compression, volumenumber)
{
}
public SignatureEntry(DateTime time, bool isFull, int volumenumber)
: base(null, null, time, isFull, null, null, null, volumenumber)
{
}
}
///
/// A class that represents a content entry
///
public class ContentEntry : PayloadEntryBase
{
public ContentEntry(string filename, Duplicati.Library.Interface.IFileEntry entry, DateTime time, bool isFull, string timeString, string encryption, string compression, int volumenumber)
: base(filename, entry, time, isFull, timeString, encryption, compression, volumenumber)
{
}
public ContentEntry(DateTime time, bool isFull, int volumenumber)
: base(null, null, time, isFull, null, null, null, volumenumber)
{
}
}
}