<commit_before>package lime.tools.platforms;


import haxe.io.Path;
import haxe.Json;
import haxe.Template;
import lime.tools.helpers.CompatibilityHelper;
import lime.tools.helpers.DeploymentHelper;
import lime.tools.helpers.FileHelper;
import lime.tools.helpers.FlashHelper;
import lime.tools.helpers.PathHelper;
import lime.tools.helpers.PlatformHelper;
import lime.tools.helpers.ProcessHelper;
import lime.project.AssetType;
import lime.project.Haxelib;
import lime.project.HXProject;
import lime.project.Platform;
import lime.project.PlatformTarget;
import sys.io.File;
import sys.FileSystem;


class FlashPlatform extends PlatformTarget {
	
	
	private var embedded:Bool;
	
	
	public function new (command:String, _project:HXProject, targetFlags:Map <String, String>) {
		
		super (command, _project, targetFlags);
		
		targetDirectory = project.app.path + "/flash";
		
	}
	
	
	public override function build ():Void {
		
		var destination = targetDirectory + "/bin";
		
		var type = "release";
		
		if (project.debug) {
			
			type = "debug";
			
		} else if (project.targetFlags.exists ("final")) {
			
			type = "final";
			
		}
		
		if (embedded) {
			
			var hxml = File.getContent (targetDirectory + "/haxe/" + type + ".hxml");
			var args = new Array<String> ();
			
			for (line in ~/[\r\n]+/g.split (hxml)) {
				
				line = StringTools.ltrim (line);
				
				if (StringTools.startsWith (line, "#") || line.indexOf ("-swf-header") > -1) {
					
					continue;
					
				}
				
				var space = line.indexOf (" ");
				
				if (space == -1) {
					
					args.push (StringTools.rtrim (line));
					
				} else {
					
					args.push (line.substr (0, space));
					
					args.push (StringTools.trim (line.substr (space + 1)));
					
				}
				
			}
			
			if (PlatformHelper.hostPlatform == Platform.MAC) {
				
				for (i in 0...args.length) {
					
					if (args[i].indexOf ("(") > -1) {
						
						var arg = StringTools.replace (args[i], "'", "'\\''");
						//arg = StringTools.replace (arg, " ", "' '");
						
						args[i] = "'" + arg + "'";
						
					} else if (args[i].indexOf (" ") > -1) {
						
						args[i] = "\"" + args[i] + "\"";
						
					}
					
				}
				
				ProcessHelper.runCommand ("", "haxe " + args.join (" "), []);
				
			} else {
				
				ProcessHelper.runCommand ("", "haxe", args);
				
			}
			
		} else {
			
			var hxml = targetDirectory + "/haxe/" + type + ".hxml";
			ProcessHelper.runCommand ("", "haxe", [ hxml ] );
			
		}
		
		/*var usesOpenFL = false;
		
		for (haxelib in project.haxelibs) {
			
			if (haxelib.name == "nme" || haxelib.name == "openfl") {
				
				usesOpenFL = true;
				
			}
			
		}<commit_msg>fix for new haxe 3.2 Sys.command escaping<commit_after>package lime.tools.platforms;


import haxe.io.Path;
import haxe.Json;
import haxe.Template;
import lime.tools.helpers.CompatibilityHelper;
import lime.tools.helpers.DeploymentHelper;
import lime.tools.helpers.FileHelper;
import lime.tools.helpers.FlashHelper;
import lime.tools.helpers.PathHelper;
import lime.tools.helpers.PlatformHelper;
import lime.tools.helpers.ProcessHelper;
import lime.project.AssetType;
import lime.project.Haxelib;
import lime.project.HXProject;
import lime.project.Platform;
import lime.project.PlatformTarget;
import sys.io.File;
import sys.FileSystem;


class FlashPlatform extends PlatformTarget {
	
	
	private var embedded:Bool;
	
	
	public function new (command:String, _project:HXProject, targetFlags:Map <String, String>) {
		
		super (command, _project, targetFlags);
		
		targetDirectory = project.app.path + "/flash";
		
	}
	
	
	public override function build ():Void {
		
		var destination = targetDirectory + "/bin";
		
		var type = "release";
		
		if (project.debug) {
			
			type = "debug";
			
		} else if (project.targetFlags.exists ("final")) {
			
			type = "final";
			
		}
		
		if (embedded) {
			
			var hxml = File.getContent (targetDirectory + "/haxe/" + type + ".hxml");
			var args = new Array<String> ();
			
			for (line in ~/[\r\n]+/g.split (hxml)) {
				
				line = StringTools.ltrim (line);
				
				if (StringTools.startsWith (line, "#") || line.indexOf ("-swf-header") > -1) {
					
					continue;
					
				}
				
				var space = line.indexOf (" ");
				
				if (space == -1) {
					
					args.push (StringTools.rtrim (line));
					
				} else {
					
					args.push (line.substr (0, space));
					
					args.push (StringTools.trim (line.substr (space + 1)));
					
				}
				
			}
				
			ProcessHelper.runCommand ("", "haxe", args);
			
		} else {
			
			var hxml = targetDirectory + "/haxe/" + type + ".hxml";
			ProcessHelper.runCommand ("", "haxe", [ hxml ] );
			
		}
		
		/*var usesOpenFL = false;
		
		for (haxelib in project.haxelibs) {
			
			if (haxelib.name == "nme" || haxelib.name == "openfl") {
				
				usesOpenFL = true;
				
			}
			
		}
{'fraction_non_alphanumeric': 0.14979338842975207, 'fraction_numerical': 0.0026859504132231405, 'mean_word_length': 2.4978323699421967, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7573076', 'n_tokens_mistral': 2131, 'n_tokens_neox': 1565, 'n_words': 343}