Coder Social home page Coder Social logo

gma's Introduction

GMA

Rust Crates.io version

Documentation

A crate to read and write to .gma files.

Reading/Writing lzma compressed files is supported. Garry's mod cant read compressed gma files but some when downloaded directly from the steam workshop some files are lzma compressed.

Reading a .gma file

    let archive = gma::open("myfile.gma").unwrap();
    println!("Version : {}", archive.version());
    println!("Author steam id : {}", archive.author_steamid());
    println!("Timestamp : {}", archive.timestamp());
    println!("Name : {}", archive.name());
    println!("Description : {}", archive.description());
    println!("Addon Type : {:?}", archive.addon_type());
    println!("Addon Tags : {:?}", archive.addon_tags());
    println!("Author name : {}", archive.author());
    println!("Compressed : {}", archive.compressed());
    println!();

    for entry in archive.entries() {
        println!("{} :", entry.filename());
        println!("\tSize : {} bytes", entry.size());
        println!("\tCRC32 : {:x}", entry.crc());

        //Only print the contents of lua files
        if entry.filename().ends_with(".lua") {
            archive
                .read_entry(entry, |_, reader| {
                    let mut file_contents = String::new();
                    reader.read_to_string(&mut file_contents).unwrap();
                    println!("\tContents : '{}'", file_contents);
                })
                .expect("Error when reading the file");
        }
    }

Creating a .gma file

    const VERSION: u8 = 3;
    const STEAMID: u64 = 123456;
    const TIMESTAMP: u64 = 987654;
    const NAME: &str = "ADDON_NAME";
    const DESC: &str = "ADDON_DESC";
    const AUTHOR: &str = "AUTHOR_NAME";
    const TYPE: AddonType = AddonType::Model;
    const TAG1: AddonTag = AddonTag::Build;
    const TAG2: AddonTag = AddonTag::Fun;

    let file = File::create("myaddon.gma").unwrap();
    let mut writer = BufWriter::new(file);

    let mut builder = GMABuilder::new();

    builder
        .version(VERSION)
        .steamid(STEAMID)
        .timestamp(TIMESTAMP)
        .name(NAME)
        .description(DESC)
        .addon_type(TYPE)
        .addon_tag(TAG1)
        .addon_tag(TAG2)
        .author(AUTHOR)
        .file_from_bytes("file1", b"hello")
        .compression(true);

    builder.write_to(&mut writer).unwrap();

gma's People

Contributors

dependabot[bot] avatar diogo464 avatar srlion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.