Skip to main content

RawSketchwareProject

Struct RawSketchwareProject 

Source
pub struct RawSketchwareProject {
    pub project: String,
    pub file: String,
    pub library: String,
    pub resource: String,
    pub view: String,
    pub logic: String,
    pub resource_files: Option<Vec<ResourceFileWrapper>>,
}
Expand description

Represents a raw (un-parsed) sketchware project

Fields§

§project: String§file: String§library: String§resource: String§view: String§logic: String§resource_files: Option<Vec<ResourceFileWrapper>>

A list of resource files that belongs to this project

None means to automatically assign missing resources with a random id

Implementations§

Source§

impl RawSketchwareProject

Source

pub fn new( project: String, file: String, library: String, resource: String, view: String, logic: String, resource_files: Vec<ResourceFileWrapper>, ) -> Self

Creates a RawSketchwareProject with the specified fields

Examples found in repository?
examples/api_demo1.rs (line 42)
9fn main() {
10    let mut args = std::env::args();
11    args.next();
12
13    let project = read(args.next().expect("File path of a project data file to parse")).expect("Invalid project path given");
14    let file = read(args.next().expect("File path of a file data file to parse")).expect("Invalid file path given");
15    let library = read(args.next().expect("File path of a library data file to parse")).expect("Invalid library path given");
16    let resource = read(args.next().expect("File path of a resource data file to parse")).expect("Invalid resource path given");
17    let view = read(args.next().expect("File path of a view data file to parse")).expect("Invalid view path given");
18    let logic = read(args.next().expect("File path of a logic data file to parse")).expect("Invalid logic path given");
19
20    // decrypt them
21
22    let project = swrs::decrypt_sw_encrypted(&project).expect("Unable to decrypt project");
23    let file = swrs::decrypt_sw_encrypted(&file).expect("Unable to decrypt file");
24    let library = swrs::decrypt_sw_encrypted(&library).expect("Unable to decrypt library");
25    let resource = swrs::decrypt_sw_encrypted(&resource).expect("Unable to decrypt resource");
26    let view = swrs::decrypt_sw_encrypted(&view).expect("Unable to decrypt view");
27    let logic = swrs::decrypt_sw_encrypted(&logic).expect("Unable to decrypt logic");
28
29    // turn them into strings
30
31    let project = String::from_utf8(project).expect("Invalid charset for project");
32    let file = String::from_utf8(file).expect("Invalid charset for file");
33    let library = String::from_utf8(library).expect("Invalid charset for library");
34    let resource = String::from_utf8(resource).expect("Invalid charset for resource");
35    let view = String::from_utf8(view).expect("Invalid charset for view");
36    let logic = String::from_utf8(logic).expect("Invalid charset for logic");
37
38    // and parse them
39
40    let sketchware_project = SketchwareProject::try_from(
41        ParsedSketchwareProject::parse_from(
42            RawSketchwareProject::new(project, file, library, resource, view, logic, vec![])
43        ).expect("Corrupted sketchware project")
44    ).expect("Corrupted sketchware project");
45
46    println!("Screens:");
47
48    for screen in sketchware_project.screens {
49        println!("  Screen {} or {}:", screen.layout_name, screen.java_name);
50        println!("    Events:");
51
52        for event in screen.events {
53            println!("      - Event {}, type: {:?}, blocks:", event.name, event.event_type);
54
55            fn print_blocks(indentation: u32, blocks: Blocks) {
56                for block in blocks {
57                    println!("{}Block #{} opcode {}", " ".repeat(indentation as usize), block.op_code, block.content.to_string());
58
59                    if let Some(blocks_ss1) = block.sub_stack1 {
60                        println!("{}substack1: ", " ".repeat(indentation as usize));
61                        print_blocks(indentation + 2, blocks_ss1);
62                    }
63
64                    if let Some(blocks_ss2) = block.sub_stack2 {
65                        println!("{}substack2: ", " ".repeat(indentation as usize));
66                        print_blocks(indentation + 2, blocks_ss2);
67                    }
68                }
69
70                println!();
71            }
72
73            print_blocks(8, event.code);
74        }
75    }
76}
Source

pub fn new_wo_res( project: String, file: String, library: String, resource: String, view: String, logic: String, ) -> Self

Creates a RawSketchwareProject with the specified fields without the resource files, they will all be assigned to random ids

Source

pub fn from_encrypted( project: Vec<u8>, file: Vec<u8>, library: Vec<u8>, resource: Vec<u8>, view: Vec<u8>, logic: Vec<u8>, resource_files: Vec<ResourceFileWrapper>, ) -> Result<Self, CryptoError>

Source

pub fn from_encrypted_wo_res( project: Vec<u8>, file: Vec<u8>, library: Vec<u8>, resource: Vec<u8>, view: Vec<u8>, logic: Vec<u8>, ) -> Result<Self, CryptoError>

Creates a RawSketchwareProject from encrypted sketchware project data without the resource files, they will all be assigned to random ids

Trait Implementations§

Source§

impl Clone for RawSketchwareProject

Source§

fn clone(&self) -> RawSketchwareProject

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RawSketchwareProject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RawSketchwareProject

Source§

fn eq(&self, other: &RawSketchwareProject) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryInto<RawSketchwareProject> for SketchwareProject

Source§

type Error = SketchwareProjectReconstructionError

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<RawSketchwareProject, Self::Error>

Performs the conversion.
Source§

impl TryInto<RawSketchwareProject> for SketchwareProject

Source§

type Error = SketchwareProjectReconstructionError

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<RawSketchwareProject, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for RawSketchwareProject

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V