in ArchivedSamples/Source_Code_Control_Provider/C#/SccProviderService.cs [767:847]
public int QuerySaveFiles([In] uint rgfQuerySave, [In] int cFiles, [In] string[] rgpszMkDocuments, [In] uint[] rgrgf, [In] VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pdwQSResult)
{
// Initialize output variables
// It's a bit unfortunate that we have to return only one set of flags for all the files involved in the operation
// The last file will win setting this flag
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_SaveOK;
// In non-UI mode attempt to silently flip the attributes of files or check them out
// and allow the save, because the user cannot be asked what to do with the file
if (_sccProvider.InCommandLineMode())
{
rgfQuerySave = rgfQuerySave | (uint)tagVSQuerySaveFlags.QSF_SilentMode;
}
try
{
for (int iFile = 0; iFile < cFiles; iFile++)
{
SourceControlStatus status = GetFileStatus(rgpszMkDocuments[iFile]);
bool fileExists = File.Exists(rgpszMkDocuments[iFile]);
bool isFileReadOnly = false;
if (fileExists)
{
isFileReadOnly = ((File.GetAttributes(rgpszMkDocuments[iFile]) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly);
}
switch (status)
{
case SourceControlStatus.scsCheckedIn:
DlgQuerySaveCheckedInFile dlgAskCheckout = new DlgQuerySaveCheckedInFile(rgpszMkDocuments[iFile]);
if ((rgfQuerySave & (uint)tagVSQuerySaveFlags.QSF_SilentMode) != 0)
{
// When called in silent mode, attempt the checkout
// (The alternative is to deny the save, return QSR_NoSave_NoisyPromptRequired and expect for a non-silent call)
dlgAskCheckout.Answer = DlgQuerySaveCheckedInFile.qscifCheckout;
}
else
{
dlgAskCheckout.ShowDialog();
}
switch (dlgAskCheckout.Answer)
{
case DlgQueryEditCheckedInFile.qecifCheckout:
// Checkout the file, and since it cannot fail, allow the save to continue
CheckoutFileAndRefreshProjectGlyphs(rgpszMkDocuments[iFile]);
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_SaveOK;
break;
case DlgQuerySaveCheckedInFile.qscifForceSaveAs:
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_ForceSaveAs;
break;
case DlgQuerySaveCheckedInFile.qscifSkipSave:
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_NoSave_Continue;
break;
default:
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_NoSave_Cancel;
break;
}
break;
case SourceControlStatus.scsCheckedOut: // fall through
case SourceControlStatus.scsUncontrolled:
if (fileExists && isFileReadOnly)
{
// Make the file writable and allow the save
File.SetAttributes(rgpszMkDocuments[iFile], FileAttributes.Normal);
}
// Allow the save now
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_SaveOK;
break;
}
}
}
catch (Exception)
{
// If an exception was caught, do not allow the save
pdwQSResult = (uint)tagVSQuerySaveResult.QSR_NoSave_Cancel;
}
return VSConstants.S_OK;
}