2015-09-03 23:43:55 +02:00
using ANX.Framework.Content ;
using ANX.Framework.Content.Pipeline.Tasks ;
using Microsoft.Win32 ;
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Text ;
namespace ContentBuilder
{
public static class BuildHelper
{
2015-09-05 12:37:48 +02:00
public static bool TryGetAnxFrameworkPath ( out Uri path )
2015-09-03 23:43:55 +02:00
{
2015-09-05 12:37:48 +02:00
path = null ;
2015-09-03 23:43:55 +02:00
var hklm = RegistryKey . OpenBaseKey ( RegistryHive . LocalMachine , RegistryView . Registry64 ) ;
var key = hklm . OpenSubKey ( @"SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\ANX.Framework" , false ) ;
2015-09-05 12:37:48 +02:00
if ( key = = null )
return false ;
2015-09-03 23:43:55 +02:00
var value = key . GetValue ( null ) as string ;
if ( value = = null )
2015-09-05 12:37:48 +02:00
return false ;
2015-09-03 23:43:55 +02:00
else
2015-09-05 12:37:48 +02:00
{
path = new Uri ( value ) ;
return true ;
}
2015-09-03 23:43:55 +02:00
}
2015-11-04 23:38:46 +01:00
public static string GetOutputFileName ( string outputDirectory , string projectDirectory , BuildItem buildItem )
2015-09-03 23:43:55 +02:00
{
2015-11-04 23:38:46 +01:00
if ( ! Path . IsPathRooted ( projectDirectory ) )
throw new ArgumentException ( "projectDirectory is not absolute: " + projectDirectory ) ;
var assetName = buildItem . AssetName ;
if ( string . IsNullOrEmpty ( assetName ) )
assetName = Path . GetFileNameWithoutExtension ( buildItem . SourceFilename ) ;
string relativeSourceFilename = buildItem . SourceFilename ;
if ( Path . IsPathRooted ( relativeSourceFilename ) )
{
if ( buildItem . SourceFilename . StartsWith ( projectDirectory ) )
relativeSourceFilename = buildItem . SourceFilename . Substring ( projectDirectory . Length ) . TrimStart ( Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar ) ;
else
throw new ArgumentException ( string . Format ( "The buildItem is not below the project root.\nProject root: {0}\nBuildItem: {1}" , projectDirectory , buildItem . SourceFilename ) ) ;
}
return Path . Combine ( outputDirectory , Path . GetDirectoryName ( relativeSourceFilename ) , assetName + ContentManager . Extension ) ;
2015-09-03 23:43:55 +02:00
}
internal static string CreateSafeFileName ( string text )
{
foreach ( var invalidChar in Path . GetInvalidFileNameChars ( ) )
text = text . Replace ( invalidChar , '_' ) ;
return text ;
}
}
}