Download RBZ file
-
I'm well aware of how to download a file use ADO Data Streams.
Would you like to run our Tech Support for a day, and deal with the myriad of people who have Security issues with it? It's the oADOStream.SaveToFile that most commonly gets snagged, and just doesn't have the ability to save to where I'd like it to. Then you end up using VBS File objects to move it around, or CIM.... oh, and wait, then you have the File object locked down, or the Domains where VBS is just not responding at all. In the mood to do a remote session with a machine in China or Dubai, where their internet is really locked down, and you have to use a Start menu in a foreign language? Trust me, it's not fun, and ADO is a security nightmare waiting to happen.I've just spent the last couple weeks re-engineering our Component delivery system to not use ADO anymore, and oh my gosh is it a better system. Loving load_from_url, such a more elegant solution.
Anyway, I'll have some code for y'all within about a week or so, and you can judge then whether it's more or less bulletproof than any of these other solutions.
--J
-
@honkinberry said:
Loving
load_from_url
, such a more elegant solution.We'll if I was tasked with using a component via
load_from_url()
, to d/l and install a plugin... I would not convert Ruby to BMP or any other image.Ruby scripts are text.. even scrambled rbs files.
I would TRY saving the plugin information (folder & file names etc.,) and the script text blocks themselves, into an attribute dictionary, and write out a "plugin" component definition, that has only this attribute dictionary.
Then download it via
load_from_url
using a customLoadHandler
class.
TheonSuccess()
callback would just use standard RubyDir
andFile
classes to create the directories, and write out the script text files, using the fields of the attributes attached to the component definition.If the definition contained images (within it's entities, or textured materials,) ... I would assume them to be toolbar button images etc., and they would be written out as images (using a custom
TextureWriter
class.)When done, the definition is deleted, and the user is asked if they wish to load the plugin at that time.
ADD: I suppose an entire RBZ file could be written as one attribute value... it's worth a try.
-
The
definitions.load_from_url
works just fine - for components - I've used it a lot... BUT you can't get it to do much else...
The download will fail if the .skp isn't 'valid' and the downloaded file is auto-deleted !Having an effectively 'empty' skp, with an attribute-dictionary containing the data might work, but isn't there a data size limit ?
BUT assuming that the RBZ file's data is of an acceptable size [or it is spread across several attributes which get recombined later]... then the 'Dan' trick might just work... -
So rather than encode a single RBZ file as a BMP, and allow SU's built in install_from_archive,
Dan is proposing I maintain a file schema of the... (at last count 100+) files involved in my plugin, write them all out to the correct location.... agh, that sounds frustrating. How are you proposing I maintain the file manifest? I suppose another unusual trick, like storing it as Text objects in the Model?I'll get you guys to come around to my idea... eventually....
--J
-
@honkinberry said:
I suppose another unusual trick, like storing it as Text objects in the Model?
It is quite normal to store text data in an AttributeDictionary
The approach I am thinking about, does not actually add entities into the model's entities collection.
AND... this is this first we are hearing that you have 100+ files.
We are just brain-storming here.
Do what you wish.. have fun.
-
Out of interest I tried writing some methods that to my surprise worked effectively.
One that encodes the RBZ file as hex strings in a number of attribute keys in a dictionary attached to a SKP - it's an all but empty file otherwise [a guide-point is need so it's not seem as empty by the loader].
The others are as some connected methods used in any SKP later on - one that uses load_from_url to add a temporary-definition of the remote SKP into the current model.definitions without need for further user interaction [after a callback action from a webdialog button], the definitions attributes are got and recombined into the needed data, and the definition is deleted from the model.
The data is written out into a RBZ in the user's Temp folder and then auto-installed from that archive...
So to recap, you make a SKP containing the RBZ's data as a attribute key values, you temporarily load that SKP from a url and extract the RBZ's data, recombining it into a local file in a Temp folder, from where it can be auto-installed into Plugins...
The only downside I can see is that the SKP is considerably bigger than the RBZ as the data is 'hexed' ~3.7x, but a 2Mb RBZ would be quite unusual ? -
Tig, that's brilliant, I wouldn't have thought of that.
That's very much the same approach, just a bit cleaner.
Yes of course there's a bit of loss in file file size, but it's all about the capability gain here.
Having an integrated update solution gives a much more professional and complete experience to the user.
Very nice. Would you care to share some of your code?--J
-
@honkinberry said:
Tig, that's brilliant, I wouldn't have thought of that.
to TIG for proving the concept.
@TIG: Do you need to hex encode it?
Would it help you, if you had Zip / Unzip methods in Ruby ? (I can PM them to you.)
-
@dan rathbun said:
Do you need to hex encode it?
Unless you're sure there is no null character, you'll have to hex encode it or Sketchup will only store up to the first null character. Binary files will probably have plenty of nulls in them.
Here's a sample of how SketchUp deals with the situation:
` nullstr = 'My Test ' + 0.chr + ' String'
puts nullstr.inspect=> "My Test \000 String"
puts nullstr.length
=> 16
Sketchup.active_model.set_attribute('test', 'nullstr', nullstr)
nullstr2 = Sketchup.active_model.get_attribute('test', 'nullstr')
puts nullstr2.inspect=> "My Test "
puts nullstr2.length
=> 8
puts 'My Test '.length
=> 8`
-
I already tested it, and I used:
data = open(path,"rb"){|io|io.read}.unpack('H*').to_s
The 'path' is the file path to the RBZ file.
Although an attribute value can be an array it is made into a string because it could need splitting into 'chunks', because there's an attribute value size limit [I use ~20,000 chars] - you will get Bugsplats if it's much bigger [test it to see] - these 'chunks' are written into sequentially named attribute keys/values attached to the current model...Later after the 'attributed' model's SKP has been added to a new model's definition using the API's
load_from_url()
methods accessed via awebdialog etc. It's then easy to extract the sequentially named 'chunks' from that new definition's attribute keys/values, recombining those into a single string, here named 'data', and then to remake the binary code 'string' using:
datab = [data].pack('H*')
This 'string' is then written into a new temp RBZ file...
Finally the temp definition can be deleted, and the RBZ file auto-installed using the API methods added in v8M2, before it too is deleted from the user's Temp folder...The only downside to this is that the 'empty' SKP that has been 'attributed' is ~3.7x bigger than the original RBZ file, simply because of the unpack of its data into hex... BUT on the upside you can use it to encrypt, download and install an RBZ [masquerading as a SKP] from a URL without any user dialogs intervening etc; simply from a single user button-click in a webdialog running a callback to do the
load_from_url()
, or less secure when the page opens and no user involvement at all... -
I guess my question should be more specific.
Can the file's data be escaped rather than hex encoded ?
Could the printable characters could remain as they are... but the non-printables (including null,) could be escaped ? -
Thanks TIG for the clear direction!
It absolutely does work, with my quick and dirty (no error handling yet) version like so:
def encoderbz () chunksize = 2**14 # attrib data doesn't like more than ~20kb, so we limit each chunk to 16k if ( file = UI.openpanel "Select RBZ file to encode" ) data = open(file) {|io|io.read}.unpack('H*').to_s # hex encode, converted to string model = Sketchup.active_model i = 0 while data and data != "" i = i + 1 # counter d = "d" + i.to_s # name of attribute chunk = data[0,chunksize] # chunk of data data = data[chunksize..-1] # trim master data model.set_attribute 'rbz',d,chunk end # while # and set the next one to nil in case user is updating with a smaller rbz i = i + 1 d = "d" + i.to_s model.set_attribute 'rbz',d,nil UI.messagebox "The selected RBZ file has been successfully encoded into the current model." end # if end # encoderbz def decoderbz () model = Sketchup.active_model i = 1 # counter d = "d" + i.to_s # name of attribute data = "" # to assemble the chunks while dx = model.get_attribute('rbz',d) data = data + dx i = i + 1 d = "d" + i.to_s # name of attribute end # while if ( data != "" ) datab = [data].pack('H*') if ( filename = UI.savepanel "Save RBZ As...","","*.rbz" ) file = File.open(filename, "w") file.write(datab) file.close UI.messagebox "The enclosed RBZ has been successfully saved out as an RBZ file." end # if end # if end # decoderbz
Yes, there is a size overhead of about 4x, but the hex encoding does feel a very bulletproof way of doing this.
Certainly a bit easier than my initial thought of encoding as an image, but same basic idea.Thanks all for the help and patience! This definitely raises the quality of the plug-in to a more professional level.
--J
-
Since my last ideas I think the better way to ensure an 'empty' SKP.
It'll work in any SKP too...
In code...
Inside a model_start/commit block...
Make a new definition.
Set its name to RBZ.basename + '.skp'
Add a cpoint to definition.entities.
Add the attributes to the definition.
Do a 'save_as' on definition into the same folder as the RBZ file.
The new SKP has the RBZ attached as attribute key[s]...
Do a definition.entities.clear! so it's removed from the Browser...Done.
The import is much as you outlined...
-
Well, snap, not working on the PC side.
Mac side is flawless.Given my 106k RBZ file, and this line of code:
data = open(file) {|io|io.read}.unpack('H*').to_s
On the Mac, data.length is 207954
While on the PC, data.length is 18216And then there's issue on the other end too.
I'll have to assume it's here:datab = [data].pack('H*')
It's adding a bunch of 0D's in there, good ol' Chr(13), carriage returns.
At least it seems it is there, I suppose it could be in the actual file.write(datab) ?
But it's adding about 352 of them in that 106k file.Soooooooooo close!
Any brilliant ideas?(And in case you're wondering how it is on the Mac side where it works? Um, it's amazing, in a word.)
--J
-
Hint:
File.open(filename, "w")
writes binary OR strings on MAC/Unix BUT only strings on PC [messing up any binary-data]
BUT
File.open(filename, "w**b**")
writes binary-data properly on all platforms ? ... -
That did it!
You're a genius!It's probably a similar problem on the encoding side, but I'm okay with keeping the development station as a Mac.
Thanks as always.
--J
-
Good day pple i downloaded plugins for sketchup 2016 but they came as .skp files how do i install them on wondows
-
What plugins did you download? Plugins won't download as .skp files. That would indicate you've downloaded SketchUp models/components.
Advertisement