@@ -16,6 +16,7 @@ class Environment:
1616 def __init__ (self , * args ):
1717 self .files = {}
1818 self .path = "."
19+ self .out_path = os .path .join (os .getcwd (), "output" )
1920
2021 if args :
2122 for arg in args :
@@ -62,18 +63,19 @@ def load_file(self, stream, parent=None):
6263 typ , reader = ImportHelper .check_file_type (stream )
6364 try :
6465 if typ == FileType .AssetsFile :
65- return files .SerializedFile (reader , parent )
66+ return files .SerializedFile (reader , parent , name = stream . name )
6667 elif typ == FileType .BundleFile :
67- return files .BundleFile (reader , parent )
68+ return files .BundleFile (reader , parent , name = stream . name )
6869 elif typ == FileType .WebFile :
69- return files .WebFile (reader , parent )
70+ return files .WebFile (reader , parent , name = stream . name )
7071 elif typ == FileType .ZIP :
7172 self .load_zip_file (stream )
7273 elif typ == FileType .ResourceFile :
7374 return EndianBinaryReader (stream )
74- except :
75+ except Exception as e :
7576 # just to be sure
7677 # cuz the SerializedFile detection isn't perfect
78+ print ("Error loading, reverting to EndianBinaryReader:\n " , e .message )
7779 return EndianBinaryReader (stream )
7880
7981 def load_zip_file (self , value ):
@@ -88,7 +90,7 @@ def load_zip_file(self, value):
8890 z = ZipFile (buffer )
8991 splits = {}
9092 for path in z .namelist ():
91-
93+
9294 if path [- 7 :- 1 ] == ".split" :
9395 name = path [:- 7 ]
9496 if name not in splits :
@@ -106,7 +108,7 @@ def load_zip_file(self, value):
106108 cur .files [d ] = files .File (self )
107109 cur = cur .files [d ]
108110 cur .files [name ] = self .load_file (stream , cur )
109-
111+
110112 # merge splits
111113 for path , items in splits .items ():
112114 # merge data
@@ -124,6 +126,16 @@ def load_zip_file(self, value):
124126
125127 z .close ()
126128
129+ def save (self , pack = "none" ):
130+ """ Saves all changed assets.
131+ Mark assets as changed using `.mark_changed()`.
132+ pack = "none" (default) or "lz4"
133+ """
134+ for f in self .files :
135+ if self .files [f ].is_changed :
136+ with open (os .path .join (self .out_path , os .path .basename (f )), 'wb' ) as out :
137+ out .write (self .files [f ].save (packer = pack ))
138+
127139 @property
128140 def objects (self ):
129141 def search (item ):
@@ -167,3 +179,4 @@ def gen_all_asset_files(file, ret = []):
167179
168180 def get (self , key , default = None ):
169181 return getattr (self , key , default )
182+
0 commit comments