⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reghelpbds3w.js

📁 Delphi的Office 2007风格界面控件
💻 JS
📖 第 1 页 / 共 3 页
字号:

/***************************************************************************
Help 2.0 system maintenance script
----------------------------------------------------------------------------
Takes the following parameters:

Action param:
0 = Remove registration information (not files)
1 = Restore or update registration information on installed file set
2 = Copy files from source media, register files to parent namespace (or create plugin)
3 = Remove registration information and listed files

Config file:
Specify file name relative to the script position.
For config file specs, see regHelp.htm.

Confirmation param:
(used when batching multiple config files; use 1 on last file)
0 = No confirmation message after applying config
1 = Show confirmation\Help launch message (per shortcut/launch param)

***************************************************************************/

var WSHShell = WScript.CreateObject ( 'WScript.Shell' );
var fo = new ActiveXObject('Scripting.FileSystemObject');
var scriptPath = fo.GetParentFolderName ( WScript.ScriptFullName ).toLowerCase() + '\\';

var args = WScript.Arguments;
if ( args.Length != 4 || args(0) > 3 )
    {
    // abort
    WSHShell.Popup ( 'ERROR: Parameters are incorrect. Please see documentation (regHelp.htm).', 0, WScript.ScriptName, 16 ) ;
    WScript.Echo ( 'ERROR: Parameters are incorrect. Please see documentation (regHelp.htm).' );
    WSHShell = '' ; WScript.Quit() ;
    }
var a = trimit(args(0));

//string vars
var mbTitle = 'Help registration utility'; //msg box title
var parentNamespace = 'borland.bds3';
//error messages
var err_closehelp = '\nPlease close your Document Explorer, then press \'OK\'\nto continue Help maintenance operations.';
var err_closehelp1 = 'The Document Explorer (dexplore.exe) must be closed\nin order to register a new Help collection.\nClose the viewer now?';
var err_closehelp2 = '\nTry again when all instances of the Document Explorer are closed.';

var c = trimit(args(1));
if ( c == '' || c == null )
    {
    WSHShell.Popup ( "Configuration file name required.", 0, mbTitle, 16 );
    WScript.Echo ( 'ERROR: Configuration file name required.' );
    WSHShell = null; WScript.Quit();
    }
var cfgFile = checkConfig(c);

//get Borland product installation path
var bdsRoot = '';
try
    {
    bdsRoot = WSHShell.RegRead('HKLM\\SOFTWARE\\Borland\\BDS\\3.0\\RootDir');
    }
catch (err_bdsroot)
    { }

if ( bdsRoot == '' || bdsRoot == 'bdsdocs' )
    {
    bdsRoot = 'C:\\Program Files\\Borland\\BDS\\3.0\\';
    WScript.Echo ( 'Could not locate BDS RootDir key. Installing to default folder: ' + bdsRoot );
    }

//collect .NET SDK registry settings and file locations
try
    {
    var sdkRoot = WSHShell.RegRead('HKLM\\Software\\Microsoft\\.NETFramework\\sdkInstallRootv1.1');
    }
catch (err_sdk11)
    {
    try
        {
        sdkRoot = WSHShell.RegRead('HKLM\\Software\\Microsoft\\.NETFramework\\sdkInstallRoot');
        }
    catch (err_sdk)
        {
        WSHShell.Popup ( 'Microsoft .NET FrameworkSDK not found.', 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: Microsoft .NET FrameworkSDK not found.' );
        WSHShell = null; WScript.Quit();
        }
    }

try
    {
    var dxLocation = WSHShell.RegRead('HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\dexplore.exe\\Path');
    }
catch (err_dxloc)
    {
    WSHShell.Popup ( 'Microsoft Documentation Explorer application not found.', 0, mbTitle, 16 );
    WScript.Echo ( 'ERROR: Microsoft Documentation Explorer application not found.' );
    WSHShell = null; WScript.Quit();
    }

var fin = rMain ( cfgFile );

WScript.Echo ( 'Help system maintenance complete for ' + args(1) );

var fMsg='', qFin=0, mbType=36;

WSHShell = null; WScript.Quit();


/**********************************************
organize and apply config data
*/
function rMain(f)
{
    //vars
    var retMain='';
    var cfgData, secData, keyData, valData;
    var nFiles=0, nFilters=0;
    var sCollectionData = false;
    var sFiles = false;
    var sFilters = false;
    var inamespace='', nsparent='', mergetype=''; mergetoctitle='', mergetocurl='';
    var arrFiles;
    var primaryNamespace = false;
    var langid = '';

    //collect config data
    var cfg = fo.OpenTextFile ( f, 1 );
    while ( !cfg.AtEndOfStream )
        {
        cfgData = trimit(cfg.readline());
        if ( cfgData.indexOf ( ';' ) != -1 ) { cfgData = trimit(cfgData.substr ( 0, cfgData.indexOf (';') )); }
        if ( cfgData != '' )
            {
            if ( cfgData.substr ( 0, 1 ) == '[' && cfgData.indexOf ( ']' ) != -1 )
                {
                secData = trimit ( cfgData.substr ( 1, cfgData.indexOf ( ']' ) - 1 ) ).toLowerCase();
                }
            }
        if ( secData != '' && cfgData != '' && cfgData.substr ( 0, 1 ) != '[' && cfgData.indexOf ( ']' ) == -1 )
            {
            if ( secData == 'collectiondata' )
                {
                sCollectionData = true;
                keyData = trimit(cfgData.substr ( 0, cfgData.indexOf ( '=' ))).toLowerCase();
                valData = trimit(cfgData.substr ( cfgData.indexOf ( '=' ) + 1));
                switch ( keyData )
                    {
                    case 'parent':
                        var nsparent = valData;
                        var primaryNamespace = true;
                        break;
                    case 'versioning':
                        var versioning = valData;
                        break;
                    case 'namespace':
                        var inamespace = valData;
                        break;
                    case 'description':
                        var nsdescription = valData;
                        break;
                    case 'langid':
                        var langid = valData;
                        break;
                    case 'installdest':
                        var installdest = valData;
                        break;
                    case 'installsrc':
                        var installsrc = valData;
                        break;
                    case 'mergetype':
                        var mergetype = valData.toLowerCase();
                        break;
                    case 'mergetoctitle':
                        var mergetoctitle = valData;
                        break;
                    case 'mergetocurl':
                        var mergetocurl = valData;
                        break;
                    default:
                    }
                }
            else
                {
                switch ( secData )
                    {
                    case 'files':
                        if ( nFiles == 0 ) { var arrFiles=new Array(); }
                        arrFiles[nFiles++] = trimit(cfgData);
                        break;
                    case 'filters':
                        if ( nFilters == 0 ) { var arrFilters=new Array(); }
                        arrFilters[nFilters++] = trimit(cfgData);
                        break;
                    default:
                    }
                }
            }
        }
    cfg.close();
    //END config data collection

    if ( nFiles > 0 ) { sFiles = true; }
    if ( nFilters > 0 ) { sFilters = true; }

    //halt if CollectionData or Files sections not found in configuration file
    if ( sCollectionData == false )
        {
        WSHShell.Popup ( 'ERROR: Data is incomplete in configuration file:\n' + f, 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: Data is incomplete in configuration file:\n' + f );
        WSHShell = null; WScript.Quit();
        }

    //halt if file list is empty
    if ( sFiles == false )
        {
        WSHShell.Popup ( 'ERROR: File list missing from configuration file:\n' + f, 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: File list missing from configuration file:\n' + f );
        WSHShell = null; WScript.Quit();
        }

    //set default Language ID
    if ( langid == '' ) { langid = '1033'; }

    //halt if source or dest directories not specified
    if ( ( installsrc == null || installsrc == '' ) || ( installdest == null || installdest == '' ) )
        {
        WSHShell.Popup ( 'ERROR: Installation directory not specified configuration file:\n' + f, 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: Installation directory not specified configuration file:\n' + f );
        WSHShell = null; WScript.Quit();
        }

    //use path refs (if any) in file list when copying from source?
    //check for an asterisk at end of installsrc; asterisk indicates
    //that all source files are stored in the same folder on install media,
    //and only the file names from file list are appended to installsrc path
    var useFileListPaths = true;
    if ( installsrc.substr ( installsrc.length -1, 1 ) == '*' )
        {
        useFileListPaths = false;
        installsrc = installsrc.substr ( 0, installsrc.length -1 );
        }
    installsrc = fo.GetAbsolutePathName ( installsrc ) + '\\';

    //test source folder
    if ( !fo.folderExists ( installsrc ) )
        {
        WSHShell.Popup ( 'ERROR: Help file source installation path:\n' + installdest + '\nnot found', 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: Help file source installation path:\n' + installdest + '\nnot found' );
        WSHShell = null; WScript.Quit();
        }

    //expand bds destination directory
    if ( installdest == 'bdsdocs' )
        {
        installdest = fo.GetAbsolutePathName(bdsRoot);
        }
    if ( installdest == 'bdshelp' )
        {
        installdest = fo.GetAbsolutePathName(bdsRoot)+'\\Help\\Thirdparty';
        }
    WScript.Echo ( 'Help file destination installation path:= ' + installdest );

    //expand frameworksdk destination directory
    if ( installdest == 'sdkdocs' )
        {
        installdest = fo.GetAbsolutePathName(sdkRoot);
        //if not English, add lang. folder to sdkdoc path
        //if ( langid != '' && langid != '1033' )
        //    {
        //    installdest = fo.GetAbsolutePathName(sdkRoot + '\\' + langid);
        //    }
        if ( args(0) == 3 ) { a = 0; }
        if ( args(0) == 2 ) { a = 1; }
        }

    //expand, if necessary, and test install target path; abort if not found
    if ( installdest != bdsRoot && installdest != sdkRoot && installdest.toLowerCase().substr ( 0,2 ) == 'hk' )
        {
        try
            {
            installdest = fo.GetAbsolutePathName(WSHShell.RegRead(installdest)) + '\\';
            }
        catch (err_installdest)
            {
            WSHShell.Popup ( 'ERROR: Registry key:\n' + installdest + '\nnot found', 0, mbTitle, 16 );
            WScript.Echo ( 'ERROR: Registry key:\n' + installdest + '\nnot found' );
            WSHShell = null; WScript.Quit();
            }
        }
    else
        {
        installdest = fo.GetAbsolutePathName ( installdest ) + '\\';
        }

    //for installs, folders are created on file copy; for other operations, exit if installdest not found
    if ( args(0) != 2 && !fo.folderExists ( installdest ) )
        {
        WSHShell.Popup ( 'ERROR: Help file installation path:\n' + installdest + '\nnot found', 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: Help file installation path:\n' + installdest + '\nnot found' );
        WSHShell = null; WScript.Quit();
        }

    //halt if destination directory < 2MB
    if ( args(0) != 0 && args(0) != 3 )
        {
        checkDrive ( fo.GetDrive(fo.GetDriveName(installdest)), 2000000 );
        }

    //assign default namespace to nsparent
    if ( inamespace != '' && inamespace == parentNamespace )
        { nsparent = inamespace; }

    WScript.Echo ( 'Configuration file: ' + fo.GetFileName(f) + ' [' + a + ']');

    //all but the parent namespace should have a parent specified
    var parentHXC = '', parentTOC = '';

    if ( nsparent == '' )
        {
        WSHShell.Popup ( 'ERROR: Parent namespace not specified in configuration file.', 0, mbTitle, 16 );
        WScript.Echo ( 'ERROR: Parent namespace not specified in configuration file.' );
        WSHShell = null; WScript.Quit();
        }
    else
        {
        if ( nsparent != parentNamespace && inamespace != parentNamespace )
            {
            WSHShell.Popup ( 'ERROR: Parent namespace unavailable.', 0, mbTitle, 16 );
            WScript.Echo ( 'ERROR: Parent namespace unavailable.' );
            WSHShell = null; WScript.Quit();
            }
        else
            {
            parentHXC = getNamespacePath(nsparent).toLowerCase();
            if ( parentHXC != '' )
                {
                parentTOC = parentHXC.replace ( '.hxc', '.hxt' );
                }
            }
        }

    if ( a == 3 ) { a = 0; } //param 3=file removal;
    //note: setting to 0 here allows removal of registration data prior to file removal

    //fix path references (if any) on file list items, create expanded file list
    var reSlash = new RegExp ('/','g');
    var fileList = new ActiveXObject ( 'Scripting.Dictionary' );
    var fName = '', fPath = '';
    var hxc = '', hxt = '', hxa = '';
    for ( i in arrFiles )
        {
        if ( arrFiles[i] != '' )
            {
            arrFiles[i] = arrFiles[i].replace ( reSlash, '\\' );
            while ( arrFiles[i].substr ( arrFiles[i].length ) == '\\' )
                { arrFiles[i] =  arrFiles[i].substr ( 0, arrFiles[i].length - 1 ) }
            while ( arrFiles[i].substr ( 0,1 ) == '\\' )
                { arrFiles[i] =  arrFiles[i].substr ( 1 ) }
            fName = fo.GetFileName (arrFiles[i]);
            if ( useFileListPaths == false )
                { fPath = installsrc + fName; }
            else
                { fPath = installsrc + arrFiles[i]; }
            if ( !fileList.exists ( fName.toLowerCase() ) )
                {
                fileList.Add ( fName.toLowerCase(), fPath + ',' + installdest + arrFiles[i] );
                if ( fo.GetExtensionName ( fName.toLowerCase() ) == 'hxc' )
                    { hxc = installdest + arrFiles[i]; }
                if ( fo.GetExtensionName ( fName.toLowerCase() ) == 'hxt' )
                    { hxt = installdest + arrFiles[i]; }
                if ( fo.GetExtensionName ( fName.toLowerCase() ) == 'hxa' )
                    { hxa = installdest + arrFiles[i]; }
                }
            }
        }

    //reassign arrFiles array
    var arrFiles = ( new VBArray(fileList.Keys())).toArray();
    var sep = -1;

    //file installation: if called, run before any reg ops
    var sp1='', sp2='', cleanTemp = false;
    if ( a == 2 && installdest != sdkRoot )
        {
        sp1 = '' + fo.GetParentFolderName ( scriptPath );
        sp2 = '' + fo.GetSpecialFolder(2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -