/// <summary>Executes the task.</summary>
		/// <param name="libzFileName">Name of the libz file.</param>
		/// <param name="includePatterns">The include patterns.</param>
		/// <param name="excludePatterns">The exclude patterns.</param>
		/// <param name="codecName">Name of the codec.</param>
		/// <param name="safeLoad">if set to <c>true</c> 'safe load' if requested.</param>
		/// <param name="move">if set to <c>true</c> moves files (deletes soure files).</param>
		/// <param name="overwrite">if set to <c>true</c> overwrites existing resources.</param>
		public virtual void Execute(
			string libzFileName,
			string[] includePatterns, string[] excludePatterns,
			string codecName, bool safeLoad, bool move, bool overwrite)
		{
			var injectedFileNames = new List<string>();
			if (string.IsNullOrEmpty(codecName))
				codecName = "deflate";

			using (var container = new LibZContainer(libzFileName, true))
			{
				foreach (var fileName in FindFiles(includePatterns, excludePatterns))
				{
					var assembly = MsilUtilities.LoadAssembly(fileName);
					if (assembly == null)
					{
						Log.Warn("Assembly from '{0}' could not be loaded", fileName);
						continue;
					}
					var assemblyName = assembly.Name;
					var managed = MsilUtilities.IsManaged(assembly);
					var architecture = MsilUtilities.GetArchitecture(assembly);
					var portable = MsilUtilities.IsPortable(assembly);

					var assemblyInfo = new AssemblyInfo {
						AssemblyName = new AssemblyName(assemblyName.FullName),
						AnyCPU = architecture == AssemblyArchitecture.AnyCPU,
						X64 = architecture == AssemblyArchitecture.X64,
						SafeLoad = safeLoad,
						Unmanaged = !managed,
						Portable = portable,
						Bytes = File.ReadAllBytes(fileName),
					};

					Log.Info("Appending '{0}' from '{1}'", assemblyInfo.AssemblyName, fileName);

					container.Append(
						assemblyInfo,
						new AppendOptions { CodecName = codecName, Overwrite = overwrite, });

					injectedFileNames.Add(fileName);
				}

				if (injectedFileNames.Count <= 0)
				{
					Log.Warn("No files injected: {0}", string.Join(", ", includePatterns));
				}
				else
				{
					if (move)
						foreach (var fn in injectedFileNames)
							DeleteFile(fn);
				}
			}
		}
Exemple #2
0
		/// <summary>Appends the assembly into container.</summary>
		/// <param name="assemblyInfo">The assembly info.</param>
		/// <param name="options">The options.</param>
		public void Append(
			AssemblyInfo assemblyInfo,
			AppendOptions options)
		{
			var flags = LibZEntry.EntryFlags.None;
			if (assemblyInfo.Unmanaged)
				flags |= LibZEntry.EntryFlags.Unmanaged;
			if (assemblyInfo.AnyCPU)
				flags |= LibZEntry.EntryFlags.AnyCPU;
			if (assemblyInfo.X64)
				flags |= LibZEntry.EntryFlags.X64;
			if (assemblyInfo.Portable)
				flags |= LibZEntry.EntryFlags.Portable;
			if (assemblyInfo.SafeLoad)
				flags |= LibZEntry.EntryFlags.SafeLoad;

			var platformId =
				assemblyInfo.AnyCPU ? string.Empty :
					assemblyInfo.X64 ? "x64:" :
						"x86:";
			var assemblyName = assemblyInfo.AssemblyName;
			var bytes = assemblyInfo.Bytes;

			SetBytes(
				platformId + assemblyName.FullName,
				assemblyName,
				bytes,
				flags,
				options);
		}