revZip - Create new Archive questions

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
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

revZip - Create new Archive questions

Post by palanolho » Sun Aug 04, 2013 5:10 pm

Greetings everyone,

I'm trying to create an archive and place some files on it.
I have created a button to ask for the archive name (to create a new archive) and them I add some file with data to the archive.
My script is not working and no file is created.

Anyone can explain me what am I doing wrong?

Code: Select all

on mouseUp
     ask file "Please name your file:"
     put (it & ".b2p") into projectPath
     answer projectPath
     revZipOpenArchive projectPath, "write"
     revZipAddUncompressedItemWithData projectPath, "config.xml", "<?xml version='1.0'?>" \
           && "<settings></settings>"
     
     revZipCloseArchive projectPath
end mouseUp

Many thanks
- Miguel Pinto

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: revZip - Create new Archive questions

Post by Simon » Sun Aug 04, 2013 9:37 pm

Hi Miguel,
I "think" I'm going to apologize for LC.
Try this:

Code: Select all

on mouseUp
     ask file "Please name your file:"
     put (it & ".b2p") into projectPath
     answer projectPath
     revZipOpenArchive projectPath, "write"
     put "<?xml version='1.0'?>" && "<settings></settings>" into tFileContent
     revZipAddUncompressedItemWithData projectPath, "config.xml", "tFileContent"
     revZipCloseArchive projectPath
end mouseUp
When does one ever put a variable in quotes???
UGH!

Well that should work for you anyways.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Contact:

Re: revZip - Create new Archive questions

Post by dave_probertGA6e24 » Mon Aug 05, 2013 6:35 am

Wow!!!

If that is the way it works then we really should get the dev teams to fix it - 'cos that definitely is not a good syntax or even obvious from the Dictionary.

Looking at the Dictionary entry example shows that Miguel's code should have worked.
But looking at the description says that it's just a Variable. I guess whoever wrote that was having an off day.

Good catch Simon.

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: revZip - Create new Archive questions

Post by Simon » Mon Aug 05, 2013 7:50 am

I really don't want to read this post again...
I think I'll have a beer.

From the film Apocalypse Now (1979)
"The horror... The horror" :(

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: revZip - Create new Archive questions

Post by dave.kilroy » Mon Aug 05, 2013 9:23 am

Yes putting variables in quotes IS weird
Simon wrote:When does one ever put a variable in quotes???
UGH!
But not unheard of:

Code: Select all

revExecuteSQL tDatabaseID,tSQL,"tArray"
"...this is not the code you are looking for..."

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7395
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: revZip - Create new Archive questions

Post by jacque » Mon Aug 05, 2013 6:22 pm

Variables in quotes only happen when dealing with externals. Due to their implementation, and for reasons I don't quite understand, the quotes are necessary in order to send the variable content to the external code. This is all likely to change when the new syntax parser is finished.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: revZip - Create new Archive questions

Post by palanolho » Thu Aug 08, 2013 8:37 pm

I just need one more hint on this matter ...

I have this script

Code: Select all

on mouseUp
     ask "Name your Project"
     put it into vProjectName
     
     ask file "Please name your file:" with filter "my zip file, *.zip"
     if it = empty then
          exit to top
     end if
  
     if not (it ends with ".zip") then put ".zip" after it
     put it into vProjectPath
     
    startProject vProjectName, vProjectPath
     
end mouseUp

on startProject tName, tPath
     revZipOpenArchive tPath, "write"
     
     put "<?xml version='1.0'?>" & return \
           & "<project>" & return \
           & tab & "<settings>" & return \
           & tab & tab & "<projectname>" & tName & "</projectname>" & return \
           & tab & "</settings>" & return \
           & "</project>" & return \
           into tFileContent  
     
     revZipAddUncompressedItemWithData tPath, "config.xml", "tFileContent"
     revZipCloseArchive tPath
     
end startProject
when I execute the code, I choose a name, I choose new name for the file and the scrip creates a new ZIP file with the XML inside and everything is OK

If I execute the script again but this time I give a new name for the project but select the previous created zip, the system ask me if I want to replace the existing file, but at the end, the original file is intact the nothing was changed.

Why is this happening? how can I reply an existing file when creating an archive with a name that already exist?

many thanks

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: revZip - Create new Archive questions

Post by Simon » Thu Aug 08, 2013 9:47 pm

Hi Miguel,
Not sure why the OS isn't deleting the file but here is a workaround:

Code: Select all

 ...
if not (it ends with ".zip") then put ".zip" after it
     put it into vProjectPath
     if there is a file vProjectPath then delete file vProjectPath --delete the file specifically
...
Canceling out of the "Save As" exits to top.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: revZip - Create new Archive questions

Post by palanolho » Thu Aug 08, 2013 9:54 pm

thanks :) it works.

but its weird that its not automatically replacing the file. It should, I presume...

many thanks
- Miguel

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7395
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: revZip - Create new Archive questions

Post by jacque » Fri Aug 09, 2013 6:10 pm

The ask and answer file commands link to the OS and return a file path. The OS itself is what interrupts and asks if you want to replace an existing file. If you say yes, it returns that file path. If you say no, it returns you to the dialog so that you can choose another path. In either case, the file itself is not accessed in any way. The dialog just gives your script a path to use.

In your script, whether or not the OS asks if you want to replace a file, you don't use that file path anyway. You use a new path created with the name parameter. So the orignal file isn't changed or overwritten because you aren't altering it.

There is no need to delete the original unless you want to. The other way to manage it would be to use the original path and alter that file instead of creating a new one.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply