ResourcePackage

CI Status Version License Platform

将 app 资源打包加密进行管理。

将资源打包成单个文件,并通过文件名作为键来访问它们。

要求

安装

TextFormater 可以通过CocoaPods安装:

ResourcePackage 可通过 CocoaPods 获取。要安装它,只需将以下行添加到你的 Podfile

pod "ResourcePackage"

结构

Structure

用法

Packager - 打包工具

git clone https://github.com/1Fr3dG/ResourcePackage.git
cd ResourcePackage
cd packager
swift build -c release
.build/release/packager

可使用该打包工具将资源目录打包为单个文件供 app 使用。

这个工具旨在将资源文件夹打包成单个文件,供 app 使用。

注意: 此工具仅支持 gzip 作为压缩算法,你可以构建自己的工具来支持更多算法。

打开一个包

let _compress: SimpleEncrypter = EncrypterCompress(with: "gzip")
let _encrypt: SimpleEncrypter = EncrypterXor(with: "password12345")
let _pkgfile: String = "filename"
let pkg = ResourcePackage(with: _pkgfile, encrypter: _encrypt, compressor: _compress)

使用包读取器打开包

let pkgReader = ResourcePackageReader(
        withCache: false,
        useTwoStepLocating: false,
        autoDeviceCustomization: false,
        useKeyPrefix: false)
pkgReader.packages["pkg1"] = pkg

let themePkgReader = ResourcePackageReader(withTheme theme: String,
                            FromThemePackages respkg: ["themePkg1" : themePkg],
                            withBackwardTheme backward: "default")

读取数据

let stringValue = String(data:pkgReader[keyofString], encoding: .utf8)
let imageValue = UIImage(data:pkgReader[keyofImage])

资源优先级

使用 UIExtensions

uibutton.loadTheme(from: themePkgReader, key: "button1")
uilable.setText(from: themePkgReader, key: "labeltext")
uiimageview.setImage(from: themePkgReader, key: "image1")

声音

pkgReader.playSound(key: "asound", withVibrate: false)
pkgReader.playMusic("bgmusic.mp3", loops: 1, volume: 0.8)

作者

Alfred Gao, alfredg@alfredg.cn

许可证

ResourcePackage 根据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。