// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixToolset
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using WixToolset.Data;
using Wix = WixToolset.Data.Serialize;
///
/// The WiX Toolset harvester core.
///
public sealed class HarvesterCore : IHarvesterCore
{
private string extensionArgument;
private string rootDirectory;
///
/// Gets whether the harvester core encountered an error while processing.
///
/// Flag if core encountered an error during processing.
public bool EncounteredError
{
get { return Messaging.Instance.EncounteredError; }
}
///
/// Gets or sets the value of the extension argument passed to heat.
///
/// The extension argument.
public string ExtensionArgument
{
get { return this.extensionArgument; }
set { this.extensionArgument = value; }
}
///
/// Gets or sets the value of the root directory that is being harvested.
///
/// The root directory being harvested.
public string RootDirectory
{
get { return this.rootDirectory; }
set { this.rootDirectory = value; }
}
///
/// Create an identifier based on passed file name
///
/// File name to generate identifer from
///
public string CreateIdentifierFromFilename(string filename)
{
return Common.GetIdentifierFromName(filename);
}
///
/// Generate an identifier by hashing data from the row.
///
/// Three letter or less prefix for generated row identifier.
/// Information to hash.
/// The generated identifier.
[SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.InvalidOperationException.#ctor(System.String)")]
public string GenerateIdentifier(string prefix, params string[] args)
{
return Common.GenerateIdentifier(prefix, args);
}
///
/// Sends a message to the message delegate if there is one.
///
/// Message event arguments.
public void OnMessage(MessageEventArgs mea)
{
Messaging.Instance.OnMessage(mea);
}
///
/// Resolves a file's path if the Wix.File.Source value starts with "SourceDir\".
///
/// The Wix.File.Source value with "SourceDir\".
/// The full path of the file.
public string ResolveFilePath(string fileSource)
{
if (fileSource.StartsWith("SourceDir\\", StringComparison.Ordinal))
{
string file = Path.GetFullPath(this.rootDirectory);
if (File.Exists(file))
{
return file;
}
else
{
fileSource = fileSource.Substring(10);
fileSource = Path.Combine(Path.GetFullPath(this.rootDirectory), fileSource);
}
}
return fileSource;
}
}
}