Ejemplo n.º 1
0
        /// <summary>Saves entry to file.</summary>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="input">The content of the assembly.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="options">The options.</param>
        private void SetBytes(
            string resourceName,
            AssemblyName assemblyName, byte[] input, LibZEntry.EntryFlags flags, AppendOptions options)
        {
            var codecName = options.CodecName;

            lock (_stream)
            {
                // prepare entry
                var entry = new LibZEntry {
                    Id             = Hash.Get(resourceName),
                    Hash           = Hash.Get(input),
                    AssemblyName   = assemblyName,
                    Offset         = _magicOffset,
                    Flags          = flags,
                    OriginalLength = input.Length,
                };

                // add it to dictionary
                if (options.Overwrite)
                {
                    _entries[entry.Id] = entry;
                }
                else
                {
                    _entries.Add(entry.Id, entry);
                }

                // encode it
                var encoded = Encode(codecName, input);
                if (encoded != null)
                {
                    entry.CodecName = codecName;
                    input           = encoded;
                }

                // write it
                _magicOffset += entry.StorageLength = WriteBytes(_stream, _magicOffset, input);
                _stream.SetLength(_stream.Position);

                _containerId = Guid.NewGuid();

                _dirty = true;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
		/// <summary>Saves entry to file.</summary>
		/// <param name="resourceName">Name of the resource.</param>
		/// <param name="assemblyName">Name of the assembly.</param>
		/// <param name="input">The content of the assembly.</param>
		/// <param name="flags">The flags.</param>
		/// <param name="options">The options.</param>
		private void SetBytes(
			string resourceName,
			AssemblyName assemblyName, byte[] input, LibZEntry.EntryFlags flags, AppendOptions options)
		{
			var codecName = options.CodecName;

			lock (_stream)
			{
				// prepare entry
				var entry = new LibZEntry {
					Id = Hash.Get(resourceName),
					Hash = Hash.Get(input),
					AssemblyName = assemblyName,
					Offset = _magicOffset,
					Flags = flags,
					OriginalLength = input.Length,
				};

				// add it to dictionary
				if (options.Overwrite)
				{
					_entries[entry.Id] = entry;
				}
				else
				{
					_entries.Add(entry.Id, entry);
				}

				// encode it
				var encoded = Encode(codecName, input);
				if (encoded != null)
				{
					entry.CodecName = codecName;
					input = encoded;
				}

				// write it
				_magicOffset += entry.StorageLength = WriteBytes(_stream, _magicOffset, input);
				_stream.SetLength(_stream.Position);

				_containerId = Guid.NewGuid();

				_dirty = true;
			}
		}
Ejemplo n.º 4
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);
		}