How to modify a Win *.pif ? 
Author Message
 How to modify a Win *.pif ?

Hi everybody,

I'm try to modify the path of a win-shortcut (MyApp.pif) after an install,
to fit the new path choosen by the user.

Does somebody knows a simple way to adjust those pathes with Clipper ?

What I want to do :
Before :
App Path : C:\Alvi\MyApp
Work Path : C:\Alvi\
Icon Name : C:\Alvi\MyIcon.ico

After :
App Path : C:\Another\Path\MyApp
Work Path : C:\Another\Path\
Icon Name : C:\Another\Path\MyIcon.ico

I tried a strtran(cPifContent, cOldPath, cNewPath) (where cPifContent is
the content of the pif file, and is written back to this file) but it
doesn't work, it seems that I mess with the structure of the file.  

Even when I preserve the lenth, I don't have a good result.
Any tips ?

TIA
--
Sebas
Alvicerto, Lda



Sun, 07 Oct 2001 03:00:00 GMT  
 How to modify a Win *.pif ?
A PIF file is a binary file, so you'll have to use the low level
file functions (FOPEN, FREAD, FWRITE). The following code has not
been tested, but it should give you a starting point:

LOCAL pif_size := FSIZE("MYAPP.PIF")
LOCAL handle := FOPEN("MYAPP.PIF",FO_READ)
LOCAL buffer, bytes_read, app_path, work_path, icon_name
IF handle <> -1
   // Start by reading the old PIF file contents.
   buffer := SPACE(pif_size)

   FCLOSE(handle)
   // Next set up the replacement text strings.
   // The trailing CHR(0)s are important.
   work_path := "C:\ANOTHER\PATH\"
   app_path  := work_path+"MyApp"+CHR(0)
   icon_name := work_path+"MyIcon.ICO"+CHR(0)
   work_path += CHR(0)
   // Put your code to replace the text strings here.

   // Finally, write the new PIF file contents.
   handle := FOPEN("MYAPP.PIF",FO_WRITE)
   IF handle <> -1
      FWRITE(handle,buffer,pif_size)
      FCLOSE(handle)
   END IF
END IF

--
David G. Holm, Managing Member
Joint Software Development L.L.C
3134 Niles Rd  Suite D
St Joseph  MI  49085
(616)556-9600 Fax: 556-9950



Sun, 07 Oct 2001 03:00:00 GMT  
 How to modify a Win *.pif ?
The structure of a .PIF file:

Header:

Position   Description                            Size (bytes)
-----------    ------------------------------------   ----------------
0x00         Reserved                                                1
0x01         Reserved                                                1
0x02         Window Title                                        30
(padded with spaces.  No null.)
0x20         Maximum mem req'd                            2
 ( integer - not used in enhanced mode )
0x22         Miniumum mem req'd                           2         "
"     "      "         "              "
0x24         Program file name                              63
 padded, no null )
0x63         Flags
2 ( integer )
0x65         Startup Directory                                 64
(padded, no null )
0xA5         Reserved                                           276
 not used in Win 3.1 up )

Note that byte 2 (the second "Reserved") is actually the Close Window
on Exit flag.  If this is set true, the value will be 0xF0 hex.  The
Max Mem and Min Mem values are only used in Win 3.1 standard mode and
earlier versions of Windows.  In Win 3.1 enhanced, and Win9x they will
always be set to 128.  Also, the last 276 byte Reserved block is
unused in versions 3.1 and later.

Body:

Position   Description                            Size (bytes)
-----------    ------------------------------------   ----------------
0x1B9       KB Desired                                             2
( integer )
0x1BB      KB Required                                           2
 integer )
0x1BD      Foreground Priority                                2
"
0x1BF      Background Priority                                2
"
0x1C1      EMS KB Limit                                         2
"
0x1C3      EMS KB Required                                  2        "
0x1C5      XMS KB Limit                                         2
"
0x1C7      XMS KB Required                                  2        "
0x1C9       Flags 1
1
0x1CA      Flags 2
1
0x1CB      Flags 3
1
0x1CC      Flags 4
1
0x1CD      Flags 5
1  ( unused - set to 0 )
0x1CE      Flags 6
1 ( unused - set to 0 )
0x1CF      Reserved                                                 2
( integer )
0x1D1       Key Scan Code                                      2
 integer )
0x1D3       Key Flags                                                2
"
0x1D5       Reserved                                               12
0x1E1       Optional Parameters                            64

Explanations of fields:

KB Desired and KB Required are the amounts of conventional memory
requested in 1024 byte increments.  Maximum value allowed is 640.

Priority levels are the multitasking priority values to be assigned to
the program.  Must be between 1 and 10,000.

EMS and XMS KB fields are same as for conventional memory, but max
value can be 16384.

Flags1  ( 0 = off, 1 = on )
  bit 0 = Allow Close When Active
  bit 1 = Background mode
  bit 2 = Exclusive
  bit 3 = Windowed  ( 1 = full screen, 0 = windowed )
  bit 4 = Shortcut Alt+Tab
  bit 5 = Shortcut Alt + Esc
  bit 6 = Reserved ( must be 0 )
  bit 7 = Shortcut Alt + Space

Flags2
  bit 0 = Shortcut Alt + Enter
  bit 1 = Shortcut Alt + PrtSc  ( print screen )
  bit 2 = Shortcut PrtSc
  bit 3 = Shortcut Ctrl + Esc
  bit 4 = Detect Idle Time
  bit 5 = Uses High Memory Area ( 0 = on, 1 = off [ it's backwards])
  bit 6 = Application Shortcut Key ( 0 = none, 1 = active )
  bit 7 = EMS Memory locked

Flags3
  bit 0 = XMS Memory locked
  bit 1 = Allow Fast Paste
  bit 2 = Lock Application Memory
  bits 3 - 7 Reserved, must be 0

Flags4 - Unused, must be 0

Flags5
  bit 0 = Emulate Text Mode  (display options)
  bit 1 = Text                                       "
  bit 2 = Low Graphics                      "
  bit 3 = High Graphics                     "
  bit 4 = Text                             ( video memory )
  bit 5 = Low Graphics                      "
  bit 6 = High Graphics                     "
  bit 7 = Retain Video Memory  ( display options )

Flags6 - Unused, must be 0

Reserved - Unused, must be 0

Key Scan Code is the shortcut key associated with the application.
Used only if bit 6 in Flags2 is set.

Key Flags is a set of bit fields that select Application shortcut
control keys:
  bit 0 = Alt + Shift
  bit 1 = Ctrl + Shift
  bit 2 = Ctrl
  bit 3 = Alt
  bits 4 - 7 reserved, must be 0

  example values:
    Alt                     0x08
    Ctrl                   0x04
    Alt+Ctrl            0x0C
    Alt+Shift           0x09
    Ctrl+Shift         0x06
    Alt+Ctrl+Shift  0x0F

Optional Parameters is a space-padded, null-terminated, fixed-length
ascii string containing any optional command line parameters required
by the program pointed to by the program file name field in the
header.



Sun, 07 Oct 2001 03:00:00 GMT  
 How to modify a Win *.pif ?

Quote:
>I tried a strtran(cPifContent, cOldPath, cNewPath) (where cPifContent is
>the content of the pif file, and is written back to this file) but it
>doesn't work, it seems that I mess with the structure of the file.  

 PIF files have a checksum byte somewhere. Go to Wotsits Format (now,
wotsits url??--The Oasis <http://www.iag.net/~philb/> may have a link
to it.) to get its structure and make some experiments.
 I don't think strtran() will do the trick though.

---
please remove the SPAMBLOCK from my address when replying by e-mail.



Mon, 08 Oct 2001 03:00:00 GMT  
 How to modify a Win *.pif ?
Hi David, Ol M.Kibe


Quote:
> A PIF file is a binary file, so you'll have to use the low level
> file functions (FOPEN, FREAD, FWRITE).

Yes I know that, and I had to use this exact logic to be able to use the
strtran :-)

<SNIP : the code for fReading the PIF file>

Quote:
>    // Put your code to replace the text strings here.

Yes, that's the point, that's the difficulty !

As M.Kibe was thinking, there is a checksum inside. Any ideas ?

Struct of a PIF file :

OFFSET              Count TYPE   Description
0000h                   1 byte   reserved
0001h                   1 byte   Checksum
0002h                  30 char   Title for the window
0020h                   1 word   Maximum memory reserved for program
0022h                   1 word   Minimum memory reserved for program
0024h                  63 char   Path and filename of the program
0063h                   1 byte   0 - Do not close window on exit
                                 other - Close window on exit
0064h                   1 byte   Default drive (0=A: ??)
0065h                  64 char   Default startup directory
00A5h                  64 char   Parameters for program
00E5h                   1 byte   Initial screen mode, 0 equals mode 3 ?
00E6h                   1 byte   Text pages to reserve for program
00E7h                   1 byte   First interrupt used by program
00E8h                   1 byte   Last interrupt used by program
00E9h                   1 byte   Rows on screen
00EAh                   1 byte   Columns on screen
00EBh                   1 byte   X position of window
00ECh                   1 byte   Y position of window
00EDh                   1 word   System memory ?? whatever
00EFh                  64 char   ?? Shared program path
012Fh                  64 char   ?? Shared program data file
016Fh                   1 word   Program flags

TIA
--
Sebas
Alvicerto, Lda



Mon, 08 Oct 2001 03:00:00 GMT  
 How to modify a Win *.pif ?

Quote:
>Hi David, Ol M.Kibe
><SNIP : the code for fReading the PIF file>

>>    // Put your code to replace the text strings here.

>Yes, that's the point, that's the difficulty !

example:
 NewPif := stuff( OldPif, 1+36, len(PrgPath), PrgPath )
 36 decimal is 26 hex; offset 0 in file is position 1 in clipper.

Quote:
>As M.Kibe was thinking, there is a checksum inside. Any ideas ?

 _Probably_ just add every byte value after checksum and divide by 256
(100h). The remainder is the checksum. Write this value to the right
place.
 But I'm just guessing. You'll have to conduct some experiments. An
hex viewer would come handy.
---
please remove the SPAMBLOCK from my address when replying by e-mail.


Tue, 09 Oct 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Shared EXE and PIF Files

2. .PIF writing

3. Create a .pif file

4. Wanted: pkg to read/write windows .lnk/.pif files

5. Brasil.pif

6. alevir.exe, brasil.pif, scrsvr.exe

7. Help, pls, with *.txt.pif file...

8. Virus readme.txt.pif

9. reader_digest_letter.txt.pif

10. Readers_Digest_Letter.txt.pif

11. Win application experience with Win+APL?

12. ST/V WIN 16 TO WIN 32 UPGRADE

 

 
Powered by phpBB® Forum Software