// 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.Harvesters
{
using System;
using System.IO;
using WixToolset.Extensibility.Services;
using WixToolset.Harvesters.Extensibility;
///
/// The WiX Toolset harvester core.
///
internal class HarvesterCore : IHarvesterCore
{
public IMessaging Messaging { get; set; }
public IParseHelper ParseHelper { get; set; }
///
/// Gets or sets the value of the extension argument passed to heat.
///
/// The extension argument.
public string ExtensionArgument { get; set; }
///
/// Gets or sets the value of the root directory that is being harvested.
///
/// The root directory being harvested.
public string RootDirectory { get; set; }
///
/// Create an identifier based on passed file name
///
/// File name to generate identifer from
///
public string CreateIdentifierFromFilename(string filename)
{
return this.ParseHelper.CreateIdentifierFromFilename(filename).Id;
}
///
/// Generate an identifier by hashing data from the row.
///
/// Three letter or less prefix for generated row identifier.
/// Information to hash.
/// The generated identifier.
public string GenerateIdentifier(string prefix, params string[] args)
{
return this.ParseHelper.CreateIdentifier(prefix, args).Id;
}
///
/// 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;
}
}
}