I imported the Microsoft SourceSafe 8.0 Type Library and am having
problems determining if the file I'm trying to add already exists in the
VSS project. No satisfactory help in the Delphi TA so I thought I'd post
here to see if any VSS people may know the answer to the problem.
I get "Unspecified error" when trying to do this:
{VSSIniFile and VSSItemPath are consts}
procedure TfrmMain.VSSCheckin(AFileName, AVSSUserName,
AVSSPassword: String;
ACheckinIfDiff: Boolean;
ACheckInComment: String;
AExclusive: Boolean = True);
var
oVSSItemPath: IVSSItem;
oVSSItem: IVSSItem;
oVSSItems: IVSSItems;
oVSSDatabase: IVSSDatabase;
iFlags: Integer;
begin
if AExclusive then
iFlags := VSSCHECKOUT_EXCLUSIVE
else
iFlags := VSSCHECKOUT_SHARED;
// Create the Database object
oVSSDatabase := CreateOleObject('SourceSafe') as IVSSDatabase;
try
oVSSDatabase.Open(VSSIniFile, AVSSUserName, AVSSPassword);
oVSSItemPath := oVSSDatabase.VSSItem[VSSItemPath, False];
oVSSItems := oVSSItemPath.Items[False];
/*** Unspecified error happens on the line between these marks ***/
oVSSItem := oVSSItems.Item[AFileName];
/*** Unspecified error happens on the line between these marks ***/
if oVSSItem <> nil then
begin
// Check it out...
oVSSItem.Checkout('Checked out by SQL Generator', AFileName,
iFlags);
// If it is different, check it in...otherwise undo
// the above checkout
if (oVSSItem.IsDifferent[AFileName]) and (ACheckinIfDiff) then
begin
oVSSItem.Checkin(ACheckInComment, AFileName, iFlags);
end
else
begin
if oVSSItem.IsCheckedOut > 0 then
oVSSItem.UndoCheckout
end;
end
else
oVSSItemPath.Add(AFileName, ACheckInComment, iFlags);
oVSSDatabase.Close;
finally
oVSSDatabase := nil;
end;
end;
Any ideas as to how to check if the file already exists in the project?
I'm currently enumerating the items to check if it is there but would
like a more "elegant" way to check.
Rudi Larno - 19 Feb 2007 12:56 GMT
Hi Mr Clean,
I use the 'exception handling' to fnd out if a file does not exist and check
the ErrorCode. Sure, not as clean as you would like perhaps, but effective.
public VSSItem Get(string vssSpec, bool Delete)
{
if (!this.isOpen) throw new VssDataBaseNotOpenException();
Debug.WriteLine("Getting: " + vssSpec);
Debug.Indent();
try
{
return vssDb.get_VSSItem(vssSpec, false);
}
catch (System.Runtime.InteropServices.COMException comEx)
{
uint FileNotFound = 0x8004D68F;
if (comEx.ErrorCode == (int)FileNotFound)
{
Debug.WriteLine("=> does not exist in VSS");
Debug.Unindent();
return null;
}
else
{
Debug.WriteLine("COM Exception ERROR: " + vssSpec);
Debug.WriteLine(comEx);
Debug.Unindent();
// raise Info event
return null;
}
}
catch (Exception ex)
{
Debug.WriteLine("ERROR: " + vssSpec);
Debug.WriteLine(ex);
Debug.Unindent();
// raise Info event
return null;
}
finally
{
Debug.Unindent();
}
}
>I imported the Microsoft SourceSafe 8.0 Type Library and am having
> problems determining if the file I'm trying to add already exists in the
[quoted text clipped - 58 lines]
> I'm currently enumerating the items to check if it is there but would
> like a more "elegant" way to check.