Suggestion.. with source..

Started by Exploration Gaming , September 01, 2010, 12:09:42 AM

Previous topic - Next topic

Exploration Gaming

It's one thing to wine about bugs.. But I'd like to make a suggestion and contribute some source.. Could you make the app associate all .ffp files with Firefly automatically.. (or ask if you want to do so during the install..)

Below is the source, if you don't have this snippet already..

cheers!


DECLARE FUNCTION RegCloseKey LIB "ADVAPI32.DLL" ALIAS "RegCloseKey" (BYVAL hKey AS DWORD) AS LONG
DECLARE FUNCTION REGCREATEKEYEX LIB "ADVAPI32.DLL" ALIAS "RegCreateKeyExA" (BYVAL hKey AS DWORD, lpSubKey AS ASCIIZ, BYVAL Reserved AS LONG, lpClass AS ASCIIZ, BYVAL dwOptions AS DWORD, BYVAL samDesired AS DWORD, _
                 lpSecurityAttributes AS SECURITY_ATTRIBUTES, phkResult AS DWORD, lpdwDisposition AS DWORD) AS LONG
DECLARE FUNCTION RegOpenKeyEx LIB "ADVAPI32.DLL" ALIAS "RegOpenKeyExA" (BYVAL hKey AS DWORD, lpSubKey AS ASCIIZ, BYVAL ulOptions AS DWORD, BYVAL samDesired AS DWORD, phkResult AS DWORD) AS LONG
DECLARE FUNCTION RegSetValueEx LIB "ADVAPI32.DLL" ALIAS "RegSetValueExA" (BYVAL hKey AS DWORD, lpValueName AS ASCIIZ, BYVAL dwReserved AS DWORD, BYVAL dwType AS DWORD, lpData AS ANY, BYVAL cbData AS DWORD) AS LONG
DECLARE FUNCTION RegDeleteValue LIB "ADVAPI32.DLL" ALIAS "RegDeleteValueA" (BYVAL hKey AS DWORD, lpValueName AS ASCIIZ) AS LONG
                                                                     
'This module will create a file associtation to any .EXE from a simple .CSV string.
'The .CSV must include.
' 1. The File Extention (TXT, MOTION)
'   2. The Title of the application   
' 3. The FULL Path to the Icon to associate with these files
'   4. A FULL Path to the application
'   5. A description of the file association
'
' Example : (Used for eMotions Render Engine)
'
' MOTION, eMotions Animation File, Myicon.ICO, D:\Program Files\eMotions\eMotionsv2.EXE, OpenGL Animation File Extension.
'

'------------------------------------------------------------------------------------------------------------------------

'------------------------------------------------------------------------------------------------------------------------
FUNCTION CreateAssociation(BYVAL RegistKey$, BYVAL AddRemove&) AS LONG   
LOCAL UseExt$, UseIcon$, UseTitle$, UseFullName$, UseComment$
LOCAL result&, Ret&, hKey&, sValue$
    LOCAL szKeyName   AS ASCIIZ * %MAX_PATH   
   
    ON ERROR RESUME NEXT
    IF PARSECOUNT(RegistKey$) = 5 THEN   
       UseExt$      = "." + TRIM$(LCASE$(PARSE$(RegistKey$, 1)), ANY CHR$(32,46))
       UseTitle$    = PARSE$(RegistKey$, 2)
       UseIcon$    = PARSE$(RegistKey$, 3)
       UseFullName$ = CHR$(34) + LCASE$(PARSE$(RegistKey$, 4)) + CHR$(34)
                      IF UseFullName$ = CHR$(34,34) THEN UseFullName$ = ""
       UseComment$  = PARSE$(RegistKey$, 5)
                                                                           
       szKeyName = UseExt$
       Ret& = RegCreateKeyEx(%HKEY_CLASSES_ROOT, szKeyName, BYVAL 0, "", %REG_OPTION_NON_VOLATILE, %KEY_ALL_ACCESS, BYVAL 0, hKey&, result&)
       CALL RegCloseKey(hKey&)
       IF Ret& = 0 THEN                   
       
          Ret& = RegOpenKeyEx(%HKEY_CLASSES_ROOT, (UseExt$), 0, %KEY_ALL_ACCESS, hKey&)
          IF Ret& = 0 THEN
             sValue$ = UseTitle$ & CHR$(0)
             Ret& = REGSETVALUEEX (hKey&, "", BYVAL 0&, %REG_SZ, BYVAL STRPTR(sValue$), LEN(sValue$)) 
             CALL REGCLOSEKEY(hKey&)
             

             IF Ret& = 0 THEN               
                szKeyName = UseTitle$ + "\shell\open\command"
                Ret& = REGCREATEKEYEX(%HKEY_CLASSES_ROOT, szKeyName, BYVAL 0, "", %REG_OPTION_NON_VOLATILE, %KEY_ALL_ACCESS, BYVAL 0, hKey&, result&)
                CALL REGCLOSEKEY(hKey&)
                IF Ret& = 0 THEN                 
             Ret& = REGOPENKEYEX(%HKEY_CLASSES_ROOT, (UseTitle$), 0, %KEY_ALL_ACCESS, hKey&) 
             IF Ret& = 0 THEN
             sValue$ = UseIcon$ & CHR$(0)
             Ret& = REGSETVALUEEX (hKey&, "DefaultIcon", BYVAL 0&, %REG_SZ, BYVAL STRPTR(sValue$), LEN(sValue$))               
             CALL REGCLOSEKEY(hKey&)         
             
                   Ret& = REGOPENKEYEX(%HKEY_CLASSES_ROOT, (UseTitle$), BYVAL 0, %KEY_ALL_ACCESS, hKey&)
                   IF Ret& = 0 THEN
                      sValue$ = UseComment$ & CHR$(0)
                      Ret& = REGSETVALUEEX (hKey&, "Comment", BYVAL 0, %REG_SZ, BYVAL STRPTR(sValue$), LEN(sValue$))
                      CALL REGCLOSEKEY(hKey&)
                      IF Ret& = 0 THEN             
                     
                         Ret& = REGOPENKEYEX(%HKEY_CLASSES_ROOT, UseTitle$ + "\shell\open\command", BYVAL 0, %KEY_ALL_ACCESS, hKey&)
                         IF Ret& = 0 THEN
                            IF AddRemove& = %REG_SZ THEN       ' Create Association
                               IF LEN(UseFullName$) THEN
                                  sValue$ = UseFullName$ & " %1" & CHR$(0)
                                  Ret& = REGSETVALUEEX (hKey&, "", BYVAL 0, %REG_SZ, BYVAL STRPTR(sValue$), LEN(sValue$))
                               END IF
                            ELSEIF AddRemove& = %REG_NONE THEN ' Remove Assocation
                               Ret& = REGDELETEVALUE(hKey&, "")
                            END IF
                            CALL REGCLOSEKEY(hKey&)
                         END IF
                      END IF
                END IF
                   END IF   
                END IF
             
             END IF
          END IF
       END IF
    ELSE
       Ret& = 999999
    END IF
    FUNCTION = Ret&
END FUNCTION

FUNCTION RegistAddExt(BYVAL RegistKey$) AS LONG
    FUNCTION = CreateAssociation(RegistKey$, %REG_SZ)
END FUNCTION

FUNCTION RegistRemExt(BYVAL RegistKey$) AS LONG
    FUNCTION = CreateAssociation(RegistKey$, %REG_NONE)
END FUNCTION



Explorations RPG System
"RPG Makers come & Go, But Explorations is Forever!"
http://www.explore-rpg.com

Paul Squires

Thanks for the code. Yes, I do have similar code that I used to use in JellyFish Pro that created the associations.

I have flipped back and forth on whether to add this type of code to FF3. Actually, the idea of adding it to the installer as an option appeals to me more because the associations could then be automatically removed by the installer when the uninstall program is run. I remember in JPro that users would forget to use the builtin functionality to remove the associations prior to uninstalling and then the associations would just stay in the Registry until the user was brave enough to try manually deleting them using RegEdit.
Paul Squires
PlanetSquires Software