Support NSWindowsCP1252StringEncoding using yore crate

Change-Id: Ie21948fe69cd50ed7aee47ba9ff1cb54b36b49aa
This commit is contained in:
ciciplusplus
2024-11-19 17:47:43 +01:00
parent 81dd3311d0
commit 23e9aa5ff7
4 changed files with 24 additions and 4 deletions

10
Cargo.lock generated
View File

@@ -786,6 +786,7 @@ dependencies = [
"touchHLE_openal_soft_wrapper",
"touchHLE_pvrt_decompress_wrapper",
"touchHLE_stb_image_wrapper",
"yore",
"zip",
]
@@ -898,6 +899,15 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
[[package]]
name = "yore"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f58c7ce1b7faa85a5c5a8b45b428c89cabdcd097bb472b7668037b291a8a20b"
dependencies = [
"thiserror",
]
[[package]]
name = "zip"
version = "0.6.4"

View File

@@ -52,6 +52,7 @@ rusttype = "0.9.3"
symphonia = { version = "0.5.3", default-features = false, features = ["aac", "isomp4", "mp3"] }
quick-xml = "0.36.2"
md5 = "0.7.0"
yore = "1.1.0"
# We currently use a fork of rust-sdl2 because we need a fix for Android builds
# that's not upstream yet.
# The HIDAPI feature is enabled because rust-sdl2 hides the SDL2 sensor features

View File

@@ -116,7 +116,7 @@ Please note that different licensing terms apply to the bundled dynamic librarie
We stand on the shoulders of giants. Thank you to:
* Everyone who has contributed to the project or supported any of its contributors financially.
* The authors of and contributors to the many libraries used by this project: [dynarmic](https://github.com/merryhime/dynarmic), [rust-macho](https://github.com/flier/rust-macho), [SDL](https://libsdl.org/), [rust-sdl2](https://github.com/Rust-SDL2/rust-sdl2), [stb\_image](https://github.com/nothings/stb), Imagination Technologies' [PVRTC decompressor](https://github.com/powervr-graphics/Native_SDK/blob/master/framework/PVRCore/texture/PVRTDecompress.cpp), [openal-soft](https://github.com/kcat/openal-soft), [hound](https://github.com/ruuda/hound), [caf](https://github.com/rustaudio/caf), [Symphonia](https://github.com/pdeljanov/Symphonia), [RustType](https://gitlab.redox-os.org/redox-os/rusttype), [the Liberation fonts](https://github.com/liberationfonts/liberation-fonts), [the Noto CJK fonts](https://github.com/googlefonts/noto-cjk), [rust-plist](https://github.com/ebarnard/rust-plist), [quick-xml](https://github.com/tafia/quick-xml), [gl-rs](https://github.com/brendanzab/gl-rs), [cargo-license](https://github.com/onur/cargo-license), [cc-rs](https://github.com/rust-lang/cc-rs), [cmake-rs](https://github.com/rust-lang/cmake-rs), [cargo-ndk](https://github.com/bbqsrc/cargo-ndk), [cargo-ndk-android-gradle](https://github.com/willir/cargo-ndk-android-gradle), [md5](https://github.com/stainless-steel/md5), and the Rust standard library.
* The authors of and contributors to the many libraries used by this project: [dynarmic](https://github.com/merryhime/dynarmic), [rust-macho](https://github.com/flier/rust-macho), [SDL](https://libsdl.org/), [rust-sdl2](https://github.com/Rust-SDL2/rust-sdl2), [stb\_image](https://github.com/nothings/stb), Imagination Technologies' [PVRTC decompressor](https://github.com/powervr-graphics/Native_SDK/blob/master/framework/PVRCore/texture/PVRTDecompress.cpp), [openal-soft](https://github.com/kcat/openal-soft), [hound](https://github.com/ruuda/hound), [caf](https://github.com/rustaudio/caf), [Symphonia](https://github.com/pdeljanov/Symphonia), [RustType](https://gitlab.redox-os.org/redox-os/rusttype), [the Liberation fonts](https://github.com/liberationfonts/liberation-fonts), [the Noto CJK fonts](https://github.com/googlefonts/noto-cjk), [rust-plist](https://github.com/ebarnard/rust-plist), [quick-xml](https://github.com/tafia/quick-xml), [gl-rs](https://github.com/brendanzab/gl-rs), [cargo-license](https://github.com/onur/cargo-license), [cc-rs](https://github.com/rust-lang/cc-rs), [cmake-rs](https://github.com/rust-lang/cmake-rs), [cargo-ndk](https://github.com/bbqsrc/cargo-ndk), [cargo-ndk-android-gradle](https://github.com/willir/cargo-ndk-android-gradle), [md5](https://github.com/stainless-steel/md5), [yore](https://github.com/bonega/yore), and the Rust standard library.
* The Skyline emulator project (RIP), for [writing the tedious boilerplate needed to replace file management on newer Android versions](https://github.com/skyline-emu/skyline/blob/dc20a615275f66bee20a4fd851ef0231daca4f14/app/src/main/java/emu/skyline/provider/DocumentsProvider.kt).
* The [Rust project](https://www.rust-lang.org/) generally.
* The various people out there who've documented the iPhone OS platform, officially or otherwise. Much of this documentation is linked to within this codebase!

View File

@@ -33,11 +33,13 @@ use std::collections::HashMap;
use std::io::Write;
use std::iter::Peekable;
use std::string::FromUtf16Error;
use yore::code_pages::CP1252;
pub type NSStringEncoding = NSUInteger;
pub const NSASCIIStringEncoding: NSUInteger = 1;
pub const NSUTF8StringEncoding: NSUInteger = 4;
pub const NSUnicodeStringEncoding: NSUInteger = 10;
pub const NSWindowsCP1252StringEncoding: NSUInteger = 12;
pub const NSMacOSRomanStringEncoding: NSUInteger = 30;
pub const NSUTF16StringEncoding: NSUInteger = NSUnicodeStringEncoding;
pub const NSUTF16BigEndianStringEncoding: NSUInteger = 0x90000100;
@@ -50,8 +52,11 @@ pub const NSBackwardsSearch: NSUInteger = 4;
pub const NSNumericSearch: NSUInteger = 64;
/// Encodings that C strings (null-terminated byte strings) can use.
const C_STRING_FRIENDLY_ENCODINGS: &[NSStringEncoding] =
&[NSASCIIStringEncoding, NSUTF8StringEncoding];
const C_STRING_FRIENDLY_ENCODINGS: &[NSStringEncoding] = &[
NSASCIIStringEncoding,
NSUTF8StringEncoding,
NSWindowsCP1252StringEncoding,
];
pub const NSMaximumStringLength: NSUInteger = (i32::MAX - 1) as _;
@@ -104,6 +109,10 @@ impl StringHostObject {
let string = String::from_utf8(bytes.into_owned()).unwrap();
StringHostObject::Utf8(Cow::Owned(string))
}
NSWindowsCP1252StringEncoding => {
let string = CP1252.decode(&bytes).to_string();
StringHostObject::Utf8(Cow::Owned(string))
}
NSUTF16StringEncoding
| NSUTF16BigEndianStringEncoding
| NSUTF16LittleEndianStringEncoding => {
@@ -1188,7 +1197,7 @@ pub const CLASSES: ClassExports = objc_classes! {
- (id)initWithCString:(ConstPtr<u8>)c_string
encoding:(NSStringEncoding)encoding {
assert!(C_STRING_FRIENDLY_ENCODINGS.contains(&encoding));
assert!(C_STRING_FRIENDLY_ENCODINGS.contains(&encoding), "encoding {}", encoding);
let len: NSUInteger = env.mem.cstr_at(c_string).len().try_into().unwrap();
msg![env; this initWithBytes:c_string length:len encoding:encoding]
}