3 releases (breaking)
|0.2.0||Mar 20, 2023|
|0.1.0||Dec 20, 2022|
|0.0.0||Dec 10, 2022|
#65 in Windows APIs
66 downloads per month
Crate for modification of windows resources.
This crate allows you to create, load and modify Windows resources inside of
.res files. This crate currently does not support actual resource data destructuring with exception of Version Strings (VS_VERSION_INFO), which is useful to modify application manifests. Loaded resources are available as raw
Vec<u8> data, useful to modify bitmaps and icons.
Please note that all operations performed on the opened resource file are accumulated and are then "flushed" to the file when the file is closed
close() function. This is due to the behavior of the underlying Win32 API (UpdateResource) functionality used by this crate.
Modifying icon data and resource strings
let mut resources = Resources::new(&Path::new("myfile.exe")); resources.load().expect("Unable to load resources"); resources.open().expect("Unable to open resource file for updates"); resources.find(resource_type::ICON,Id::Integer(1)) .expect("unable to find main icon") .replace(icon_data)? .update()?; let version: [u16;4] = [0,1,0,0]; resources.get_version_info()?.expect("Unable to get version info") .set_file_version(&version) .set_product_version(&version) .insert_strings( &[ ("ProductName","My Product") ("FileDescription","My File") ] ) .remove_string("SomeExistingString") .update()?; // make sure to explicitly call close() as that flushes all the session changes resources.close();
Adding a new icon
let res = Resource::new( &resources, resource_type::ICON.into(), Id::Integer(14).into(), 1033, target_icon.data(), ); res.update()?;
This crate works well in conjunction with the
ico crate that can be used to load/store external
.ico files as well as load
.png files and encode them into windows-compatible resource format.
let iconfile = std::fs::File::open("myicon.ico").unwrap(); let icon_dir = ico::IconDir::read(iconfile).unwrap(); let target_icon = icon_dir .entries() .iter() .find(|&e| e.width() == 256) .expect("can't find 256x256 icon"); let icon_data = target_icon.data();
This crate also works well in conjunction with the
image crate that can interact with the
ico crate to load, resize and and store custom icons within resource files.