Harbour Minigui

HexView ( Bicahi Esgici )

  • Archivo: HexView.Prg 

/*

  MINIGUI - Harbour Win32 GUI library Demo/Sample
 
  Copyright 2002-06 Roberto Lopez
  http://www.geocities.com/harbour_minigui/
 
  HexView is Freevare Hex Viewer for any file.
 
  Without changing and modifying any vay,
  using and distributing is totally free.

  All bug reports and suggestions are welcome.
   
  Developed under Harbour Compiler and
  MINIGUI - Harbour Win32 GUI library (HMG).
 
  Thanks to "Le Roy" Roberto Lopez.
 
  Copyright 2006 Bicahi Esgici
 
  History :
 
     6.2006 : v.1.6 : For useability with Windows's "Open with ..." feature, initial file
                      specification parameter added to the main modul.
     2.2006 : Introduced
*/

#include <minigui.ch>

#define CRLF2 CRLF + CRLF
#define NTrim( n ) LTrim( TRAN( n,"999,999,999,999,999,999" ) )
#translate ISNIL(  <xVal> )   => ( <xVal> == NIL )

PROC Main( cOpFName )

   PUBL cBegFoldr := GetCurrentFolder(),;
      cTempFNam := '',;
        nFilSize  := 0,;
        aBrwHeds  := {},;    // Column Headers
        aBrwLens  := {},;    // Column Lengths ( in pixel )
        aBrwFlds  := {},;    // Field List
        aBrwROCs  := {},;    // Read-Only Columns 
    aTabStru  := {}      // Table Structure
   
 SET BROWSESYNC ON 
 SET DATE GERM
 SET CENT ON
 
 MakBrwArs()
 
   DEFINE WINDOW frmHVMain  ;
      AT     0,0 ;
      WIDTH  GetDesktopWidth() * 0.9 ;
      HEIGHT GetDesktopHeight() * 0.9 ;
      TITLE  "HMG Hex Viewer" ;
      MAIN ;
      ON INIT OpenFile( cOpFName ) ;
      ON RELEASE ClosFile()
     
      ON KEY ESCAPE ACTION frmHVMain.Release 

      DEFINE MAIN MENU
         POPUP "&File"
            ITEM "&Open"    NAME mitOpen ACTION OpenFile()
            ITEM "&Close"   NAME mitClos ACTION ClosFile()
            SEPARATOR
            ITEM "E&xit"     ACTION frmHVMain.Release
         END POPUP
         POPUP "&Help"
            ITEM "&About"    ACTION SayAbout()
         END POPUP  
      END MENU

  @ 0,0 BROWSE HexVwBrw ;
      WIDTH  frmHVMain.WIDTH - 10 ;
    HEIGHT frmHVMain.HEIGHT - 100 ; 
    HEADERS aBrwHeds  ;
    FONT "FixedSys" SIZE 12 ;
    WIDTHS aBrwLens ;
    READONLY aBrwROCs ;
    WORKAREA TEMP ;
    FIELDS aBrwFlds ;    
    ON CHANGE frmHVMain.StatusBar.Item(2) := PADC(NTrim(CTON(TEMP->PT,16))+"/"+NTrim(nFilSize),18)
     
  @ 450,200 PROGRESSBAR pbrPBar1 ;
    RANGE 0 , 100   ;
    WIDTH 300    ;
    HEIGHT 16    

      DEFINE STATUSBAR FONT 'Verdana' SIZE 8 // OF winMuavMain 
        
         STATUSITEM ""
         STATUSITEM "" WIDTH 100
         DATE          WIDTH 80
         CLOCK         WIDTH 83
        
      END STATUSBAR
     
   END WINDOW
  
   frmHVMain.mitClos.Enabled := .F.
  
   frmHVMain.HexVwBrw.Hide
   frmHVMain.pbrPBar1.Hide
   CENTER   WINDOW frmHVMain
   ACTIVATE WINDOW frmHVMain
       

RETU // HexEdMain()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

PROC ClosFile()
   CLOS DATA
   ERAS (cTempFNam)
   frmHVMain.mitClos.Enabled := .F.
   frmHVMain.HexVwBrw.Hide 
   frmHVMain.StatusBar.Item(1) := ''
   frmHVMain.StatusBar.Item(2) := ''
RETU // ClosFile()
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

FUNC AFileSiz(;                         // Size of any given file
               cFFName )  // Full File Name

   LOCA aFInf := DIRECTORY( cFFName )
  
   LOCA nRVal := aFInf[ 1, 2 ]
        
RETU nRVal // AFileSiz()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

PROC SayAbout()
   MsgInfo( PADC("Harbour MiniGUI Hex Viewer v.1.6",41)  + CRLF2 + ;
            PADC("FREEWARE", 41)                         + CRLF2 + ;
    PADC(' Thanks to "Le Roy" Roberto Lopez :', 41) + CRLF2 + ; 
    "http://www.geocities.com/harbour_minigui" )
RETU // SayAbout()     

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

FUNC TmpFName( ;                               // Make a temp file name in given folder
                 cFolder,;                     // and build it in 0 length
                 cExtns )  

   LOCA aTFiles := {},;
        cFSpec  := '',;
        cTFName := DTOC(DATE()) + TIME(),;
        cRVal   := '',;
        nHandle :=  0
  
   IF cExtns == NIL    
      cExtns := "tmp"
   ENDIF  
  
   cFSpec := cFolder + IF(RIGHT(cFolder,1) # "\", "\", "") + "*." + cExtns
  
   aTFiles := DIRECTORY(cFSpec) 
  
 cTFName := RIGHT(STRTRAN(STRTRAN(STRTRAN(STRTRAN( cTFName, "/", ""),"-",""),".",""),":",""),8)

 cRVal := cFolder + IF(RIGHT(cFolder,1) # "\", "\", "") + cTFName + "." + cExtns
 
 WHILE FILE( cRVal )
    cTFName := STR(VAL(cTFName)+1,8)
  cMsg += cTFName
    cRVal := cFolder + IF(RIGHT(cFolder,1) # "\", "\", "") + cTFName + "." + cExtns
 ENDDO
 
 nHandle := FCREATE( cRVal )
 
 FCLOSE( nHandle )
 
  
RETU cRVal // TmpFName()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._


PROC MakTable()

   LOCA cTempFold := GetTempFolder()
       
   cTempFNam := TmpFName( cTempFold )
                    
   DBCREATE( cTempFNam, aTabStru )
                
   USE (cTempFNam) ALIAS TEMP
  
  
RETU // MakTable()  
  
*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

PROC OpenFile( cFName )

   LOCA cOpFName := IF( ISNIL( cFName ),;
                        GetFile ( {{ "All Files", "*.*" }} ,;   // File Select Filter
                               "Open File" ,;             // Get File Window Title
                               cBegFoldr ,;         // File Find Beginning folder
                               .F. ,;                     // Multiple Select
                                 .T. ),;                    // Change Folder right
                         cFName )
                                 
   LOCA cFileStr := '',;
        nFPntr   :=  0,;
        c1Line   :=  '',;
        nFldNum  :=  0
                               
   IF !EMPTY( cOpFName )
     
      nFilSize := AFileSiz( cOpFName )
      cFileStr := MEMOREAD( cOpFName )
     
      IF nFilSize - LEN( cFileStr ) > 1
         MsgExclamation( "Size Error ! " + CRLF + ;
                         NTrim(nFilSize)+"/"+NTrim(LEN( cFileStr )), "Error" )
      ELSE
       cBegFoldr := cOpFName
       ClosFile()
       frmHVMain.StatusBar.Item(1) := IF( LEN( cOpFName ) > 70,;
                                          LEFT( cOpFName, 7 ) + '...' + RIGHT( cOpFName, 60 ),;
                                          cOpFName )
       frmHVMain.StatusBar.Item(2) := PADC("0/"+NTrim(nFilSize),18)
         MakTable()
   frmHVMain.pbrPBar1.Show
   
   FOR nFPntr := 1 TO nFilSize STEP 16
      IF (nFPntr + 16 ) < nFilSize
           c1Line :=  SUBS( cFileStr, nFPntr, 16 )
      ELSE
         c1Line :=  SUBS( cFileStr, nFPntr )
      ENDIF
      DBAPPEND()
      REPL  PT  WITH PADL(NTOC( nFPntr-1,16 ),8,'0'),;
      ASCII WITH c1Line
          FOR nFldNum  := 2 TO LEN( c1Line ) + 1
     FIELDPUT( nFldNum, PADL(NTOC( ASC( SUBS( c1Line, nFldNum-1, 1 ) ), 16 ),2,"0") )
    NEXT nFldNum
    frmHVMain.pbrPBar1.Value := nFPntr * 100 / nFilSize
   NEXT nFPntr
   
   frmHVMain.pbrPBar1.Hide
     frmHVMain.mitClos.Enabled := .T.
   
         DBGOTOP()
  
     frmHVMain.HexVwBrw.Refresh
     frmHVMain.HexVwBrw.Show

      ENDIF nFilSize # LEN( cFileStr )
   ENDIF !EMPTY( cOpFName )
    
RETU // OpenFile()

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._

PROC MakBrwArs()

   LOCA nColNum := 0,;
        cFldNam := ''
  
   AADD( aTabStru, { "PT", "C",  8, 0 } )  // Hex Pointer
   AADD( aBrwHeds, '' )         
   AADD( aBrwLens, 80 )        
   AADD( aBrwFlds, 'PT' )        
   AADD( aBrwROCs, .T. )        
  
   FOR nColNum := 2 TO 17
      cFldNam := 'X' + PADL(NTOC(nColNum-2,16),1,'0')
  AADD(aTabStru, { cFldNam, 'C', 8, 0 } )   // Table Structure
      AADD(aBrwHeds, '' )         // Column Headers
  AADD(aBrwLens, 29 )        // Column Lengths ( in pixel )
  AADD(aBrwFlds, cFldNam )        // Field List
  AADD(aBrwROCs, .F. )        // Read-Only Columns 
   NEXT nColNum
  
   AADD( aTabStru, { "ASCII",  "C",  16, 0 } ) // ASCII String
   AADD( aBrwHeds, '' )             
   AADD( aBrwLens, 145 )         
   AADD( aBrwFlds, 'ASCII' )         
   AADD( aBrwROCs, .F. )         
  
RETU // MakBrwArs()  

*-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._