This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
forked from Squirrel/Squirrel.Windows
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove WriteZipToSetup project; this can be done in C#
- Loading branch information
Showing
13 changed files
with
120 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// If updating HostModel, mark the ResourceUpdater.cs class as partial so these functions can get mixed in | ||
|
||
using System; | ||
|
||
namespace Microsoft.NET.HostModel | ||
{ | ||
public partial class ResourceUpdater | ||
{ | ||
public ResourceUpdater(string peFile, bool bDeleteExistingResources) | ||
{ | ||
hUpdate = Kernel32.BeginUpdateResource(peFile, bDeleteExistingResources); | ||
if (hUpdate.IsInvalid) { | ||
ThrowExceptionForLastWin32Error(); | ||
} | ||
} | ||
|
||
public ResourceUpdater AddResource(byte[] data, string lpType, IntPtr lpName, ushort langId) | ||
{ | ||
if (hUpdate.IsInvalid) { | ||
ThrowExceptionForInvalidUpdate(); | ||
} | ||
|
||
if (!IsIntResource(lpName)) { | ||
throw new ArgumentException("AddResource can only be used with integer resource names"); | ||
} | ||
|
||
if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, langId, data, (uint) data.Length)) { | ||
ThrowExceptionForLastWin32Error(); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public ResourceUpdater ClearResource(string lpType, IntPtr lpName, ushort langId) | ||
{ | ||
if (hUpdate.IsInvalid) { | ||
ThrowExceptionForInvalidUpdate(); | ||
} | ||
|
||
if (!IsIntResource(lpName)) { | ||
throw new ArgumentException("AddResource can only be used with integer resource names"); | ||
} | ||
|
||
if (!Kernel32.UpdateResource(hUpdate, lpType, lpName, langId, null, 0)) { | ||
ThrowExceptionForLastWin32Error(); | ||
} | ||
|
||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.NET.HostModel; | ||
|
||
namespace SquirrelCli | ||
{ | ||
internal class SetupResourceWriter | ||
{ | ||
// these values come from Setup.rc | ||
private static readonly ushort RESOURCE_LANG = 0x0409; | ||
private static readonly IntPtr IDR_UPDATE_ZIP = new IntPtr(131); | ||
private static readonly IntPtr IDR_FX_VERSION_FLAG = new IntPtr(132); | ||
private static readonly IntPtr IDR_SPLASH_IMG = new IntPtr(138); | ||
|
||
public static void WriteZipToSetup(string targetSetupExe, string zipFile, string targetFramework, string splashImage) | ||
{ | ||
try { | ||
using var writer = new ResourceUpdater(targetSetupExe); | ||
|
||
var zipBytes = File.ReadAllBytes(zipFile); | ||
writer.AddResource(zipBytes, "DATA", IDR_UPDATE_ZIP, RESOURCE_LANG); | ||
|
||
if (!String.IsNullOrWhiteSpace(targetFramework)) { | ||
var stringBytes = Encoding.Unicode.GetBytes(String.Concat(targetFramework, "\0\0")); | ||
writer.AddResource(stringBytes, "FLAGS", IDR_FX_VERSION_FLAG, RESOURCE_LANG); | ||
} | ||
|
||
if (!String.IsNullOrWhiteSpace(splashImage)) { | ||
var splashBytes = File.ReadAllBytes(splashImage); | ||
writer.AddResource(splashBytes, "DATA", IDR_SPLASH_IMG, RESOURCE_LANG); | ||
} else { | ||
// the template Setup.exe has a built-in splash image used for testing. we need to remove it | ||
writer.ClearResource("DATA", IDR_SPLASH_IMG, RESOURCE_LANG); | ||
} | ||
|
||
writer.Update(); | ||
} catch (HResultException hr) { | ||
throw new Win32Exception(hr.Win32HResult); | ||
} | ||
} | ||
|
||
public static void CopyStubExecutableResources(string peToCopy, string targetStubExecutable) | ||
{ | ||
try { | ||
using var writer = new ResourceUpdater(targetStubExecutable, true); | ||
writer.AddResourcesFromPEImage(peToCopy); | ||
writer.Update(); | ||
} catch (HResultException hr) { | ||
throw new Win32Exception(hr.Win32HResult); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.