Page 2 of 2

Re: 7Zip extraction code needed

Posted: Sun Feb 01, 2015 1:43 am
by Fangbeast
JHPJHP wrote:Hi Fangbeast,

I'm sorry to say that packed executables are not supported. The interface has the same functionality as the 7-zip command line tool (7za.exe): 7z and zip.
- this means that a command line interface is also not an option
Damn, that's the end of that idea then. Oh well, back to mowing the lawns:):)

Thanks for your efforts. Looks like I might have to unpack the entire archive with some other dll from shell and then check for the one I want.

Okay, lawns first, then play:) (Why does the damned grass grow so fast around here???)

Re: 7Zip extraction code needed

Posted: Sun Feb 01, 2015 5:30 am
by JHPJHP
Hi Fangbeast,

Are you creating the packed executables or are they from another source? The reason I ask is because the Interface can create a self-extracting executable using the 7z compression, allowing for script access control. I've also just figured out the use of sfx files, and their ability to control/supress dialog boxes when creating the executables.

Re: 7Zip extraction code needed

Posted: Sun Feb 01, 2015 5:55 am
by Fangbeast
JHPJHP wrote:Hi Fangbeast,

Are you creating the packed executables or are they from another source?
Another source. They are from PortableApps.com. They use the NSIS installation tool (Maybe that confuses normal routines somehow?) but 7zip archiver must have special routines for NSIS?

I'm guessing here.

Still haven't done the grass.

Re: 7Zip extraction code needed

Posted: Sun Feb 01, 2015 10:05 am
by JHPJHP
Hi Fangbeast,

While the 7-zip command line tool doesn't support Packed executables, the main executable combined with it's DLL can be run from a command prompt, extending support.

I know you stated that you'd rather not run scripts from a command line, but I thought if it was available and no other solution presented itself...
- if most of the files you're dealing with are 7z, then the interface should handle a majority of the overhead
- the latest beta version of 7-zip may prove more reliable then your previous experiences

I've updated the PureBasic Interface to SevenZip with a RunProgram Procedure that will execute the desired command if the previous call to the Interface fails.

Examples: SevenZip_Extract1.pb, SevenZip_Extract2.pb, SevenZip_List.pb, and SevenZip_Test.pb utilize the OpenFileRequester Function, making it easier to test the various archive formats.

Re: 7Zip extraction code needed

Posted: Sun Feb 01, 2015 11:25 am
by Fangbeast
I know you stated that you'd rather not run scripts from a command line, but I thought if it was available and no other solution presented itself...
It's more a case of memory resource issues that I've had in the past when I was cataloguing 38,000 files at a time using the RunProgram method and watching as the memory was leaking away.

This time I will only be working on up to 600 programs.

Thank you for doing all of this valuable work, I'm sure that it will benefit everyone. I am very grateful.

Re: 7Zip extraction code needed

Posted: Fri Feb 20, 2015 7:54 am
by Fangbeast
Thanks to JHPJHP, i've finally sorted my PortableApps archive collection into subdirectories. For the first time in 3 years:):)

When you use my code below with his SevenZip library, this will enable you to create subdirectories in the directory where your PortableApps archives reside, based on the category name contained in the appinfo.ini inside the portableapps archive being examined. All but 22 files out of the 550 I had were sorted just fine.

No directory recursion here, didn't need it. Might add a text catalogue later for all the info in the appinfo.ini file.

Code: Select all

Global CurrentPath.s = GetCurrentDirectory()
Global TempDirectory.s = CurrentPath() + "Temporary\"

Declare   SortPortableApps(SearchDir.s)
; 

Procedure SortPortableApps(Directory.s)
  DirectoryId.i = ExamineDirectory(#PB_Any, Directory.s, "*.*")
  If DirectoryId.i
    Repeat
      TypeOfFile.i = NextDirectoryEntry(DirectoryId.i) 
      FileName.s = DirectoryEntryName(DirectoryId.i)
      If TypeOfFile.i = 1
        FileName.s        = DirectoryEntryName(DirectoryId.i)
        CurrentFileName.s = Directory.s  + FileName.s
        If CurrentFileName.s
          szCmdLine.s = "e " + Chr(34) + CurrentFileName.s + Chr(34) + " -aoa -o" + TempDirectory.s + " appinfo.ini -r"
          ; Debug szCmdLine.s
          Result.s    = RunCMD(szCmdLine + " -hide")                    ; Standard ZIP
          If FindString(Result, "Can not open file as archive")         ; Do not change this message!
            Result = Run7zCMD(szCmdLine)
          EndIf
          ; Debug Result
          If FindString(Result, "Everything is Ok")                     ; Do not change this message!
            ; Debug "appinfo.ini found and extracted"
            If OpenPreferences(TempDirectory.s + "appinfo.ini")  <> 0
              PreferenceGroup("Details")  
              ; Debug ReadPreferenceString("Name",        "")
              ; Debug ReadPreferenceString("AppID",       "")
              ; Debug ReadPreferenceString("Publisher",   "")
              ; Debug ReadPreferenceString("Homepage",    "")
              ; Debug ReadPreferenceString("Category",    "")
              ; Debug ReadPreferenceString("Description", "")
              CategoryString.s  = ReadPreferenceString("Category",    "")
              ClosePreferences()
              If CategoryString.s <> ""
                CreateDirectory(Directory.s + CategoryString.s)   ; Don't need to wrap this
                If FileSize(Directory.s + CategoryString.s) = -2
                  If RenameFile(CurrentFileName.s, Directory.s + CategoryString.s + "\" + FileName.s)
                    Debug "File moved:        " + Directory.s + CategoryString.s + "\" + FileName.s
                  Else
                    Debug "File not moved:    " + FileName.s
                  EndIf
                Else
                  Debug "Directory:    " + CategoryString.s  + "   does not exist"
                EndIf
              Else
                Debug CategoryString.s  + "   not found in appinfo.ini, cannot move file"
              EndIf
            Else
              Debug "Could not open:    "   + TempDirectory.s + "appinfo.ini"
            EndIf
          Else
            Debug "Could not extract appinfo.ini from:    " + CurrentFileName.s ; If archive is corrupt, CurrentFileName.s is blank
          EndIf
        Else
          ; Debug "There is no current filename"
        EndIf
        ; 
      Else
        ; Debug "This is not a file"
      EndIf
      ; 
    Until TypeOfFile.i = 0 
    ; 
  Else
    Debug "Could not list files in the selected directory"
  EndIf
EndProcedure

PathToSearch.s    = PathRequester("directory to catalogue", "")

If PathToSearch.s <> ""
  SortPortableApps(PathToSearch.s)
Else
  Debug "Nothing to do:   " + PathToSearch.s  + " does not exist or job was aborted"
EndIf

Re: 7Zip extraction code needed

Posted: Fri Mar 20, 2015 6:35 am
by Fangbeast
Been refining the code and managed to sort over 490 PortableApps files into directories with only 10 not moving, stubbornly.

Manual extraction shows the unmoved files do contain the appinfo.ini file and do have a valid category so I don't know what is going on here.

Added extra error messages and also a few extra lines to delete the original source file if it already exists at the target.

I still know quite a few (mainly elderly) people who don't have the internet and don't want to install EVERYTHING from Portableapps.

Next I will add a proper catalogueing function as the filenames don't tell us always (Unless you know all your software personally) what they are/do.

Then I'll post the crappy code if anyone wants it.