本文整理汇总了C#中ResourceInfo.Load方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceInfo.Load方法的具体用法?C# ResourceInfo.Load怎么用?C# ResourceInfo.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ResourceInfo
的用法示例。
在下文中一共展示了ResourceInfo.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSaveStringResource
public void TestSaveStringResource()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
string sourceFilename = Path.Combine(uriPath, @"Binaries\gutils.dll");
string targetFilename = Path.Combine(Path.GetTempPath(), "testSaveStringResource.dll");
File.Copy(sourceFilename, targetFilename, true);
// a new resource
StringResource sr = new StringResource();
sr.Name = new ResourceId(StringResource.GetBlockId(1256));
sr[1256] = Guid.NewGuid().ToString();
sr.SaveTo(targetFilename);
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(targetFilename);
Assert.AreEqual(2, ri[Kernel32.ResourceTypes.RT_STRING].Count);
Assert.AreEqual(StringResource.GetBlockId(1256), ri[Kernel32.ResourceTypes.RT_STRING][1].Name.Id.ToInt32());
Assert.AreEqual(sr[1256], ((StringResource) ri[Kernel32.ResourceTypes.RT_STRING][1])[1256]);
foreach (StringResource rc in ri[Kernel32.ResourceTypes.RT_STRING])
{
Console.WriteLine("StringResource: {0}, {1}", rc.Name, rc.TypeName);
DumpResource.Dump(rc);
}
}
}
示例2: TestAddDialogResource
public void TestAddDialogResource()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
string gutilsdll = Path.Combine(uriPath, @"Binaries\gutils.dll");
int dialogsBefore = 0;
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(gutilsdll);
dialogsBefore = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_DIALOG)].Count;
}
string targetFilename = Path.Combine(Path.GetTempPath(), "testAddDialogResource.dll");
File.Copy(gutilsdll, targetFilename, true);
// copy an existing dialog inside gutils.dll
DialogResource sourceDialog = new DialogResource();
sourceDialog.Name = new ResourceId("GABRTDLG");
sourceDialog.LoadFrom(gutilsdll);
sourceDialog.Name = new ResourceId("NEWGABRTDLG");
Console.WriteLine(targetFilename);
sourceDialog.SaveTo(targetFilename);
// check that the dialog was written
sourceDialog.LoadFrom(targetFilename);
DumpResource.Dump(sourceDialog);
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(targetFilename);
int dialogsAfter = ri.Resources[new ResourceId(Kernel32.ResourceTypes.RT_DIALOG)].Count;
DumpResource.Dump(ri);
Assert.AreEqual(dialogsBefore + 1, dialogsAfter);
}
}
示例3: TestCustom
public void TestCustom()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string filename = Path.Combine(Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath)), "Binaries\\custom.exe");
Assert.IsTrue(File.Exists(filename));
using (ResourceInfo vi = new ResourceInfo())
{
vi.Load(filename);
// version resources (well-known)
List<Resource> versionResources = vi[Kernel32.ResourceTypes.RT_VERSION]; // RT_VERSION
Assert.IsNotNull(versionResources);
Assert.AreEqual(1, versionResources.Count);
Resource versionResource = versionResources[0];
Assert.AreEqual(versionResource.Name.ToString(), "1");
Assert.AreEqual(versionResource.Type.ToString(), "16");
// custom resources
List<Resource> customResources = vi["CUSTOM"];
Assert.IsNotNull(customResources);
Assert.AreEqual(1, customResources.Count);
Resource customResource = customResources[0];
// check whether the properties are string representations
Assert.AreEqual(customResource.Name.ToString(), "RES_CONFIGURATION");
Assert.AreEqual(customResource.Type.ToString(), "CUSTOM");
}
}
示例4: FindSmallestBinaryWithResources
//[Test]
//public void FindSmallestBinaryWithResources()
//{
// FindSmallestBinaryWithResources(
// Environment.SystemDirectory,
// "*.exe",
// Kernel32.ResourceTypes.RT_MENU);
//}
private void FindSmallestBinaryWithResources(
string path, string ext, Kernel32.ResourceTypes rt)
{
long smallest = 0;
string[] files = Directory.GetFiles(path, ext);
foreach (string filename in files)
{
try
{
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
if (!ri.Resources.ContainsKey(new ResourceId(rt)))
continue;
FileInfo fi = new FileInfo(filename);
//if (fi.Length < smallest || smallest == 0)
//{
Console.WriteLine("{0} {1}", filename, new FileInfo(filename).Length);
smallest = fi.Length;
// }
break;
}
}
catch
{
}
}
}
示例5: TestLoad
public void TestLoad()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
string[] files =
{
// Path.Combine(Environment.SystemDirectory, "regedt32.exe"),
// Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe"),
Path.Combine(uriPath, "Binaries\\gutils.dll"),
Path.Combine(uriPath, "Binaries\\6to4svc.dll"),
Path.Combine(uriPath, "Binaries\\custom.exe"),
};
foreach (string filename in files)
{
Console.WriteLine(filename);
Assert.IsTrue(File.Exists(filename));
using (ResourceInfo vi = new ResourceInfo())
{
vi.Load(filename);
DumpResource.Dump(vi);
}
}
}
示例6: TestLoad
public void TestLoad(string filename)
{
Console.WriteLine(filename);
Assert.IsTrue(File.Exists(filename));
using (ResourceInfo vi = new ResourceInfo())
{
vi.Load(filename);
DumpResource.Dump(vi);
}
}
示例7: TestLoadMenuResourcesEx
public void TestLoadMenuResourcesEx()
{
string filename = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
foreach (MenuResource rc in ri[Kernel32.ResourceTypes.RT_MENU])
{
Console.WriteLine("MenuResource: {0}, {1}", rc.Name, rc.TypeName);
DumpResource.Dump(rc);
}
}
}
示例8: TestLoadBitmapResources
public void TestLoadBitmapResources()
{
string filename = Path.Combine(Environment.SystemDirectory, "msftedit.dll");
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
foreach(BitmapResource rc in ri[Kernel32.ResourceTypes.RT_BITMAP])
{
Console.WriteLine("BitmapResource: {0}, {1}", rc.Name, rc.TypeName);
Console.WriteLine("DIB: {0}x{1} {2}", rc.Bitmap.Image.Width, rc.Bitmap.Image.Height,
rc.Bitmap.Header.PixelFormatString);
}
}
}
示例9: TestLoadMenuResourcesEx
public void TestLoadMenuResourcesEx()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
string filename = Path.Combine(uriPath, @"Binaries\custom.exe");
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
foreach (MenuResource rc in ri[Kernel32.ResourceTypes.RT_MENU])
{
Console.WriteLine("MenuResource: {0}, {1}", rc.Name, rc.TypeName);
DumpResource.Dump(rc);
}
}
}
示例10: CopyResources
/// <summary>
/// A
/// </summary>
/// <param name="target"></param>
/// <param name="source"></param>
public static void CopyResources(this FileInfo target, FileInfo source) {
if (File.Exists(target.FullName) == false) throw new FileNotFoundException("Couldnt find the given file", target.FullName);
if (File.Exists(source.FullName) == false) throw new FileNotFoundException("Couldnt find the given file", source.FullName);
var ri = new ResourceInfo();
ri.Load(source.FullName);
foreach (var res in ri) {
try {
res.SaveTo(target.FullName);
} catch { //copy what ever it can. skip errory ones.
}
}
ri.Dispose();
}
示例11: SampleEnumerateResources
public void SampleEnumerateResources(string filename)
{
using (ResourceInfo vi = new ResourceInfo())
{
vi.Load(filename);
foreach (ResourceId id in vi.ResourceTypes)
{
Console.WriteLine(id);
foreach (Resource resource in vi.Resources[id])
{
Console.WriteLine("{0} ({1}) - {2} byte(s)",
resource.Name, resource.Language, resource.Size);
}
}
}
}
示例12: TestLoadStringResources
public void TestLoadStringResources()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
string filename = Path.Combine(uriPath, @"Binaries\gutils.dll");
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
Assert.AreEqual(1, ri[Kernel32.ResourceTypes.RT_STRING].Count);
foreach (StringResource rc in ri[Kernel32.ResourceTypes.RT_STRING])
{
Console.WriteLine("StringResource: {0}, {1}", rc.Name, rc.TypeName);
DumpResource.Dump(rc);
}
}
}
示例13: TestControlLicenseResources
public void TestControlLicenseResources()
{
InstallerLinkerArguments args = new InstallerLinkerArguments();
string licenseFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".txt");
try
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string binPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
ConfigFile configFile = new ConfigFile();
SetupConfiguration setupConfiguration = new SetupConfiguration();
configFile.Children.Add(setupConfiguration);
ControlLicense license = new ControlLicense();
license.LicenseFile = licenseFile;
Console.WriteLine("Writing '{0}'", license.LicenseFile);
File.WriteAllText(license.LicenseFile, "Lorem ipsum");
setupConfiguration.Children.Add(license);
args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
Console.WriteLine("Writing '{0}'", args.config);
configFile.SaveAs(args.config);
args.output = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
Console.WriteLine("Linking '{0}'", args.output);
args.template = dotNetInstallerExeUtils.Executable;
InstallerLib.InstallerLinker.CreateInstaller(args);
// check that the linker generated output
Assert.IsTrue(File.Exists(args.output));
Assert.IsTrue(new FileInfo(args.output).Length > 0);
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(args.output);
Assert.IsTrue(ri.Resources.ContainsKey(new ResourceId("CUSTOM")));
List<Resource> custom = ri.Resources[new ResourceId("CUSTOM")];
Assert.AreEqual("RES_BANNER", custom[0].Name.Name);
Assert.AreEqual("RES_CONFIGURATION", custom[1].Name.ToString());
Assert.AreEqual("RES_LICENSE", custom[2].Name.ToString());
}
}
finally
{
if (File.Exists(licenseFile))
File.Delete(licenseFile);
if (File.Exists(args.config))
File.Delete(args.config);
if (File.Exists(args.output))
File.Delete(args.output);
}
}
示例14: TestLoadAcceleratorResources
public void TestLoadAcceleratorResources()
{
Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
string uriPath = Path.GetDirectoryName(HttpUtility.UrlDecode(uri.AbsolutePath));
string filename = Path.Combine(uriPath, @"Binaries\custom.exe");
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
Assert.AreEqual(2, ri[Kernel32.ResourceTypes.RT_ACCELERATOR].Count);
foreach (AcceleratorResource rc in ri[Kernel32.ResourceTypes.RT_ACCELERATOR])
{
Console.WriteLine("AcceleratorResource: {0}, {1}", rc.Name, rc.TypeName);
DumpResource.Dump(rc);
}
Assert.AreEqual(109, ri[Kernel32.ResourceTypes.RT_ACCELERATOR][0].Name.Id.ToInt64());
Assert.AreEqual(110, ri[Kernel32.ResourceTypes.RT_ACCELERATOR][1].Name.Id.ToInt64());
}
}
示例15: TestReadWriteMenuMixedResourceBytes
public void TestReadWriteMenuMixedResourceBytes()
{
string filename = Path.Combine(Environment.GetEnvironmentVariable("WINDIR"), "explorer.exe");
using (ResourceInfo ri = new ResourceInfo())
{
ri.Load(filename);
foreach (MenuResource rc in ri[Kernel32.ResourceTypes.RT_MENU])
{
GenericResource genericResource = new GenericResource(
rc.Type,
rc.Name,
rc.Language);
genericResource.LoadFrom(filename);
byte[] data = rc.WriteAndGetBytes();
ByteUtils.CompareBytes(genericResource.Data, data);
}
}
}