public virtual int Save(string fileToBeSaved, int remember, uint formatIndex)
{
// The file name can be null. Then try to use the Url.
string tempFileToBeSaved = fileToBeSaved;
if (String.IsNullOrEmpty(tempFileToBeSaved) && !String.IsNullOrEmpty(this.Url))
{
tempFileToBeSaved = this.Url;
}
if (String.IsNullOrEmpty(tempFileToBeSaved))
{
throw new ArgumentException(SR.GetString(SR.InvalidParameter, CultureInfo.CurrentUICulture), "fileToBeSaved");
}
bool setProjectFileDirtyAfterSave = false;
if (remember == 0)
{
setProjectFileDirtyAfterSave = this.IsProjectFileDirty;
}
// Update the project with the latest flavor data (if needed)
PersistXMLFragments();
int result = VSConstants.S_OK;
bool saveAs = true;
if (NativeMethods.IsSamePath(tempFileToBeSaved, this.filename))
{
saveAs = false;
}
if (!saveAs)
{
SuspendFileChanges fileChanges = new SuspendFileChanges(this.Site, this.filename);
fileChanges.Suspend();
try
{
// Ensure the directory exist
string saveFolder = Path.GetDirectoryName(tempFileToBeSaved);
if (!Directory.Exists(saveFolder))
Directory.CreateDirectory(saveFolder);
// Save the project
this.buildProject.Save(tempFileToBeSaved);
this.SetProjectFileDirty(false);
}
finally
{
fileChanges.Resume();
}
}
else
{
result = this.SaveAs(tempFileToBeSaved);
if (result != VSConstants.OLE_E_PROMPTSAVECANCELLED)
{
ErrorHandler.ThrowOnFailure(result);
}
}
if (setProjectFileDirtyAfterSave)
{
this.SetProjectFileDirty(true);
}
return result;
}