Transferring an Array from desktop to mobile

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Transferring an Array from desktop to mobile

Post by glenn9 » Wed Feb 03, 2021 4:34 pm

Dear All,

I've created on desktop a basic two card 'dictionary' type of app with a scrolling list of of 'terms' on Card A which when clicked leads to an information field corresponding to that term on Card B.

On the desktop the two cards are populated from an array which successfully saves and loads using the encode and decode commands to specialfolderpath ("documents").

I now would like to run the app on mobile (android) and although the app transfers to mobile nicely, the Array data is missing and here lies my problem as I'm not understanding how to transfer the 'array' that is saved on the desktop to the mobile device.

So far I thought I might save the array as a custom property within the app using the code from the BYU Array example

Code: Select all

on closeStack
  set the dictionaryArray of this stack to gDictArray
end closeStack

but I'm not sure how to save the 'gDictArray' to the mobile specialfolderpath("documents") so that it can then be loaded up by the mobile app.

Hope this makes sense!

Grateful for any advice.

Many thanks,

Glenn

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Transferring an Array from desktop to mobile

Post by Thierry » Wed Feb 03, 2021 5:04 pm

Hi Glenn,


From the dicionary:

Description
Use the arrayDecode function to rebuild an array from an encoded string produced by the arrayEncode function.

Encoding and decoding arrays is designed to allow arrays to be written to a file on disk, or sent across a network. See the arrayEncode reference for more information on doing this.
HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Transferring an Array from desktop to mobile

Post by glenn9 » Wed Feb 03, 2021 5:21 pm

Thanks Thierry, I'll study this as it seems as though this will give me the answer. Regards, Glenn

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Transferring an Array from desktop to mobile

Post by mrcoollion » Thu Feb 04, 2021 8:32 am

Here are my routines (code snippets) for saving and reading encrypted Array's.
Hope they are of some help.

Regards,

Paul

Code: Select all

------------------------------------------------------------------------------------------------------------------------------------------
// General Read and Write Encrypted File routines
------------------------------------------------------------------------------------------------------------------------------------------
command ReadFile tInPathAndFile InPassword @OutArrayData
   put "binfile:"&tInPathAndFile into tBinPathFile
   put URL tBinPathFile into tB64EncrArray
   // Now Decrypt
   DeCryptData tB64EncrArray, INPassword ,OutDecryptedEncodedArray
   ----
   put arrayDecode(OutDecryptedEncodedArray) into OutArrayData
end ReadFile
--
Function ReadFile tInPathAndFile InPassword
   put "binfile:"&tInPathAndFile into tBinPathFile
   put URL tBinPathFile into tB64EncrArray
   // Now Decrypt
   DeCryptData tB64EncrArray, INPassword ,OutDecryptedEncodedArray
   ----
   return arrayDecode(OutDecryptedEncodedArray)
end ReadFile
--
// Save data to file
command SaveFile tInPathAndFile InArrayData InPassword
   put arrayEncode(InArrayData) into InEncArray
   // Now Encrypt
   EnCryptData InEncArray, InPassword, OutB64EncrData
   ----
   delete file tInPathAndFile
   put "binfile:"&tInPathAndFile into tBinPathFile
   put OutB64EncrData into URL tBinPathFile
end SaveFile

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Encrypt and Decrypt Data to and from encrypted and base64 coded data (base64 coded data can be sent over the internet and put in databases without problems)
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Command DeCryptData InB64EncrData, INPassword @OutDecryptedData
   put base64Decode(InB64EncrData) into tEncrData
   decrypt tEncrData using "aes-256-cbc" with password INPassword
   put it into OutDecryptedData
end DeCryptData
--
Command EnCryptData InData, InPassword @OutB64EncrData
   encrypt InData using "aes-256-cbc" with password InPassword
   put base64Encode(It) into OutB64EncrData
end EnCryptData
--------------------------------------------------------------------------------------------------------------------------------------------------------------


elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Re: Transferring an Array from desktop to mobile

Post by elanorb » Thu Feb 04, 2021 10:18 am

Hi Glenn

If the array data is read in from file you will probably want to include the initial version of the files in the Copy Files pane of the Standalone Application Settings. This will include the files in the standalone. You can then reference them using specialFolderPath("resources").

You can't write to specialFolderPath("resources") so you could copy them to specialFolderPath("documents") on the first run of the app and then load/save them from there.

Kind regards

Elanor
Elanor Buchanan
Software Developer
LiveCode

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Transferring an Array from desktop to mobile

Post by glenn9 » Mon Feb 08, 2021 2:09 pm

I'm still tying myself up in knots trying to transfer the Array of my 'dictionary' app from desktop to mobile...

I've been trying to do this by saving the Array as a custom property using ArrayEncode and then trying to save it to the specialfoldpath("documents") on mobile so I can use the array in the mobile app.

However, not having much success!

Elanor's suggestion of including the Array file in the Copy Files pane of the Standalone Application Settings sounds a whole lot easier but I'm not sure i understand how to reference it using using specialFolderPath("resources") so I can then start using it within the app?

I was wondering whether anyone could show me some code snippets illustrating how to reference the included Standalone file using Elanor's suggestion?

Many thanks,

Kind regards,

Glenn

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Transferring an Array from desktop to mobile

Post by Klaus » Mon Feb 08, 2021 2:18 pm

Hi Glenn,
glenn9 wrote:
Mon Feb 08, 2021 2:09 pm
...
Elanor's suggestion of including the Array file in the Copy Files pane of the Standalone Application Settings sounds a whole lot easier but I'm not sure i understand how to reference it using using specialFolderPath("resources") so I can then start using it within the app?
...
really no rocket science! :-)

Code: Select all

...
put specialfolderpath("resources") & "/your_encoded_array.bin" into tBinFile
put url(tBinFile) into tEncodedArrayData
## Dou your thing with tEncodedArrayData...
...
Best

Klaus

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Transferring an Array from desktop to mobile

Post by glenn9 » Mon Feb 08, 2021 2:36 pm

Thanks Klaus, I'll give that a go...

Regards,

Glenn

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Transferring an Array from desktop to mobile

Post by Klaus » Mon Feb 08, 2021 2:41 pm

Sorry, forgot BINFILE:

Code: Select all

...
put specialfolderpath("resources") & "/your_encoded_array.bin" into tBinFile
put url("binfile:" & tBinFile) into tEncodedArrayData
## Dou your thing with tEncodedArrayData...
...

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: Transferring an Array from desktop to mobile

Post by glenn9 » Mon Feb 08, 2021 4:11 pm

Hi Klaus,

this has worked perfectly, thank you so much again for your help.

5 lines of code has sorted it all out...I'm embarrassed to disclose exactly how many hours I've spent over the last few days trying to solve this... I think almost as many hours as lines of code.... how do you say in Germany... Lehrgeld?

Kind regards,

Glenn

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Transferring an Array from desktop to mobile

Post by Klaus » Mon Feb 08, 2021 4:13 pm

Hi Glenn,

glad I could help, and yes, it is called "Lehrgeld" in german. :-)


Best

Klaus

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: Transferring an Array from desktop to mobile

Post by liveme » Tue Mar 02, 2021 3:38 am

AES 256 "generating" a distinct new string after each click ?
Hi guys,
I'm trying to figure out if AES 256 standard behaviour is to generate a new string after each click...eventhough all the parameters, InData, PW, etc...do not change ? (I'm not an expert in Cryptography :oops: )

From the Sample script above I've build this one script :

Code: Select all

on mouseUp pButtonNumber
   put "" into fld "Resu"
   put "IsWhateverString" into InData
   put "1234567890123456" into InPassword
   encrypt InData using "aes-256-cbc" with password InPassword
   put base64Encode(It) into OutB64EncrData
   put  OutB64EncrData into fld "Resu"
end mouseUp
after 3 clicks, I get :
U2FsdGVkX1/4095rcdk1F+pT4FpL+jkSPMIMZoG8sQbjUMitFQO29jkLV+QVPiTs
U2FsdGVkX1+OpzogjZFN66k/amYJJ4lsf8XAACu2lMvz3E/5rvYM0G0QLBU9NFxb
U2FsdGVkX1+pZJPEFc5FPfFfgYCKul6iWEsqoC4VXMN5SpC50I4tofH6Q4AD2BYZ

Isnt it weird to get dif. results ? or I made some error along the Script ?
:roll: :roll:

*I had open this other Topic where, when using the AES 128 (128 !)...it always returns only one single answer.
viewtopic.php?f=7&t=35463&p=202428&hili ... 56#p202428


Thanks for your expertise....

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: Transferring an Array from desktop to mobile

Post by liveme » Tue Mar 02, 2021 6:41 am

Okie..I could solve my pervious Topic after checking needed param config with this online tool : Great ! :wink: 8) 8)
see : www devglan com online-tools aes-encryption-decryption
:idea:
5 stars checking tool !

Post Reply