All pastes #779183 Raw Edit

Stuff

public text v1 · immutable
·published 2007-11-18 08:10 UTC
rendered paste body
; -------------------------------------------
; Title:    Upx Gui
; Version:  1.0
; PB Ver:   4.00
;
; About:
; A simple GUI for UPX.
; -------------------------------------------

Enumeration ;-Enumerate gadgets
  #Path
  #Browse
  #Level
  #Compress
  #Decompress
  #About
EndEnumeration

LoadFont(0,"Arial",8,#PB_Font_Bold)

;-Open window
OpenWindow(0, 0, 0, 320, 55, "Simple Upx Gui v1.0",  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
CreateGadgetList(WindowID(0))

SetGadgetFont(TextGadget(#PB_Any,5,8,25,20,"Exe:"),FontID(0))
StringGadget(#Path, 30, 5, 190, 20, "")
ButtonGadget(#Browse, 225, 5, 60, 20, "Browse")

SetGadgetFont(TextGadget(#PB_Any,5,33,120,20,"Compression level:"),FontID(0))
ComboBoxGadget(#Level, 120, 30, 60, 200)
ButtonGadget(#Compress, 185, 30, 60, 20, "Compress")
ButtonGadget(#About, 290, 5, 20, 20, "?")
ButtonGadget(#Decompress, 250, 30, 65, 20, "Decompress")


;-Add levels
For Level=1 To 9
  AddGadgetItem(#Level,-1,"Level "+Str(Level))
Next
AddGadgetItem(#Level,-1,"Best")
AddGadgetItem(#Level,-1,"Insane")
SetGadgetState(#Level,9)

Repeat
  WindowEvent = WaitWindowEvent()
  Select WindowEvent
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #About
          MessageRequester("About","Simple Upx Gui" ,#MB_ICONINFORMATION)
         Case #Browse ;-Browse
          SetGadgetText(#Path,OpenFileRequester("Select executable:","","Executable (*.exe)|*.exe",0))
         Case #Decompress
          If RunProgram("upx.exe", "-d " + GetGadgetText(#Path), "")
         Case #Compress ;-Compress
          If GetGadgetText(#Path) > "" And FileSize(GetGadgetText(#Path)) > 0
            Select GetGadgetState(#Level)
              Case 0 To 8
                Parameter$ = "-"+Str(GetGadgetState(#Level)+1)+" "
              Case 9
                Parameter$ = "--best "
              Case 10
                Parameter$ = "--brute "
            EndSelect
            OldSize = FileSize(GetGadgetText(#Path))
            If RunProgram("upx.exe",Parameter$+Chr(34)+GetGadgetText(#Path)+Chr(34),"",#PB_Program_Wait)
              If Oldsize = FileSize(GetGadgetText(#Path))
                MessageRequester("Warning","File was not compressed, maybe it's allready compressed?",#MB_ICONWARNING)
              Else
                MessageRequester("Done","Old size: "+Str(OldSize)+#CRLF$+"New size: "+Str(FileSize(GetGadgetText(#Path))),#MB_ICONINFORMATION)
              EndIf
            Else
              MessageRequester("Warning","Can't open UPX, the UPX executable must be in the same directory as UPX GUI!",#MB_ICONWARNING)
            EndIf
          Else
            MessageRequester("Error","No file selected!",#MB_ICONWARNING)
          EndIf
      EndSelect
  EndSelect
Until WindowEvent = #PB_Event_CloseWindow