--- oup/rewrite/DataAccess/ConnectionManager.pas 2007/01/18 17:15:59 93 +++ oup/current/DataAccess/ConnectionManager.pas 2007/11/25 14:24:53 247 @@ -1,7 +1,7 @@ unit ConnectionManager; interface -uses TypeDefs, DataAccess, Access_OniArchive, Access_OUP_ADB; +uses TypeDefs, DataAccess, Access_OniArchive, Access_OUP_ADB, Access_OniSplitArchive; type TConnections = array of TDataAccess; @@ -17,12 +17,14 @@ type function GetConnectionCount: Integer; function GetConnection(ConnectionID: Integer): TDataAccess; function GetConnectionByIndex(Index: Integer): TDataAccess; + function GetConnectionIndex(ConnectionID: Integer): Integer; procedure RemoveConnection(ArrayIndex: Integer); protected public property Count: Integer read GetConnectionCount; property Connection[ConnectionID: Integer]: TDataAccess read GetConnection; property ConnectionByIndex[Index: Integer]: TDataAccess read GetConnectionByIndex; + property ConnectionIndexByID[ConnectionID: Integer]: Integer read GetConnectionIndex; property OnCoonnectionListChanged: TConnectionListChangedEvent read FConnectionListChanged write FConnectionListChanged; constructor Create; @@ -32,10 +34,15 @@ type function CloseConnectionByIndex(Index: Integer; var Msg: TStatusMessages): Boolean; overload; function CloseConnection(ID: Integer; var Msg: TStatusMessages): Boolean; overload; function CloseConnection(FileName: String; var Msg: TStatusMessages): Boolean; overload; + function FileOpened(FileName: String): Integer; published end; +var + ConManager: TConnectionManager; + + implementation uses SysUtils, Dialogs; @@ -50,6 +57,20 @@ begin Result := Length(FConnections); end; +function TConnectionManager.GetConnectionIndex(ConnectionID: Integer): Integer; +var + i: Integer; +begin + Result := -1; + if Count > 0 then + for i := 0 to Count - 1 do + if ConnectionByIndex[i].ConnectionID = ConnectionID then + begin + Result := i; + Break; + end; +end; + function TConnectionManager.GetConnection(ConnectionID: Integer): TDataAccess; var i: Integer; @@ -129,10 +150,12 @@ begin ext := UpperCase(ExtractFileExt(FileName)); - if ext = 'ODB' then + if ext = '.OLDB' then backend := DB_ADB - else if ext = 'DAT' then + else if ext = '.DAT' then backend := DB_ONI + else if ext = '.ONI' then + backend := DB_ONISPLIT else begin Msg := SM_UnknownExtension; @@ -146,20 +169,22 @@ begin FConnections[i] := TAccess_OniArchive.Create(FileName, FLastID + 1, CreateMsg); DB_ADB: FConnections[i] := TAccess_OUP_ADB.Create(FileName, FLastID + 1, CreateMsg); + DB_ONISPLIT: + FConnections[i] := TAccess_OniSplitArchive.Create(FileName, FLastID + 1, CreateMsg); end; if CreateMsg = SM_OK then begin FLastID := FConnections[i].ConnectionID; Result := FLastID; + Msg := SM_OK; end else begin FConnections[i].Close; - FConnections[i].Free; FConnections[i] := nil; SetLength(FConnections, Length(FConnections) - 1); - Msg := SM_UnknownError; + Msg := CreateMsg; end; end; @@ -239,4 +264,23 @@ begin end; +function TConnectionManager.FileOpened(FileName: String): Integer; +var + i: Integer; +begin + Result := -1; + if Length(FConnections) > 0 then + for i := 0 to High(FConnections) do + if FConnections[i].FileName = FileName then + begin + Result := FConnections[i].ConnectionID; + Exit; + end; +end; + + +initialization + ConManager := TConnectionManager.Create; +finalization + ConManager.Free; end.