home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PhotoFinish 4.0 (French)
/
Photofinish-v4-FrenchVersion-Win31.iso
/
instfont.rul
< prev
next >
Wrap
Text File
|
1996-11-26
|
8KB
|
255 lines
/*---------------------------------------------------------------------------*\
*
* Function: InstallFonts
*
* Purpose: This is a general purpose font installing function
*
* Input: Path to the fonts on source
*
* Returns:
*
* Comments: The calling function should surround this call with
* VarSave and VarRestore. If you don't want fonts to be
* uninstallable, diable logging befopre call.
* Also the source directory should contain
* a text file containing a list of the fonts, one per line, in fonts.txt.
\*---------------------------------------------------------------------------*/
function InstallFonts( szSource )
STRING szTarget, svDlgTitle, svDlgMsg, svAddStr, szSourceFile, szFileCaption;
STRING szTargetFile, szResult, szHeaderFile;
LIST listTopics, listDetails, listFonts;
NUMBER nFilePercent, nTotalPercent, nFileFound, nEndOfList;
begin
//uses gdi32 and user32 function calls, so we must be in 32-bitland.
if( ISVersion = 16 ) then
_ErrMsg( "CantInstFont", FALSE );
return;
endif;
//Set up Dialog to ask
DlgStrFromProfile( "FontDlgTitle", svDlgTitle );
DlgStrFromProfile( "FontDlgMessage", svDlgMsg );
listTopics = ListCreate( STRINGLIST );
listDetails = ListCreate( STRINGLIST );
DlgStrFromProfile( "FontDlgTopic", svAddStr );
ListAddString( listTopics, svAddStr, AFTER );
DlgStrFromProfile( "FontDlgDetail", svAddStr );
ListAddString( listDetails, svAddStr, AFTER );
ListAddString( listTopics, "", AFTER );
ListAddString( listDetails, "", AFTER );
ListAddString( listTopics, "", AFTER );
ListAddString( listDetails, "", AFTER );
Disable( BACKBUTTON );
if( SdDisplayTopics( svDlgTitle, svDlgMsg, listTopics, listDetails, 0 ) = NEXT ) then
//See where the fonts go.
if !( GetFontDir( szTarget ) ) then
return;
endif;
//Make list of fonts from txt file.
listFonts = ListCreate( STRINGLIST );
szSourceFile = szSource ^ "fonts.txt";
ListReadFromFile( listFonts, szSourceFile );
nFilePercent = ListCount( listFonts );
nFilePercent = 100 / nFilePercent;
nTotalPercent = 0;
//Enable progress bar
PlaceWindow( STATUS, CENTERED, CENTERED, CENTERED );
Enable( STATUS );
Enable( INDVFILESTATUS );
DlgStrFromProfile( "InstallingFonts", szFileCaption );
//SetStatusForFirstFile
SetStatusWindow( nTotalPercent, szFileCaption );
nTotalPercent = nFilePercent;
StatusUpdate( ON, nTotalPercent );
//SetDirectories
TARGETDIR = szTarget;
SRCDIR = szSource;
//Start Copying
nEndOfList = ListGetFirstString( listFonts, szSourceFile );
while( nEndOfList = 0 );
//See if its already there
SafeFontCopyInstall( szTarget, szSourceFile );
nEndOfList = ListGetNextString( listFonts, szSourceFile );
nTotalPercent = nTotalPercent + nFilePercent;
StatusUpdate( ON, nTotalPercent );
endwhile;
Disable( INDVFILESTATUS );
Disable( STATUS );
endif;
Enable( BACKBUTTON );
end;
/*---------------------------------------------------------------------------*\
*
* Function: GetFontDir
*
* Purpose: This Function determines the correct Font directory
*
* Input:
*
* Returns: Path in string passedin BYREF
*
* Comments:
\*---------------------------------------------------------------------------*/
function GetFontDir( szTarget )
NUMBER nSize, nCheck, nType;
begin
if( bExplorer ) then
//Check to see if were using a shared Windows OS
RegDBSetDefaultRoot( HKEY_LOCAL_MACHINE );
//if return is < 0 no name existed so we're not shared
//Otherwise szTarget contains path to server or local Windows directory
nType = REGDB_STRING;
if( RegDBGetKeyValueEx( "Software\\Microsoft\\Windows\\CurrentVersion\\Setup", "SharedDir", nType, szTarget, nSize ) = 0 ) then
if( nSize >= 1 ) then //make sure we got something.
szTarget = szTarget ^ "Fonts";
//Make sure we can write there
nCheck = Is( DIR_WRITEABLE , szTarget );
// If access rights inadequate, display a message and return FALSE.
if ( nCheck != TRUE ) then
_ErrFmtMsg( "ERR_SYSDIR", szTarget, FALSE );
return FALSE;
endif;
else
szTarget = WINDIR ^ "Fonts";
endif;
else
szTarget = WINDIR ^ "Fonts";
endif;
else
//we're on Win32s or WinNT3.51, no Fonts dir.
szTarget = WINSYSDIR;
endif;
return TRUE;
end;
/*---------------------------------------------------------------------------*\
*
* Function: SafeFontCopyInstall
*
* Purpose: This function looks for anexeisting font of the same name,
* Querys whether to replace it if found, copies it, and
* Enables it in the system.
*
* Input: Source file and Target path. SRCDIR and TARGETDIR already set.
*
* Returns:
*
* Comments: Calls FindFont, and EnableFont
*
\*---------------------------------------------------------------------------*/
function SafeFontCopyInstall( szTarget, szSourceFile )
BOOL nInstall;
STRING szDllName, svTypeFaceName;
NUMBER nTypeFaceSize;
LIST listFontNames;
begin
//GetFile name and typeface name out of string;
listFontNames = ListCreate( STRINGLIST );
StrGetTokens( listFontNames, szSourceFile, "|" );
ListGetFirstString( listFontNames, szSourceFile );
ListGetNextString( listFontNames, svTypeFaceName );
ListDestroy( listFontNames );
nInstall = FindFont( szTarget, szSourceFile, svTypeFaceName );
if( nInstall != DONT_REPLACE_FONT ) then
//Copy 'er on over
XCopyFile( szSourceFile, "*.*", EXCLUDE_SUBDIR | LOCKEDFILE );
EnableFont( szSourceFile, szTarget, svTypeFaceName );
endif;
end;
/*---------------------------------------------------------------------------*\
*
* Function: FindFont
*
* Purpose: This Function determines if a font is installed,
* and Queries whether to replace it.
*
* Input: Target Path and FontName
*
* Returns: True if we're going to install it, false if user chooses not to.
*
* Comments:
\*---------------------------------------------------------------------------*/
function FindFont( szTarget, szSourceFile, svTypeFaceName )
STRING szResult, szTargetFile;
NUMBER nFileFound;
begin
nFileFound = FindFile( szTarget, szSourceFile, szResult );
//if nFile Found not = 0 its not there so we can install it.
if( nFileFound != 0 ) then
return INSTALL_NEW_FONT;
elseif ( _AskYesNoFmt( "OldFont", svTypeFaceName ) = YES ) then
//Make sure we can get rid of it.
szTargetFile = szTarget ^ szSourceFile;
SetFileInfo( szTargetFile, FILE_ATTRIBUTE, FILE_ATTR_NORMAL, szResult );
return INSTALL_OVER_FONT;
else
return DONT_REPLACE_FONT;
endif;
end;
/*---------------------------------------------------------------------------*\
*
* Function: EnableFont
*
* Purpose: Loads font into font table, and registers it with windows
*
* Input: Source file and Target path and typefacename
*
* Returns:
*
* Comments: Platform independent, works with WinNT,Win95 and 32s
\*---------------------------------------------------------------------------*/
function EnableFont( szSourceFile, szTarget, szTypeFaceName )
STRING szHeaderFile, szWinIni, szKey;
begin
//Create resource file if we're in 32s
if(( nPlatform != IS_WINDOWSNT ) && ( nPlatform != IS_WINDOWS95 )) then
ParsePath( szHeaderFile, szSourceFile, FILENAME_ONLY );
szHeaderFile = szHeaderFile + ".FOT";
CreateScalableFontResource( 0, WINSYSDIR ^ szHeaderFile, szSourceFile, WINSYSDIR );
szSourceFile = szHeaderFile;
endif;
//add the font to the table, and let everyone know.
AddFontResource( szSourceFile );
SendMessage( HWND_BROADCAST, WM_FONTCHANGE, 0, 0 );
//do proper registration
//if we're in 32s add font to the WIN.INI
if(( nPlatform != IS_WINDOWSNT ) && ( nPlatform != IS_WINDOWS95 )) then
szWinIni = WINDIR ^ "win.ini";
WriteProfString( szWinIni, "fonts", szTypeFaceName, szSourceFile );
else //put it in the registry
RegDBSetDefaultRoot( HKEY_LOCAL_MACHINE );
if( nPlatform = IS_WINDOWSNT ) then
szKey = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts";
else
szKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Fonts";
endif;
RegDBSetKeyValueEx( szKey, szTypeFaceName, REGDB_STRING, szSourceFile, -1 );
endif;
end;