public void WriteToStream(Stream fs, bool embedBinaryData) { fs.WriteByte(142); WriteFiles.WriteInt(fs, 1, (int)RegOperation); WriteFiles.WriteInt(fs, 2, (int)RegBasekey); WriteFiles.WriteInt(fs, 3, (int)RegValueKind); WriteFiles.WriteDeprecatedString(fs, 4, SubKey); if (!string.IsNullOrEmpty(ValueName)) { WriteFiles.WriteDeprecatedString(fs, 5, ValueName); } bool flag = !embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string; if (flag) { fs.WriteByte(128); } if (RegOperation == RegOperations.CreateValue) { switch (RegValueKind) { case RegistryValueKind.Binary: if (flag) { WriteFiles.WriteDeprecatedString(fs, 7, (string)ValueData); } else if (embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string) { WriteOutFile(fs, 7, (string)ValueData); } else { WriteFiles.WriteByteArray(fs, 7, (byte[])ValueData); } break; case RegistryValueKind.DWord: WriteFiles.WriteInt(fs, 7, (int)ValueData); break; case RegistryValueKind.QWord: WriteFiles.WriteLong(fs, 7, (long)ValueData); break; case RegistryValueKind.MultiString: WriteFiles.WriteDeprecatedString(fs, 7, MultiStringToString(ValueData)); break; case RegistryValueKind.String: case RegistryValueKind.ExpandString: WriteFiles.WriteDeprecatedString(fs, 7, (string)ValueData); break; } } if (Is32BitKey) { fs.WriteByte(129); } fs.WriteByte(158); }
public byte[] GetByteArray() { using (MemoryStream memoryStream = new MemoryStream()) { WriteFiles.WriteInt(memoryStream, 1, (int)Action); WriteFiles.WriteInt(memoryStream, 2, (int)UpdateStep); for (int i = 0; i < ExtraData.Count; i++) { if (!string.IsNullOrEmpty(ExtraData[i])) { if (ExtraDataIsRTF[i]) { memoryStream.WriteByte(128); } WriteFiles.WriteString(memoryStream, 3, ExtraData[i]); } } if (ProcessID != 0) { WriteFiles.WriteInt(memoryStream, 4, ProcessID); } if (Progress > -1 && Progress <= 100) { WriteFiles.WriteInt(memoryStream, 5, Progress); } if (ResponseType != 0) { WriteFiles.WriteInt(memoryStream, 6, (int)ResponseType); } memoryStream.WriteByte(byte.MaxValue); return(memoryStream.ToArray()); } }
public void SaveToStream(Stream fs, bool saveRelativePath) { fs.WriteByte(141); if (!string.IsNullOrEmpty(Path)) { WriteFiles.WriteDeprecatedString(fs, 1, Path); } if (!string.IsNullOrEmpty(WorkingDirectory)) { WriteFiles.WriteDeprecatedString(fs, 2, WorkingDirectory); } if (!string.IsNullOrEmpty(Arguments)) { WriteFiles.WriteDeprecatedString(fs, 3, Arguments); } if (!string.IsNullOrEmpty(Description)) { WriteFiles.WriteDeprecatedString(fs, 4, Description); } if (!string.IsNullOrEmpty(IconPath)) { WriteFiles.WriteDeprecatedString(fs, 5, IconPath); } WriteFiles.WriteInt(fs, 6, IconIndex); WriteFiles.WriteInt(fs, 7, (int)WindowStyle); if (saveRelativePath) { WriteFiles.WriteDeprecatedString(fs, 8, RelativeOuputPath); } fs.WriteByte(154); }
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()); } }
Stream SaveClientFile() { MemoryStream ms = new MemoryStream(); try { // file-identification data WriteFiles.WriteHeader(ms, "IUCDFV2"); //Company Name WriteFiles.WriteDeprecatedString(ms, 0x01, CompanyName); //Product Name WriteFiles.WriteDeprecatedString(ms, 0x02, ProductName); // GUID if (m_GUID != null) { WriteFiles.WriteString(ms, 0x0A, m_GUID); } //Installed Version WriteFiles.WriteDeprecatedString(ms, 0x03, InstalledVersion); foreach (string site in ServerFileSites) { //Server File Site WriteFiles.WriteDeprecatedString(ms, 0x04, site); } foreach (string site in ClientServerSites) { //Client Server File Site WriteFiles.WriteDeprecatedString(ms, 0x09, site); } //Header image alignment WriteFiles.WriteDeprecatedString(ms, 0x11, HeaderImageAlign.ToString()); //Header text indent WriteFiles.WriteInt(ms, 0x12, HeaderTextIndent); //Header text color if (!string.IsNullOrEmpty(HeaderTextColorName)) { WriteFiles.WriteDeprecatedString(ms, 0x13, HeaderTextColorName); } //Top image filename if (!string.IsNullOrEmpty(TopImageFilename)) { WriteFiles.WriteDeprecatedString(ms, 0x14, TopImageFilename); } //Side image filename if (!string.IsNullOrEmpty(SideImageFilename)) { WriteFiles.WriteDeprecatedString(ms, 0x15, SideImageFilename); } foreach (DictionaryEntry dLang in Languages) { LanguageCulture lang = (LanguageCulture)dLang.Value; //Language culture WriteFiles.WriteDeprecatedString(ms, 0x18, lang.Culture); //Language filename if (!string.IsNullOrEmpty(lang.Filename)) { WriteFiles.WriteDeprecatedString(ms, 0x16, lang.Filename); } } //Hide the header divider if (HideHeaderDivider) { WriteFiles.WriteBool(ms, 0x17, true); } if (CloseOnSuccess) { WriteFiles.WriteBool(ms, 0x19, true); } if (!string.IsNullOrEmpty(CustomWyUpdateTitle)) { WriteFiles.WriteString(ms, 0x1A, CustomWyUpdateTitle); } if (!string.IsNullOrEmpty(PublicSignKey)) { WriteFiles.WriteString(ms, 0x1B, PublicSignKey); } if (!string.IsNullOrEmpty(UpdatePassword)) { WriteFiles.WriteString(ms, 0x1C, UpdatePassword); } ms.WriteByte(0xFF); ms.Position = 0; } catch (Exception) { ms.Dispose(); throw; } return(ms); }
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); }
private Stream SaveClientFile() { MemoryStream memoryStream = new MemoryStream(); try { WriteFiles.WriteHeader(memoryStream, "IUCDFV2"); WriteFiles.WriteDeprecatedString(memoryStream, 1, CompanyName); WriteFiles.WriteDeprecatedString(memoryStream, 2, ProductName); if (m_GUID != null) { WriteFiles.WriteString(memoryStream, 10, m_GUID); } WriteFiles.WriteDeprecatedString(memoryStream, 3, InstalledVersion); foreach (string serverFileSite in ServerFileSites) { WriteFiles.WriteDeprecatedString(memoryStream, 4, serverFileSite); } foreach (string clientServerSite in ClientServerSites) { WriteFiles.WriteDeprecatedString(memoryStream, 9, clientServerSite); } WriteFiles.WriteDeprecatedString(memoryStream, 17, HeaderImageAlign.ToString()); WriteFiles.WriteInt(memoryStream, 18, HeaderTextIndent); if (!string.IsNullOrEmpty(HeaderTextColorName)) { WriteFiles.WriteDeprecatedString(memoryStream, 19, HeaderTextColorName); } if (!string.IsNullOrEmpty(TopImageFilename)) { WriteFiles.WriteDeprecatedString(memoryStream, 20, TopImageFilename); } if (!string.IsNullOrEmpty(SideImageFilename)) { WriteFiles.WriteDeprecatedString(memoryStream, 21, SideImageFilename); } foreach (DictionaryEntry language in Languages) { LanguageCulture languageCulture = (LanguageCulture)language.Value; WriteFiles.WriteDeprecatedString(memoryStream, 24, languageCulture.Culture); if (!string.IsNullOrEmpty(languageCulture.Filename)) { WriteFiles.WriteDeprecatedString(memoryStream, 22, languageCulture.Filename); } } if (HideHeaderDivider) { WriteFiles.WriteBool(memoryStream, 23, val: true); } if (CloseOnSuccess) { WriteFiles.WriteBool(memoryStream, 25, val: true); } if (!string.IsNullOrEmpty(CustomWyUpdateTitle)) { WriteFiles.WriteString(memoryStream, 26, CustomWyUpdateTitle); } if (!string.IsNullOrEmpty(PublicSignKey)) { WriteFiles.WriteString(memoryStream, 27, PublicSignKey); } if (!string.IsNullOrEmpty(UpdatePassword)) { WriteFiles.WriteString(memoryStream, 28, UpdatePassword); } memoryStream.WriteByte(byte.MaxValue); memoryStream.Position = 0L; return(memoryStream); } catch (Exception) { memoryStream.Dispose(); throw; } }
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); }