/// <summary>Executes the task.</summary>
		/// <param name="libzFileName">Name of the libz file.</param>
		public virtual void Execute(string libzFileName)
		{
			Log.Info("Opening '{0}'", libzFileName);
			using (var container = new LibZContainer(libzFileName))
			{
				var orderedEnties = container.Entries
					.OrderBy(e => e.AssemblyName.Name)
					.ThenBy(e => e.AssemblyName.Version);

				foreach (var entry in orderedEnties)
				{
					var ratio = entry.OriginalLength != 0
						? entry.StorageLength * 100 / entry.OriginalLength
						: 100;

					Log.Info(entry.AssemblyName.FullName);
					Log.Debug("    flags:{0}, codec:'{1}', size:{2}, compession:{3}%, id:{4}",
						string.Join("|", GetFlagsText(entry.Flags)),
						entry.CodecName ?? "<none>",
						entry.OriginalLength,
						ratio,
						entry.Id.ToString("N"));
				}
			}
		}
		/// <summary>Executes the task.</summary>
		/// <param name="libzFileName">Name of the libz file.</param>
		public virtual void Execute(string libzFileName)
		{
			Log.Info("Opening '{0}'", libzFileName);
			var tempFileName = libzFileName + ".temp";
			using (var container = new LibZContainer(libzFileName))
			{
				Log.Info("Saving '{0}'", libzFileName);
				container.SaveAs(tempFileName);
			}
			RenameFile(tempFileName, libzFileName);
		}
Beispiel #3
0
		/// <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);
				}
			}
		}