Book a Demo

Author Topic: Encoding ShapeScripts, Icons and Images into Base64  (Read 15294 times)

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Encoding ShapeScripts, Icons and Images into Base64
« on: October 07, 2021, 09:43:19 am »
Hey all

I am trying to encode and decode the Shape Scripts, Icons and Icons To/From Base64 programmatically.
So far, I can (relatively) easily decode the values from Base64 to plain text.

However, whenever I try to encode the plain text into Base64 it all turns to crap:

1. If I take plain text and try to "round trip" it from encoded text -> plain text -> encoded text, the final encoded textt differs from the original encoded text.
2. If I plug this into the MDG, Sparx promptly ignores it.

I know that the Image & Shape script files are zip archives with a single file named "str.dat".
However, what I think is happening is that there is some formatting options that I need to specify when encoding the string that is somehow not required when de-coding (single decoding works ok).

Dunno if this is something my fellow users can help with or if it is a Sparxian only problem.
Geert, I know you have likewise managed to decode Shapescripts programmatically. Have you ever managed to successfully reverse the process as I am trying to?

Cheers

Jays :-)


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #1 on: October 07, 2021, 10:39:36 am »
The number of chars is important. Only if you can re-decode your pasted stuff EA will have a chance. Took me some time to get it right. Are you using Notepad++?

q.

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #2 on: October 07, 2021, 10:52:54 am »
Hey qwerty

I am using C#.
What do you mean by number of characters are important?

I can de-code ok and am assuming that if I use the correct method for re-coding that the re-coded Base64 string will match the original.

Cheers :-)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #3 on: October 07, 2021, 11:31:03 am »
Hey qwerty

I am using C#.
What do you mean by the number of characters are important?

I can de-code ok and am assuming that if I use the correct method for re-coding that the re-coded Base64 string will match the original.

Cheers :-)
Jays, I use the UltraEdit editor to do our conversions.  That works OK.  You might use a temporary copy of that to confirm that your conversions are generating the right Base64.  i.e. "Compare and Contrast".
If you go that route, PM me and I can send you the scripts we use to round trip this stuff.

HTH,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #4 on: October 07, 2021, 12:18:50 pm »
Doneburgers

Thanks Paolo!

Eve/Kp, are you able to shed light on the specific nature of my stupidity?
I can send the C# code I am using for de-code and re-code if that would be useful?

Cheers :-)

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #5 on: October 07, 2021, 12:57:21 pm »
Eve/Kp, are you able to shed light on the specific nature of my stupidity?

Sorry, busy. Please send in a bug report.
The Sparx Team
[email protected]

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #6 on: October 07, 2021, 12:59:42 pm »
Eve/Kp, are you able to shed light on the specific nature of my stupidity?

Sorry, busy. Please send in a bug report.
I'd give a flat no. There's no support available for anything other than a file EA has generated here, we certainly can't look at your code.

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #7 on: October 07, 2021, 01:50:51 pm »
Okie dokie :-(

Is there any info you can share on the details of the encoding?

Cheers :-)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #8 on: October 07, 2021, 06:42:32 pm »
Actually base64 is a standard where only a ascii subset is used to encode binary data. It takes 6 bits in stream and makes them bytes. So it bloats the binary (as will be done sending attachments per mail) by 8/6 (or 1 and 1/3rd). There seem to be flavors how to encode the EOL which might be some option in you C# code (look up the library documentation). Other than that you can manually create output with Notepad++ by using Plugins/MIME Tools. You can try out the changes in EA and see if it works. Then you can compare to what you code has generated.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #9 on: October 08, 2021, 02:49:54 am »
I'm guessing the hardest part to get right is zipping the contents.
There are many algorithms to zip files, and I can imagine you have to get it exactly the same as EA when encoding stuff.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #10 on: October 08, 2021, 03:13:09 am »
I just noticed that I needed Encode with Padding in Notepad++. Without EA complained about wrong XML format.

q.

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #11 on: October 08, 2021, 06:51:03 am »
Hey Q
What precisely do you mean by padding?
Sorry for my ignorance, I've never used Base64 before this and the decoding process what infinitely easier than the encoding seems to be.
If only there was some documentation somewhere.

Cheers

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Encoding ShapeScripts, Icons and Images into Base64
« Reply #12 on: October 08, 2021, 09:17:53 am »
With padding the string is filled (IIRC with "=") so the last nibble will contain all remaining bits of a byte (or just so I guessed). The gory details you can find in Wikipedia (which seems to confirm my assumption; look for Padding).

q.