//
//  TeXDistributionUtils.m
//  TeXDist
//
//  Created by coder on 08/12/06.
//  Copyright 2006 Laurens'Tribune. All rights reserved.
//

#import "TeXDistCommon.h"

#ifdef __TeXDist_DRAFT__
#define PREFIX @"/tmp"
#else
#define PREFIX
#endif

NSInteger TeXDistLogLevel = 0;

NSString * const TeXDistLogLevelPreferenceKey = @"TeXDistLogLevelPreference";
NSString * const TeXDistPreferenceID = TeXDist_PREFERENCE_ID;

NSString * const TeXDistDomain = @"TeXDistDomain";
NSString * const TeXDist_texbin = @"texbin";
NSString * const TeXDistComponentRoot = @"Root";
NSString * const TeXDistComponentPrograms = @"Programs";

NSString * const TeXDistSetUpExpectedProgramsKey = @"ExpectedPrograms";
NSString * const TeXDistSetUpCPUNamesPriorityByArchKey = @"CPUNamesPriorityByArch";
NSString * const TeXDistSetUpMinimumSystemVersionsByArchKey = @"MinimumSystemVersionByArch";
NSString * const TeXDistSetUpMaximumSystemVersionsByArchKey = @"MaximumSystemVersionByArch";
NSString * const TeXDistSetUpArchitecturePrioritiesByArchKey = @"ArchitecturePriorityByArch";

NSString * const TeXDistSetUpLibraryTeXKey = @"/Library/TeX/Distributions/";
NSString * const TeXDistSetUpDefaultTeXKey = @"/Library/TeX/Distributions/.DefaultTeX/";
NSString * const TeXDistSetUpProgramsRelativeKey = @"Contents/Programs/";
NSString * const TeXDistSetUpRootRelativeKey = @"Contents/Root/";
NSString * const TeXDistSetUp_usr_texbin_Key = PREFIX @"/usr/texbin";
NSString * const TeXDistExtensionKey = @"texdist";

NSString * const kTeXDistErrorStatusKey = @"kTeXDistErrorStatus";
NSString * const kTeXDistErrorMessageKey = @"kTeXDistErrorMessage";
NSString * const kTeXDisMissingDirectoryKey = @"kTeXDisMissingDirectory";
NSString * const kTeXDistCantCreateKey = @"kTeXDistCantCreate";
NSString * const kTeXDistCantRemoveKey = @"kTeXDistCantRemove";
NSString * const kTeXDistCantLinkSourceKey = @"kTeXDistCantLinkSource";
NSString * const kTeXDistCantLinkDestinationKey = @"kTeXDistCantLinkDestination";
NSString * const kTeXDistCantMoveFromKey = @"kTeXDistCantMoveFrom";
NSString * const kTeXDistCantMoveToKey = @"kTeXDistCantMoveTo";
NSString * const kTeXDistResetCantRemoveKey = @"kTeXDistResetCantRemove";
NSString * const kTeXDistResetMissingDirectoryKey = @"kTeXDistResetMissingDirectory";
NSString * const kTeXDistResetMissingArgumentKey = @"kTeXDistResetMissingArgument";
NSString * const kTeXDistResetCantLinkFromKey = @"kTeXDistResetCantLinkFrom";
NSString * const kTeXDistResetCantLinkToKey = @"kTeXDistResetCantLinkTo";

NSString * const kTeXDistNoAuthorisationMessage = @"No authorisation";
NSString * const kTeXDistNoDistributionsMessage = @"No distributions";
NSString * const kTeXDistNoDefaultTeXMessage = @"No .DefaultTeX directory";
NSString * const kTeXDistNoDefaultTeXContentsMessage = @"No .DefaultTeX/Contents soft link";
NSString * const kTeXDistNoActiveDistributionMessage = @"No active distribution";
NSString * const kTeXDistCannotUpdate_usr_texbin_Message = @"Failed to update /usr/texbin";
NSString * const kTeXDistNoArchitectureMessage = @"Wrong set of binaries";
NSString * const kTeXDistMissingDistributionMessage = @"Missing distribution name";
NSString * const kTeXDistCantActivateMessage = @"Cannot activate the distribution";

NSString * const kTeXDistHelpArgument = @"--help";
NSString * const kTeXDistResetArgument = @"--reset";
NSString * const kTeXDistListDistributionsArgument = @"--list-distributions";
NSString * const kTeXDistListActiveDistributionArgument = @"--list-active-distribution";
NSString * const kTeXDistUpdateArgument = @"--update";
NSString * const kTeXDistNoCredentialsArgument = @"--no-texdist-credentials";
NSString * const kTeXDistNoUserInterfaceArgument = @"--texdist-no-user-interface";
NSString * const kTeXDistActivateArgument = @"--activate";
NSString * const kTeXDistributionArgument = @"--distribution";
NSString * const kTeXDistArchitectureArgument = @"--architecture";

NSString * const TeXDistUtilityCommand_ln = @"ln";
NSString * const TeXDistUtilityCommand_mkdir = @"mkdir";
NSString * const TeXDistUtilityCommand_rm = @"rm";
NSString * const TeXDistUtilityOption_create_intermediates = @"--create-intermediates";
NSString * const TeXDistUtilityOption_dest_path = @"--dest-path";
NSString * const TeXDistUtilityOption_path = @"--path";
NSString * const TeXDistUtilitySubTask = @"--sub-task";

@implementation NSDictionary(TeXDist)
- (void)TeXDist_writeTo_stdout;
{
	NSString * errorString = NULL;
	NSData * dataRep = [NSPropertyListSerialization dataFromPropertyList: self
							format: NSPropertyListXMLFormat_v1_0
							errorDescription: &errorString];
	if (dataRep) {
		write(fileno(stdout),[dataRep bytes],[dataRep length]);
	} else if (errorString) {
		// Handle error
		NSLog(@"%@",errorString);
		[errorString release];
	}
	return;
}
@end
