Topic: gman

do you have any simple code for ading a dir to a zip keeping the file structure as i have tried to play about with it but im not getting to far here is my code so far

SuperStrict

Import maxGui.Drivers
Import gman.zipengine

Local myStyle:Int                            = WINDOW_TITLEBAR | WINDOW_STATUS | WINDOW_CLIENTCOORDS 
Local myWinSX:Int                            = 636
Local myWinSY:Int                            = 471
Local myDir:String                           = Null 
Local myFile:String                          = Null 
Local myFolder:Int                           = Null 
Local myPassword:String                      = Null 
Local myZipFile:ZipWriter                    = New ZipWriter
Local myWindow:TGadget                       = CreateWindow( "Zip Maker", 195, 16, myWinSX, myWinSY, Null, myStyle )
Local myTreeView:TGadget                     = CreateTreeView( 140, 1, 490, 465, myWindow, Null )
Local myDirChoice:TGadget                    = CreateButton( "Choose Dir", 9, 270, 121, 33, myWindow, BUTTON_OK )
Local mySetPassword:TGadget                  = CreateButton( "Choose Password", 9, 304, 121, 35, myWindow, BUTTON_OK )
Local myCreateZip:TGadget                    = CreateButton( "Create Zip", 9, 339, 121, 37, myWindow, BUTTON_OK )
Local myExit:TGadget                         = CreateButton( "Exit", 8, 378, 122, 86, myWindow, BUTTON_OK )



Repeat 
 WaitEvent()
 Select EventID()
  Case EVENT_GADGETACTION
   Select EventSource()
    Case myDirChoice
         myDir = RequestDir( "Select a Folder" )
         myFolder = ReadDir( myDir )
         SetStatusText myWindow, myDir
         Repeat 
           myFile = NextFile( myFolder )
           If myFile=".." Or myFile="." Or myFile=Null Then
              NextFile( myFolder )
           Else
              AddTreeViewNode( myFile, TreeViewRoot( myTreeView ) )  
           EndIf    
         Until myFile = Null 
    Case mySetPassword
         Local myChildWindow:TGadget         = CreateWindow:TGadget( "Password", 113, 96, 376, 121, myWindow, WINDOW_TITLEBAR | WINDOW_CHILD )
         Local myPasswordEntry:TGadget       = CreateTextField:TGadget( 32, 25, 302, 20, myChildWindow, TEXTFIELD_PASSWORD )
         Local myOk:TGadget                  = CreateButton:TGadget( "Ok", 133, 59, 104, 22, myChildWindow, BUTTON_OK )
         Local myLabel:TGadget               = CreateLabel:TGadget( "Enter Password", 32, 3, 301, 14, myChildWindow, Null ) 
         Local mySelection:Int               = Null 
         Repeat 
           WaitEvent()
            Select EventID()
             Case EVENT_GADGETACTION
              Select EventSource()
               Case myOk   
                myPassword = GadgetText( myPasswordEntry ) 
                HideGadget( myChildWindow )
                FreeGadget( myChildWindow )
                mySelection = 1
              EndSelect 
           EndSelect
         Until mySelection = 1                          
    Case myCreateZip
         myFolder = ReadDir( myDir )
         ChangeDir( myDir )
         SetStatusText myWindow, myPassword
         If ( myZipFile.OpenZip( myDir+"-data.zip", False ) ) Then
            Repeat  
             myFile = NextFile( myFolder )        
             If myFile=".." Or myFile="." Or myFile=Null Then
                NextFile( myFolder ) 
              Else 
                Delay(4000) 
                SetStatusText myWindow, myFile   
                myZipFile.AddFile( myFile, myPassword ) 
              EndIf                
            Until myFile = Null
            myZipFile.CloseZip()
            SetStatusText myWindow, "Zip File Complete!"
         End If
    Case myExit
     End 
   End Select 
 End Select 
Forever

Re: gman

greetings smile  for folders you need to have the folder included in the AddFile command.   so to create a zip of a directory structure i would call AddFile something like:

AddFile("my_sub_dir/myfile1.txt")
AddFile("my_sub_dir/myfile2.txt")

in the zip, you would have my_sub_dir at the root level and inside would be the files.  hope this helps.