File: encoderunitypackage

package info (click to toggle)
faust 2.81.10%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 431,496 kB
  • sloc: cpp: 283,941; ansic: 116,215; javascript: 18,529; sh: 14,356; vhdl: 14,052; java: 5,900; python: 5,091; objc: 3,852; makefile: 2,725; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 111; tcl: 26
file content (113 lines) | stat: -rwxr-xr-x 3,548 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#! /bin/bash -e

#####################################################
#                                                   #
#   Encode an unitypackage archive                  #
#                                                   #
#   (c) Grame, 2017                                 #
#                                                   #
#####################################################


# Structure of a unitypackage archive
#----------------------------------------------------------------------------------
#   FaustPlugin_<dspname>.unitypackage/
#        <md5 key of file1>/
#           asset (file1 renamed)
#           pathname (file containing the address of file1 in the Unity hierarchy
#        <md5 key of file2>/
#           asset (file2 renamed)
#           pathname (file containing the address of file2 in the Unity hierarchy
#        <md5 key of file3>/
#           ...

# The Unity hierarchy will be the same as the original folder hierarchy.
# However, the first folder needs to be called "Assets", if not the script creates it before packing.
# When the package is imported, Unity retrieves the hierarchy from the pathname files

#-------------------------------------------------------------------
#Dispatch command arguments

for p in $@; do
    if [ $p = "-help" ] || [ $p = "-h" ]; then
        echo "encoderunitypackage <folder>"
        echo "Builds a unity package according to the specified sub folder hierarchy."
        echo "Handles if the folder isn't called Assets/ (adds a parent folder called Assets/)."
        echo "If the package is called FaustPlugin_<pluginname>, change <pluginname> to the correct name."
        echo "See architecture/unity/README.md for more info."
        exit
    fi

    if [ ${p:0:1} = "-" ]; then
	    OPTIONS="$OPTIONS $p"
    elif [[ -d "$p" ]]; then
	    FOLDER="$FOLDER $p"
	else
	    OPTIONS="$OPTIONS $p"        
	fi
done

for p in $FOLDER; do

    # If the parent folder is not called "Assets", create it (to respect the Unity hierarchy).
    if [ ! $p = "Assets" ]; then
        mkdir Assets
        mv $p Assets
        p=Assets
    fi

    # Retrieve the name of the dsp file stored in ".VAR"
    if [ -f .VAR ]; then
        FNAME=FaustPlugin_$(cat .VAR)
    else
        FNAME=FaustPlugin_\<pluginname\>
    fi

    rm -rf .VAR
    TMP=$(mktemp -d unity.XXXX)

    # Finds all files in $p to encode them
    FILES=$(find $p -type f)

    for f in $FILES; do
        FILE=$(basename $f)

        # Computes the md5 key of each file, for Darwin system the command is md5, if not the command is md5sum
        if [[ $(uname) == Darwin ]]; then
            DIR=$(md5 -q $f)
        else
            DIR=$(md5sum $f | cut -f1 -d" ")
        fi

        # Creates the folder named with the md5 key of the file
        if [ -d "$DIR" ]; then
            rm -rf "$DIR"
        fi
        mkdir -p "$DIR"
        mv $DIR $TMP/$DIR

        # Retrieves the file address and creates the pathname file
        echo "$f" >> $TMP/$DIR/pathname

        # Moves and renames the file in the $DIR (md5 key folder)
        mv "$f" "$TMP/$DIR/asset"

    done

    # Make sure all .* files have been deleted
    FILES=$(find $p -name "\.*")
    for f in $FILES; do
        rm -rf $f
    done

    # Compresses the folder and renames it FaustPlugin_<dspname>.unityackage
    # The archive needs to be a tar gz archive to be correctly read by Unity
    cd unity.*
    tar zcvf $FNAME.unitypackage * &> /dev/null
    mv "$FNAME.unitypackage" ../
    cd ..
    rm -rf unity.* $p

done