会社の誰かが 3 ~ 4 年前に作成した .hta を修正しようとしています。現在、他の誰かが既に開いているファイルを開くと、そのファイルに対して行った作業がすべて失われ、手動でやり直す必要があります。そのため、ファイルが既に開いているかどうかを確認してから、編集をロックするか、「保存しようとするとがっかりするだろう」というポップアップを作成することを考えていました。ファイルが既に JavaScript で開かれているかどうかを確認する簡単な方法はありますか?
ファイルを開くコードは...
function FileOpen( strSetup )
{
if( ! strSetup )
{
strSetup = ShowDialog( "choose-setup", {"DialogTitle" : "Load Setup"} );
}
if( strSetup )
{
if( FileSystem.FileExists( App.Paths.Configs + "/" + strSetup + ".setup" ) )
{
var fFile = FileSystem.GetFile( App.Paths.Configs + "/" + strSetup + ".setup" );
App.Config = LoadXMLDocument( fFile.Path );
// SaveCurrentConfig();
RefreshView( "setup-summary" );
}
else
{
alert( "Could not find setup '" + strSetup + "'" );
}
}
}
LoadXMLDocument のコードは...
//-----------------------------------------------------------------------------
// FUNCTION : LoadXMLDocument - Loads an XML document
// params : strPath - the path/file of the document to load
// : bCritical- if set true, we die if the document doesn't load
// returns : an XML dom object on success, false otherwise
//-----------------------------------------------------------------------------
function LoadXMLDocument( strPath, bCritical )
{
var xmlDoc = new ActiveXObject( "Msxml2.DOMDocument.3.0" );
xmlDoc.setProperty( "SelectionLanguage", "XPath" );
if( ! FileSystem.FileExists( strPath ) )
{
Error( "'" + strPath + "' is not a valid file path" );
if( bCritical ) Abort();
return( false );
}
var fFile = FileSystem.GetFile( strPath );
xmlDoc.load( fFile.Path );
if( xmlDoc.documentElement == null )
{
Error( "Could not load XML document '" + fFile.Path + "'" );
if( bCritical ) Abort();
return( false );
}
return( xmlDoc );
}