J'essaye de réparer un .hta que quelqu'un de mon entreprise a créé il y a 3 ou 4 ans. En ce moment, si vous ouvrez un fichier que quelqu'un d'autre a déjà ouvert, vous perdrez tout travail que vous avez fait dessus et devrez le refaire manuellement. Donc je pensais juste à vérifier si le fichier est déjà ouvert et ensuite soit en le verrouillant, soit en faisant un popup disant "hé, si tu essayes de sauver tu seras déçu". Y at-il un moyen facile de vérifier si le fichier est déjà ouvert en JavaScript?Détection si un fichier est déjà ouvert en javascript/hta
Le code pour ouvrir le fichier est ...
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 + "'");
}
}
}
et le code pour LoadXMLDocument est ...
//-----------------------------------------------------------------------------
// 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);
}