public byte[] GetByteArray() { using (MemoryStream ms = new MemoryStream()) { WriteFiles.WriteInt(ms, 0x01, (int)Action); // what update step are we on? WriteFiles.WriteInt(ms, 0x02, (int)UpdateStep); // write extra string data for (int i = 0; i < ExtraData.Count; i++) { if (!string.IsNullOrEmpty(ExtraData[i])) { if (ExtraDataIsRTF[i]) { ms.WriteByte(0x80); } WriteFiles.WriteString(ms, 0x03, ExtraData[i]); } } // 0x07, 0x08, and 0x09 used to be links data - obsolete if (ProcessID != 0) { WriteFiles.WriteInt(ms, 0x04, ProcessID); } if (Progress > -1 && Progress <= 100) { WriteFiles.WriteInt(ms, 0x05, Progress); } if (ResponseType != Response.Nothing) { WriteFiles.WriteInt(ms, 0x06, (int)ResponseType); } ms.WriteByte(0xFF); return(ms.ToArray()); } }
public void SaveToStream(Stream fs, bool saveRelativePath) { fs.WriteByte(0x8D); if (!string.IsNullOrEmpty(Path)) { WriteFiles.WriteDeprecatedString(fs, 0x01, Path); } if (!string.IsNullOrEmpty(WorkingDirectory)) { WriteFiles.WriteDeprecatedString(fs, 0x02, WorkingDirectory); } if (!string.IsNullOrEmpty(Arguments)) { WriteFiles.WriteDeprecatedString(fs, 0x03, Arguments); } if (!string.IsNullOrEmpty(Description)) { WriteFiles.WriteDeprecatedString(fs, 0x04, Description); } if (!string.IsNullOrEmpty(IconPath)) { WriteFiles.WriteDeprecatedString(fs, 0x05, IconPath); } WriteFiles.WriteInt(fs, 0x06, IconIndex); WriteFiles.WriteInt(fs, 0x07, (int)WindowStyle); if (saveRelativePath) { WriteFiles.WriteDeprecatedString(fs, 0x08, RelativeOuputPath); } fs.WriteByte(0x9A); }
public Stream Save() { MemoryStream ms = new MemoryStream(); try { // Write any file-identification data you want to here WriteFiles.WriteHeader(ms, "IUUDFV2"); //number of registry changes WriteFiles.WriteInt(ms, 0x20, RegistryModifications.Count); for (int i = 0; i < RegistryModifications.Count; i++) { RegistryModifications[i].WriteToStream(ms, true); } //Shortcut information foreach (ShortcutInfo si in ShortcutInfos) { si.SaveToStream(ms, true); } //Previous shortcuts that needs to be installed in order to install new shortcuts foreach (string shortcut in PreviousCommonDesktopShortcuts) { WriteFiles.WriteDeprecatedString(ms, 0x30, shortcut); } foreach (string shortcut in PreviousCommonSMenuShortcuts) { WriteFiles.WriteDeprecatedString(ms, 0x31, shortcut); } foreach (string shortcut in PreviousCUserDesktopShortcuts) { WriteFiles.WriteString(ms, 0x36, shortcut); } foreach (string shortcut in PreviousCUserSMenuShortcuts) { WriteFiles.WriteString(ms, 0x37, shortcut); } //number of file infos WriteFiles.WriteInt(ms, 0x21, CountFileInfos()); // write file info for ngening .NET, execution of files, etc. foreach (UpdateFile file in UpdateFiles) { if (file.Execute || file.IsNETAssembly || file.DeleteFile || file.DeltaPatchRelativePath != null || file.RegisterCOMDll != COMRegistration.None) { ms.WriteByte(0x8B);//Beginning of the file information //relative path to file WriteFiles.WriteDeprecatedString(ms, 0x40, file.RelativePath); //execution of files if (file.Execute) { // execute? WriteFiles.WriteBool(ms, 0x41, true); // execute before update? WriteFiles.WriteBool(ms, 0x42, file.ExBeforeUpdate); if (file.WaitForExecution) { WriteFiles.WriteBool(ms, 0x45, file.WaitForExecution); if (file.RollbackOnNonZeroRet) { // we are rolling back on non-zero return code ms.WriteByte(0x8F); // write all the exceptions we're making for rollback codes if (file.RetExceptions != null) { foreach (int except in file.RetExceptions) { WriteFiles.WriteInt(ms, 0x4D, except); } } } } //commandline arguments if (!string.IsNullOrEmpty(file.CommandLineArgs)) { WriteFiles.WriteDeprecatedString(ms, 0x43, file.CommandLineArgs); } if (file.ProcessWindowStyle != System.Diagnostics.ProcessWindowStyle.Normal) { WriteFiles.WriteInt(ms, 0x4A, (int)file.ProcessWindowStyle); } if (file.ElevationType != ElevationType.SameAswyUpdate) { WriteFiles.WriteInt(ms, 0x4E, (int)file.ElevationType); } } //is it a .NET assembly? if (file.IsNETAssembly) { WriteFiles.WriteBool(ms, 0x44, true); // save whether the files is AnyCPU, x86, or x64 WriteFiles.WriteInt(ms, 0x49, (int)file.CPUVersion); // .NET framework is by default 2.0 - only save the framework version if it's .NET 4.0 or unknown if (file.FrameworkVersion != FrameworkVersion.Net2_0) { WriteFiles.WriteInt(ms, 0x4B, (int)file.FrameworkVersion); } } if (file.RegisterCOMDll != COMRegistration.None) { WriteFiles.WriteInt(ms, 0x4C, (int)file.RegisterCOMDll); } //Delta update particulars: if (file.DeleteFile) { WriteFiles.WriteBool(ms, 0x46, true); } else if (file.DeltaPatchRelativePath != null) { WriteFiles.WriteDeprecatedString(ms, 0x47, file.DeltaPatchRelativePath); if (file.NewFileAdler32 != 0) { WriteFiles.WriteLong(ms, 0x48, file.NewFileAdler32); } } ms.WriteByte(0x9B);//End of the file information } } foreach (string folder in FoldersToDelete) { WriteFiles.WriteDeprecatedString(ms, 0x60, folder); } foreach (string service in ServicesToStop) { WriteFiles.WriteString(ms, 0x32, service); } foreach (StartService service in ServicesToStart) { WriteFiles.WriteString(ms, 0x33, service.Name); if (service.Arguments != null) { WriteFiles.WriteInt(ms, 0x34, service.Arguments.Length); foreach (string arg in service.Arguments) { WriteFiles.WriteString(ms, 0x35, arg); } } } // end of file ms.WriteByte(0xFF); // set the pointer to the top of the file ms.Position = 0; } catch (Exception) { ms.Dispose(); throw; } return(ms); }
public void WriteToStream(Stream fs, bool embedBinaryData) { // beginning of RegChange fs.WriteByte(0x8E); // save the operation WriteFiles.WriteInt(fs, 0x01, (int)RegOperation); // save BaseKey WriteFiles.WriteInt(fs, 0x02, (int)RegBasekey); // Save the valueKind WriteFiles.WriteInt(fs, 0x03, (int)RegValueKind); // Save SubKey WriteFiles.WriteDeprecatedString(fs, 0x04, SubKey); // Value Name if (!string.IsNullOrEmpty(ValueName)) { WriteFiles.WriteDeprecatedString(fs, 0x05, ValueName); } bool isBinaryString = !embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string; if (isBinaryString) { fs.WriteByte(0x80); } if (RegOperation == RegOperations.CreateValue) { // Value Data switch (RegValueKind) { case RegistryValueKind.Binary: if (isBinaryString) { //just saving the string pointing to a file on the disk WriteFiles.WriteDeprecatedString(fs, 0x07, (string)ValueData); } else if (embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string) { //load the file and immediately write it out to fs WriteOutFile(fs, 0x07, (string)ValueData); } else { //the byte array is already in memory, just write it out WriteFiles.WriteByteArray(fs, 0x07, (byte[])ValueData); } break; case RegistryValueKind.DWord: WriteFiles.WriteInt(fs, 0x07, (int)ValueData); break; case RegistryValueKind.QWord: WriteFiles.WriteLong(fs, 0x07, (long)ValueData); break; case RegistryValueKind.MultiString: WriteFiles.WriteDeprecatedString(fs, 0x07, MultiStringToString(ValueData)); break; case RegistryValueKind.ExpandString: case RegistryValueKind.String: WriteFiles.WriteDeprecatedString(fs, 0x07, (string)ValueData); break; } } // should treat as x86 under x64 systems if (Is32BitKey) { fs.WriteByte(0x81); } //end of RegChange fs.WriteByte(0x9E); }